Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OVMPropertyModelT.cc
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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
51 
52 #define OVM_PROPERTY_MODEL_CC
53 
54 #include "OVMPropertyModel.hh"
55 
56 
57 template <typename MeshT>
58 OVMPropertyModel<MeshT>::OVMPropertyModel(MeshT* mesh, int objectID, QObject *parent)
59  : OVMPropertyModelSubclass(parent),
60  mesh_(mesh),
61  objectID_(objectID),
62  mCombineProperty1(0),
63  mCombineProperty2(0)
64 {
65  gatherProperties();
66  bCombine.setText(tr("Combine"));
67  bCombine.hide();
68  connect(&bCombine, SIGNAL(clicked()),
69  this, SLOT(slotCombine()));
70  widgets->layout()->addWidget(&bCombine);
71 
72  widgets->layout()->addWidget(&mLoadSaveWidget);
73 
74  connect(mLoadSaveWidget.save_property , SIGNAL(clicked()),
75  this, SLOT(slotSaveProperty()));
76 
77  connect(mLoadSaveWidget.load_property , SIGNAL(clicked()),
78  this, SLOT(slotLoadProperty()));
79 
80  widgets->layout()->addWidget(&mPickWidget);
81  connect(mPickWidget.pickButton, SIGNAL(clicked()),
82  this, SLOT(slotPickProperty()));
83  mPickWidget.hide();
84  QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
85  mPickWidget.pickButton->setIcon( QIcon(iconPath + "color-picker.png") );
86 
87  lastPickMode = PluginFunctions::pickMode();
88  lastActionMode = PluginFunctions::actionMode();
89 
90  initializeSupportedPropertyTypes();
91 }
92 
93 #undef INITIALIZE_PROPTYPES
94 
95 template <typename MeshT>
96 void OVMPropertyModel<MeshT>::updateWidget(const QModelIndexList& selectedIndices)
97 {
99 
100  if (selectedIndices.size() == 2)
101  {
102  if (combinable(propertyVisualizers[selectedIndices[0].row()], propertyVisualizers[selectedIndices[1].row()]))
103  {
104 
105  bCombine.show();
106  mCombineProperty1 = &propertyVisualizers[selectedIndices[0].row()]->getPropertyInfo();
107  mCombineProperty2 = &propertyVisualizers[selectedIndices[1].row()]->getPropertyInfo();
108  }
109  else
110  bCombine.hide();
111  }
112  else
113  {
114  bCombine.hide();
115  }
116 
117  if (selectedIndices.size() == 1)
118  mPickWidget.show();
119  else
120  {
121  mPickWidget.hide();
122  //reset Picking, just if picking was enabled
123  if (mPickWidget.pickButton->isChecked())
124  resetPicking();
125  }
126 
127 }
128 
129 template <typename MeshT>
130 void OVMPropertyModel<MeshT>::resetPicking()
131 {
132  PluginFunctions::pickMode(lastPickMode);
133  PluginFunctions::actionMode(lastActionMode);
134 }
135 
136 
142 template <typename MeshT>
143 void OVMPropertyModel<MeshT>::pickProperty()
144 {
145  if ( mPickWidget.pickButton->isChecked() ){
146 
147  lastPickMode = PluginFunctions::pickMode();
148  lastActionMode = PluginFunctions::actionMode();
149 
150  PluginFunctions::pickMode(PROP_VIS);
151  PluginFunctions::actionMode(Viewer::PickingMode);
152 
153  } else {
154  resetPicking();
155  }
156 }
157 
158 template <typename MeshT>
159 void OVMPropertyModel<MeshT>::pickModeChanged(const std::string& _mode)
160 {
161  pickModeActive = (_mode == PROP_VIS);
162 
163  if (!pickModeActive)
164  {
165  lastPickMode = _mode;
166  }
167 
168  mPickWidget.pickButton->setChecked(pickModeActive);
169 }
170 
177 template <typename MeshT>
178 void OVMPropertyModel<MeshT>::mouseEvent(QMouseEvent* _event)
179 {
180  if (!pickModeActive) return;
181  if (currentlySelectedIndices.size() < 1) return;
182 
183  if (_event->type() == QEvent::MouseButtonPress)
184  {
185  unsigned int node_idx;
186  ACG::Vec3d hit_point;
187 
188 
189  OVMPropertyVisualizer<MeshT>* viz = dynamic_cast<OVMPropertyVisualizer<MeshT>*>(propertyVisualizers[currentlySelectedIndices.first().row()]);
190  unsigned int entityId = 0;
191 
192  ACG::SceneGraph::PickTarget pickTarget;
193  if (viz->getPropertyInfo().isCellProp())
194  pickTarget = ACG::SceneGraph::PICK_CELL;
195  if (viz->getPropertyInfo().isFaceProp())
196  pickTarget = ACG::SceneGraph::PICK_FACE;
197  if (viz->getPropertyInfo().isHalffaceProp())
198  pickTarget = ACG::SceneGraph::PICK_FACE;
199  if (viz->getPropertyInfo().isEdgeProp())
200  pickTarget = ACG::SceneGraph::PICK_EDGE;
201  if (viz->getPropertyInfo().isHalfedgeProp())
202  pickTarget = ACG::SceneGraph::PICK_FACE;
203  if (viz->getPropertyInfo().isVertexProp())
204  pickTarget = ACG::SceneGraph::PICK_VERTEX;
205 
206  if (PluginFunctions::scenegraphPick(pickTarget, _event->pos(),node_idx, entityId, &hit_point)) {
207  BaseObjectData* object;
208  PluginFunctions::getPickedObject(node_idx, object);
209 
210  if (object->id() == objectID_)
211  {
212  if (viz->getPropertyInfo().isHalfedgeProp() || viz->getPropertyInfo().isHalffaceProp()) //cant be picked directly
213  entityId = viz->getClosestPrimitiveId(entityId, hit_point);
214 
215  mPickWidget.pickedHandle->setText(tr("%1").arg(entityId));
216  mPickWidget.pickedValue->setText(viz->getPropertyText(entityId));
217  }
218  }
219 
220  }
221 }
222 
223 template <typename MeshT>
224 bool OVMPropertyModel<MeshT>::parseHeader(QString header, PropertyVisualizer*& propVis, unsigned int& n)
225 {
226  QStringList headerParts = header.split(tr(", "), QString::SkipEmptyParts );
227  int headerVersion = headerParts[0].toUInt();
228  if (headerVersion == 1)
229  {
230  n = headerParts[1].toUInt();
231  unsigned int nExpected = 0;
232 
233  PropertyInfo::ENTITY_FILTER filter = (PropertyInfo::ENTITY_FILTER)headerParts[2].toInt();
234  switch (filter)
235  {
236  case PropertyInfo::EF_CELL:
237  nExpected = mesh_->n_cells();
238  break;
239  case PropertyInfo::EF_FACE:
240  nExpected = mesh_->n_faces();
241  break;
242  case PropertyInfo::EF_HALFFACE:
243  nExpected = mesh_->n_halffaces();
244  break;
245  case PropertyInfo::EF_EDGE:
246  nExpected = mesh_->n_edges();
247  break;
248  case PropertyInfo::EF_HALFEDGE:
249  nExpected = mesh_->n_halfedges();
250  break;
251  case PropertyInfo::EF_VERTEX:
252  nExpected = mesh_->n_vertices();
253  break;
254  default:
255  nExpected = -1;
256  break;
257  }
258 
259  if (n != nExpected)
260  {
261  std::cerr << "unexpected number of entities" << std::endl;
262  return false;
263  }
264 
265  QString friendlyName = headerParts[3];
266 
267  if (!isSupported(friendlyName))
268  {
269  std::cerr << "unsupported property type " << friendlyName.toStdString() << std::endl;
270  return false;
271  }
272 
273 
274  TypeInfoWrapper typeInfo = getSupportedTypeInfoWrapper(friendlyName, filter);
275 
276  QString propName = QInputDialog::getText(0, "Property Name", "Please enter name.",QLineEdit::Normal,headerParts[4]);
277  if (propName == "") return false;
278 
279  bool replace = false;
280  if (!(isPropertyFree(propName, filter, typeInfo) || replace))
281  {
282  NewNameMessageBox* msgBox = new NewNameMessageBox(propName);
283  msgBox->exec();
284 
285  if (msgBox->rename)
286  propName = QInputDialog::getText(0, "New Property Name", "Please enter new name.");
287  else if (msgBox->cancel)
288  return false;
289  else if (msgBox->replace)
290  replace = true;
291 
292  delete msgBox;
293  }
294 
295  if (!replace)
296  {
297  addProperty(propName, friendlyName, filter);
298  gatherProperties();
299  }
300 
301  propVis = getPropertyVisualizer(propName, filter, typeInfo);
302 
303  return true;
304 
305  }
306  else
307  {
308  std::cerr << "unsupported header format" << std::endl;
309  return false;
310  }
311 }
312 
313 
314 template<typename MeshT>
315 QString OVMPropertyModel<MeshT>::getLoadFilenameFilter()
316 {
317  QString filter;
318  filter = tr("Vertex Property (*.vprop)");
319  filter += tr(";; HalfEdge Property (*.hprop)");
320  filter += tr(";; Edge Property (*.eprop)");
321  filter += tr(";; Halfface Property (*.hfprop)");
322  filter += tr(";; Face Property (*.fprop)");
323  filter += tr(";; Cell Property (*.cprop)");
324  filter += tr(";; All Files (*)");
325  return filter;
326 }
327 
328 template<typename MeshT>
329 QString OVMPropertyModel<MeshT>::getSaveFilenameFilter(unsigned int propId)
330 {
331  PropertyVisualizer* propViz = propertyVisualizers[propId];
332 
333  QString filter;
334 
335  if (propViz->getPropertyInfo().isVertexProp())
336  filter = tr("Vertex Property (*.vprop)");
337  else if (propViz->getPropertyInfo().isHalfedgeProp())
338  filter = tr("HalfEdge Property (*.hprop)");
339  else if (propViz->getPropertyInfo().isEdgeProp())
340  filter = tr("Edge Property (*.eprop)");
341  else if (propViz->getPropertyInfo().isFaceProp())
342  filter = tr("Face Property (*.fprop)");
343 
344  filter += tr(";; All Files (*)");
345 
346  return filter;
347 }
348 
349 
359 template<typename MeshT>
360 bool OVMPropertyModel<MeshT>::isPropertyFree(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
361 {
362  return getPropertyVisualizer(propName, filter, typeInfo) == 0;
363 }
364 
373 template<typename MeshT>
374 void OVMPropertyModel<MeshT>::combine()
375 {
376  beginResetModel();
377  propertyVisualizers.push_back(new OVMPropertyVisualizerVectorFieldDifference<MeshT>(mesh_, objectID_, *mCombineProperty1, *mCombineProperty2));
378  endResetModel();
379 }
380 
381 template<typename MeshT>
382 void OVMPropertyModel<MeshT>::saveProperty()
383 {
384  for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
385  it != it_end; ++it) {
387  }
388 }
389 
403 template<typename MeshT>
404 bool OVMPropertyModel<MeshT>::combinable(PropertyVisualizer* propertyVisualizer1, PropertyVisualizer* propertyVisualizer2) const
405 {
406  const PropertyInfo& propInfo1 = propertyVisualizer1->getPropertyInfo();
407  const PropertyInfo& propInfo2 = propertyVisualizer2->getPropertyInfo();
408  TypeInfoWrapper typeInfo1 = propInfo1.typeinfo();
409  TypeInfoWrapper typeInfo2 = propInfo2.typeinfo();
410 
411  return (isVectorType(typeInfo1) && isVectorType(typeInfo2)) && (propInfo1.entityType() == propInfo2.entityType());
412 }
413 
414 template<typename MeshT>
415 void OVMPropertyModel<MeshT>::gatherProperties( MeshT* mesh,
416  typename MeshT::Properties::const_iterator props_first,
417  typename MeshT::Properties::const_iterator props_last,
418  PropertyInfo::ENTITY_FILTER filter)
419 {
420  for (typename MeshT::Properties::const_iterator pit = props_first; pit != props_last; ++pit) {
421  OpenVolumeMesh::BaseProperty*const baseProp = *pit;
422  if (baseProp && isSupported(baseProp) && isNew(baseProp, filter))
423  addPropertyVisualizer(baseProp, mesh, filter);
424  }
425 }
426 
427 
428 template<typename MeshT>
429 void OVMPropertyModel<MeshT>::gatherProperties()
430 {
431  beginResetModel();
432  if (mesh_) {
433  gatherProperties(mesh_, mesh_->face_props_begin(), mesh_->face_props_end(), PropertyInfo::EF_FACE);
434  gatherProperties(mesh_, mesh_->edge_props_begin(), mesh_->edge_props_end(), PropertyInfo::EF_EDGE);
435  gatherProperties(mesh_, mesh_->halfedge_props_begin(), mesh_->halfedge_props_end(), PropertyInfo::EF_HALFEDGE);
436  gatherProperties(mesh_, mesh_->vertex_props_begin(), mesh_->vertex_props_end(), PropertyInfo::EF_VERTEX);
437  gatherProperties(mesh_, mesh_->halfface_props_begin(), mesh_->halfface_props_end(), PropertyInfo::EF_HALFFACE);
438  gatherProperties(mesh_, mesh_->cell_props_begin(), mesh_->cell_props_end(), PropertyInfo::EF_CELL);
439  }
440  endResetModel();
441 }
442 
443 
451 template<typename MeshT>
452 bool OVMPropertyModel<MeshT>::isSupported(OpenVolumeMesh::BaseProperty* const baseProp) const
453 {
454  TypeInfoWrapper bp_type = typeid(*baseProp);
455  TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
456  return propIt != supportedPropertyTypes.end();
457 }
458 
469 template<typename MeshT>
470 bool OVMPropertyModel<MeshT>::isSupported(QString friendlyName) const
471 {
472  for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
473  it != supportedPropertyTypes.end();
474  ++it )
475  {
476  if (friendlyName.toStdString().compare(it->getName()) == 0)
477  return true;
478  }
479  return false;
480 }
481 
490 template<typename MeshT>
491 bool OVMPropertyModel<MeshT>::isNew(OpenVolumeMesh::BaseProperty* const baseProp, PropertyInfo::ENTITY_FILTER filter) const
492 {
493  for (unsigned int i = 0; i < propertyVisualizers.size(); ++i)
494  {
495  const PropertyInfo& propInfo = propertyVisualizers[i]->getPropertyInfo();
496  if (propInfo == PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter))
497  return false;
498  }
499  return true;
500 }
501 
502 
510 template<typename MeshT>
511 TypeInfoWrapper OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty* const baseProp) const
512 {
513  TypeInfoWrapper bp_type = typeid(*baseProp);
514  TypeInfoWrapperSet::const_iterator propIt = supportedPropertyTypes.find(bp_type);
515  if (propIt != supportedPropertyTypes.end())
516  return *propIt;
517  else
518  {
519  std::cerr << "error" << std::endl;
520  return *propIt;
521  }
522 }
523 
532 template<typename MeshT>
533 TypeInfoWrapper OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(QString friendlyName, PropertyInfo::ENTITY_FILTER filter) const
534 {
535 
536  for (TypeInfoWrapperSet::const_iterator it = supportedPropertyTypes.begin();
537  it != supportedPropertyTypes.end();
538  ++it )
539  {
540  if ((friendlyName.toStdString().compare(it->getName()) == 0) && isEntityType(*it, filter))
541  return *it;
542  }
543  throw std::exception();
544 }
545 
546 template<typename MeshT>
547 bool OVMPropertyModel<MeshT>::isBoolType(const PropertyInfo& propInfo)
548 {
549  return isBoolType(propInfo.typeinfo());
550 }
551 
552 template<typename MeshT>
553 bool OVMPropertyModel<MeshT>::isBoolType(const TypeInfoWrapper& typeInfo)
554 {
555  return typeInfo == proptype_Cell_bool ||
556  typeInfo == proptype_Face_bool ||
557  typeInfo == proptype_HalfFace_bool ||
558  typeInfo == proptype_Edge_bool ||
559  typeInfo == proptype_HalfEdge_bool ||
560  typeInfo == proptype_Vertex_bool;
561 }
562 
563 template<typename MeshT>
564 bool OVMPropertyModel<MeshT>::isIntType(const PropertyInfo& propInfo)
565 {
566  return isIntType(propInfo.typeinfo());
567 }
568 
569 template<typename MeshT>
570 bool OVMPropertyModel<MeshT>::isIntType(const TypeInfoWrapper& typeInfo)
571 {
572  return typeInfo == proptype_Cell_int ||
573  typeInfo == proptype_Face_int ||
574  typeInfo == proptype_HalfFace_int ||
575  typeInfo == proptype_Edge_int ||
576  typeInfo == proptype_HalfEdge_int ||
577  typeInfo == proptype_Vertex_int;
578 }
579 
580 template<typename MeshT>
581 bool OVMPropertyModel<MeshT>::isDoubleType(const PropertyInfo& propInfo)
582 {
583  return isDoubleType(propInfo.typeinfo());
584 }
585 
586 template<typename MeshT>
587 bool OVMPropertyModel<MeshT>::isDoubleType(const TypeInfoWrapper& typeInfo)
588 {
589  return typeInfo == proptype_Cell_double ||
590  typeInfo == proptype_Face_double ||
591  typeInfo == proptype_HalfFace_double ||
592  typeInfo == proptype_Edge_double ||
593  typeInfo == proptype_HalfEdge_double ||
594  typeInfo == proptype_Vertex_double;
595 }
596 
597 template<typename MeshT>
598 bool OVMPropertyModel<MeshT>::isUnsignedIntType(const PropertyInfo& propInfo)
599 {
600  return isUnsignedIntType(propInfo.typeinfo());
601 }
602 
603 template<typename MeshT>
604 bool OVMPropertyModel<MeshT>::isUnsignedIntType(const TypeInfoWrapper& typeInfo)
605 {
606  return typeInfo == proptype_Cell_uint ||
607  typeInfo == proptype_Face_uint ||
608  typeInfo == proptype_HalfFace_uint ||
609  typeInfo == proptype_Edge_uint ||
610  typeInfo == proptype_HalfEdge_uint ||
611  typeInfo == proptype_Vertex_uint;
612 }
613 
614 template<typename MeshT>
615 bool OVMPropertyModel<MeshT>::isVec3dType(const PropertyInfo& propInfo)
616 {
617  return isVec3dType(propInfo.typeinfo());
618 }
619 
620 template<typename MeshT>
621 bool OVMPropertyModel<MeshT>::isVec3dType(const TypeInfoWrapper& typeInfo)
622 {
623  return typeInfo == proptype_Cell_Vec3d ||
624  typeInfo == proptype_Face_Vec3d ||
625  typeInfo == proptype_HalfFace_Vec3d ||
626  typeInfo == proptype_Edge_Vec3d ||
627  typeInfo == proptype_HalfEdge_Vec3d ||
628  typeInfo == proptype_Vertex_Vec3d;
629 }
630 
631 template<typename MeshT>
632 bool OVMPropertyModel<MeshT>::isVec3fType(const PropertyInfo& propInfo)
633 {
634  return isVec3fType(propInfo.typeinfo());
635 }
636 
637 template<typename MeshT>
638 bool OVMPropertyModel<MeshT>::isVec3fType(const TypeInfoWrapper& typeInfo)
639 {
640  return typeInfo == proptype_Cell_Vec3f ||
641  typeInfo == proptype_Face_Vec3f ||
642  typeInfo == proptype_HalfFace_Vec3f ||
643  typeInfo == proptype_Edge_Vec3f ||
644  typeInfo == proptype_HalfEdge_Vec3f ||
645  typeInfo == proptype_Vertex_Vec3f;
646 }
647 
648 template<typename MeshT>
649 bool OVMPropertyModel<MeshT>::isVectorType(const PropertyInfo& propInfo)
650 {
651  return isVec3fType(propInfo) || isVec3dType(propInfo);
652 }
653 
654 template<typename MeshT>
655 bool OVMPropertyModel<MeshT>::isVectorType(const TypeInfoWrapper& typeInfo)
656 {
657  return isVec3fType(typeInfo) || isVec3dType(typeInfo);
658 }
659 
660 template<typename MeshT>
661 bool OVMPropertyModel<MeshT>::isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const
662 {
663  bool result = false;
664  if (entity_type & PropertyInfo::EF_CELL)
665  {
666  result |= (typeInfo == proptype_Cell_bool)
667  || (typeInfo == proptype_Cell_int)
668  || (typeInfo == proptype_Cell_double)
669  || (typeInfo == proptype_Cell_uint)
670  || (typeInfo == proptype_Cell_Vec3d)
671  || (typeInfo == proptype_Cell_Vec3f);
672  }
673  if (entity_type & PropertyInfo::EF_FACE)
674  {
675  result |= (typeInfo == proptype_Face_bool)
676  || (typeInfo == proptype_Face_int)
677  || (typeInfo == proptype_Face_double)
678  || (typeInfo == proptype_Face_uint)
679  || (typeInfo == proptype_Face_Vec3d)
680  || (typeInfo == proptype_Face_Vec3f);
681  }
682  if (entity_type & PropertyInfo::EF_HALFFACE)
683  {
684  result |= (typeInfo == proptype_HalfFace_bool)
685  || (typeInfo == proptype_HalfFace_int)
686  || (typeInfo == proptype_HalfFace_double)
687  || (typeInfo == proptype_HalfFace_uint)
688  || (typeInfo == proptype_HalfFace_Vec3d)
689  || (typeInfo == proptype_HalfFace_Vec3f);
690  }
691  if (entity_type & PropertyInfo::EF_EDGE)
692  {
693  result |= (typeInfo == proptype_Edge_bool)
694  || (typeInfo == proptype_Edge_int)
695  || (typeInfo == proptype_Edge_double)
696  || (typeInfo == proptype_Edge_uint)
697  || (typeInfo == proptype_Edge_Vec3d)
698  || (typeInfo == proptype_Edge_Vec3f);
699  }
700  if (entity_type & PropertyInfo::EF_HALFEDGE)
701  {
702  result |= (typeInfo == proptype_HalfEdge_bool)
703  || (typeInfo == proptype_HalfEdge_int)
704  || (typeInfo == proptype_HalfEdge_double)
705  || (typeInfo == proptype_HalfEdge_uint)
706  || (typeInfo == proptype_HalfEdge_Vec3d)
707  || (typeInfo == proptype_HalfEdge_Vec3f);
708  }
709  if (entity_type & PropertyInfo::EF_VERTEX)
710  {
711  result |= (typeInfo == proptype_Vertex_bool)
712  || (typeInfo == proptype_Vertex_int)
713  || (typeInfo == proptype_Vertex_double)
714  || (typeInfo == proptype_Vertex_uint)
715  || (typeInfo == proptype_Vertex_Vec3d)
716  || (typeInfo == proptype_Vertex_Vec3f);
717  }
718  return result;
719 }
720 
721 
732 template<typename MeshT>
733 void OVMPropertyModel<MeshT>::addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter)
734 {
735  PropertyInfo propInfo = PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter);
736  if (isBoolType(propInfo))
737  propertyVisualizers.push_back(new OVMPropertyVisualizerBoolean<MeshT>(mesh, objectID_, propInfo));
738  else if (isIntType(propInfo))
739  propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, int>(mesh, objectID_, propInfo, false));
740  else if (isUnsignedIntType(propInfo))
741  propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, unsigned int>(mesh, objectID_, propInfo, true));
742  else if (isDoubleType(propInfo))
743  propertyVisualizers.push_back(new OVMPropertyVisualizerDouble<MeshT>(mesh, objectID_, propInfo));
744  else if (isVectorType(propInfo))
745  propertyVisualizers.push_back(new OVMPropertyVisualizerVector<MeshT>(mesh, objectID_, propInfo));
746  connectLogs(propertyVisualizers.back());
747 }
748 
759 template<typename MeshT>
760 void OVMPropertyModel<MeshT>::addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
761 {
762 
763  QString dtype = friendlyTypeName;
764  std::string pname = propName.toStdString();
765 
766  MeshT* mesh = mesh_;
767 
768  if ( filter == PropertyInfo::EF_VERTEX )
769  {
770  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
771  {
772  OpenVolumeMesh::VertexPropertyT< ACG::Vec3d > prop = mesh->template request_vertex_property< ACG::Vec3d >(pname);
773  mesh->set_persistent(prop, true);
774  }
775  else if ( dtype == tr("double") )
776  {
777  OpenVolumeMesh::VertexPropertyT< double > prop = mesh->template request_vertex_property< double >(pname);
778  mesh->set_persistent(prop, true);
779  }
780  else if ( dtype == tr("unsigned int") )
781  {
782  OpenVolumeMesh::VertexPropertyT< unsigned int > prop = mesh->template request_vertex_property< unsigned int >(pname);
783  mesh->set_persistent(prop, true);
784  }
785  else if ( dtype == tr("int") )
786  {
787  OpenVolumeMesh::VertexPropertyT< int > prop = mesh->template request_vertex_property< int >(pname);
788  mesh->set_persistent(prop, true);
789  }
790  else if ( dtype == tr("bool") )
791  {
792  OpenVolumeMesh::VertexPropertyT< bool > prop = mesh->template request_vertex_property< bool >(pname);
793  mesh->set_persistent(prop, true);
794  }
795  }
796  else if ( filter == PropertyInfo::EF_EDGE )
797  {
798  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
799  {
800  OpenVolumeMesh::EdgePropertyT< ACG::Vec3d > prop = mesh->template request_edge_property< ACG::Vec3d >(pname);
801  mesh->set_persistent(prop, true);
802  }
803  else if ( dtype == tr("double") )
804  {
805  OpenVolumeMesh::EdgePropertyT< double > prop = mesh->template request_edge_property< double >(pname);
806  mesh->set_persistent(prop, true);
807  }
808  else if ( dtype == tr("unsgined int") )
809  {
810  OpenVolumeMesh::EdgePropertyT< unsigned int > prop = mesh->template request_edge_property< unsigned int >(pname);
811  mesh->set_persistent(prop, true);
812  }
813  else if ( dtype == tr("int") )
814  {
815  OpenVolumeMesh::EdgePropertyT< int > prop = mesh->template request_edge_property< int >(pname);
816  mesh->set_persistent(prop, true);
817  }
818  else if ( dtype == tr("bool") )
819  {
820  OpenVolumeMesh::EdgePropertyT< bool > prop = mesh->template request_edge_property< bool >(pname);
821  mesh->set_persistent(prop, true);
822  }
823  }
824  else if ( filter == PropertyInfo::EF_FACE )
825  {
826  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
827  {
828  OpenVolumeMesh::FacePropertyT< ACG::Vec3d > prop = mesh->template request_face_property< ACG::Vec3d >(pname);
829  mesh->set_persistent(prop, true);
830  }
831  else if ( dtype == tr("double") )
832  {
833  OpenVolumeMesh::FacePropertyT< double > prop = mesh->template request_face_property< double >(pname);
834  mesh->set_persistent(prop, true);
835  }
836  else if ( dtype == tr("unsigned int") )
837  {
838  OpenVolumeMesh::FacePropertyT< unsigned int > prop = mesh->template request_face_property< unsigned int >(pname);
839  mesh->set_persistent(prop, true);
840  }
841  else if ( dtype == tr("int") )
842  {
843  OpenVolumeMesh::FacePropertyT< int > prop = mesh->template request_face_property< int >(pname);
844  mesh->set_persistent(prop, true);
845  }
846  else if ( dtype == tr("bool") )
847  {
848  OpenVolumeMesh::FacePropertyT< bool > prop = mesh->template request_face_property< bool >(pname);
849  mesh->set_persistent(prop, true);
850  }
851  }
852  else if ( filter == PropertyInfo::EF_HALFEDGE )
853  {
854  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
855  {
856  OpenVolumeMesh::HalfEdgePropertyT< ACG::Vec3d > prop = mesh->template request_halfedge_property< ACG::Vec3d >(pname);
857  mesh->set_persistent(prop, true);
858  }
859  else if ( dtype == tr("double") )
860  {
861  OpenVolumeMesh::HalfEdgePropertyT< double > prop = mesh->template request_halfedge_property< double >(pname);
862  mesh->set_persistent(prop, true);
863  }
864  else if ( dtype == tr("unsigned int") )
865  {
866  OpenVolumeMesh::HalfEdgePropertyT< unsigned int > prop = mesh->template request_halfedge_property< unsigned int >(pname);
867  mesh->set_persistent(prop, true);
868  }
869  else if ( dtype == tr("int") )
870  {
871  OpenVolumeMesh::HalfEdgePropertyT< int > prop = mesh->template request_halfedge_property< int >(pname);
872  mesh->set_persistent(prop, true);
873  }
874  else if ( dtype == tr("bool") )
875  {
876  OpenVolumeMesh::HalfEdgePropertyT< bool > prop = mesh->template request_halfedge_property< bool >(pname);
877  mesh->set_persistent(prop, true);
878  }
879  }
880  else if ( filter == PropertyInfo::EF_HALFFACE )
881  {
882  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
883  {
884  OpenVolumeMesh::HalfFacePropertyT< ACG::Vec3d > prop = mesh->template request_halfface_property< ACG::Vec3d >(pname);
885  mesh->set_persistent(prop, true);
886  }
887  else if ( dtype == tr("double") )
888  {
889  OpenVolumeMesh::HalfFacePropertyT< double > prop = mesh->template request_halfface_property< double >(pname);
890  mesh->set_persistent(prop, true);
891  }
892  else if ( dtype == tr("unsigned int") )
893  {
894  OpenVolumeMesh::HalfFacePropertyT< unsigned int > prop = mesh->template request_halfface_property< unsigned int >(pname);
895  mesh->set_persistent(prop, true);
896  }
897  else if ( dtype == tr("int") )
898  {
899  OpenVolumeMesh::HalfFacePropertyT< int > prop = mesh->template request_halfface_property< int >(pname);
900  mesh->set_persistent(prop, true);
901  }
902  else if ( dtype == tr("bool") )
903  {
904  OpenVolumeMesh::HalfFacePropertyT< bool > prop = mesh->template request_halfface_property< bool >(pname);
905  mesh->set_persistent(prop, true);
906  }
907  }
908  else if ( filter == PropertyInfo::EF_CELL )
909  {
910  if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
911  {
912  OpenVolumeMesh::CellPropertyT< ACG::Vec3d > prop = mesh->template request_cell_property< ACG::Vec3d >(pname);
913  mesh->set_persistent(prop, true);
914  }
915  else if ( dtype == tr("double") )
916  {
917  OpenVolumeMesh::CellPropertyT< double > prop = mesh->template request_cell_property< double >(pname);
918  mesh->set_persistent(prop, true);
919  }
920  else if ( dtype == tr("unsigned int") )
921  {
922  OpenVolumeMesh::CellPropertyT< unsigned int > prop = mesh->template request_cell_property< unsigned int >(pname);
923  mesh->set_persistent(prop, true);
924  }
925  else if ( dtype == tr("int") )
926  {
927  OpenVolumeMesh::CellPropertyT< int > prop = mesh->template request_cell_property< int >(pname);
928  mesh->set_persistent(prop, true);
929  }
930  else if ( dtype == tr("bool") )
931  {
932  OpenVolumeMesh::CellPropertyT< bool > prop = mesh->template request_cell_property< bool >(pname);
933  mesh->set_persistent(prop, true);
934  }
935  }
936 
937 }
938 
939 template <typename MeshT>
940 void OVMPropertyModel<MeshT>::initializeSupportedPropertyTypes()
941 {
942 
943 #define INSERT_PROPTYPES(primitive) \
944 supportedPropertyTypes.insert(proptype_##primitive##_bool); \
945 supportedPropertyTypes.insert(proptype_##primitive##_int); \
946 supportedPropertyTypes.insert(proptype_##primitive##_uint); \
947 supportedPropertyTypes.insert(proptype_##primitive##_double); \
948 supportedPropertyTypes.insert(proptype_##primitive##_Vec3d); \
949 supportedPropertyTypes.insert(proptype_##primitive##_Vec3f); \
950 
951  INSERT_PROPTYPES(Cell)
952  INSERT_PROPTYPES(Face)
953  INSERT_PROPTYPES(HalfFace)
954  INSERT_PROPTYPES(Edge)
955  INSERT_PROPTYPES(HalfEdge)
956  INSERT_PROPTYPES(Vertex)
957 
958 #undef INITIALIZE_PROPTYPES
959 
960 
961 
962 }
963 
964 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
This class vizualizes a property.
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
picks faces (should be implemented for all nodes)
Definition: BaseNode.hh:104
Wraps the information of a type.
Definition: Utils.hh:79
void saveProperty(unsigned int propId)
Saves property.
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
picks verices (may not be implemented for all nodes)
Definition: BaseNode.hh:108
picks edges (may not be implemented for all nodes)
Definition: BaseNode.hh:106
const std::string pickMode()
Get the current Picking mode.
picks faces (may not be implemented for all nodes)
Definition: BaseNode.hh:102
Property classes for the different entity types.
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Viewer::ActionMode actionMode()
Get the current Action mode.
Asks the user how to proceed after a name clash.
Definition: Utils.hh:176
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Cellection of information about a property.
Definition: Utils.hh:115
int id() const
Definition: BaseObject.cc:201