HoleFillerPlugin.cc 20.2 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#define HOLEINFO "HoleInfoData"

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

}

/// Initialize the toolbox widget
void HoleFillerPlugin::initializePlugin()
{
   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);
} 

/// add PickModes after initialization
void HoleFillerPlugin::pluginsInitialized()
{
   emit addPickMode("Separator");
   emit addPickMode("Hole Filler");

   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(","));

   //build the tableWidget with headers
   update_menu();
}

Matthias Möller's avatar
Matthias Möller committed
94 95 96
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
97

Matthias Möller's avatar
Matthias Möller committed
98 99 100 101
  //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
102

Matthias Möller's avatar
Matthias Möller committed
103 104 105 106
    _holeIds.push_back  ( holeID );
    _objIds.push_back( objID );
  }
}
Jan Möbius's avatar
 
Jan Möbius committed
107

Matthias Möller's avatar
Matthias Möller committed
108 109
/// Fill all selected holes
void HoleFillerPlugin::slotFillSelection(){
Jan Möbius's avatar
 
Jan Möbius committed
110 111 112 113

  //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
114
  getSelectedHoles(holes,objects);
Jan Möbius's avatar
 
Jan Möbius committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

  //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
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {

    // 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
151
      emit updatedObject(o_it->id(),UPDATE_ALL);
Jan Möbius's avatar
 
Jan Möbius committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
    
      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
179
  getSelectedHoles(holes,objects);
Jan Möbius's avatar
 
Jan Möbius committed
180 181 182 183 184 185 186

  //iterate over all objects with holes that should be displayed
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {

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

Jan Möbius's avatar
Jan Möbius committed
187
      TriMeshObject* object = PluginFunctions::triMeshObject(*o_it);
Jan Möbius's avatar
 
Jan Möbius committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
      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
206
      // We only fly if we have exacly one object and one hole
207
      if (  (objects.size() == 1) && (holes.size() == 1) && ( objects[0] == o_it->id() ) ){
Jan Möbius's avatar
Jan Möbius committed
208 209 210

        TriMesh::Point center;
        TriMesh::Normal normal;
Jan Möbius's avatar
Jan Möbius committed
211
        holeInfo->getHolePostitionInfo(holes[0], normal, center);
Jan Möbius's avatar
Jan Möbius committed
212 213 214 215 216 217 218 219 220 221

        // 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
222
      //update the object
223
      emit updatedObject(o_it->id(),UPDATE_SELECTION);
Jan Möbius's avatar
 
Jan Möbius committed
224 225 226 227
    }
    // DATATYPE is  POLYMESH
    else if ( o_it->dataType( DATA_POLY_MESH ) ) {

228
      PolyMeshObject* object = PluginFunctions::polyMeshObject(*o_it);
Jan Möbius's avatar
 
Jan Möbius committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
      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] );

247 248 249 250 251
      // 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
252
        holeInfo->getHolePostitionInfo(holes[0], normal, center);
253 254 255 256 257 258 259 260 261 262

        // 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
263
      //update the object
264
      emit updatedObject(o_it->id(),UPDATE_SELECTION);
Jan Möbius's avatar
 
Jan Möbius committed
265 266 267 268 269 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

    }
  }

  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"));
317

Jan Möbius's avatar
 
Jan Möbius committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    return;
  }
}

/// detect holes on all objects
void HoleFillerPlugin::detectButton( )
{
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {

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

      HoleInfo< TriMesh >* holeInfo = dynamic_cast< HoleInfo< TriMesh >* > ( o_it->objectData(HOLEINFO) );
    
      if ( holeInfo == 0 ){
        TriMesh* mesh = PluginFunctions::triMesh(*o_it);
        holeInfo = new HoleInfo< TriMesh >( mesh );
        o_it->setObjectData(HOLEINFO, holeInfo);
      }

      holeInfo->getHoles();
    }

341 342 343 344 345 346 347 348 349 350 351 352 353
     //case POLYMESH
     if ( o_it->dataType( DATA_POLY_MESH ) ) {

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

       if (holeInfo == 0){
         PolyMesh* mesh = PluginFunctions::polyMesh(*o_it);
         holeInfo = new HoleInfo< PolyMesh >( mesh );
         o_it->setObjectData(HOLEINFO, holeInfo);
       }

       holeInfo->getHoles();
     }
Jan Möbius's avatar
 
Jan Möbius committed
354 355 356 357 358 359
  }

  update_menu();
}

/// check for holes if an object has changed
360
void HoleFillerPlugin::slotObjectUpdated( int _identifier, const UpdateType& _type ) {
Jan Möbius's avatar
 
Jan Möbius committed
361 362 363 364 365 366 367 368 369

  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
370
  if ( _type.contains(UPDATE_TOPOLOGY) ) {
Jan Möbius's avatar
 
Jan Möbius committed
371

Jan Möbius's avatar
Jan Möbius committed
372 373 374 375 376 377 378 379 380
    // 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
381 382
    }

Jan Möbius's avatar
Jan Möbius committed
383 384
    // get holes for POLYMESH
    else if ( object->dataType( DATA_POLY_MESH ) ) {
Jan Möbius's avatar
 
Jan Möbius committed
385

Jan Möbius's avatar
Jan Möbius committed
386 387 388 389 390 391
      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
392 393 394 395 396 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 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    }
  }

  // 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
  for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::ALL_OBJECTS) ; o_it != PluginFunctions::objectsEnd(); ++o_it) {

    // 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() );
          name->setFlags( 0 );
          name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,0,name);
Jan Möbius's avatar
Jan Möbius committed
439 440 441

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

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

Jan Möbius's avatar
 
Jan Möbius committed
446
          // Set Number of the edges
Jan Möbius's avatar
Jan Möbius committed
447
          QTableWidgetItem* size = new QTableWidgetItem( QString::number( egde_count ) );
Jan Möbius's avatar
 
Jan Möbius committed
448 449 450 451 452 453 454 455 456 457 458 459 460 461
          size->setFlags( 0 );
          size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,1,size);
    
          // Set boundary Length
          QTableWidgetItem* boundaryLengthWidget = new QTableWidgetItem( QString::number(boundaryLength) );
          boundaryLengthWidget->setFlags( 0 );
          boundaryLengthWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,2,boundaryLengthWidget);

          QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
          bbDiagonalWidget->setFlags( 0 );
          bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,3,bbDiagonalWidget);
462

Jan Möbius's avatar
 
Jan Möbius committed
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
          // 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() );
          name->setFlags( 0 );
          name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,0,name);
487

Jan Möbius's avatar
Jan Möbius committed
488 489 490 491 492 493
          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
494
          // Set Number of the edges
Jan Möbius's avatar
Jan Möbius committed
495
          QTableWidgetItem* size = new QTableWidgetItem( QString::number( egde_count ) );
Jan Möbius's avatar
 
Jan Möbius committed
496 497 498 499
          size->setFlags( 0 );
          size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,1,size);
    
Jan Möbius's avatar
Jan Möbius committed
500
          // Set Bounding box diagonal
501
          QTableWidgetItem* radius = new QTableWidgetItem( QString::number(boundaryLength) );
Jan Möbius's avatar
 
Jan Möbius committed
502 503 504
          radius->setFlags( 0 );
          radius->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,2,radius);
505

Jan Möbius's avatar
Jan Möbius committed
506
          // Set Bounding box diagonal
507 508 509 510
          QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
          bbDiagonalWidget->setFlags( 0 );
          bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
          tool_->tableWidget->setItem(count,3,bbDiagonalWidget);
Jan Möbius's avatar
 
Jan Möbius committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 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
    
          // 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;
  }
}