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()) {
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);
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;
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;
335 distances.push_back(nearest.dist);
338 TriMesh::CFVIter fv_it = compMesh->cfv_iter(closestFace);
340 const TriMesh::Point& p0 = compMesh->point(*fv_it);
342 const TriMesh::VertexHandle& v0 = *fv_it;
344 const TriMesh::Point& p1 = compMesh->point(*(++fv_it));
346 const TriMesh::VertexHandle& v1 = *fv_it;
348 const TriMesh::Point& p2 = compMesh->point(*(++fv_it));
350 const TriMesh::VertexHandle& v2 = *fv_it;
353 TriMesh::Point projectedPoint;
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);
390 TriMesh::Scalar
curvature = compMesh->property(meanComp, v0) * projectedPoint[0] +
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);
402 if (gaussCurvature) {
404 TriMesh::Scalar
curvature = compMesh->property(gaussComp, v0) * projectedPoint[0] +
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);
421 tool_->minValue->setText( QString::number(0.0) );
423 if (
tool_->distance->isChecked() ) {
425 }
else if (
tool_->normalAngle->isChecked() ) {
427 }
else if (
tool_->meanCurvature->isChecked() ) {
429 }
else if (
tool_->gaussCurvature->isChecked() ) {
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.
double maximalDistance_
Last maximal computed distance.
bool removeAdditionalNode(NodeT *&_node, QString _pluginName, QString _nodeName, int _id=0)
remove an additional node from the object
const QStringList ALL_OBJECTS
Iterable object range.
void slotObjectUpdated(int _identifier, const UpdateType &_type)
Called when an object gets updated.
unsigned int applyProperties() const
get properties that will be applied (OR'ed ApplyProperties)
void slotClampBox(bool _checked)
If the checkbox is changed to be checked, the values in the labels will be written into the spin boxe...
QtTranslationManipulatorNode * manipulatorNode()
void add_color(const ACG::Vec4f &_c)
add color
MeshCompareToolbarWidget * tool_
The toolbar widget of this plugin.
double maxMeanCurvatureDev_
Last maximal mean curvature deviation.
Type for a MeshObject containing a triangle mesh.
bool getAdditionalNode(NodeT *&_node, QString _pluginName, QString _nodeName, int _id=0)
get an addition node from the object
bool getObject(int _identifier, BSplineCurveObject *&_object)
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
void clear()
clear points and normals and colors
OMTriangleBSP * requestTriangleBsp()
const QStringList TARGET_OBJECTS("target")
Iterable object range.
double maxNormalDeviation_
Last maximal computed normal deviation in degree.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
ACG::Vec4f color_float4(float _v) const
color coding
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void visualizeData(const std::vector< double > &_data, double _maxValue, ACG::SceneGraph::PointNode *_pnode)
Visualize data.
void slotClear()
Clears the visualization.
void set_point_size(float _sz)
set point size (default: 1.0)
double maxGaussCurvatureDev_
Last maximal gauss curvature deviation.
QScriptValue callFunction(QString _plugin, QString _functionName, std::vector< QScriptValue > _parameters)
Call a function provided by a plugin getting multiple parameters.
void reserve(unsigned int _np, unsigned int _nn, unsigned int _nc)
reserve mem for _np points and _nn normals
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
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)
Class for generating nice colors for doubles.
NearestNeighbor nearest(const Point &_p) const
Return handle of the nearest neighbor face.
Add normals to mesh item (vertices/faces)
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)
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
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)
#define DATA_TRIANGLE_MESH
void add_point(const ACG::Vec3d &_p)
add point
void compareButton()
Triggers comparison of the selected meshes.