Developer Documentation
OVMPropertyModelT_impl.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 
43 
44 #define OVM_PROPERTY_MODEL_CC
45 
46 template <typename MeshT>
47 OVMPropertyModel<MeshT>::OVMPropertyModel(MeshT* mesh, int objectID, QObject *parent)
48  : OVMPropertyModelSubclass(parent),
49  mesh_(mesh),
50  objectID_(objectID),
51  mCombineProperty1(0),
52  mCombineProperty2(0)
53 {
55  bCombine.setText(tr("Combine"));
56  bCombine.hide();
57  connect(&bCombine, SIGNAL(clicked()),
58  this, SLOT(slotCombine()));
59  widgets->layout()->addWidget(&bCombine);
60 
61  widgets->layout()->addWidget(&mLoadSaveWidget);
62 
63  connect(mLoadSaveWidget.save_property , SIGNAL(clicked()),
64  this, SLOT(slotSaveProperty()));
65 
66  connect(mLoadSaveWidget.load_property , SIGNAL(clicked()),
67  this, SLOT(slotLoadProperty()));
68 
69  widgets->layout()->addWidget(&mPickWidget);
70  connect(mPickWidget.pickButton, SIGNAL(clicked()),
71  this, SLOT(slotPickProperty()));
72  mPickWidget.hide();
73  QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
74  mPickWidget.pickButton->setIcon( QIcon(iconPath + "color-picker.png") );
75 
76  lastPickMode = PluginFunctions::pickMode();
77  lastActionMode = PluginFunctions::actionMode();
78 
79  initializeSupportedPropertyTypes();
80 }
81 
82 #undef INITIALIZE_PROPTYPES
83 
84 template <typename MeshT>
85 void OVMPropertyModel<MeshT>::updateWidget(const QModelIndexList& selectedIndices)
86 {
88 
89  if (selectedIndices.size() == 2)
90  {
91  if (combinable(propertyVisualizers[selectedIndices[0].row()], propertyVisualizers[selectedIndices[1].row()]))
92  {
93 
94  bCombine.show();
95  mCombineProperty1 = &propertyVisualizers[selectedIndices[0].row()]->getPropertyInfo();
96  mCombineProperty2 = &propertyVisualizers[selectedIndices[1].row()]->getPropertyInfo();
97  }
98  else
99  bCombine.hide();
100  }
101  else
102  {
103  bCombine.hide();
104  }
105 
106  if (selectedIndices.size() == 1)
107  mPickWidget.show();
108  else
109  {
110  mPickWidget.hide();
111  //reset Picking, just if picking was enabled
112  if (mPickWidget.pickButton->isChecked())
113  resetPicking();
114  }
115 
116 }
117 
118 template <typename MeshT>
120 {
121  PluginFunctions::pickMode(lastPickMode);
122  PluginFunctions::actionMode(lastActionMode);
123 }
124 
125 
131 template <typename MeshT>
133 {
134  if ( mPickWidget.pickButton->isChecked() ){
135 
136  lastPickMode = PluginFunctions::pickMode();
137  lastActionMode = PluginFunctions::actionMode();
138 
139  PluginFunctions::pickMode(PROP_VIS);
140  PluginFunctions::actionMode(Viewer::PickingMode);
141 
142  } else {
143  resetPicking();
144  }
145 }
146 
147 template <typename MeshT>
148 void OVMPropertyModel<MeshT>::pickModeChanged(const std::string& _mode)
149 {
150  pickModeActive = (_mode == PROP_VIS);
151 
152  if (!pickModeActive)
153  {
154  lastPickMode = _mode;
155  }
156 
157  mPickWidget.pickButton->setChecked(pickModeActive);
158 }
159 
166 template <typename MeshT>
167 void OVMPropertyModel<MeshT>::mouseEvent(QMouseEvent* _event)
168 {
169  if (!pickModeActive) return;
170  if (currentlySelectedIndices.size() < 1) return;
171 
172  if (_event->type() == QEvent::MouseButtonPress)
173  {
174  size_t node_idx;
175  ACG::Vec3d hit_point;
176 
177 
178  OVMPropertyVisualizer<MeshT>* viz = dynamic_cast<OVMPropertyVisualizer<MeshT>*>(propertyVisualizers[currentlySelectedIndices.first().row()]);
179  size_t entityId = 0;
180 
181  ACG::SceneGraph::PickTarget pickTarget;
182  if (viz->getPropertyInfo().isCellProp())
183  pickTarget = ACG::SceneGraph::PICK_CELL;
184  if (viz->getPropertyInfo().isFaceProp())
185  pickTarget = ACG::SceneGraph::PICK_FACE;
186  if (viz->getPropertyInfo().isHalffaceProp())
187  pickTarget = ACG::SceneGraph::PICK_FACE;
188  if (viz->getPropertyInfo().isEdgeProp())
189  pickTarget = ACG::SceneGraph::PICK_EDGE;
190  if (viz->getPropertyInfo().isHalfedgeProp())
191  pickTarget = ACG::SceneGraph::PICK_FACE;
192  if (viz->getPropertyInfo().isVertexProp())
193  pickTarget = ACG::SceneGraph::PICK_VERTEX;
194 
195  if (PluginFunctions::scenegraphPick(pickTarget, _event->pos(),node_idx, entityId, &hit_point)) {
196  BaseObjectData* object;
197  PluginFunctions::getPickedObject(node_idx, object);
198 
199  if (object->id() == objectID_)
200  {
201  if (viz->getPropertyInfo().isHalfedgeProp() || viz->getPropertyInfo().isHalffaceProp()) //cant be picked directly
202  entityId = viz->getClosestPrimitiveId(entityId, hit_point);
203 
204  mPickWidget.pickedHandle->setText(tr("%1").arg(entityId));
205  mPickWidget.pickedValue->setText(viz->getPropertyText(entityId));
206  }
207  }
208 
209  }
210 }
211 
212 template <typename MeshT>
213 bool OVMPropertyModel<MeshT>::parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int& n)
214 {
215  QStringList headerParts = header.split(tr(", "), QString::SkipEmptyParts );
216  int headerVersion = headerParts[0].toUInt();
217  if (headerVersion == 1)
218  {
219  n = headerParts[1].toUInt();
220  unsigned int nExpected = 0;
221 
222  PropertyInfo::ENTITY_FILTER filter = (PropertyInfo::ENTITY_FILTER)headerParts[2].toInt();
223  switch (filter)
224  {
225  case PropertyInfo::EF_CELL:
226  nExpected = mesh_->n_cells();
227  break;
228  case PropertyInfo::EF_FACE:
229  nExpected = mesh_->n_faces();
230  break;
231  case PropertyInfo::EF_HALFFACE:
232  nExpected = mesh_->n_halffaces();
233  break;
234  case PropertyInfo::EF_EDGE:
235  nExpected = mesh_->n_edges();
236  break;
237  case PropertyInfo::EF_HALFEDGE:
238  nExpected = mesh_->n_halfedges();
239  break;
240  case PropertyInfo::EF_VERTEX:
241  nExpected = mesh_->n_vertices();
242  break;
243  default:
244  nExpected = -1;
245  break;
246  }
247 
248  if (n != nExpected)
249  {
250  std::cerr << "unexpected number of entities" << std::endl;
251  return false;
252  }
253 
254  QString friendlyName = headerParts[3];
255 
256  if (!isSupported(friendlyName))
257  {
258  std::cerr << "unsupported property type " << friendlyName.toStdString() << std::endl;
259  return false;
260  }
261 
262 
263  TypeInfoWrapper typeInfo = getSupportedTypeInfoWrapper(friendlyName, filter);
264 
265  QString propName = QInputDialog::getText(0, "Property Name", "Please enter name.",QLineEdit::Normal,headerParts[4]);
266  if (propName == "") return false;
267 
268  bool replace = false;
269  if (!(isPropertyFree(propName, filter, typeInfo) || replace))
270  {
271  NewNameMessageBox* msgBox = new NewNameMessageBox(propName);
272  msgBox->exec();
273 
274  if (msgBox->rename)
275  propName = QInputDialog::getText(0, "New Property Name", "Please enter new name.");
276  else if (msgBox->cancel)
277  return false;
278  else if (msgBox->replace)
279  replace = true;
280 
281  delete msgBox;
282  }
283 
284  if (!replace)
285  {
286  addProperty(propName, friendlyName, filter);
288  }
289 
290  propVis = getPropertyVisualizer(propName, filter, typeInfo);
291 
292  return true;
293 
294  }
295  else
296  {
297  std::cerr << "unsupported header format" << std::endl;
298  return false;
299  }
300 }
301 
302 
303 template<typename MeshT>
305 {
306  QString filter;
307  filter = tr("Vertex Property (*.vprop)");
308  filter += tr(";; HalfEdge Property (*.hprop)");
309  filter += tr(";; Edge Property (*.eprop)");
310  filter += tr(";; Halfface Property (*.hfprop)");
311  filter += tr(";; Face Property (*.fprop)");
312  filter += tr(";; Cell Property (*.cprop)");
313  filter += tr(";; All Files (*)");
314  return filter;
315 }
316 
317 template<typename MeshT>
319 {
320  PropertyVisualizer* propViz = propertyVisualizers[propId];
321 
322  QString filter;
323 
324  if (propViz->getPropertyInfo().isVertexProp())
325  filter = tr("Vertex Property (*.vprop)");
326  else if (propViz->getPropertyInfo().isHalfedgeProp())
327  filter = tr("HalfEdge Property (*.hprop)");
328  else if (propViz->getPropertyInfo().isEdgeProp())
329  filter = tr("Edge Property (*.eprop)");
330  else if (propViz->getPropertyInfo().isFaceProp())
331  filter = tr("Face Property (*.fprop)");
332 
333  filter += tr(";; All Files (*)");
334 
335  return filter;
336 }
337 
338 
348 template<typename MeshT>
349 bool OVMPropertyModel<MeshT>::isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
350 {
351  return getPropertyVisualizer(propName, filter, typeInfo) == 0;
352 }
353 
362 template<typename MeshT>
364 {
365  beginResetModel();
366  propertyVisualizers.push_back(new OVMPropertyVisualizerVectorFieldDifference<MeshT>(mesh_, objectID_, *mCombineProperty1, *mCombineProperty2));
367  endResetModel();
368 }
369 
370 template<typename MeshT>
372 {
373  for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
374  it != it_end; ++it) {
376  }
377 }
378 
392 template<typename MeshT>
393 bool OVMPropertyModel<MeshT>::combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2) const
394 {
395  const PropertyInfo& propInfo1 = propertyVisualizer1->getPropertyInfo();
396  const PropertyInfo& propInfo2 = propertyVisualizer2->getPropertyInfo();
397  TypeInfoWrapper typeInfo1 = propInfo1.typeinfo();
398  TypeInfoWrapper typeInfo2 = propInfo2.typeinfo();
399 
400  return (isVectorType(typeInfo1) && isVectorType(typeInfo2)) && (propInfo1.entityType() == propInfo2.entityType());
401 }
402 
403 template<typename MeshT>
405  typename MeshT::Properties::const_iterator props_first,
406  typename MeshT::Properties::const_iterator props_last,
407  PropertyInfo::ENTITY_FILTER filter)
408 {
409  for (typename MeshT::Properties::const_iterator pit = props_first; pit != props_last; ++pit) {
410  OpenVolumeMesh::BaseProperty*const baseProp = *pit;
411  if (baseProp && isSupported(baseProp) && isNew(baseProp, filter))
412  addPropertyVisualizer(baseProp, mesh, filter);
413  }
414 }
415 
416 
417 template<typename MeshT>
419 {
420  beginResetModel();
421  if (mesh_) {
422  gatherProperties(mesh_, mesh_->face_props_begin(), mesh_->face_props_end(), PropertyInfo::EF_FACE);
423  gatherProperties(mesh_, mesh_->edge_props_begin(), mesh_->edge_props_end(), PropertyInfo::EF_EDGE);
424  gatherProperties(mesh_, mesh_->halfedge_props_begin(), mesh_->halfedge_props_end(), PropertyInfo::EF_HALFEDGE);
425  gatherProperties(mesh_, mesh_->vertex_props_begin(), mesh_->vertex_props_end(), PropertyInfo::EF_VERTEX);
426  gatherProperties(mesh_, mesh_->halfface_props_begin(), mesh_->halfface_props_end(), PropertyInfo::EF_HALFFACE);
427  gatherProperties(mesh_, mesh_->cell_props_begin(), mesh_->cell_props_end(), PropertyInfo::EF_CELL);
428  }
429  endResetModel();
430 }
431 
432 
440 template<typename MeshT>
442 {
443  TypeInfoWrapper bp_type = typeid(*baseProp);
444  TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
445  return propIt != supportedPropertyTypes.end();
446 }
447 
458 template<typename MeshT>
459 bool OVMPropertyModel<MeshT>::isSupported(QString friendlyName) const
460 {
461  for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
462  it != supportedPropertyTypes.end();
463  ++it )
464  {
465  if (friendlyName.toStdString().compare(it->getName()) == 0)
466  return true;
467  }
468  return false;
469 }
470 
479 template<typename MeshT>
480 bool OVMPropertyModel<MeshT>::isNew(OpenVolumeMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter) const
481 {
482  for (unsigned int i = 0; i < propertyVisualizers.size(); ++i)
483  {
484  const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
485  if (propInfo == PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter))
486  return false;
487  }
488  return true;
489 }
490 
491 
499 template<typename MeshT>
501 {
502  TypeInfoWrapper bp_type = typeid(*baseProp);
503  TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
504  if (propIt != supportedPropertyTypes.end())
505  return *propIt;
506  else
507  {
508  std::cerr << "error" << std::endl;
509  return *propIt;
510  }
511 }
512 
521 template<typename MeshT>
522 TypeInfoWrapper OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const
523 {
524 
525  for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
526  it != supportedPropertyTypes.end();
527  ++it )
528  {
529  if ((friendlyName.toStdString().compare(it->getName()) == 0) && isEntityType(*it, filter))
530  return *it;
531  }
532  throw std::exception();
533 }
534 
535 template<typename MeshT>
537 {
538  return isBoolType(propInfo.typeinfo());
539 }
540 
541 template<typename MeshT>
543 {
544  return typeInfo == proptype_Cell_bool ||
545  typeInfo == proptype_Face_bool ||
546  typeInfo == proptype_HalfFace_bool ||
547  typeInfo == proptype_Edge_bool ||
548  typeInfo == proptype_HalfEdge_bool ||
549  typeInfo == proptype_Vertex_bool;
550 }
551 
552 template<typename MeshT>
554 {
555  return isIntType(propInfo.typeinfo());
556 }
557 
558 template<typename MeshT>
560 {
561  return typeInfo == proptype_Cell_int ||
562  typeInfo == proptype_Face_int ||
563  typeInfo == proptype_HalfFace_int ||
564  typeInfo == proptype_Edge_int ||
565  typeInfo == proptype_HalfEdge_int ||
566  typeInfo == proptype_Vertex_int;
567 }
568 
569 template<typename MeshT>
571 {
572  return isDoubleType(propInfo.typeinfo());
573 }
574 
575 template<typename MeshT>
577 {
578  return typeInfo == proptype_Cell_double ||
579  typeInfo == proptype_Face_double ||
580  typeInfo == proptype_HalfFace_double ||
581  typeInfo == proptype_Edge_double ||
582  typeInfo == proptype_HalfEdge_double ||
583  typeInfo == proptype_Vertex_double;
584 }
585 
586 template<typename MeshT>
588 {
589  return isUnsignedIntType(propInfo.typeinfo());
590 }
591 
592 template<typename MeshT>
594 {
595  return typeInfo == proptype_Cell_uint ||
596  typeInfo == proptype_Face_uint ||
597  typeInfo == proptype_HalfFace_uint ||
598  typeInfo == proptype_Edge_uint ||
599  typeInfo == proptype_HalfEdge_uint ||
600  typeInfo == proptype_Vertex_uint;
601 }
602 
603 template<typename MeshT>
605 {
606  return isVec3dType(propInfo.typeinfo());
607 }
608 
609 template<typename MeshT>
611 {
612  return typeInfo == proptype_Cell_Vec3d ||
613  typeInfo == proptype_Face_Vec3d ||
614  typeInfo == proptype_HalfFace_Vec3d ||
615  typeInfo == proptype_Edge_Vec3d ||
616  typeInfo == proptype_HalfEdge_Vec3d ||
617  typeInfo == proptype_Vertex_Vec3d;
618 }
619 
620 template<typename MeshT>
622 {
623  return isVec3fType(propInfo.typeinfo());
624 }
625 
626 template<typename MeshT>
628 {
629  return typeInfo == proptype_Cell_Vec3f ||
630  typeInfo == proptype_Face_Vec3f ||
631  typeInfo == proptype_HalfFace_Vec3f ||
632  typeInfo == proptype_Edge_Vec3f ||
633  typeInfo == proptype_HalfEdge_Vec3f ||
634  typeInfo == proptype_Vertex_Vec3f;
635 }
636 
637 template<typename MeshT>
639 {
640  return isVec3fType(propInfo) || isVec3dType(propInfo);
641 }
642 
643 template<typename MeshT>
645 {
646  return isVec3fType(typeInfo) || isVec3dType(typeInfo);
647 }
648 
649 template<typename MeshT>
651 {
652  return isMatrix3x3Type(propInfo.typeinfo());
653 }
654 
655 template<typename MeshT>
657 {
658  return typeInfo == proptype_Cell_Matrix3x3d ||
659  typeInfo == proptype_Face_Matrix3x3d ||
660  typeInfo == proptype_HalfFace_Matrix3x3d ||
661  typeInfo == proptype_Edge_Matrix3x3d ||
662  typeInfo == proptype_HalfEdge_Matrix3x3d ||
663  typeInfo == proptype_Vertex_Matrix3x3d;
664 }
665 
666 template<typename MeshT>
667 bool OVMPropertyModel<MeshT>::isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const
668 {
669  bool result = false;
670  if (entity_type & PropertyInfo::EF_CELL)
671  {
672  result |= (typeInfo == proptype_Cell_bool)
673  || (typeInfo == proptype_Cell_int)
674  || (typeInfo == proptype_Cell_double)
675  || (typeInfo == proptype_Cell_uint)
676  || (typeInfo == proptype_Cell_Vec3d)
677  || (typeInfo == proptype_Cell_Vec3f);
678  }
679  if (entity_type & PropertyInfo::EF_FACE)
680  {
681  result |= (typeInfo == proptype_Face_bool)
682  || (typeInfo == proptype_Face_int)
683  || (typeInfo == proptype_Face_double)
684  || (typeInfo == proptype_Face_uint)
685  || (typeInfo == proptype_Face_Vec3d)
686  || (typeInfo == proptype_Face_Vec3f);
687  }
688  if (entity_type & PropertyInfo::EF_HALFFACE)
689  {
690  result |= (typeInfo == proptype_HalfFace_bool)
691  || (typeInfo == proptype_HalfFace_int)
692  || (typeInfo == proptype_HalfFace_double)
693  || (typeInfo == proptype_HalfFace_uint)
694  || (typeInfo == proptype_HalfFace_Vec3d)
695  || (typeInfo == proptype_HalfFace_Vec3f);
696  }
697  if (entity_type & PropertyInfo::EF_EDGE)
698  {
699  result |= (typeInfo == proptype_Edge_bool)
700  || (typeInfo == proptype_Edge_int)
701  || (typeInfo == proptype_Edge_double)
702  || (typeInfo == proptype_Edge_uint)
703  || (typeInfo == proptype_Edge_Vec3d)
704  || (typeInfo == proptype_Edge_Vec3f);
705  }
706  if (entity_type & PropertyInfo::EF_HALFEDGE)
707  {
708  result |= (typeInfo == proptype_HalfEdge_bool)
709  || (typeInfo == proptype_HalfEdge_int)
710  || (typeInfo == proptype_HalfEdge_double)
711  || (typeInfo == proptype_HalfEdge_uint)
712  || (typeInfo == proptype_HalfEdge_Vec3d)
713  || (typeInfo == proptype_HalfEdge_Vec3f);
714  }
715  if (entity_type & PropertyInfo::EF_VERTEX)
716  {
717  result |= (typeInfo == proptype_Vertex_bool)
718  || (typeInfo == proptype_Vertex_int)
719  || (typeInfo == proptype_Vertex_double)
720  || (typeInfo == proptype_Vertex_uint)
721  || (typeInfo == proptype_Vertex_Vec3d)
722  || (typeInfo == proptype_Vertex_Vec3f);
723  }
724  return result;
725 }
726 
727 
738 template<typename MeshT>
739 void OVMPropertyModel<MeshT>::addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter)
740 {
741  PropertyInfo propInfo = PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter);
742  if (isBoolType(propInfo))
743  propertyVisualizers.push_back(new OVMPropertyVisualizerBoolean<MeshT>(mesh, objectID_, propInfo));
744  else if (isIntType(propInfo))
745  propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, int>(mesh, objectID_, propInfo, false));
746  else if (isUnsignedIntType(propInfo))
747  propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, unsigned int>(mesh, objectID_, propInfo, true));
748  else if (isDoubleType(propInfo))
749  propertyVisualizers.push_back(new OVMPropertyVisualizerDouble<MeshT>(mesh, objectID_, propInfo));
750  else if (isVectorType(propInfo))
751  propertyVisualizers.push_back(new OVMPropertyVisualizerVector<MeshT>(mesh, objectID_, propInfo));
752  else if (isMatrix3x3Type(propInfo))
753  propertyVisualizers.push_back(new OVMPropertyVisualizerMatrix3x3<MeshT>(mesh, objectID_, propInfo));
754  connectLogs(propertyVisualizers.back());
755 }
756 
767 template<typename MeshT>
768 void OVMPropertyModel<MeshT>::addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
769 {
770 
771  QString dtype = friendlyTypeName;
772  std::string pname = propName.toStdString();
773 
774  MeshT* mesh = mesh_;
775 
776  if ( filter == PropertyInfo::EF_VERTEX )
777  {
778  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
779  {
780  OpenVolumeMesh::VertexPropertyT< ACG::Vec3d > prop = mesh->template request_vertex_property< ACG::Vec3d >(pname);
781  mesh->set_persistent(prop, true);
782  }
783  else if ( dtype == tr("double") )
784  {
785  OpenVolumeMesh::VertexPropertyT< double > prop = mesh->template request_vertex_property< double >(pname);
786  mesh->set_persistent(prop, true);
787  }
788  else if ( dtype == tr("unsigned int") )
789  {
790  OpenVolumeMesh::VertexPropertyT< unsigned int > prop = mesh->template request_vertex_property< unsigned int >(pname);
791  mesh->set_persistent(prop, true);
792  }
793  else if ( dtype == tr("int") )
794  {
795  OpenVolumeMesh::VertexPropertyT< int > prop = mesh->template request_vertex_property< int >(pname);
796  mesh->set_persistent(prop, true);
797  }
798  else if ( dtype == tr("bool") )
799  {
800  OpenVolumeMesh::VertexPropertyT< bool > prop = mesh->template request_vertex_property< bool >(pname);
801  mesh->set_persistent(prop, true);
802  }
803  }
804  else if ( filter == PropertyInfo::EF_EDGE )
805  {
806  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
807  {
808  OpenVolumeMesh::EdgePropertyT< ACG::Vec3d > prop = mesh->template request_edge_property< ACG::Vec3d >(pname);
809  mesh->set_persistent(prop, true);
810  }
811  else if ( dtype == tr("double") )
812  {
813  OpenVolumeMesh::EdgePropertyT< double > prop = mesh->template request_edge_property< double >(pname);
814  mesh->set_persistent(prop, true);
815  }
816  else if ( dtype == tr("unsgined int") )
817  {
818  OpenVolumeMesh::EdgePropertyT< unsigned int > prop = mesh->template request_edge_property< unsigned int >(pname);
819  mesh->set_persistent(prop, true);
820  }
821  else if ( dtype == tr("int") )
822  {
823  OpenVolumeMesh::EdgePropertyT< int > prop = mesh->template request_edge_property< int >(pname);
824  mesh->set_persistent(prop, true);
825  }
826  else if ( dtype == tr("bool") )
827  {
828  OpenVolumeMesh::EdgePropertyT< bool > prop = mesh->template request_edge_property< bool >(pname);
829  mesh->set_persistent(prop, true);
830  }
831  }
832  else if ( filter == PropertyInfo::EF_FACE )
833  {
834  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
835  {
836  OpenVolumeMesh::FacePropertyT< ACG::Vec3d > prop = mesh->template request_face_property< ACG::Vec3d >(pname);
837  mesh->set_persistent(prop, true);
838  }
839  else if ( dtype == tr("double") )
840  {
841  OpenVolumeMesh::FacePropertyT< double > prop = mesh->template request_face_property< double >(pname);
842  mesh->set_persistent(prop, true);
843  }
844  else if ( dtype == tr("unsigned int") )
845  {
846  OpenVolumeMesh::FacePropertyT< unsigned int > prop = mesh->template request_face_property< unsigned int >(pname);
847  mesh->set_persistent(prop, true);
848  }
849  else if ( dtype == tr("int") )
850  {
851  OpenVolumeMesh::FacePropertyT< int > prop = mesh->template request_face_property< int >(pname);
852  mesh->set_persistent(prop, true);
853  }
854  else if ( dtype == tr("bool") )
855  {
856  OpenVolumeMesh::FacePropertyT< bool > prop = mesh->template request_face_property< bool >(pname);
857  mesh->set_persistent(prop, true);
858  }
859  }
860  else if ( filter == PropertyInfo::EF_HALFEDGE )
861  {
862  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
863  {
864  OpenVolumeMesh::HalfEdgePropertyT< ACG::Vec3d > prop = mesh->template request_halfedge_property< ACG::Vec3d >(pname);
865  mesh->set_persistent(prop, true);
866  }
867  else if ( dtype == tr("double") )
868  {
869  OpenVolumeMesh::HalfEdgePropertyT< double > prop = mesh->template request_halfedge_property< double >(pname);
870  mesh->set_persistent(prop, true);
871  }
872  else if ( dtype == tr("unsigned int") )
873  {
874  OpenVolumeMesh::HalfEdgePropertyT< unsigned int > prop = mesh->template request_halfedge_property< unsigned int >(pname);
875  mesh->set_persistent(prop, true);
876  }
877  else if ( dtype == tr("int") )
878  {
879  OpenVolumeMesh::HalfEdgePropertyT< int > prop = mesh->template request_halfedge_property< int >(pname);
880  mesh->set_persistent(prop, true);
881  }
882  else if ( dtype == tr("bool") )
883  {
884  OpenVolumeMesh::HalfEdgePropertyT< bool > prop = mesh->template request_halfedge_property< bool >(pname);
885  mesh->set_persistent(prop, true);
886  }
887  }
888  else if ( filter == PropertyInfo::EF_HALFFACE )
889  {
890  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
891  {
892  OpenVolumeMesh::HalfFacePropertyT< ACG::Vec3d > prop = mesh->template request_halfface_property< ACG::Vec3d >(pname);
893  mesh->set_persistent(prop, true);
894  }
895  else if ( dtype == tr("double") )
896  {
897  OpenVolumeMesh::HalfFacePropertyT< double > prop = mesh->template request_halfface_property< double >(pname);
898  mesh->set_persistent(prop, true);
899  }
900  else if ( dtype == tr("unsigned int") )
901  {
902  OpenVolumeMesh::HalfFacePropertyT< unsigned int > prop = mesh->template request_halfface_property< unsigned int >(pname);
903  mesh->set_persistent(prop, true);
904  }
905  else if ( dtype == tr("int") )
906  {
907  OpenVolumeMesh::HalfFacePropertyT< int > prop = mesh->template request_halfface_property< int >(pname);
908  mesh->set_persistent(prop, true);
909  }
910  else if ( dtype == tr("bool") )
911  {
912  OpenVolumeMesh::HalfFacePropertyT< bool > prop = mesh->template request_halfface_property< bool >(pname);
913  mesh->set_persistent(prop, true);
914  }
915  }
916  else if ( filter == PropertyInfo::EF_CELL )
917  {
918  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
919  {
920  OpenVolumeMesh::CellPropertyT< ACG::Vec3d > prop = mesh->template request_cell_property< ACG::Vec3d >(pname);
921  mesh->set_persistent(prop, true);
922  }
923  else if ( dtype == tr("double") )
924  {
925  OpenVolumeMesh::CellPropertyT< double > prop = mesh->template request_cell_property< double >(pname);
926  mesh->set_persistent(prop, true);
927  }
928  else if ( dtype == tr("unsigned int") )
929  {
930  OpenVolumeMesh::CellPropertyT< unsigned int > prop = mesh->template request_cell_property< unsigned int >(pname);
931  mesh->set_persistent(prop, true);
932  }
933  else if ( dtype == tr("int") )
934  {
935  OpenVolumeMesh::CellPropertyT< int > prop = mesh->template request_cell_property< int >(pname);
936  mesh->set_persistent(prop, true);
937  }
938  else if ( dtype == tr("bool") )
939  {
940  OpenVolumeMesh::CellPropertyT< bool > prop = mesh->template request_cell_property< bool >(pname);
941  mesh->set_persistent(prop, true);
942  }
943  }
944 
945 }
946 
947 template <typename MeshT>
949 {
950 
951 #define INSERT_PROPTYPES(primitive) \
952 supportedPropertyTypes.insert(proptype_##primitive##_bool); \
953 supportedPropertyTypes.insert(proptype_##primitive##_int); \
954 supportedPropertyTypes.insert(proptype_##primitive##_uint); \
955 supportedPropertyTypes.insert(proptype_##primitive##_double); \
956 supportedPropertyTypes.insert(proptype_##primitive##_Vec3d); \
957 supportedPropertyTypes.insert(proptype_##primitive##_Vec3f); \
958 supportedPropertyTypes.insert(proptype_##primitive##_Matrix3x3d); \
959 
960  INSERT_PROPTYPES(Cell)
961  INSERT_PROPTYPES(Face)
962  INSERT_PROPTYPES(HalfFace)
963  INSERT_PROPTYPES(Edge)
964  INSERT_PROPTYPES(HalfEdge)
965  INSERT_PROPTYPES(Vertex)
966 
967 #undef INITIALIZE_PROPTYPES
968 
969 
970 
971 }
972 
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
picks edges (may not be implemented for all nodes)
Definition: PickTarget.hh:80
virtual void pickProperty()
Toggle picking on and off.
Wraps the information of a type.
Definition: Utils.hh:73
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
virtual void mouseEvent(QMouseEvent *_event)
Handles mouse events for picking.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
Adds a new property to the mesh.
TypeInfoWrapper getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty *const baseProp) const
Returns the TypeInfoWrapper for the property if it is supported.
bool isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Checks if a property name is still available for an entity type and a property type.
void connectLogs(PropertyVisualizer *propViz) override
Connects the PropertyVisualizer log signals with the log slot.
int id() const
Definition: BaseObject.cc:190
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
virtual void pickModeChanged(const std::string &_mode)
Handles changing of pick mode.
void saveProperty(unsigned int propId)
Saves property.
virtual void saveProperty()
Saves the currently slected properties.
Asks the user how to proceed after a name clash.
Definition: Utils.hh:170
Viewer::ActionMode actionMode()
Get the current Action mode.
bool isSupported(OpenVolumeMesh::BaseProperty *const baseProp) const
Checks if visualizing this property is supported.
void addPropertyVisualizer(OpenVolumeMesh::BaseProperty *const baseProp, MeshT *mesh, PropertyInfo::ENTITY_FILTER filter)
Adds a new PropertyVisualizer.
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
Cellection of information about a property.
Definition: Utils.hh:109
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
void resetPicking()
Disables picking.
const std::string pickMode()
Get the current Picking mode.
This class vizualizes a property.
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
void gatherProperties()
Searches for all properties and creates the visualizers.
virtual void combine()
Combines two properties.
virtual void updateWidget(const QModelIndexList &selectedIndices) override
Updates the widget.
picks faces (may not be implemented for all nodes)
Definition: PickTarget.hh:76
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
bool combinable(PropertyVisualizer *propertyVisualizer1, PropertyVisualizer *propertyVisualizer2) const
Checks if two properties are combinable.
virtual QString getPropertyText(unsigned int index)=0
Returns the value of a property in text form.
bool isNew(OpenVolumeMesh::BaseProperty *const baseProp, PropertyInfo::ENTITY_FILTER filter) const
Checks if we already created a PropertyVisualizer for this property.