44 #define OM_PROPERTY_MODEL_CC 46 #include "OMPropertyModel.hh" 48 #include "OMPropertyVisualizerBoolean.hh" 49 #include "OMPropertyVisualizerDouble.hh" 50 #include "OMPropertyVisualizerInteger.hh" 51 #include "OMPropertyVisualizerVector.hh" 52 #include "OMPropertyVisualizerVector2.hh" 53 #include "OMPropertyVisualizerVectorFieldDifference.hh" 55 #ifdef ENABLE_SKELETON_SUPPORT 56 #include "OMPropertyVisualizerSkinWeights.hh" 59 #include "../Utils.hh" 63 #include <QInputDialog> 64 #include <QTextStream> 66 #define PROP_VIS "PropertyVisualization" 68 template<
typename MeshT>
78 bCombine.setText(tr(
"Combine"));
80 connect(&bCombine, SIGNAL(clicked()),
81 this, SLOT(slotCombine()));
82 widgets->layout()->addWidget(&bCombine);
83 widgets->layout()->addWidget(&mLoadSaveWidget);
85 connect(mLoadSaveWidget.save_property , SIGNAL(clicked()),
86 this, SLOT(slotSaveProperty()));
88 connect(mLoadSaveWidget.load_property , SIGNAL(clicked()),
89 this, SLOT(slotLoadProperty()));
91 widgets->layout()->addWidget(&mPickWidget);
92 connect(mPickWidget.pickButton, SIGNAL(clicked()),
93 this, SLOT(slotPickProperty()));
95 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
96 mPickWidget.pickButton->setIcon( QIcon(iconPath +
"color-picker.png") );
102 initializeSupportedPropertyTypes();
106 template<
typename MeshT>
111 if (selectedIndices.size() == 2)
113 if (combinable(propertyVisualizers[selectedIndices[0].row()], propertyVisualizers[selectedIndices[1].row()]))
117 mCombineProperty1 = &propertyVisualizers[selectedIndices[0].row()]->getPropertyInfo();
118 mCombineProperty2 = &propertyVisualizers[selectedIndices[1].row()]->getPropertyInfo();
126 if (selectedIndices.size() == 1)
132 if (mPickWidget.pickButton->isChecked())
137 template<
typename MeshT>
141 filter = tr(
"Vertex Property (*.vprop)");
142 filter += tr(
";; HalfEdge Property (*.hprop)");
143 filter += tr(
";; Edge Property (*.eprop)");
144 filter += tr(
";; Face Property (*.fprop)");
145 filter += tr(
";; All Files (*)");
149 template<
typename MeshT>
157 filter = tr(
"Vertex Property (*.vprop)");
159 filter = tr(
"HalfEdge Property (*.hprop)");
161 filter = tr(
"Edge Property (*.eprop)");
163 filter = tr(
"Face Property (*.fprop)");
165 filter += tr(
";; All Files (*)");
178 template<
typename MeshT>
182 if (isVectorType(mCombineProperty1->typeinfo()))
200 template<
typename MeshT>
208 return (isVectorType(typeInfo1) && isVectorType(typeInfo2)) && (propInfo1.entityType() == propInfo2.entityType());
211 template<
typename MeshT>
214 for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
215 it != it_end; ++it) {
220 template<
typename MeshT>
223 QStringList headerParts = header.split(tr(
", "), QString::SkipEmptyParts );
224 int headerVersion = headerParts[0].toUInt();
225 if (headerVersion == 1)
227 n = headerParts[1].toUInt();
228 unsigned int nExpected = 0;
230 PropertyInfo::ENTITY_FILTER filter = (PropertyInfo::ENTITY_FILTER)headerParts[2].toInt();
233 case PropertyInfo::EF_FACE:
234 nExpected = mesh_->n_faces();
236 case PropertyInfo::EF_EDGE:
237 nExpected = mesh_->n_edges();
239 case PropertyInfo::EF_HALFEDGE:
240 nExpected = mesh_->n_halfedges();
242 case PropertyInfo::EF_VERTEX:
243 nExpected = mesh_->n_vertices();
252 emit log(
LOGERR,
"Could not load property: unexpected number of entities");
256 QString friendlyName = headerParts[3];
258 if (!isSupported(friendlyName))
260 emit log(
LOGERR, tr(
"Could not load property: unsupported property type %1").arg(friendlyName));
266 QString propName = QInputDialog::getText(0,
"Property Name",
"Please enter name.",QLineEdit::Normal,headerParts[4]);
267 if (propName ==
"")
return false;
269 bool replace =
false;
276 propName = QInputDialog::getText(0,
"New Property Name",
"Please enter new name.");
277 else if (msgBox->cancel)
279 else if (msgBox->replace)
287 addProperty(propName, friendlyName, filter);
298 emit log(
LOGERR,
"Could not load property: unsupported header format");
304 template<
typename MeshT>
307 #ifdef ENABLE_SKELETON_SUPPORT 310 for (
unsigned int i = 0; i < n; ++i)
312 QString propertyText =
"";
314 while ((tmp = file_stream.readLine()) !=
"")
315 propertyText = propertyText + tmp;
326 template<
typename MeshT>
339 template<
typename MeshT>
342 if ( mPickWidget.pickButton->isChecked() ){
356 template<
typename MeshT>
359 pickModeActive = (_mode == PROP_VIS);
363 lastPickMode = _mode;
366 mPickWidget.pickButton->setChecked(pickModeActive);
375 template<
typename MeshT>
378 if (!pickModeActive)
return;
380 if (_event->type() == QEvent::MouseButtonPress)
382 size_t node_idx, face_idx;
389 if (object->
id() == objectID_ && !currentlySelectedIndices.empty())
393 mPickWidget.pickedHandle->setText(tr(
"%1").arg(primitiveId));
400 template<
typename MeshT>
403 return (typeInfo == proptype_Vec3f) || (typeInfo == proptype_Vec3d);
406 template<
typename MeshT>
408 typename MeshT::prop_iterator props_first,
409 typename MeshT::prop_iterator props_last,
410 PropertyInfo::ENTITY_FILTER filter)
412 for (
typename MeshT::prop_iterator pit = props_first; pit != props_last; ++pit) {
414 if (baseProp && isSupported(baseProp) && isNew(baseProp, filter))
415 addPropertyVisualizer(baseProp, mesh, filter);
419 template<
typename MeshT>
424 gatherProperties(mesh_, mesh_->fprops_begin(), mesh_->fprops_end(), PropertyInfo::EF_FACE);
425 gatherProperties(mesh_, mesh_->eprops_begin(), mesh_->eprops_end(), PropertyInfo::EF_EDGE);
426 gatherProperties(mesh_, mesh_->hprops_begin(), mesh_->hprops_end(), PropertyInfo::EF_HALFEDGE);
427 gatherProperties(mesh_, mesh_->vprops_begin(), mesh_->vprops_end(), PropertyInfo::EF_VERTEX);
440 template<
typename MeshT>
444 TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
445 return propIt != supportedPropertyTypes.end();
458 template<
typename MeshT>
461 for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
462 it != supportedPropertyTypes.end();
465 if (friendlyName.toStdString().compare(it->getName()) == 0)
479 template<
typename MeshT>
482 for (
unsigned int i = 0; i < propertyVisualizers.size(); ++i)
484 const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
485 if (propInfo ==
PropertyInfo(baseProp->
name(), getSupportedTypeInfoWrapper(baseProp) , filter))
498 template<
typename MeshT>
502 TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
513 template<
typename MeshT>
516 for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
517 it != supportedPropertyTypes.end();
520 if (friendlyName.toStdString().compare(it->getName()) == 0)
523 throw std::exception();
537 template<
typename MeshT>
541 if (propInfo.typeinfo() == proptype_bool)
543 else if (propInfo.typeinfo() == proptype_int)
545 else if (propInfo.typeinfo() == proptype_uint)
547 else if (propInfo.typeinfo() == proptype_uint8_t)
549 else if (propInfo.typeinfo() == proptype_double)
551 else if ((propInfo.typeinfo() == proptype_Vec3d) || (propInfo.typeinfo() == proptype_Vec3f))
553 else if ((propInfo.typeinfo() == proptype_Vec2d))
555 else if ((propInfo.typeinfo() == proptype_Vec2f))
557 #ifdef ENABLE_SKELETON_SUPPORT 558 else if (propInfo.typeinfo() == proptype_SkinWeights)
559 propertyVisualizers.push_back(
new OMPropertyVisualizerSkinWeights<MeshT>(mesh, objectID_, propInfo));
574 template<
typename MeshT>
578 QString dtype = friendlyTypeName;
579 QString pname = propName;
583 if ( filter == PropertyInfo::EF_VERTEX )
585 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
588 mesh->add_property(prop, pname.toStdString());
590 else if (dtype == tr(
"Vec2d"))
593 mesh->add_property(prop, pname.toStdString());
595 else if (dtype == tr(
"Vec2f"))
598 mesh->add_property(prop, pname.toStdString());
600 else if ( dtype == tr(
"double") )
603 mesh->add_property(prop, pname.toStdString());
605 else if ( dtype == tr(
"unsigned int") )
608 mesh->add_property(prop, pname.toStdString());
610 else if ( dtype == tr(
"uint8_t") )
613 mesh->add_property(prop, pname.toStdString());
615 else if ( dtype == tr(
"int") )
618 mesh->add_property(prop, pname.toStdString());
620 else if ( dtype == tr(
"bool") )
623 mesh->add_property(prop, pname.toStdString());
627 #ifdef ENABLE_SKELETON_SUPPORT 628 else if ( dtype == tr(
"SkinWeights") )
631 mesh->add_property(prop, pname.toStdString());
635 else if ( filter == PropertyInfo::EF_EDGE )
637 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
640 mesh->add_property(prop, pname.toStdString());
642 else if ( dtype == tr(
"Vec2d") )
645 mesh->add_property(prop, pname.toStdString());
647 else if ( dtype == tr(
"Vec2f") )
650 mesh->add_property(prop, pname.toStdString());
652 else if ( dtype == tr(
"double") )
655 mesh->add_property(prop, pname.toStdString());
657 else if ( dtype == tr(
"unsgined int") )
660 mesh->add_property(prop, pname.toStdString());
662 else if ( dtype == tr(
"uint8_t") )
665 mesh->add_property(prop, pname.toStdString());
667 else if ( dtype == tr(
"int") )
670 mesh->add_property(prop, pname.toStdString());
672 else if ( dtype == tr(
"bool") )
675 mesh->add_property(prop, pname.toStdString());
678 else if ( filter == PropertyInfo::EF_FACE )
680 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
683 mesh->add_property(prop, pname.toStdString());
685 else if ( dtype == tr(
"Vec2d") )
688 mesh->add_property(prop, pname.toStdString());
690 else if ( dtype == tr(
"Vec2f") )
693 mesh->add_property(prop, pname.toStdString());
695 else if ( dtype == tr(
"double") )
698 mesh->add_property(prop, pname.toStdString());
700 else if ( dtype == tr(
"unsigned int") )
703 mesh->add_property(prop, pname.toStdString());
705 else if ( dtype == tr(
"uint8_t") )
708 mesh->add_property(prop, pname.toStdString());
710 else if ( dtype == tr(
"int") )
713 mesh->add_property(prop, pname.toStdString());
715 else if ( dtype == tr(
"bool") )
718 mesh->add_property(prop, pname.toStdString());
721 else if ( filter == PropertyInfo::EF_HALFEDGE )
723 if ( (dtype == tr(
"Vec3d")) || (dtype == tr(
"Vec3f")) )
726 mesh->add_property(prop, pname.toStdString());
728 else if ( dtype == tr(
"double") )
731 mesh->add_property(prop, pname.toStdString());
733 else if ( dtype == tr(
"unsigned int") )
736 mesh->add_property(prop, pname.toStdString());
738 else if ( dtype == tr(
"uint8_t") )
741 mesh->add_property(prop, pname.toStdString());
743 else if ( dtype == tr(
"int") )
746 mesh->add_property(prop, pname.toStdString());
748 else if ( dtype == tr(
"bool") )
751 mesh->add_property(prop, pname.toStdString());
758 template<
typename MeshT>
763 supportedPropertyTypes.insert(proptype_bool);
764 supportedPropertyTypes.insert(proptype_int);
765 supportedPropertyTypes.insert(proptype_uint);
766 supportedPropertyTypes.insert(proptype_uint8_t);
767 supportedPropertyTypes.insert(proptype_double);
768 supportedPropertyTypes.insert(proptype_Vec3d);
769 supportedPropertyTypes.insert(proptype_Vec3f);
770 supportedPropertyTypes.insert(proptype_Vec2d);
771 supportedPropertyTypes.insert(proptype_Vec2f);
773 #ifdef ENABLE_SKELETON_SUPPORT 774 supportedPropertyTypes.insert(proptype_SkinWeights);
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
Adds a new property to the mesh.
Asks the user how to proceed after a name clash.
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
bool isNew(OpenMesh::BaseProperty *const baseProp, PropertyInfo::ENTITY_FILTER filter)
Checks if we already created a PropertyVisualizer for this property.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
virtual void pickProperty()
Toggle picking on and off.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
bool isSupported(OpenMesh::BaseProperty *const baseProp) const
Checks if visualizing this property is supported.
const std::string & name() const
Return the name of the property.
Wraps the information of a type.
Added for signal/slot support.
bool combinable(PropertyVisualizer *propertyVisualizer1, PropertyVisualizer *propertyVisualizer2)
Checks if two properties are combinable.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
virtual void pickModeChanged(const std::string &_mode)
Handles changing of pick mode.
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
void gatherProperties()
Searches for all properties and creates the visualizers.
void addPropertyVisualizer(OpenMesh::BaseProperty *const baseProp, MeshT *mesh, PropertyInfo::ENTITY_FILTER filter)
Adds a new PropertyVisualizer.
virtual void gatherProperties()
Searches for properties and creates PropertyVisualizers.
void resetPicking()
Disables picking.
virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
This class vizualizes a property.
virtual void mouseEvent(QMouseEvent *_event)
Handles mouse events for picking.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if the property name is still available.
void saveProperty(unsigned int propId)
Saves property.
TypeInfoWrapper getSupportedTypeInfoWrapper(OpenMesh::BaseProperty *const baseProp)
Returns the TypeInfoWrapper for the property if it is supported.
virtual void saveProperty()
Saves the currently slected properties.
picks faces (should be implemented for all nodes)
virtual void combine()
Combines two properties.
Viewer::ActionMode actionMode()
Get the current Action mode.
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
Cellection of information about a property.
virtual void setPropertyFromFile(QTextStream &file_stream, unsigned int n, PropertyVisualizer *propVis)
Sets the property values from a given file.
const std::string pickMode()
Get the current Picking mode.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.