Commit d2c7b25f authored by Jan Möbius's avatar Jan Möbius
Browse files

- Fixed crash on object modification

- Added support for computing polymesh hole information
parent f351abba
...@@ -215,7 +215,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() { ...@@ -215,7 +215,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
holeInfo->selectHole( holes[i] ); holeInfo->selectHole( holes[i] );
// We only fly if we have exacly one object and one hole // We only fly if we have exacly one object and one hole
if ( ( objects[0] == o_it->id() ) && (objects.size() == 1) && (holes.size() == 1) ){ if ( (objects.size() == 1) && (holes.size() == 1) && ( objects[0] == o_it->id() ) ){
TriMesh::Point center; TriMesh::Point center;
TriMesh::Normal normal; TriMesh::Normal normal;
...@@ -236,6 +236,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() { ...@@ -236,6 +236,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
// DATATYPE is POLYMESH // DATATYPE is POLYMESH
else if ( o_it->dataType( DATA_POLY_MESH ) ) { else if ( o_it->dataType( DATA_POLY_MESH ) ) {
PolyMeshObject* object = PluginFunctions::polyMeshObject(*o_it);
PolyMesh* mesh = PluginFunctions::polyMesh(o_it); PolyMesh* mesh = PluginFunctions::polyMesh(o_it);
//get perObjectData //get perObjectData
...@@ -254,6 +255,22 @@ void HoleFillerPlugin::slotItemSelectionChanged() { ...@@ -254,6 +255,22 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
if ( objects[i] == o_it->id() ) if ( objects[i] == o_it->id() )
holeInfo->selectHole( holes[i] ); holeInfo->selectHole( holes[i] );
// 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;
holeInfo->getHoleInfo(holes[0], normal, center);
// 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);
}
//update the object //update the object
emit updatedObject(o_it->id(),UPDATE_SELECTION); emit updatedObject(o_it->id(),UPDATE_SELECTION);
...@@ -307,18 +324,8 @@ void HoleFillerPlugin::slotCellDoubleClicked(int _row , int /*_col*/) { ...@@ -307,18 +324,8 @@ void HoleFillerPlugin::slotCellDoubleClicked(int _row , int /*_col*/) {
// DATATYPE is POLYMESH // DATATYPE is POLYMESH
else if ( object->dataType( DATA_POLY_MESH ) ) { else if ( object->dataType( DATA_POLY_MESH ) ) {
// PolyMesh* mesh = PluginFunctions::polyMesh(object);
//
// HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( object->objectData(HOLEINFO) );
//
// if (holeInfo == 0){
// holeInfo = new HoleInfo< PolyMesh >( mesh );
// object->setObjectData(HOLEINFO, holeInfo);
// }
//
// holeInfo->getHoles();
emit log(LOGWARN,tr("HoleFilling unsupported for poly meshes")); emit log(LOGWARN,tr("HoleFilling unsupported for poly meshes"));
return; return;
} }
} }
...@@ -342,19 +349,19 @@ void HoleFillerPlugin::detectButton( ) ...@@ -342,19 +349,19 @@ void HoleFillerPlugin::detectButton( )
holeInfo->getHoles(); holeInfo->getHoles();
} }
// //case POLYMESH //case POLYMESH
// if ( o_it->dataType( DATA_POLY_MESH ) ) { if ( o_it->dataType( DATA_POLY_MESH ) ) {
//
// HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( o_it->objectData(HOLEINFO) ); HoleInfo< PolyMesh >* holeInfo = dynamic_cast< HoleInfo< PolyMesh >* > ( o_it->objectData(HOLEINFO) );
//
// if (holeInfo == 0){ if (holeInfo == 0){
// PolyMesh* mesh = PluginFunctions::polyMesh(*o_it); PolyMesh* mesh = PluginFunctions::polyMesh(*o_it);
// holeInfo = new HoleInfo< PolyMesh >( mesh ); holeInfo = new HoleInfo< PolyMesh >( mesh );
// o_it->setObjectData(HOLEINFO, holeInfo); o_it->setObjectData(HOLEINFO, holeInfo);
// } }
//
// holeInfo->getHoles(); holeInfo->getHoles();
// } }
} }
update_menu(); update_menu();
...@@ -480,7 +487,7 @@ void HoleFillerPlugin::update_menu() { ...@@ -480,7 +487,7 @@ void HoleFillerPlugin::update_menu() {
bbDiagonalWidget->setFlags( 0 ); bbDiagonalWidget->setFlags( 0 );
bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,3,bbDiagonalWidget); tool_->tableWidget->setItem(count,3,bbDiagonalWidget);
// remember the id for the hole // remember the id for the hole
holeMapping_.push_back( std::pair<int , int>( o_it->id() , i ) ); holeMapping_.push_back( std::pair<int , int>( o_it->id() , i ) );
...@@ -505,18 +512,48 @@ void HoleFillerPlugin::update_menu() { ...@@ -505,18 +512,48 @@ void HoleFillerPlugin::update_menu() {
name->setFlags( 0 ); name->setFlags( 0 );
name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,0,name); tool_->tableWidget->setItem(count,0,name);
// Set Number of the edges // Set Number of the edges
QTableWidgetItem* size = new QTableWidgetItem( QString::number( (*holeInfo->holes())[i].size() ) ); QTableWidgetItem* size = new QTableWidgetItem( QString::number( (*holeInfo->holes())[i].size() ) );
size->setFlags( 0 ); size->setFlags( 0 );
size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,1,size); tool_->tableWidget->setItem(count,1,size);
// Set boundary Length
std::vector< PolyMesh::EdgeHandle >::iterator endIter = (*holeInfo->holes())[i].end();
double boundaryLength = 0.0;
PolyMesh* mesh = 0;
PluginFunctions::getMesh(o_it->id(),mesh);
for (std::vector< PolyMesh::EdgeHandle >::iterator edgeIter = (*holeInfo->holes())[i].begin(); edgeIter != endIter; ++edgeIter)
boundaryLength += mesh->calc_edge_length(*edgeIter);
// Set radius // Set radius
QTableWidgetItem* radius = new QTableWidgetItem( "TODO" ); QTableWidgetItem* radius = new QTableWidgetItem( QString::number(boundaryLength) );
radius->setFlags( 0 ); radius->setFlags( 0 );
radius->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); radius->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,2,radius); tool_->tableWidget->setItem(count,2,radius);
//compute bounding box
PolyMesh::Point minCoord = PolyMesh::Point(std::numeric_limits<PolyMesh::Scalar>::max(),std::numeric_limits<PolyMesh::Scalar>::max(),std::numeric_limits<PolyMesh::Scalar>::max());
PolyMesh::Point maxCoord = PolyMesh::Point(-std::numeric_limits<PolyMesh::Scalar>::max(),-std::numeric_limits<PolyMesh::Scalar>::max(),-std::numeric_limits<PolyMesh::Scalar>::max());
for (std::vector< PolyMesh::EdgeHandle >::iterator edgeIter = (*holeInfo->holes())[i].begin(); edgeIter != endIter; ++edgeIter)
{
PolyMesh::Point pos = mesh->point(mesh->from_vertex_handle(mesh->halfedge_handle(*edgeIter,0)));
minCoord[0] = std::min(minCoord[0],pos[0]);
minCoord[1] = std::min(minCoord[1],pos[1]);
minCoord[2] = std::min(minCoord[2],pos[2]);
maxCoord[0] = std::max(maxCoord[0],pos[0]);
maxCoord[1] = std::max(maxCoord[1],pos[1]);
maxCoord[2] = std::max(maxCoord[2],pos[2]);
}
PolyMesh::Scalar bbDiagonal = (minCoord-maxCoord).length();
QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
bbDiagonalWidget->setFlags( 0 );
bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,3,bbDiagonalWidget);
// remember the id for the hole // remember the id for the hole
holeMapping_.push_back( std::pair<int , int>( o_it->id() , i ) ); holeMapping_.push_back( std::pair<int , int>( o_it->id() , i ) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment