HoleFillerPlugin.cc 20.9 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
 
Jan Möbius committed
39
40
41
42
*                                                                            *
\*===========================================================================*/

#include "HoleFillerPlugin.hh"
Jan Möbius's avatar
Jan Möbius committed
43
#include "holefillerToolbar.hh"
Jan Möbius's avatar
 
Jan Möbius committed
44
45
46
47

#include <MeshTools/MeshSelectionT.hh>
#include "HoleInfoT.hh"

48
49
#include <QProgressDialog>

Jan Möbius's avatar
 
Jan Möbius committed
50
51
52
53
54
55
56
57
58
59
60
61
#define HOLEINFO "HoleInfoData"

/// Constructor
HoleFillerPlugin::HoleFillerPlugin() :
       tool_(0)
{

}

/// Initialize the toolbox widget
void HoleFillerPlugin::initializePlugin()
{
Jan Möbius's avatar
Jan Möbius committed
62
  if ( OpenFlipper::Options::gui()) {
Jan Möbius's avatar
 
Jan Möbius committed
63
64
65
66
67
68
69
70
71
72
73
74
75
76
   tool_ = new HoleFillerToolbarWidget();
   QSize size(300, 300);
   tool_->resize(size);

   connect(tool_->tableWidget,SIGNAL(itemSelectionChanged()),this,SLOT(slotItemSelectionChanged()));
   
   connect(tool_->tableWidget,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(slotCellDoubleClicked(int,int)));

   connect(tool_->detect,SIGNAL(clicked()),this,SLOT(detectButton()));
   connect(tool_->fillButton, SIGNAL(clicked()), this, SLOT(slotFillSelection()) );

   QIcon* toolIcon = new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"holefilling.png");

   emit addToolbox( tr("Hole Filler") , tool_ , toolIcon);
Jan Möbius's avatar
Jan Möbius committed
77
  }
Jan Möbius's avatar
 
Jan Möbius committed
78
79
80
81
82
} 

/// add PickModes after initialization
void HoleFillerPlugin::pluginsInitialized()
{
Jan Möbius's avatar
Jan Möbius committed
83
  if ( OpenFlipper::Options::gui()) {
Jan Möbius's avatar
 
Jan Möbius committed
84
85
86
   emit addPickMode("Separator");
   emit addPickMode("Hole Filler");

Jan Möbius's avatar
Jan Möbius committed
87
88
89
90
   //build the tableWidget with headers
   update_menu();
  }

Jan Möbius's avatar
 
Jan Möbius committed
91
92
93
94
95
96
97
98
   emit setSlotDescription("fillAllHoles(int)", tr("Fill all holes from a given Mesh"),
                           QString("objectId").split(","), QString("Id of the mesh").split(","));

   emit setSlotDescription("fillHole(int,int)", tr("Fill a holes from a given Mesh where edgeHandle is on the boundary"),
                           QString("objectId,edgeHandle").split(","), QString("Id of the mesh,Handle of one boundary edge of the hole").split(","));

}

Matthias Möller's avatar
Matthias Möller committed
99
100
101
void HoleFillerPlugin::getSelectedHoles(std::vector<int>& _holeIds, std::vector<int>& _objIds)
{
  QModelIndexList indices = tool_->tableWidget->selectionModel()->selectedRows();
Jan Möbius's avatar
 
Jan Möbius committed
102

Matthias Möller's avatar
Matthias Möller committed
103
104
105
106
  //get a map from objectID to (selected) holeIDs
  for (int i=0; i < indices.size(); i++){
    int objID  = holeMapping_[ indices[i].row() ].first;
    int holeID = holeMapping_[ indices[i].row() ].second;
Jan Möbius's avatar
 
Jan Möbius committed
107

Matthias Möller's avatar
Matthias Möller committed
108
109
110
111
    _holeIds.push_back  ( holeID );
    _objIds.push_back( objID );
  }
}
Jan Möbius's avatar
 
Jan Möbius committed
112

Matthias Möller's avatar
Matthias Möller committed
113
114
/// Fill all selected holes
void HoleFillerPlugin::slotFillSelection(){
Jan Möbius's avatar
 
Jan Möbius committed
115
116
117
118

  //get a map from objectID to (selected) holeIDs
  std::vector< int > holes;
  std::vector< int > objects;
Matthias Möller's avatar
Matthias Möller committed
119
  getSelectedHoles(holes,objects);
Jan Möbius's avatar
 
Jan Möbius committed
120
121
122
123
124
125
126
127
128

  //init progressDialog
  QProgressDialog progress(tr("Filling holes..."), tr("Abort"), 0, holes.size(), 0);
  progress.setWindowModality(Qt::ApplicationModal);
  progress.setValue(0);

  int counter = 0;

  //iterate over all objects with holes that should be filled
129
  for (auto* o_it : PluginFunctions::objects(PluginFunctions::ALL_OBJECTS) ) {
Jan Möbius's avatar
 
Jan Möbius committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

    // TYPE is TRIMESH
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {

      TriMesh* mesh = PluginFunctions::triMesh(o_it);

      //get perObjectData
      HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( o_it->objectData(HOLEINFO) );
    
      if (holeInfo == 0){
        holeInfo = new HoleInfo< TriMesh >( mesh );
        o_it->setObjectData(HOLEINFO, holeInfo);
      }

      //fill the holes
      for (uint i = 0; i < objects.size(); i++)
        if ( objects[i] == o_it->id() ){
          holeInfo->fillHole( holes[i]);

          if (progress.wasCanceled())
            break;
          else
            progress.setValue(++counter);
        }

      //update the object
156
      emit updatedObject(o_it->id(),UPDATE_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
    
      holeInfo->getHoles();
    
      update_menu();
      emit createBackup( o_it->id(), "Hole Filling", UPDATE_GEOMETRY | UPDATE_TOPOLOGY | UPDATE_SELECTION);
    }
    // DATATYPE is  POLYMESH
    else if ( o_it->dataType( DATA_POLY_MESH ) ) {
      emit log(LOGWARN, tr("HoleFilling unsupported for poly meshes") );
      continue;
    }
    
    //abort if user wants to
    if (progress.wasCanceled())
      break;
  }

  progress.close();

  emit updateView();
}

/// slot for displaying selected holes
void HoleFillerPlugin::slotItemSelectionChanged() {

  std::vector< int > holes;
  std::vector< int > objects;
Matthias Möller's avatar
Matthias Möller committed
184
  getSelectedHoles(holes,objects);
Jan Möbius's avatar
 
Jan Möbius committed
185
186

  //iterate over all objects with holes that should be displayed
187
  for (auto* o_it : PluginFunctions::objects(PluginFunctions::ALL_OBJECTS) ) {
Jan Möbius's avatar
 
Jan Möbius committed
188
189
190
191

    // TYPE is TRIMESH
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {

192
      TriMeshObject* object = PluginFunctions::triMeshObject(o_it);
Jan Möbius's avatar
 
Jan Möbius committed
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
      TriMesh* mesh = PluginFunctions::triMesh(o_it);

      //get perObjectData
      HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( o_it->objectData(HOLEINFO) );
    
      if (holeInfo == 0){
        holeInfo = new HoleInfo< TriMesh >( mesh );
        o_it->setObjectData(HOLEINFO, holeInfo);
      }

      //clear the edge selection
      MeshSelection::clearEdgeSelection(mesh);

      //select the holes
      for (uint i = 0; i < objects.size(); i++)
        if ( objects[i] == o_it->id() )
          holeInfo->selectHole( holes[i] );

Jan Möbius's avatar
Jan Möbius committed
211
      // We only fly if we have exacly one object and one hole
212
      if (  (objects.size() == 1) && (holes.size() == 1) && ( objects[0] == o_it->id() ) ){
Jan Möbius's avatar
Jan Möbius committed
213
214
215

        TriMesh::Point center;
        TriMesh::Normal normal;
Jan Möbius's avatar
Jan Möbius committed
216
        holeInfo->getHolePostitionInfo(holes[0], normal, center);
Jan Möbius's avatar
Jan Möbius committed
217
218
219
220
221
222
223
224
225
226

        // Get bounding box to get a scaling for the movement
        TriMesh::Point _bbMin;
        TriMesh::Point _bbMax;

        object->boundingBox(_bbMin, _bbMax);

        PluginFunctions::flyTo(center + normal * (_bbMax-_bbMin).length() , center, 10.0);
      }

Jan Möbius's avatar
 
Jan Möbius committed
227
      //update the object
228
      emit updatedObject(o_it->id(),UPDATE_SELECTION);
Jan Möbius's avatar
 
Jan Möbius committed
229
230
231
232
    }
    // DATATYPE is  POLYMESH
    else if ( o_it->dataType( DATA_POLY_MESH ) ) {

233
      PolyMeshObject* object = PluginFunctions::polyMeshObject(o_it);
Jan Möbius's avatar
 
Jan Möbius committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
      PolyMesh* mesh = PluginFunctions::polyMesh(o_it);

      //get perObjectData
      HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( o_it->objectData(HOLEINFO) );
    
      if (holeInfo == 0){
        holeInfo = new HoleInfo< PolyMesh >( mesh );
        o_it->setObjectData(HOLEINFO, holeInfo);
      }

      //clear the edge selection
      MeshSelection::clearEdgeSelection(mesh);

      //select the holes
      for (uint i = 0; i < objects.size(); i++)
        if ( objects[i] == o_it->id() )
          holeInfo->selectHole( holes[i] );

252
253
254
255
256
      // We only fly if we have exacly one object and one hole
      if (  (objects.size() == 1) && (holes.size() == 1) && ( objects[0] == o_it->id() ) ){

        PolyMesh::Point center;
        PolyMesh::Normal normal;
Jan Möbius's avatar
Jan Möbius committed
257
        holeInfo->getHolePostitionInfo(holes[0], normal, center);
258
259
260
261
262
263
264
265
266
267

        // Get bounding box to get a scaling for the movement
        PolyMesh::Point _bbMin;
        PolyMesh::Point _bbMax;

        object->boundingBox(_bbMin, _bbMax);

        PluginFunctions::flyTo(center + normal * (_bbMax-_bbMin).length() , center, 10.0);
      }

Jan Möbius's avatar
 
Jan Möbius committed
268
      //update the object
269
      emit updatedObject(o_it->id(),UPDATE_SELECTION);
Jan Möbius's avatar
 
Jan Möbius committed
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321

    }
  }

  emit updateView();
}

/// Slot for filling holes from double-clicked rows
void HoleFillerPlugin::slotCellDoubleClicked(int _row , int /*_col*/) {

  if ( _row > (int)holeMapping_.size() ) {
    emit log(LOGWARN, tr("Error for holeMapping_ vector size") );
    return;
  }

  BaseObjectData* object;
  int objID  = holeMapping_[_row].first;
  int holeID = holeMapping_[_row].second;

  if ( !PluginFunctions::getObject( objID, object ) ) {
    emit log(LOGWARN, tr("Unable to find object for hole (should not happen!!)") );
    return;
  }

  // TYPE is TRIMESH
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh* mesh = PluginFunctions::triMesh(object);

    //get perObjectData
    HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( object->objectData(HOLEINFO) );
  
    if (holeInfo == 0){
      holeInfo = new HoleInfo< TriMesh >( mesh );
      object->setObjectData(HOLEINFO, holeInfo);
    }

    //fill the hole
    holeInfo->fillHole( holeID );

    emit updatedObject(object->id(),UPDATE_ALL);

    holeInfo->getHoles();

    update_menu();

    emit updateView();
  }
  // DATATYPE is  POLYMESH
  else if ( object->dataType( DATA_POLY_MESH ) ) {
    
    emit log(LOGWARN,tr("HoleFilling unsupported for poly meshes"));
322

Jan Möbius's avatar
 
Jan Möbius committed
323
324
325
326
327
328
329
    return;
  }
}

/// detect holes on all objects
void HoleFillerPlugin::detectButton( )
{
330
  for (auto* o_it : PluginFunctions::objects(PluginFunctions::ALL_OBJECTS) ) {
Jan Möbius's avatar
 
Jan Möbius committed
331
332
333
334
335
336
337

    //case TRIMESH
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {

      HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( o_it->objectData(HOLEINFO) );
    
      if ( holeInfo == 0 ){
338
        TriMesh* mesh = PluginFunctions::triMesh(o_it);
Jan Möbius's avatar
 
Jan Möbius committed
339
340
341
342
343
344
345
        holeInfo = new HoleInfo< TriMesh >( mesh );
        o_it->setObjectData(HOLEINFO, holeInfo);
      }

      holeInfo->getHoles();
    }

346
347
348
349
350
351
     //case POLYMESH
     if ( o_it->dataType( DATA_POLY_MESH ) ) {

       HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( o_it->objectData(HOLEINFO) );

       if (holeInfo == 0){
352
         PolyMesh* mesh = PluginFunctions::polyMesh(o_it);
353
354
355
356
357
358
         holeInfo = new HoleInfo< PolyMesh >( mesh );
         o_it->setObjectData(HOLEINFO, holeInfo);
       }

       holeInfo->getHoles();
     }
Jan Möbius's avatar
 
Jan Möbius committed
359
360
361
362
363
364
  }

  update_menu();
}

/// check for holes if an object has changed
365
void HoleFillerPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type ) {
Jan Möbius's avatar
 
Jan Möbius committed
366
367
368
369
370
371
372
373
374

  BaseObjectData* object;

  // Check if this is a usable Object
  if ( !PluginFunctions::getObject(_identifier,object) ) 
    return;

  bool updated = false;
  
Jan Möbius's avatar
Jan Möbius committed
375
  if ( _type.contains(UPDATE_TOPOLOGY) ) {
Jan Möbius's avatar
 
Jan Möbius committed
376

Jan Möbius's avatar
Jan Möbius committed
377
378
379
380
381
382
383
384
385
    // get holes for TRIMESH
    if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

      HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( object->objectData(HOLEINFO) );

      if ( holeInfo ) {
        holeInfo->getHoles();
        updated = true;
      }
Jan Möbius's avatar
 
Jan Möbius committed
386
387
    }

Jan Möbius's avatar
Jan Möbius committed
388
389
    // get holes for POLYMESH
    else if ( object->dataType( DATA_POLY_MESH ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
390

Jan Möbius's avatar
Jan Möbius committed
391
392
393
394
395
396
      HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( object->objectData(HOLEINFO) );

      if ( holeInfo ) {
        holeInfo->getHoles();
        updated = true;
      }
Jan Möbius's avatar
 
Jan Möbius committed
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    }
  }

  // Only update if something has changed!
  if ( updated )
    update_menu();
}

///update the entries in the tableWidget
void HoleFillerPlugin::update_menu() {

  holeMapping_.clear();

  tool_->tableWidget->clear();

  tool_->tableWidget->setRowCount ( 0 );
  tool_->tableWidget->setColumnCount ( 4 );

  QStringList headerdata;
  headerdata << "Object" << "Edges" << "Boundary Length" << "BB Diagonal";

  tool_->tableWidget->setHorizontalHeaderLabels(headerdata);
  tool_->updateGeometry();
  
  int elements = 0;
  int count = 0;

  //iterate over all objects
425
  for (auto* o_it : PluginFunctions::objects(PluginFunctions::ALL_OBJECTS) ) {
Jan Möbius's avatar
 
Jan Möbius committed
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

    // DATATYPE is  TRIMESH
    if ( o_it->dataType( DATA_TRIANGLE_MESH ) ) {

      //get perObjectData  
      HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( o_it->objectData(HOLEINFO) );

      if (holeInfo != 0){
        elements += holeInfo->holes()->size();
        tool_->tableWidget->setRowCount ( elements );

        //add holes to the table
        for (uint i = 0 ; i < holeInfo->holes()->size() ; ++i ) {
          // Set Name of the object
          QTableWidgetItem* name = new QTableWidgetItem( o_it->name() );
Jan Möbius's avatar
Jan Möbius committed
441
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
442
          name->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
443
444
445
#else
          name->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
446
447
          name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,0,name);
Jan Möbius's avatar
Jan Möbius committed
448
449
450

          size_t egde_count = 0;
          TriMesh::Scalar bbDiagonal = 0.0;
451
          double boundaryLength = 0.0;
Jan Möbius's avatar
Jan Möbius committed
452

453
          holeInfo->getHoleInfo(i, egde_count, bbDiagonal, boundaryLength);
Jan Möbius's avatar
Jan Möbius committed
454

Jan Möbius's avatar
 
Jan Möbius committed
455
          // Set Number of the edges
Jan Möbius's avatar
Jan Möbius committed
456
          QTableWidgetItem* size = new QTableWidgetItem( QString::number( egde_count ) );
Jan Möbius's avatar
Jan Möbius committed
457
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
458
          size->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
459
460
461
#else
          size->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
462
463
464
465
466
          size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,1,size);
    
          // Set boundary Length
          QTableWidgetItem* boundaryLengthWidget = new QTableWidgetItem( QString::number(boundaryLength) );
Jan Möbius's avatar
Jan Möbius committed
467
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
468
          boundaryLengthWidget->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
469
470
471
#else
          boundaryLengthWidget->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
472
473
474
475
          boundaryLengthWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,2,boundaryLengthWidget);

          QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
Jan Möbius's avatar
Jan Möbius committed
476
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
477
          bbDiagonalWidget->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
478
479
480
#else
          bbDiagonalWidget->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
481
482
          bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,3,bbDiagonalWidget);
483

Jan Möbius's avatar
 
Jan Möbius committed
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
          // remember the id for the hole
          holeMapping_.push_back( std::pair<int , int>( o_it->id() , i ) );
    
          ++count;
        }
      }
    }
    // DATATYPE is  POLYMESH
    else if ( o_it->dataType( DATA_POLY_MESH ) ) {

      //get perObjectData  
      HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( o_it->objectData(HOLEINFO) );

      if (holeInfo != 0){
        elements += holeInfo->holes()->size();
        tool_->tableWidget->setRowCount ( elements );

        //add holes to the table
        for (uint i = 0 ; i < holeInfo->holes()->size() ; ++i ) {
          // Set Name of the object
          QTableWidgetItem* name = new QTableWidgetItem( o_it->name() );
Jan Möbius's avatar
Jan Möbius committed
505
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
506
          name->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
507
508
509
#else
          name->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
510
511
          name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,0,name);
512

Jan Möbius's avatar
Jan Möbius committed
513
514
515
516
517
518
          size_t egde_count = 0;
          double boundaryLength = 0.0;
          TriMesh::Scalar bbDiagonal = 0.0;

          holeInfo->getHoleInfo(i, egde_count, boundaryLength, bbDiagonal);

Jan Möbius's avatar
 
Jan Möbius committed
519
          // Set Number of the edges
Jan Möbius's avatar
Jan Möbius committed
520
          QTableWidgetItem* size = new QTableWidgetItem( QString::number( egde_count ) );
Jan Möbius's avatar
Jan Möbius committed
521
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
522
          size->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
523
524
525
#else
          size->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
526
527
528
          size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,1,size);
    
Jan Möbius's avatar
Jan Möbius committed
529
          // Set Bounding box diagonal
530
          QTableWidgetItem* radius = new QTableWidgetItem( QString::number(boundaryLength) );
Jan Möbius's avatar
Jan Möbius committed
531
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
Jan Möbius's avatar
 
Jan Möbius committed
532
          radius->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
533
534
535
#else
          radius->setFlags( Qt::ItemFlags() );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
536
537
          radius->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,2,radius);
538

Jan Möbius's avatar
Jan Möbius committed
539
          // Set Bounding box diagonal
540
          QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
Jan Möbius's avatar
Jan Möbius committed
541
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
542
          bbDiagonalWidget->setFlags( 0 );
Jan Möbius's avatar
Jan Möbius committed
543
544
545
#else
          bbDiagonalWidget->setFlags( Qt::ItemFlags() );
#endif
546
547
          bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,3,bbDiagonalWidget);
Jan Möbius's avatar
 
Jan Möbius committed
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
    
          // remember the id for the hole
          holeMapping_.push_back( std::pair<int , int>( o_it->id() , i ) );
    
          ++count;
        }
      }
    }
  }

  tool_->tableWidget->resizeColumnToContents ( 1 );
}

/// fill all holes from a given object
void HoleFillerPlugin::fillAllHoles(int _objectID){
  BaseObjectData* object = 0;
  PluginFunctions::getObject( _objectID , object );

  if (object == 0){
    emit log(LOGERR, tr("Could not get object from ID.") );
    return;
  }
  
  emit scriptInfo( "fillAllHoles( ObjectId )"  );


  // TYPE is TRIMESH
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh* mesh = PluginFunctions::triMesh(object);

    //get perObjectData
    HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( object->objectData(HOLEINFO) );
  
    if (holeInfo == 0){
      holeInfo = new HoleInfo< TriMesh >( mesh );
      object->setObjectData(HOLEINFO, holeInfo);
    }

    //fill the hole
    holeInfo->fillAllHoles();

    //and update everything
    emit updatedObject(object->id(),UPDATE_ALL);

    holeInfo->getHoles();

    update_menu();

    emit updateView();
  }
  // DATATYPE is  POLYMESH
  else if ( object->dataType( DATA_POLY_MESH ) ) {
    emit log(LOGERR, tr("HoleFilling unsopported for poly meshes.") );
    return;
  }
}


/// fill a hole in given object where _edgeHandle is on the boundary
void HoleFillerPlugin::fillHole(int _objectID, int _edgeHandle){
  BaseObjectData* object = 0;
  PluginFunctions::getObject( _objectID , object );

  if (object == 0){
    emit log(LOGERR, tr("Could not get object from ID.") );
    return;
  }
  
  emit scriptInfo( "fillHole( ObjectId , EdgeHandle )"  );


  // TYPE is TRIMESH
  if ( object->dataType( DATA_TRIANGLE_MESH ) ) {

    TriMesh* mesh = PluginFunctions::triMesh(object);

    //get perObjectData
    HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( object->objectData(HOLEINFO) );
  
    if (holeInfo == 0){
      holeInfo = new HoleInfo< TriMesh >( mesh );
      object->setObjectData(HOLEINFO, holeInfo);
    }

    //check edgeHandle
    TriMesh::EdgeHandle eh(_edgeHandle);

    if ( !eh.is_valid() || !mesh->is_boundary(eh) ){
      emit log(LOGERR, tr("Invalid edge handle.") );
      return;
    }

    //fill the hole
    holeInfo->fillHole( eh );

    //and update everything
    emit updatedObject(object->id(),UPDATE_ALL);

    holeInfo->getHoles();

    update_menu();

    emit updateView();
  }
  // DATATYPE is  POLYMESH
  else if ( object->dataType( DATA_POLY_MESH ) ) {
    emit log(LOGERR, tr("HoleFilling unsopported for poly meshes.") );
    return;
  }
}