diff --git a/PropertyVisPlugin.cc b/PropertyVisPlugin.cc index 8dafa01bb005545d61d1f8c575069e7eefb70869..c386b57e7e0f31a33929b56bb7e4c8982e0aaa16 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<const PropertyNameListModel::PROP_INFO*> propList; + std::vector<const PropertyNameListModel::PROP_INFO*> 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 PropertyNameListModel::PROP_INFO*>::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, scalarFn_norm_of_diff<TriMesh> >(triMesh, **it, **(it+1)); - else if (polyMesh) visualizeVectorFieldDifference<PolyMesh, scalarFn_norm_of_diff<PolyMesh> >(polyMesh, **it, **(it+1)); - } else if (tool_->vecFieldDiff_diff_norm_rb->isChecked()) { - if (triMesh) visualizeVectorFieldDifference<TriMesh, scalarFn_diff_of_norms<TriMesh> >(triMesh, **it, **(it+1)); - else if (polyMesh) visualizeVectorFieldDifference<PolyMesh, scalarFn_diff_of_norms<PolyMesh> >(polyMesh, **it, **(it+1)); - } else if (tool_->vecFieldDiff_4symm_rb->isChecked()) { - if (triMesh) visualizeVectorFieldDifference<TriMesh, scalarFn_4_symm_diff<TriMesh> >(triMesh, **it, **(it+1)); - else if (polyMesh) visualizeVectorFieldDifference<PolyMesh, scalarFn_4_symm_diff<PolyMesh> >(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 PropertyNameListModel::PROP_INFO*>::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, scalarFn_norm_of_diff<TriMesh> >( + triMesh, **it, **(it + 1)); + else if (polyMesh) + visualizeVectorFieldDifference<PolyMesh, scalarFn_norm_of_diff<PolyMesh> >( + polyMesh, **it, **(it + 1)); + } else if (tool_->vecFieldDiff_diff_norm_rb->isChecked()) { + if (triMesh) + visualizeVectorFieldDifference<TriMesh, scalarFn_diff_of_norms<TriMesh> >( + triMesh, **it, **(it + 1)); + else if (polyMesh) + visualizeVectorFieldDifference<PolyMesh, scalarFn_diff_of_norms<PolyMesh> >( + polyMesh, **it, **(it + 1)); + } else if (tool_->vecFieldDiff_4symm_rb->isChecked()) { + if (triMesh) + visualizeVectorFieldDifference<TriMesh, scalarFn_4_symm_diff<TriMesh> >( + triMesh, **it, **(it + 1)); + else if (polyMesh) + visualizeVectorFieldDifference<PolyMesh, scalarFn_4_symm_diff<PolyMesh> >( + 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 d985503a67f96b05d82ffdacee57854221bdedfb..3231ca4c70671c5aefb975f5ed3871c507166e85 100644 --- a/PropertyVisPlugin.hh +++ b/PropertyVisPlugin.hh @@ -83,8 +83,14 @@ #include <ACG/Scenegraph/LineNode.hh> #include <ACG/Utils/ColorGenerator.hh> +#include <stdexcept> + //== 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 2d74c3ec4d111626aa20c6b214d1b67beca1b813..7e01b3b39acfe31af7869e3ea0bd1384406de45c 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<class MeshT> +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<typename PROPTYPE, typename MeshT, typename ENTITY_IT, typename PROPINFO_TYPE> +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<class MeshT> +void PropertyVisPlugin::visualizeVector_asColor( + MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp) { + + if (currentProp.isFaceProp()) { + visualizeVector_asColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >( + _mesh, _mesh->faces_begin(), _mesh->faces_end(), currentProp); + PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED); + } else if (currentProp.isVertexProp()) { + visualizeVector_asColorForEntity<OpenMesh::VPropHandleT<typename MeshT::Point> >( + _mesh, _mesh->vertices_begin(), _mesh->vertices_end(), currentProp); + PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED); + } else if (currentProp.isEdgeProp()) { + visualizeVector_asColorForEntity<OpenMesh::EPropHandleT<typename MeshT::Point> >( + _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<class MeshT> +void PropertyVisPlugin::visualizeVector_asStroke( + MeshT* _mesh, const PropertyNameListModel::PROP_INFO ¤tProp) { //perhaps add the node diff --git a/PropertyVisToolbarBase.ui b/PropertyVisToolbarBase.ui index 50f49a56092eb5a456e86523331bc37fbb967456..9c217192be13b4c3a13773426afccc5df222f4ef 100644 --- a/PropertyVisToolbarBase.ui +++ b/PropertyVisToolbarBase.ui @@ -659,54 +659,92 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QCheckBox" name="normalize"> + <widget class="QRadioButton" name="vectors_strokes_rb"> <property name="text"> - <string>Normalize</string> + <string>Strokes</string> </property> <property name="checked"> - <bool>false</bool> + <bool>true</bool> </property> + <attribute name="buttonGroup"> + <string>vector_buttonGroup</string> + </attribute> </widget> </item> <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QCheckBox" name="scale"> - <property name="text"> - <string>Scale with factor</string> - </property> - <property name="checked"> - <bool>false</bool> - </property> - </widget> - </item> - <item> - <widget class="QDoubleSpinBox" name="scaleBox"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="decimals"> - <number>7</number> - </property> - <property name="value"> - <double>0.200000000000000</double> - </property> - </widget> - </item> - </layout> + <widget class="QWidget" name="vector_strokes_widget" native="true"> + <layout class="QVBoxLayout" name="verticalLayout_11"> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <widget class="QCheckBox" name="normalize"> + <property name="text"> + <string>Normalize</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QCheckBox" name="scale"> + <property name="text"> + <string>Scale with factor</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QDoubleSpinBox" name="scaleBox"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="decimals"> + <number>7</number> + </property> + <property name="value"> + <double>0.200000000000000</double> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QtColorChooserButton" name="lineColor"> + <property name="text"> + <string>Line color: </string> + </property> + <property name="color" stdset="0"> + <color> + <red>198</red> + <green>0</green> + <blue>3</blue> + </color> + </property> + </widget> + </item> + </layout> + </widget> </item> <item> - <widget class="QtColorChooserButton" name="lineColor"> + <widget class="QRadioButton" name="vectors_colors_rb"> <property name="text"> - <string>Line color: </string> - </property> - <property name="color" stdset="0"> - <color> - <red>198</red> - <green>0</green> - <blue>3</blue> - </color> + <string>Colors</string> </property> + <attribute name="buttonGroup"> + <string>vector_buttonGroup</string> + </attribute> </widget> </item> </layout> @@ -1007,10 +1045,8 @@ <tabstop>vecFieldDiff_4symm_rb</tabstop> <tabstop>vecFieldDiff_diff_norm_rb</tabstop> <tabstop>vecFieldDiff_norm_diff_rb</tabstop> - <tabstop>normalize</tabstop> <tabstop>scale</tabstop> <tabstop>scaleBox</tabstop> - <tabstop>lineColor</tabstop> <tabstop>boneId</tabstop> <tabstop>pickButton</tabstop> <tabstop>propertyDataType</tabstop> @@ -1254,14 +1290,33 @@ <slot>setEnabled(bool)</slot> <hints> <hint type="sourcelabel"> - <x>192</x> - <y>1308</y> + <x>224</x> + <y>1348</y> + </hint> + <hint type="destinationlabel"> + <x>418</x> + <y>1351</y> + </hint> + </hints> + </connection> + <connection> + <sender>vectors_strokes_rb</sender> + <signal>toggled(bool)</signal> + <receiver>vector_strokes_widget</receiver> + <slot>setVisible(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>60</x> + <y>1273</y> </hint> <hint type="destinationlabel"> - <x>266</x> - <y>1307</y> + <x>29</x> + <y>1328</y> </hint> </hints> </connection> </connections> + <buttongroups> + <buttongroup name="vector_buttonGroup"/> + </buttongroups> </ui>