52 #include "MeshComparePlugin.hh" 58 #include <ACG/Utils/ColorCoder.hh> 61 MeshComparePlugin::MeshComparePlugin() :
64 maxNormalDeviation_(-1),
65 maxMeanCurvatureDev_(-1),
66 maxGaussCurvatureDev_(-1)
74 MeshComparePlugin::~MeshComparePlugin()
79 void MeshComparePlugin::initializePlugin()
81 if ( OpenFlipper::Options::gui()) {
84 connect( tool_->compare, SIGNAL(clicked()),
this, SLOT(compareButton()) );
85 connect( tool_->clear, SIGNAL(clicked()),
this, SLOT(slotClear()) );
87 QIcon* toolIcon =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"MeshCompare.png");
88 emit addToolbox( tr(
"Mesh Compare") , tool_ , toolIcon);
90 connect(tool_->doClamp,SIGNAL(toggled(
bool)),
this,SLOT(slotClampBox(
bool)));
93 QVBoxLayout* layout =
new QVBoxLayout(tool_->frame);
95 plot_ =
new QwtFunctionPlot(0);
96 plot_->setMinimumHeight(150);
98 layout->addWidget(plot_);
101 tool_->frame->hide();
106 void MeshComparePlugin::pluginsInitialized() {
111 emit
setSlotDescription(tr(
"compare(int,int)"), tr(
"Compare two meshes. Use lastMaximalDistance() and lastMaximalNormalDeviation() to get the results."),
112 QStringList(tr(
"ObjectId,ObjectId")), QStringList(tr(
"Id of the reference mesh, Id of the comparison mesh")));
113 emit
setSlotDescription(tr(
"lastMaximalDistance()"), tr(
"Get the maximal distance between the meshes of the last comparison."),
114 QStringList(tr(
"")), QStringList(tr(
"")));
115 emit
setSlotDescription(tr(
"lastMaximalNormalDeviation()"), tr(
"Get the maximal normal deviation in degree between the meshes of the last comparison."),
116 QStringList(tr(
"")), QStringList(tr(
"")));
117 emit
setSlotDescription(tr(
"lastMaximalMeanCurvatureDeviation()"), tr(
"Get the maximal mean curvature deviation between the meshes of the last comparison."),
118 QStringList(tr(
"")), QStringList(tr(
"")));
119 emit
setSlotDescription(tr(
"lastMaximalGaussCurvatureDeviation()"), tr(
"Get the maximal gauss curvature deviation between the meshes of the last comparison."),
120 QStringList(tr(
"")), QStringList(tr(
"")));
125 bool meanCurvature =
false;
126 emit pluginExists(
"meancurvature" , meanCurvature );
128 if ( OpenFlipper::Options::gui() && !meanCurvature )
129 tool_->meanCurvature->setEnabled(
false);
134 bool gaussCurvature =
false;
135 emit pluginExists(
"gausscurvature" , gaussCurvature );
137 if ( OpenFlipper::Options::gui() && !gaussCurvature )
138 tool_->gaussCurvature->setEnabled(
false);
150 if ( targetObject != 0 ) {
151 emit log(
LOGERR,tr(
"Please select one source and one target mesh to compare! Source will be the reference mesh."));
155 targetObject = (*o_it);
165 if ( sourceObject != 0 ) {
166 emit log(
LOGERR,tr(
"Please select one source and one target mesh to compare! Source will be the reference mesh."));
170 sourceObject = (*o_it);
175 if ( (targetObject != 0) && (sourceObject != 0) ) {
176 compare(sourceObject->
id(),targetObject->
id(), tool_->distance->isChecked() ,
177 tool_->normalAngle->isChecked(),
178 tool_->gaussCurvature->isChecked(),
179 tool_->meanCurvature->isChecked() );
181 emit log(
LOGERR,tr(
"Please select one source and one target mesh to compare! Source will be the reference mesh."));
206 if ( o_it->getAdditionalNode(pMatNode,
name(),
"MeshCompareDistanceMaterial" ) )
207 o_it->removeAdditionalNode(pMatNode,
name(),
"MeshCompareDistanceMaterial");
217 tool_->minVal->setValue(tool_->minValue->text().toDouble());
218 tool_->maxVal->setValue(tool_->maxValue->text().toDouble());
222 void MeshComparePlugin::compare(
int _sourceId,
int _targetId,
bool _computeDist,
bool _computeNormal,
bool _computeGauss ,
bool _computeMean) {
228 if ( (target == 0 ) || (source == 0) ) {
229 emit log(
LOGERR,tr(
"Please select one source and one target mesh to compare! Source will be the reference mesh."));
230 emit log(
LOGERR,tr(
"Only triangle meshes are currently supported!"));
240 if ( OpenFlipper::Options::gui() ) {
257 pNode->
reserve(refMesh->n_vertices(),refMesh->n_vertices(),refMesh->n_vertices() );
267 bool meanCurvature =
false;
271 if ( _computeMean ) {
272 emit pluginExists(
"meancurvature" , meanCurvature );
274 if ( meanCurvature ) {
280 ((!refMesh->get_property_handle( meanRef ,
"Mean Curvature") ) ||
281 (!compMesh->get_property_handle( meanComp,
"Mean Curvature") ))) {
282 meanCurvature =
false;
289 bool gaussCurvature =
false;
293 if ( _computeGauss ) {
294 emit pluginExists(
"gausscurvature" , gaussCurvature );
296 if ( gaussCurvature ) {
301 if( gaussCurvature &&
302 ((!refMesh->get_property_handle( gaussRef ,
"Gaussian Curvature") ) ||
303 (!compMesh->get_property_handle( gaussComp,
"Gaussian Curvature") ))) {
304 gaussCurvature =
false;
313 maximalDistance_ = -1.0;
314 maxNormalDeviation_ = -1.0;
315 maxMeanCurvatureDev_ = -1.0;
316 maxGaussCurvatureDev_ = -1.0;
320 std::vector<double> distances;
321 std::vector<double> normalAngles;
322 std::vector<double> meanCurvatures;
323 std::vector<double> gaussCurvatures;
325 for ( TriMesh::VertexIter v_it = refMesh->vertices_begin() ; v_it != refMesh->vertices_end(); ++ v_it) {
327 TriMeshObject::OMTriangleBSP::NearestNeighbor nearest = compBSP->
nearest(refMesh->point(*v_it));
328 TriMesh::FaceHandle closestFace = nearest.handle;
331 if (nearest.dist > maximalDistance_)
332 maximalDistance_ = nearest.dist;
335 distances.push_back(nearest.dist);
338 TriMesh::CFVIter fv_it = compMesh->cfv_iter(closestFace);
363 if ( _computeNormal) {
366 normal = n0 * projectedPoint[0];
367 normal += n1 * projectedPoint[1];
368 normal += n2 * projectedPoint[2];
372 double normalDeviation = (refMesh->normal(*v_it) | normal);
374 if (normalDeviation < -1.0)
375 normalDeviation = -1.0;
376 else if (normalDeviation > 1.0)
377 normalDeviation = 1.0;
379 normalDeviation = 180.0 / M_PI * acos(normalDeviation);
382 normalAngles.push_back(normalDeviation);
384 if (normalDeviation > maxNormalDeviation_)
385 maxNormalDeviation_ = normalDeviation;
391 compMesh->property(meanComp, v1) * projectedPoint[1] +
392 compMesh->property(meanComp, v2) * projectedPoint[2];
394 const double curvatureDev = fabs(refMesh->property(meanRef, *v_it) - curvature);
396 meanCurvatures.push_back(curvatureDev);
398 if (curvatureDev > maxMeanCurvatureDev_)
399 maxMeanCurvatureDev_ = curvatureDev;
402 if (gaussCurvature) {
405 compMesh->property(gaussComp, v1) * projectedPoint[1] +
406 compMesh->property(gaussComp, v2) * projectedPoint[2];
408 const double curvatureDev = fabs(refMesh->property(gaussRef, *v_it) - curvature);
410 gaussCurvatures.push_back(curvatureDev);
412 if (curvatureDev > maxGaussCurvatureDev_)
413 maxGaussCurvatureDev_ = curvatureDev;
421 tool_->minValue->setText( QString::number(0.0) );
423 if ( tool_->distance->isChecked() ) {
424 visualizeData(distances,maximalDistance_,pNode);
425 }
else if ( tool_->normalAngle->isChecked() ) {
426 visualizeData(normalAngles,maxNormalDeviation_,pNode);
427 }
else if ( tool_->meanCurvature->isChecked() ) {
428 visualizeData(meanCurvatures,maxMeanCurvatureDev_,pNode);
429 }
else if ( tool_->gaussCurvature->isChecked() ) {
430 visualizeData(gaussCurvatures,maxGaussCurvatureDev_,pNode);
441 tool_->maxValue->setText( QString::number(_maxValue) );
446 if ( tool_->doClamp->isChecked() ) {
447 min = tool_->minVal->value();
448 max = std::min(tool_->maxVal->value(),_maxValue);
454 for (
unsigned int i = 0 ; i < _data.size() ; ++i) {
459 plot_->setMinMax(min,max);
460 plot_->setFunction( _data );
466 #if QT_VERSION < 0x050000 QString name()
Return a name for the plugin.
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
virtual void setSlotDescription(QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions)
Set a description for a public slot.
void slotClampBox(bool _checked)
If the checkbox is changed to be checked, the values in the labels will be written into the spin boxe...
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
void slotClear()
Clears the visualization.
void clear()
clear points and normals and colors
Type for a MeshObject containing a triangle mesh.
bool getObject(int _identifier, BSplineCurveObject *&_object)
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
void compareButton()
Triggers comparison of the selected meshes.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void visualizeData(const std::vector< double > &_data, double _maxValue, ACG::SceneGraph::PointNode *_pnode)
Visualize data.
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
bool baryCoord(const VectorT< Scalar, 3 > &_p, const VectorT< Scalar, 3 > &_u, const VectorT< Scalar, 3 > &_v, const VectorT< Scalar, 3 > &_w, VectorT< Scalar, 3 > &_result)
const QStringList ALL_OBJECTS
Iterable object range.
QtTranslationManipulatorNode * manipulatorNode()
void add_point(const ACG::Vec3d &_p)
add point
ACG::Vec4f color_float4(float _v) const
color coding
void reserve(unsigned int _np, unsigned int _nn, unsigned int _nc)
reserve mem for _np points and _nn normals
Kernel::Normal Normal
Normal type.
bool getAdditionalNode(NodeT *&_node, QString _pluginName, QString _nodeName, int _id=0)
get an addition node from the object
Vec::value_type distPointTriangle(const Vec &_p, const Vec &_v0, const Vec &_v1, const Vec &_v2, Vec &_nearestPoint)
distance from point _p to triangle (_v0, _v1, _v2)
OMTriangleBSP * requestTriangleBsp()
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
unsigned int applyProperties() const
get properties that will be applied (OR'ed ApplyProperties)
void slotObjectUpdated(int _identifier, const UpdateType &_type)
Called when an object gets updated.
virtual void updateView()
Update current view in Main Application.
bool removeAdditionalNode(NodeT *&_node, QString _pluginName, QString _nodeName, int _id=0)
remove an additional node from the object
NearestNeighbor nearest(const Point &_p) const
Return handle of the nearest neighbor face.
Kernel::Point Point
Coordinate type.
bool addAdditionalNode(NodeT *_node, QString _pluginName, QString _nodeName, int _id=0)
add an additional node to the object
void compare(int _sourceId, int _targetId, bool _computeDist=true, bool _computeNormal=true, bool _computeGauss=true, bool _computeMean=true)
Class for generating nice colors for doubles.
Kernel::Scalar Scalar
Scalar type.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
#define DATA_TRIANGLE_MESH
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void add_color(const ACG::Vec4f &_c)
add color
void set_point_size(float _sz)
set point size (default: 1.0)