46#include "MeshComparePlugin.hh"
52#include <ACG/Utils/ColorCoder.hh>
54#include <ACG/Scenegraph/MaterialNode.hh>
55#include <ACG/QtScenegraph/QtTranslationManipulatorNode.hh>
60MeshComparePlugin::MeshComparePlugin() :
64 maxNormalDeviation_(-1),
65 maxMeanCurvatureDev_(-1),
66 maxGaussCurvatureDev_(-1),
72MeshComparePlugin::~MeshComparePlugin()
77void MeshComparePlugin::initializePlugin()
79 if ( OpenFlipper::Options::gui()) {
83 connect(
tool_->clear, SIGNAL(clicked()),
this, SLOT(
slotClear()) );
85 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"MeshCompare.png");
90 QVBoxLayout* layout =
new QVBoxLayout(
tool_->frame);
93 plot_->setMinimumHeight(300);
95 layout->addWidget(plot_);
99bool MeshComparePlugin::eventFilter(QObject *obj, QEvent *event) {
100 if (event->type() != QEvent::Move) {
101 std::cout <<
"Event: " <<
event->type() << std::endl;
106void 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(),
180 tool_->selection->isChecked());
182 emit log(
LOGERR,tr(
"Please select one source and one target mesh to compare! Source will be the reference mesh."));
197 object->removeAdditionalNode(pMatNode,
name(),
"MeshCompareDistanceMaterial");
207 if ( o_it->getAdditionalNode(pMatNode,
name(),
"MeshCompareDistanceMaterial" ) )
208 o_it->removeAdditionalNode(pMatNode,
name(),
"MeshCompareDistanceMaterial");
218 tool_->minVal->setValue(
tool_->minValue->text().toDouble());
219 tool_->maxVal->setValue(
tool_->maxValue->text().toDouble());
223void MeshComparePlugin::compare(
int _sourceId,
int _targetId,
bool _computeDist,
bool _computeNormal,
bool _computeGauss ,
bool _computeMean,
bool _selection) {
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;
326 for (
auto v_it : refMesh->vertices()) {
327 if ( _selection && refMesh->status(v_it).selected() ==
false) {
339 distances.push_back(nearest.dist);
342 TriMesh::CFVIter fv_it = compMesh->cfv_iter(closestFace);
367 if ( _computeNormal) {
370 normal = n0 * projectedPoint[0];
371 normal += n1 * projectedPoint[1];
372 normal += n2 * projectedPoint[2];
376 double normalDeviation = (refMesh->normal(v_it) | normal);
378 if (normalDeviation < -1.0)
379 normalDeviation = -1.0;
380 else if (normalDeviation > 1.0)
381 normalDeviation = 1.0;
383 normalDeviation = 180.0 / M_PI * acos(normalDeviation);
386 normalAngles.push_back(normalDeviation);
394 TriMesh::Scalar curvature = compMesh->property(meanComp, v0) * projectedPoint[0] +
395 compMesh->property(meanComp, v1) * projectedPoint[1] +
396 compMesh->property(meanComp, v2) * projectedPoint[2];
398 const double curvatureDev = fabs(refMesh->property(meanRef, v_it) - curvature);
400 meanCurvatures.push_back(curvatureDev);
406 if (gaussCurvature) {
408 TriMesh::Scalar curvature = compMesh->property(gaussComp, v0) * projectedPoint[0] +
409 compMesh->property(gaussComp, v1) * projectedPoint[1] +
410 compMesh->property(gaussComp, v2) * projectedPoint[2];
412 const double curvatureDev = fabs(refMesh->property(gaussRef, v_it) - curvature);
414 gaussCurvatures.push_back(curvatureDev);
425 tool_->minValue->setText( QString::number(0.0) );
427 if (
tool_->distance->isChecked() ) {
429 }
else if (
tool_->normalAngle->isChecked() ) {
431 }
else if (
tool_->meanCurvature->isChecked() ) {
433 }
else if (
tool_->gaussCurvature->isChecked() ) {
445 tool_->maxValue->setText( QString::number(_maxValue) );
450 if (
tool_->doClamp->isChecked() ) {
451 min =
tool_->minVal->value();
452 max = std::min(
tool_->maxVal->value(),_maxValue);
458 for (
unsigned int i = 0 ; i < _data.size() ; ++i) {
459 _pnode->
add_color(cCoder.color_float4(_data[i]));
462 plot_->setMinMax(min,max);
#define DATA_TRIANGLE_MESH
Class for generating nice colors for doubles.
DrawModes::DrawMode drawMode() const
Return the own draw modes of this node.
@ PointSize
apply point size
unsigned int applyProperties() const
get properties that will be applied (OR'ed ApplyProperties)
void set_point_size(float _sz)
set point size (default: 1.0)
void add_color(const ACG::Vec4f &_c)
add color
void add_point(const ACG::Vec3d &_p)
add point
void clear()
clear points and normals and colors
void reserve(unsigned int _np, unsigned int _nn, unsigned int _nc)
reserve mem for _np points and _nn normals
NearestNeighbor nearest(const Point &_p) const
Return handle of the nearest neighbor face.
bool getAdditionalNode(NodeT *&_node, QString _pluginName, QString _nodeName, int _id=0)
get an addition node from the object
QtTranslationManipulatorNode * manipulatorNode()
bool addAdditionalNode(NodeT *_node, QString _pluginName, QString _nodeName, int _id=0)
add an additional node to the object
QString name()
Return a name for the plugin.
void slotObjectUpdated(int _identifier, const UpdateType &_type)
Called when an object gets updated.
MeshCompareToolbarWidget * tool_
The toolbar widget of this plugin.
void compare(int _sourceId, int _targetId, bool _computeDist=true, bool _computeNormal=true, bool _computeGauss=true, bool _computeMean=true, bool _selection_=false)
double maxGaussCurvatureDev_
Last maximal gauss curvature deviation.
void slotClear()
Clears the visualization.
void compareButton()
Triggers comparison of the selected meshes.
double maxMeanCurvatureDev_
Last maximal mean curvature deviation.
void visualizeData(const std::vector< double > &_data, double _maxValue, ACG::SceneGraph::PointNode *_pnode)
Visualize data.
QIcon * toolIcon_
Icon for the toolbar.
double maximalDistance_
Last maximal computed distance.
double maxNormalDeviation_
Last maximal computed normal deviation in degree.
void slotClampBox(bool _checked)
If the checkbox is changed to be checked, the values in the labels will be written into the spin boxe...
OMTriangleBSP * requestTriangleBsp()
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Kernel::Scalar Scalar
Scalar type.
Kernel::Normal Normal
Normal type.
Kernel::FaceHandle FaceHandle
Scalar type.
Kernel::Point Point
Coordinate type.
void setFunction(const std::vector< double > &_values)
set the function to plot
Type for a MeshObject containing a triangle mesh.
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)
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)
DrawMode POINTS_COLORED
draw colored, but not lighted points (requires point colors)
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
const QStringList SOURCE_OBJECTS("source")
Iterable object range.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
const QStringList ALL_OBJECTS
Iterable object range.
void callFunction(QString _plugin, QString _functionName)
call a function in another plugin
Store nearest neighbor information.