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

Reduced redundant code

parent d2c7b25f
...@@ -219,7 +219,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() { ...@@ -219,7 +219,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
TriMesh::Point center; TriMesh::Point center;
TriMesh::Normal normal; TriMesh::Normal normal;
holeInfo->getHoleInfo(holes[0], normal, center); holeInfo->getHolePostitionInfo(holes[0], normal, center);
// Get bounding box to get a scaling for the movement // Get bounding box to get a scaling for the movement
TriMesh::Point _bbMin; TriMesh::Point _bbMin;
...@@ -260,7 +260,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() { ...@@ -260,7 +260,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
PolyMesh::Point center; PolyMesh::Point center;
PolyMesh::Normal normal; PolyMesh::Normal normal;
holeInfo->getHoleInfo(holes[0], normal, center); holeInfo->getHolePostitionInfo(holes[0], normal, center);
// Get bounding box to get a scaling for the movement // Get bounding box to get a scaling for the movement
PolyMesh::Point _bbMin; PolyMesh::Point _bbMin;
...@@ -447,42 +447,25 @@ void HoleFillerPlugin::update_menu() { ...@@ -447,42 +447,25 @@ 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);
size_t egde_count = 0;
double boundaryLength = 0.0;
TriMesh::Scalar bbDiagonal = 0.0;
holeInfo->getHoleInfo(i, egde_count, boundaryLength, bbDiagonal);
// 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( egde_count ) );
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 // Set boundary Length
std::vector< TriMesh::EdgeHandle >::iterator endIter = (*holeInfo->holes())[i].end();
double boundaryLength = 0.0;
TriMesh* mesh = 0;
PluginFunctions::getMesh(o_it->id(),mesh);
for (std::vector< TriMesh::EdgeHandle >::iterator edgeIter = (*holeInfo->holes())[i].begin(); edgeIter != endIter; ++edgeIter)
boundaryLength += mesh->calc_edge_length(*edgeIter);
QTableWidgetItem* boundaryLengthWidget = new QTableWidgetItem( QString::number(boundaryLength) ); QTableWidgetItem* boundaryLengthWidget = new QTableWidgetItem( QString::number(boundaryLength) );
boundaryLengthWidget->setFlags( 0 ); boundaryLengthWidget->setFlags( 0 );
boundaryLengthWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); boundaryLengthWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,2,boundaryLengthWidget); tool_->tableWidget->setItem(count,2,boundaryLengthWidget);
//compute bounding box
TriMesh::Point minCoord = TriMesh::Point(std::numeric_limits<TriMesh::Scalar>::max(),std::numeric_limits<TriMesh::Scalar>::max(),std::numeric_limits<TriMesh::Scalar>::max());
TriMesh::Point maxCoord = TriMesh::Point(-std::numeric_limits<TriMesh::Scalar>::max(),-std::numeric_limits<TriMesh::Scalar>::max(),-std::numeric_limits<TriMesh::Scalar>::max());
for (std::vector< TriMesh::EdgeHandle >::iterator edgeIter = (*holeInfo->holes())[i].begin(); edgeIter != endIter; ++edgeIter)
{
TriMesh::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]);
}
TriMesh::Scalar bbDiagonal = (minCoord-maxCoord).length();
QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) ); QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
bbDiagonalWidget->setFlags( 0 ); bbDiagonalWidget->setFlags( 0 );
bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
...@@ -513,43 +496,25 @@ void HoleFillerPlugin::update_menu() { ...@@ -513,43 +496,25 @@ void HoleFillerPlugin::update_menu() {
name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,0,name); tool_->tableWidget->setItem(count,0,name);
size_t egde_count = 0;
double boundaryLength = 0.0;
TriMesh::Scalar bbDiagonal = 0.0;
holeInfo->getHoleInfo(i, egde_count, boundaryLength, bbDiagonal);
// 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( egde_count ) );
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 // Set Bounding box diagonal
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
QTableWidgetItem* radius = new QTableWidgetItem( QString::number(boundaryLength) ); 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 // Set Bounding box diagonal
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) ); QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
bbDiagonalWidget->setFlags( 0 ); bbDiagonalWidget->setFlags( 0 );
bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled); bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
#include <MeshTools/MeshSelectionT.hh> #include <MeshTools/MeshSelectionT.hh>
#include <algorithm>
/// Constructor /// Constructor
template< class MeshT > template< class MeshT >
HoleInfo< MeshT >::HoleInfo(MeshT * _mesh) HoleInfo< MeshT >::HoleInfo(MeshT * _mesh)
...@@ -236,9 +238,8 @@ void HoleInfo< MeshT >::selectHole(int _index) ...@@ -236,9 +238,8 @@ void HoleInfo< MeshT >::selectHole(int _index)
} }
/// select a hole with given index
template< class MeshT > template< class MeshT >
void HoleInfo< MeshT >::getHoleInfo(const int _index, typename MeshT::Normal& _holeNormal, typename MeshT::Point& _holeCenter) const void HoleInfo< MeshT >::getHolePostitionInfo(const int _index, typename MeshT::Normal& _holeNormal, typename MeshT::Point& _holeCenter) const
{ {
_holeCenter = typename MeshT::Point(0.0,0.0,0.0); _holeCenter = typename MeshT::Point(0.0,0.0,0.0);
...@@ -259,6 +260,38 @@ void HoleInfo< MeshT >::getHoleInfo(const int _index, typename MeshT::Normal& _h ...@@ -259,6 +260,38 @@ void HoleInfo< MeshT >::getHoleInfo(const int _index, typename MeshT::Normal& _h
} }
template< class MeshT >
void HoleInfo< MeshT >::getHoleInfo(const unsigned int _index, size_t& _edges, typename MeshT::Scalar& _diagonal, typename MeshT::Scalar& _boundaryLength) const
{
if ( _index >= holes_.size() ) {
std::cerr << "Invalid hole index " << _index << std::endl;
return;
}
_boundaryLength = 0.0;
typename MeshT::Point minCoord = typename MeshT::Point(std::numeric_limits<typename MeshT::Scalar>::max(),std::numeric_limits<typename MeshT::Scalar>::max(),std::numeric_limits<typename MeshT::Scalar>::max());
typename MeshT::Point maxCoord = typename MeshT::Point(-std::numeric_limits<typename MeshT::Scalar>::max(),-std::numeric_limits<typename MeshT::Scalar>::max(),-std::numeric_limits<typename MeshT::Scalar>::max());
for (size_t i = 0 ; i < holes_[_index].size() ; ++i) {
_boundaryLength += mesh_->calc_edge_length(holes_[_index][i]);
typename MeshT::Point pos = mesh_->point(mesh_->from_vertex_handle(mesh_->halfedge_handle(holes_[_index][i],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]);
}
_edges = holes_[_index].size();
_diagonal = (maxCoord - minCoord).length();
}
/// get the holes vector /// get the holes vector
template< class MeshT > template< class MeshT >
......
...@@ -75,29 +75,40 @@ class HoleInfo : public PerObjectData ...@@ -75,29 +75,40 @@ class HoleInfo : public PerObjectData
public : public :
//Konstruktor /// Konstruktor
HoleInfo(MeshT* _mesh); HoleInfo(MeshT* _mesh);
//Destruktor /// Destruktor
~HoleInfo(); ~HoleInfo();
// find all holes in the mesh /** Find all holes in the mesh
* and store them in the internal list of holes.
*/
void getHoles(); void getHoles();
//fill hole with given index /// fill hole with given index
void fillHole(int _index, int _stages = 3 ); void fillHole(int _index, int _stages = 3 );
//fill hole with given boundary edgeHandle /// fill hole with given boundary edgeHandle
void fillHole(typename MeshT::EdgeHandle _eh, int _stages = 3 ); void fillHole(typename MeshT::EdgeHandle _eh, int _stages = 3 );
//fill all holes /// fill all holes
void fillAllHoles( int _stages = 3 ); void fillAllHoles( int _stages = 3 );
//select a hole with given index /// select a hole with given index
void selectHole(int _index); void selectHole(int _index);
//Collect information to fly to a hole /// Collect information to fly to a hole
void getHoleInfo(const int _index, typename MeshT::Normal& _holeNormal, typename MeshT::Point& _holeCenter) const; void getHolePostitionInfo(const int _index, typename MeshT::Normal& _holeNormal, typename MeshT::Point& _holeCenter) const;
/** Collect bounding box size and boundary length of holes
*
* @param _index Index of the hole
* @param _edges Count of boundary edges
* @param _diagonal Length of the hole bounding box diagonal
* @param _boundary_Length Boundary length of the hole
*/
void getHoleInfo(const unsigned int _index, size_t& _edges, typename MeshT::Scalar& _diagonal, typename MeshT::Scalar& _boundaryLength) const;
std::vector< std::vector< typename MeshT::EdgeHandle > >* holes(); std::vector< std::vector< typename MeshT::EdgeHandle > >* holes();
}; };
......
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