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

Reduced redundant code

parent d2c7b25f
......@@ -219,7 +219,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
TriMesh::Point center;
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
TriMesh::Point _bbMin;
......@@ -260,7 +260,7 @@ void HoleFillerPlugin::slotItemSelectionChanged() {
PolyMesh::Point center;
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
PolyMesh::Point _bbMin;
......@@ -447,42 +447,25 @@ void HoleFillerPlugin::update_menu() {
name->setFlags( 0 );
name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
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
QTableWidgetItem* size = new QTableWidgetItem( QString::number( (*holeInfo->holes())[i].size() ) );
QTableWidgetItem* size = new QTableWidgetItem( QString::number( egde_count ) );
size->setFlags( 0 );
size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
tool_->tableWidget->setItem(count,1,size);
// 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) );
boundaryLengthWidget->setFlags( 0 );
boundaryLengthWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
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) );
bbDiagonalWidget->setFlags( 0 );
bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
......@@ -513,43 +496,25 @@ void HoleFillerPlugin::update_menu() {
name->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
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
QTableWidgetItem* size = new QTableWidgetItem( QString::number( (*holeInfo->holes())[i].size() ) );
QTableWidgetItem* size = new QTableWidgetItem( QString::number( egde_count ) );
size->setFlags( 0 );
size->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
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 Bounding box diagonal
QTableWidgetItem* radius = new QTableWidgetItem( QString::number(boundaryLength) );
radius->setFlags( 0 );
radius->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
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();
// Set Bounding box diagonal
QTableWidgetItem* bbDiagonalWidget = new QTableWidgetItem( QString::number(bbDiagonal) );
bbDiagonalWidget->setFlags( 0 );
bbDiagonalWidget->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled);
......
......@@ -53,6 +53,8 @@
#include <MeshTools/MeshSelectionT.hh>
#include <algorithm>
/// Constructor
template< class MeshT >
HoleInfo< MeshT >::HoleInfo(MeshT * _mesh)
......@@ -236,9 +238,8 @@ void HoleInfo< MeshT >::selectHole(int _index)
}
/// select a hole with given index
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);
......@@ -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
template< class MeshT >
......
......@@ -75,29 +75,40 @@ class HoleInfo : public PerObjectData
public :
//Konstruktor
/// Konstruktor
HoleInfo(MeshT* _mesh);
//Destruktor
/// Destruktor
~HoleInfo();
// find all holes in the mesh
/** Find all holes in the mesh
* and store them in the internal list of holes.
*/
void getHoles();
//fill hole with given index
/// fill hole with given index
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 );
//fill all holes
/// fill all holes
void fillAllHoles( int _stages = 3 );
//select a hole with given index
/// select a hole with given index
void selectHole(int _index);
//Collect information to fly to a hole
void getHoleInfo(const int _index, typename MeshT::Normal& _holeNormal, typename MeshT::Point& _holeCenter) const;
/// Collect information to fly to a hole
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();
};
......
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