From 4f240755e7a01c19bbb6585690a07ca3e8b749da Mon Sep 17 00:00:00 2001 From: Hans-Christian Ebke Date: Tue, 3 Jul 2012 08:51:35 +0000 Subject: [PATCH] Plugin-PropertyVis: Added color viz for vector properties. git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14826 383ad7c9-94d9-4d36-a494-682f7c89f535 --- PropertyVisPlugin.cc | 144 ++++++++++++++++++++++---------------- PropertyVisPlugin.hh | 12 ++++ PropertyVisPluginT.cc | 57 ++++++++++++++- PropertyVisToolbarBase.ui | 141 +++++++++++++++++++++++++------------ 4 files changed, 247 insertions(+), 107 deletions(-) diff --git a/PropertyVisPlugin.cc b/PropertyVisPlugin.cc index 8dafa01..c386b57 100644 --- a/PropertyVisPlugin.cc +++ b/PropertyVisPlugin.cc @@ -433,81 +433,103 @@ namespace { }; } -void PropertyVisPlugin::slotVisualize() -{ +void PropertyVisPlugin::slotVisualize() { - int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); - BaseObjectData* object = 0; + int id = tool_->meshNames->itemData( tool_->meshNames->currentIndex() ).toInt(); + BaseObjectData* object = 0; - PluginFunctions::getObject( id, object ); + PluginFunctions::getObject( id, object ); - if (object == 0){ - emit log(LOGERR, "Unable to get object"); - return; - } + if (object == 0){ + emit log(LOGERR, "Unable to get object"); + return; + } - TriMesh * const triMesh = (object->dataType(DATA_TRIANGLE_MESH) ? PluginFunctions::triMesh(object) : 0); - PolyMesh * const polyMesh = (object->dataType(DATA_POLY_MESH) ? PluginFunctions::polyMesh(object) : 0);; + TriMesh * const triMesh = (object->dataType(DATA_TRIANGLE_MESH) ? PluginFunctions::triMesh(object) : 0); + PolyMesh * const polyMesh = (object->dataType(DATA_POLY_MESH) ? PluginFunctions::polyMesh(object) : 0);; - if (triMesh == 0 && polyMesh == 0) { - emit log(LOGERR,"Unable to get mesh"); - return; - } + if (triMesh == 0 && polyMesh == 0) { + emit log(LOGERR,"Unable to get mesh"); + return; + } - /* - * Visualize single properties. - */ - QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - for (QModelIndexList::const_iterator it = selectedIndices.begin(), it_end = selectedIndices.end(); - it != it_end; ++it) { + // Actual Viz takes place in try-catch block to catch VizExceptions. + try { - const PropertyNameListModel::PROP_INFO ¤tProp = propertyNameListModel_[it->row()]; + /* + * Visualize single properties. + */ + QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); + for (QModelIndexList::const_iterator it = selectedIndices.begin(), it_end = selectedIndices.end(); + it != it_end; ++it) { - if (triMesh) visualizeProperty(triMesh, currentProp); - else if (polyMesh) visualizeProperty(polyMesh, currentProp); - } + const PropertyNameListModel::PROP_INFO ¤tProp = propertyNameListModel_[it->row()]; + + if (triMesh) + visualizeProperty(triMesh, currentProp); + else if (polyMesh) + visualizeProperty(polyMesh, currentProp); + } - /* - * Visualize composed properties. - */ - if (tool_->visualizeVectorDifference_cb->isChecked()) { + /* + * Visualize composed properties. + */ + if (tool_->visualizeVectorDifference_cb->isChecked()) { - // Look for two vector properties of the same type and entity. + // Look for two vector properties of the same type and entity. - std::vector propList; + std::vector propList; - QModelIndexList selectedIndices = tool_->propertyName_lv->selectionModel()->selectedIndexes(); - for (QModelIndexList::const_iterator it = selectedIndices.begin(), it_end = selectedIndices.end(); - it != it_end; ++it) { - const PropertyNameListModel::PROP_INFO ¤tProp = propertyNameListModel_[it->row()]; - if (currentProp.typeinfo() == PropertyNameListModel::proptype_Vec3d || currentProp.typeinfo() == PropertyNameListModel::proptype_Vec3f) - propList.push_back(¤tProp); - } + QModelIndexList selectedIndices = + tool_->propertyName_lv->selectionModel()->selectedIndexes(); + for (QModelIndexList::const_iterator it = selectedIndices.begin(), it_end = + selectedIndices.end(); it != it_end; ++it) { + const PropertyNameListModel::PROP_INFO ¤tProp = + propertyNameListModel_[it->row()]; + if (currentProp.typeinfo() == PropertyNameListModel::proptype_Vec3d + || currentProp.typeinfo() == PropertyNameListModel::proptype_Vec3f) + propList.push_back(¤tProp); + } - std::sort(propList.begin(), propList.end(), PROP_INFO_TYPE_SORTER()); - std::vector::const_iterator it = - std::adjacent_find(propList.begin(), propList.end(), PROP_INFO_TYPE_EQUAL()); - - /* - * Are there two selected properties of equal vector type? - */ - if (it != propList.end()) { - if (tool_->vecFieldDiff_norm_diff_rb->isChecked()) { - if (triMesh) visualizeVectorFieldDifference >(triMesh, **it, **(it+1)); - else if (polyMesh) visualizeVectorFieldDifference >(polyMesh, **it, **(it+1)); - } else if (tool_->vecFieldDiff_diff_norm_rb->isChecked()) { - if (triMesh) visualizeVectorFieldDifference >(triMesh, **it, **(it+1)); - else if (polyMesh) visualizeVectorFieldDifference >(polyMesh, **it, **(it+1)); - } else if (tool_->vecFieldDiff_4symm_rb->isChecked()) { - if (triMesh) visualizeVectorFieldDifference >(triMesh, **it, **(it+1)); - else if (polyMesh) visualizeVectorFieldDifference >(polyMesh, **it, **(it+1)); - } else { - emit log("This vector field difference mode is not implemented."); - } - } - } + std::sort(propList.begin(), propList.end(), PROP_INFO_TYPE_SORTER()); + std::vector::const_iterator it = + std::adjacent_find(propList.begin(), propList.end(), PROP_INFO_TYPE_EQUAL()); + + /* + * Are there two selected properties of equal vector type? + */ + if (it != propList.end()) { + if (tool_->vecFieldDiff_norm_diff_rb->isChecked()) { + if (triMesh) + visualizeVectorFieldDifference >( + triMesh, **it, **(it + 1)); + else if (polyMesh) + visualizeVectorFieldDifference >( + polyMesh, **it, **(it + 1)); + } else if (tool_->vecFieldDiff_diff_norm_rb->isChecked()) { + if (triMesh) + visualizeVectorFieldDifference >( + triMesh, **it, **(it + 1)); + else if (polyMesh) + visualizeVectorFieldDifference >( + polyMesh, **it, **(it + 1)); + } else if (tool_->vecFieldDiff_4symm_rb->isChecked()) { + if (triMesh) + visualizeVectorFieldDifference >( + triMesh, **it, **(it + 1)); + else if (polyMesh) + visualizeVectorFieldDifference >( + polyMesh, **it, **(it + 1)); + } else { + emit log("This vector field difference mode is not implemented."); + } + } + } + } catch (const VizException &e) { + QMessageBox::warning(this->tool_, trUtf8("Error in Visualization"), trUtf8(e.what()), QMessageBox::Cancel, QMessageBox::Cancel); + } - emit updatedObject( object->id(), UPDATE_COLOR ); + emit updatedObject( object->id(), UPDATE_COLOR ); } diff --git a/PropertyVisPlugin.hh b/PropertyVisPlugin.hh index d985503..3231ca4 100644 --- a/PropertyVisPlugin.hh +++ b/PropertyVisPlugin.hh @@ -83,8 +83,14 @@ #include #include +#include + //== CLASS DEFINITION ========================================================= +class VizException : public std::logic_error { + public: + VizException(const std::string &msg) : std::logic_error(msg) {} +}; class PropertyVisPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface, ScriptInterface, MouseInterface, PickingInterface, LoggingInterface, INIInterface { @@ -252,6 +258,12 @@ private: template< class MeshT > typename MeshT::Point halfedge_point(const typename MeshT::HalfedgeHandle _heh, const MeshT *_mesh); + template< class MeshT > + void visualizeVector_asStroke( MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp); + + template< class MeshT > + void visualizeVector_asColor( MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp); + template< class MeshT > void visualizeDouble( MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp); diff --git a/PropertyVisPluginT.cc b/PropertyVisPluginT.cc index 2d74c3e..7e01b3b 100644 --- a/PropertyVisPluginT.cc +++ b/PropertyVisPluginT.cc @@ -55,9 +55,60 @@ //------------------------------------------------------------------------------ -template< class MeshT > -void PropertyVisPlugin::visualizeVector( MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp) -{ +template +void PropertyVisPlugin::visualizeVector( + MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp) { + + if (tool_->vectors_strokes_rb->isChecked()) { + visualizeVector_asStroke(_mesh, currentProp); + } else if (tool_->vectors_colors_rb->isChecked()) { + visualizeVector_asColor(_mesh, currentProp); + } else { + throw VizException("Unknown vector viz mode selected."); + } +} + +namespace { + +template +void visualizeVector_asColorForEntity(MeshT *mesh, const ENTITY_IT e_begin, const ENTITY_IT e_end, + const PROPINFO_TYPE &propinfo) { + PROPTYPE prop; + if (!mesh->get_property_handle(prop, propinfo.propName())) + throw VizException("Getting PropHandle from mesh for selected property failed."); + for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) { + + typename MeshT::Point v = mesh->property(prop, e_it).normalized() * .5 + typename MeshT::Point(.5, .5, .5); + mesh->set_color(*e_it, typename MeshT::Color(v[0], v[1], v[2], 1.0)); + } +} + +} /* anonymous namespace */ + +template +void PropertyVisPlugin::visualizeVector_asColor( + MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp) { + + if (currentProp.isFaceProp()) { + visualizeVector_asColorForEntity >( + _mesh, _mesh->faces_begin(), _mesh->faces_end(), currentProp); + PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED); + } else if (currentProp.isVertexProp()) { + visualizeVector_asColorForEntity >( + _mesh, _mesh->vertices_begin(), _mesh->vertices_end(), currentProp); + PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED); + } else if (currentProp.isEdgeProp()) { + visualizeVector_asColorForEntity >( + _mesh, _mesh->edges_begin(), _mesh->edges_end(), currentProp); + PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::EDGES_COLORED); + } else { + throw VizException("PropertyVisPlugin::visualizeVector_asColor: Unknown property type."); + } +} + +template +void PropertyVisPlugin::visualizeVector_asStroke( + MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp) { //perhaps add the node diff --git a/PropertyVisToolbarBase.ui b/PropertyVisToolbarBase.ui index 50f49a5..9c21719 100644 --- a/PropertyVisToolbarBase.ui +++ b/PropertyVisToolbarBase.ui @@ -659,54 +659,92 @@ - + - Normalize + Strokes - false + true + + vector_buttonGroup + - - - - - Scale with factor - - - false - - - - - - - false - - - 7 - - - 0.200000000000000 - - - - + + + + 0 + + + 0 + + + 0 + + + + + Normalize + + + false + + + + + + + + + Scale with factor + + + false + + + + + + + false + + + 7 + + + 0.200000000000000 + + + + + + + + + Line color: + + + + 198 + 0 + 3 + + + + + + - + - Line color: - - - - 198 - 0 - 3 - + Colors + + vector_buttonGroup + @@ -1007,10 +1045,8 @@ vecFieldDiff_4symm_rb vecFieldDiff_diff_norm_rb vecFieldDiff_norm_diff_rb - normalize scale scaleBox - lineColor boneId pickButton propertyDataType @@ -1254,14 +1290,33 @@ setEnabled(bool) - 192 - 1308 + 224 + 1348 + + + 418 + 1351 + + + + + vectors_strokes_rb + toggled(bool) + vector_strokes_widget + setVisible(bool) + + + 60 + 1273 - 266 - 1307 + 29 + 1328 + + + -- GitLab