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 {
54 gatherProperties();
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 {
87 SingleObjectPropertyModel::updateWidget(selectedIndices);
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>
119 void OVMPropertyModel<MeshT>::resetPicking()
120 {
121 PluginFunctions::pickMode(lastPickMode);
122 PluginFunctions::actionMode(lastActionMode);
123 }
124
125
131 template <typename MeshT>
132 void OVMPropertyModel<MeshT>::pickProperty()
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);
287 gatherProperties();
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>
304 QString OVMPropertyModel<MeshT>::getLoadFilenameFilter()
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>
318 QString OVMPropertyModel<MeshT>::getSaveFilenameFilter(unsigned int propId)
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>
363 void OVMPropertyModel<MeshT>::combine()
364 {
365 beginResetModel();
366 propertyVisualizers.push_back(new OVMPropertyVisualizerVectorFieldDifference<MeshT>(mesh_, objectID_, *mCombineProperty1, *mCombineProperty2));
367 endResetModel();
368 }
369
370 template<typename MeshT>
371 void OVMPropertyModel<MeshT>::saveProperty()
372 {
373 for (QModelIndexList::const_iterator it = currentlySelectedIndices.begin(), it_end = currentlySelectedIndices.end();
374 it != it_end; ++it) {
375 SingleObjectPropertyModel::saveProperty(it->row());
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>
404 void OVMPropertyModel<MeshT>::gatherProperties( MeshT* mesh,
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>
418 void OVMPropertyModel<MeshT>::gatherProperties()
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>
441 bool OVMPropertyModel<MeshT>::isSupported(OpenVolumeMesh::BaseProperty* const baseProp) const
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>
500 TypeInfoWrapper OVMPropertyModel<MeshT>::getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty* const baseProp) const
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>
536 bool OVMPropertyModel<MeshT>::isBoolType(const PropertyInfo& propInfo)
537 {
538 return isBoolType(propInfo.typeinfo());
539 }
540
541 template<typename MeshT>
542 bool OVMPropertyModel<MeshT>::isBoolType(const TypeInfoWrapper& typeInfo)
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>
553 bool OVMPropertyModel<MeshT>::isIntType(const PropertyInfo& propInfo)
554 {
555 return isIntType(propInfo.typeinfo());
556 }
557
558 template<typename MeshT>
559 bool OVMPropertyModel<MeshT>::isIntType(const TypeInfoWrapper& typeInfo)
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>
570 bool OVMPropertyModel<MeshT>::isDoubleType(const PropertyInfo& propInfo)
571 {
572 return isDoubleType(propInfo.typeinfo());
573 }
574
575 template<typename MeshT>
576 bool OVMPropertyModel<MeshT>::isDoubleType(const TypeInfoWrapper& typeInfo)
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>
587 bool OVMPropertyModel<MeshT>::isUnsignedIntType(const PropertyInfo& propInfo)
588 {
589 return isUnsignedIntType(propInfo.typeinfo());
590 }
591
592 template<typename MeshT>
593 bool OVMPropertyModel<MeshT>::isUnsignedIntType(const TypeInfoWrapper& typeInfo)
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>
604 bool OVMPropertyModel<MeshT>::isVec3dType(const PropertyInfo& propInfo)
605 {
606 return isVec3dType(propInfo.typeinfo());
607 }
608
609 template<typename MeshT>
610 bool OVMPropertyModel<MeshT>::isVec3dType(const TypeInfoWrapper& typeInfo)
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>
621 bool OVMPropertyModel<MeshT>::isVec3fType(const PropertyInfo& propInfo)
622 {
623 return isVec3fType(propInfo.typeinfo());
624 }
625
626 template<typename MeshT>
627 bool OVMPropertyModel<MeshT>::isVec3fType(const TypeInfoWrapper& typeInfo)
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>
638 bool OVMPropertyModel<MeshT>::isVectorType(const PropertyInfo& propInfo)
639 {
640 return isVec3fType(propInfo) || isVec3dType(propInfo);
641 }
642
643 template<typename MeshT>
644 bool OVMPropertyModel<MeshT>::isVectorType(const TypeInfoWrapper& typeInfo)
645 {
646 return isVec3fType(typeInfo) || isVec3dType(typeInfo);
647 }
648
649 template<typename MeshT>
650 bool OVMPropertyModel<MeshT>::isEntityType(const TypeInfoWrapper& typeInfo, PropertyInfo::ENTITY_FILTER entity_type) const
651 {
652 bool result = false;
653 if (entity_type & PropertyInfo::EF_CELL)
654 {
655 result |= (typeInfo == proptype_Cell_bool)
656 || (typeInfo == proptype_Cell_int)
657 || (typeInfo == proptype_Cell_double)
658 || (typeInfo == proptype_Cell_uint)
659 || (typeInfo == proptype_Cell_Vec3d)
660 || (typeInfo == proptype_Cell_Vec3f);
661 }
662 if (entity_type & PropertyInfo::EF_FACE)
663 {
664 result |= (typeInfo == proptype_Face_bool)
665 || (typeInfo == proptype_Face_int)
666 || (typeInfo == proptype_Face_double)
667 || (typeInfo == proptype_Face_uint)
668 || (typeInfo == proptype_Face_Vec3d)
669 || (typeInfo == proptype_Face_Vec3f);
670 }
671 if (entity_type & PropertyInfo::EF_HALFFACE)
672 {
673 result |= (typeInfo == proptype_HalfFace_bool)
674 || (typeInfo == proptype_HalfFace_int)
675 || (typeInfo == proptype_HalfFace_double)
676 || (typeInfo == proptype_HalfFace_uint)
677 || (typeInfo == proptype_HalfFace_Vec3d)
678 || (typeInfo == proptype_HalfFace_Vec3f);
679 }
680 if (entity_type & PropertyInfo::EF_EDGE)
681 {
682 result |= (typeInfo == proptype_Edge_bool)
683 || (typeInfo == proptype_Edge_int)
684 || (typeInfo == proptype_Edge_double)
685 || (typeInfo == proptype_Edge_uint)
686 || (typeInfo == proptype_Edge_Vec3d)
687 || (typeInfo == proptype_Edge_Vec3f);
688 }
689 if (entity_type & PropertyInfo::EF_HALFEDGE)
690 {
691 result |= (typeInfo == proptype_HalfEdge_bool)
692 || (typeInfo == proptype_HalfEdge_int)
693 || (typeInfo == proptype_HalfEdge_double)
694 || (typeInfo == proptype_HalfEdge_uint)
695 || (typeInfo == proptype_HalfEdge_Vec3d)
696 || (typeInfo == proptype_HalfEdge_Vec3f);
697 }
698 if (entity_type & PropertyInfo::EF_VERTEX)
699 {
700 result |= (typeInfo == proptype_Vertex_bool)
701 || (typeInfo == proptype_Vertex_int)
702 || (typeInfo == proptype_Vertex_double)
703 || (typeInfo == proptype_Vertex_uint)
704 || (typeInfo == proptype_Vertex_Vec3d)
705 || (typeInfo == proptype_Vertex_Vec3f);
706 }
707 return result;
708 }
709
710
721 template<typename MeshT>
722 void OVMPropertyModel<MeshT>::addPropertyVisualizer(OpenVolumeMesh::BaseProperty* const baseProp, MeshT* mesh, PropertyInfo::ENTITY_FILTER filter)
723 {
724 PropertyInfo propInfo = PropertyInfo(baseProp->name(), getSupportedTypeInfoWrapper(baseProp) , filter);
725 if (isBoolType(propInfo))
726 propertyVisualizers.push_back(new OVMPropertyVisualizerBoolean<MeshT>(mesh, objectID_, propInfo));
727 else if (isIntType(propInfo))
728 propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, int>(mesh, objectID_, propInfo, false));
729 else if (isUnsignedIntType(propInfo))
730 propertyVisualizers.push_back(new OVMPropertyVisualizerInteger<MeshT, unsigned int>(mesh, objectID_, propInfo, true));
731 else if (isDoubleType(propInfo))
732 propertyVisualizers.push_back(new OVMPropertyVisualizerDouble<MeshT>(mesh, objectID_, propInfo));
733 else if (isVectorType(propInfo))
734 propertyVisualizers.push_back(new OVMPropertyVisualizerVector<MeshT>(mesh, objectID_, propInfo));
735 connectLogs(propertyVisualizers.back());
736 }
737
748 template<typename MeshT>
749 void OVMPropertyModel<MeshT>::addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
750 {
751
752 QString dtype = friendlyTypeName;
753 std::string pname = propName.toStdString();
754
755 MeshT* mesh = mesh_;
756
757 if ( filter == PropertyInfo::EF_VERTEX )
758 {
759 if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
760 {
761 OpenVolumeMesh::VertexPropertyT< ACG::Vec3d > prop = mesh->template request_vertex_property< ACG::Vec3d >(pname);
762 mesh->set_persistent(prop, true);
763 }
764 else if ( dtype == tr("double") )
765 {
766 OpenVolumeMesh::VertexPropertyT< double > prop = mesh->template request_vertex_property< double >(pname);
767 mesh->set_persistent(prop, true);
768 }
769 else if ( dtype == tr("unsigned int") )
770 {
771 OpenVolumeMesh::VertexPropertyT< unsigned int > prop = mesh->template request_vertex_property< unsigned int >(pname);
772 mesh->set_persistent(prop, true);
773 }
774 else if ( dtype == tr("int") )
775 {
776 OpenVolumeMesh::VertexPropertyT< int > prop = mesh->template request_vertex_property< int >(pname);
777 mesh->set_persistent(prop, true);
778 }
779 else if ( dtype == tr("bool") )
780 {
781 OpenVolumeMesh::VertexPropertyT< bool > prop = mesh->template request_vertex_property< bool >(pname);
782 mesh->set_persistent(prop, true);
783 }
784 }
785 else if ( filter == PropertyInfo::EF_EDGE )
786 {
787 if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
788 {
789 OpenVolumeMesh::EdgePropertyT< ACG::Vec3d > prop = mesh->template request_edge_property< ACG::Vec3d >(pname);
790 mesh->set_persistent(prop, true);
791 }
792 else if ( dtype == tr("double") )
793 {
794 OpenVolumeMesh::EdgePropertyT< double > prop = mesh->template request_edge_property< double >(pname);
795 mesh->set_persistent(prop, true);
796 }
797 else if ( dtype == tr("unsgined int") )
798 {
799 OpenVolumeMesh::EdgePropertyT< unsigned int > prop = mesh->template request_edge_property< unsigned int >(pname);
800 mesh->set_persistent(prop, true);
801 }
802 else if ( dtype == tr("int") )
803 {
804 OpenVolumeMesh::EdgePropertyT< int > prop = mesh->template request_edge_property< int >(pname);
805 mesh->set_persistent(prop, true);
806 }
807 else if ( dtype == tr("bool") )
808 {
809 OpenVolumeMesh::EdgePropertyT< bool > prop = mesh->template request_edge_property< bool >(pname);
810 mesh->set_persistent(prop, true);
811 }
812 }
813 else if ( filter == PropertyInfo::EF_FACE )
814 {
815 if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
816 {
817 OpenVolumeMesh::FacePropertyT< ACG::Vec3d > prop = mesh->template request_face_property< ACG::Vec3d >(pname);
818 mesh->set_persistent(prop, true);
819 }
820 else if ( dtype == tr("double") )
821 {
822 OpenVolumeMesh::FacePropertyT< double > prop = mesh->template request_face_property< double >(pname);
823 mesh->set_persistent(prop, true);
824 }
825 else if ( dtype == tr("unsigned int") )
826 {
827 OpenVolumeMesh::FacePropertyT< unsigned int > prop = mesh->template request_face_property< unsigned int >(pname);
828 mesh->set_persistent(prop, true);
829 }
830 else if ( dtype == tr("int") )
831 {
832 OpenVolumeMesh::FacePropertyT< int > prop = mesh->template request_face_property< int >(pname);
833 mesh->set_persistent(prop, true);
834 }
835 else if ( dtype == tr("bool") )
836 {
837 OpenVolumeMesh::FacePropertyT< bool > prop = mesh->template request_face_property< bool >(pname);
838 mesh->set_persistent(prop, true);
839 }
840 }
841 else if ( filter == PropertyInfo::EF_HALFEDGE )
842 {
843 if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
844 {
845 OpenVolumeMesh::HalfEdgePropertyT< ACG::Vec3d > prop = mesh->template request_halfedge_property< ACG::Vec3d >(pname);
846 mesh->set_persistent(prop, true);
847 }
848 else if ( dtype == tr("double") )
849 {
850 OpenVolumeMesh::HalfEdgePropertyT< double > prop = mesh->template request_halfedge_property< double >(pname);
851 mesh->set_persistent(prop, true);
852 }
853 else if ( dtype == tr("unsigned int") )
854 {
855 OpenVolumeMesh::HalfEdgePropertyT< unsigned int > prop = mesh->template request_halfedge_property< unsigned int >(pname);
856 mesh->set_persistent(prop, true);
857 }
858 else if ( dtype == tr("int") )
859 {
860 OpenVolumeMesh::HalfEdgePropertyT< int > prop = mesh->template request_halfedge_property< int >(pname);
861 mesh->set_persistent(prop, true);
862 }
863 else if ( dtype == tr("bool") )
864 {
865 OpenVolumeMesh::HalfEdgePropertyT< bool > prop = mesh->template request_halfedge_property< bool >(pname);
866 mesh->set_persistent(prop, true);
867 }
868 }
869 else if ( filter == PropertyInfo::EF_HALFFACE )
870 {
871 if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
872 {
873 OpenVolumeMesh::HalfFacePropertyT< ACG::Vec3d > prop = mesh->template request_halfface_property< ACG::Vec3d >(pname);
874 mesh->set_persistent(prop, true);
875 }
876 else if ( dtype == tr("double") )
877 {
878 OpenVolumeMesh::HalfFacePropertyT< double > prop = mesh->template request_halfface_property< double >(pname);
879 mesh->set_persistent(prop, true);
880 }
881 else if ( dtype == tr("unsigned int") )
882 {
883 OpenVolumeMesh::HalfFacePropertyT< unsigned int > prop = mesh->template request_halfface_property< unsigned int >(pname);
884 mesh->set_persistent(prop, true);
885 }
886 else if ( dtype == tr("int") )
887 {
888 OpenVolumeMesh::HalfFacePropertyT< int > prop = mesh->template request_halfface_property< int >(pname);
889 mesh->set_persistent(prop, true);
890 }
891 else if ( dtype == tr("bool") )
892 {
893 OpenVolumeMesh::HalfFacePropertyT< bool > prop = mesh->template request_halfface_property< bool >(pname);
894 mesh->set_persistent(prop, true);
895 }
896 }
897 else if ( filter == PropertyInfo::EF_CELL )
898 {
899 if ( (dtype == tr("Vec3d")) || (dtype == tr("Vec3f")) )
900 {
901 OpenVolumeMesh::CellPropertyT< ACG::Vec3d > prop = mesh->template request_cell_property< ACG::Vec3d >(pname);
902 mesh->set_persistent(prop, true);
903 }
904 else if ( dtype == tr("double") )
905 {
906 OpenVolumeMesh::CellPropertyT< double > prop = mesh->template request_cell_property< double >(pname);
907 mesh->set_persistent(prop, true);
908 }
909 else if ( dtype == tr("unsigned int") )
910 {
911 OpenVolumeMesh::CellPropertyT< unsigned int > prop = mesh->template request_cell_property< unsigned int >(pname);
912 mesh->set_persistent(prop, true);
913 }
914 else if ( dtype == tr("int") )
915 {
916 OpenVolumeMesh::CellPropertyT< int > prop = mesh->template request_cell_property< int >(pname);
917 mesh->set_persistent(prop, true);
918 }
919 else if ( dtype == tr("bool") )
920 {
921 OpenVolumeMesh::CellPropertyT< bool > prop = mesh->template request_cell_property< bool >(pname);
922 mesh->set_persistent(prop, true);
923 }
924 }
925
926 }
927
928 template <typename MeshT>
929 void OVMPropertyModel<MeshT>::initializeSupportedPropertyTypes()
930 {
931
932 #define INSERT_PROPTYPES(primitive) \
933 supportedPropertyTypes.insert(proptype_##primitive##_bool); \
934 supportedPropertyTypes.insert(proptype_##primitive##_int); \
935 supportedPropertyTypes.insert(proptype_##primitive##_uint); \
936 supportedPropertyTypes.insert(proptype_##primitive##_double); \
937 supportedPropertyTypes.insert(proptype_##primitive##_Vec3d); \
938 supportedPropertyTypes.insert(proptype_##primitive##_Vec3f); \
939
940 INSERT_PROPTYPES(Cell)
941 INSERT_PROPTYPES(Face)
942 INSERT_PROPTYPES(HalfFace)
943 INSERT_PROPTYPES(Edge)
944 INSERT_PROPTYPES(HalfEdge)
945 INSERT_PROPTYPES(Vertex)
946
947 #undef INITIALIZE_PROPTYPES
948
949
950
951 }
952
OVMPropertyModel::saveProperty
virtual void saveProperty()
Saves the currently slected properties.
Definition: OVMPropertyModelT_impl.hh:371
NewNameMessageBox
Asks the user how to proceed after a name clash.
Definition: Utils.hh:170
SingleObjectPropertyModel::connectLogs
void connectLogs(PropertyVisualizer *propViz)
Connects the PropertyVisualizer log signals with the log slot.
Definition: SingleObjectPropertyModel.cc:162
PluginFunctions::scenegraphPick
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Definition: PluginFunctions.cc:478
PropertyVisualizer::getPropertyInfo
const PropertyInfo & getPropertyInfo() const
Returns the PropertyInfo.
Definition: PropertyVisualizer.hh:129
OVMPropertyVisualizer::getPropertyText
virtual QString getPropertyText(unsigned int index)=0
Returns the value of a property in text form.
SingleObjectPropertyModel::getPropertyVisualizer
PropertyVisualizer * getPropertyVisualizer(QString propName, PropertyInfo::ENTITY_FILTER filter, TypeInfoWrapper typeInfo)
Returns a PropertyVisualizer.
Definition: SingleObjectPropertyModel.cc:315
OVMPropertyVisualizer::getClosestPrimitiveId
unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint)
Returns the ID of the closest primitive.
Definition: OVMPropertyVisualizerT_impl.hh:144
OVMPropertyModel::mouseEvent
virtual void mouseEvent(QMouseEvent *_event)
Handles mouse events for picking.
Definition: OVMPropertyModelT_impl.hh:167
OVMPropertyModelSubclass
Definition: OVMPropertyModelSubclass.hh:55
BaseObject::id
int id() const
Definition: BaseObject.cc:190
PluginFunctions::getPickedObject
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Definition: PluginFunctions.cc:259
OVMPropertyVisualizerVectorFieldDifference
Definition: OVMPropertyVisualizerVectorFieldDifference.hh:60
OVMPropertyVisualizerDouble
Definition: OVMPropertyVisualizerDouble.hh:59
OVMPropertyModel::addPropertyVisualizer
void addPropertyVisualizer(OpenVolumeMesh::BaseProperty *const baseProp, MeshT *mesh, PropertyInfo::ENTITY_FILTER filter)
Adds a new PropertyVisualizer.
Definition: OVMPropertyModelT_impl.hh:722
OVMPropertyModel::getLoadFilenameFilter
virtual QString getLoadFilenameFilter()
Returns the filename filter for loading.
Definition: OVMPropertyModelT_impl.hh:304
OVMPropertyModel::pickProperty
virtual void pickProperty()
Toggle picking on and off.
Definition: OVMPropertyModelT_impl.hh:132
OVMPropertyModel::gatherProperties
void gatherProperties()
Searches for all properties and creates the visualizers.
Definition: OVMPropertyModelT_impl.hh:418
OpenVolumeMesh::BaseProperty
Definition: BaseProperty.hh:54
TypeInfoWrapper
Wraps the information of a type.
Definition: Utils.hh:73
OVMPropertyVisualizer
Definition: OVMPropertyVisualizer.hh:61
SingleObjectPropertyModel::updateWidget
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
Definition: SingleObjectPropertyModel.cc:142
OVMPropertyModel::isPropertyFree
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.
Definition: OVMPropertyModelT_impl.hh:349
OVMPropertyVisualizerVector
Definition: OVMPropertyVisualizerVector.hh:60
OVMPropertyVisualizerBoolean
Definition: OVMPropertyVisualizerBoolean.hh:54
OVMPropertyModel
Definition: OVMPropertyModelT.hh:71
OpenVolumeMesh::PropertyTT
Definition: ForwardDeclarations.hh:18
ACG::SceneGraph::PICK_EDGE
picks edges (may not be implemented for all nodes)
Definition: PickTarget.hh:80
OVMPropertyModel::getSupportedTypeInfoWrapper
TypeInfoWrapper getSupportedTypeInfoWrapper(OpenVolumeMesh::BaseProperty *const baseProp) const
Returns the TypeInfoWrapper for the property if it is supported.
Definition: OVMPropertyModelT_impl.hh:500
PropertyVisualizer
This class vizualizes a property.
Definition: PropertyVisualizer.hh:77
OVMPropertyModel::isNew
bool isNew(OpenVolumeMesh::BaseProperty *const baseProp, PropertyInfo::ENTITY_FILTER filter) const
Checks if we already created a PropertyVisualizer for this property.
Definition: OVMPropertyModelT_impl.hh:480
OVMPropertyVisualizerInteger
Definition: OVMPropertyVisualizerInteger.hh:57
OVMPropertyModel::resetPicking
void resetPicking()
Disables picking.
Definition: OVMPropertyModelT_impl.hh:119
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
ACG::SceneGraph::PICK_CELL
picks faces (may not be implemented for all nodes)
Definition: PickTarget.hh:76
OVMPropertyModel::parseHeader
virtual bool parseHeader(QString header, PropertyVisualizer *&propVis, unsigned int &n)
Parses the property file header.
Definition: OVMPropertyModelT_impl.hh:213
SingleObjectPropertyModel::saveProperty
void saveProperty(unsigned int propId)
Saves property.
Definition: SingleObjectPropertyModel.cc:253
OpenMesh::VectorT
Definition: Vector11T.hh:83
OVMPropertyModel::combinable
bool combinable(PropertyVisualizer *propertyVisualizer1, PropertyVisualizer *propertyVisualizer2) const
Checks if two properties are combinable.
Definition: OVMPropertyModelT_impl.hh:393
ACG::SceneGraph::PICK_FACE
picks faces (should be implemented for all nodes)
Definition: PickTarget.hh:78
PluginFunctions::actionMode
Viewer::ActionMode actionMode()
Get the current Action mode.
Definition: PluginFunctions.cc:586
OVMPropertyModel::updateWidget
virtual void updateWidget(const QModelIndexList &selectedIndices)
Updates the widget.
Definition: OVMPropertyModelT_impl.hh:85
OVMPropertyModel::isSupported
bool isSupported(OpenVolumeMesh::BaseProperty *const baseProp) const
Checks if visualizing this property is supported.
Definition: OVMPropertyModelT_impl.hh:441
PropertyInfo
Cellection of information about a property.
Definition: Utils.hh:109
BaseObjectData
Definition: BaseObjectData.hh:102
OVMPropertyModel::addProperty
void addProperty(QString propName, QString friendlyTypeName, PropertyInfo::ENTITY_FILTER filter)
Adds a new property to the mesh.
Definition: OVMPropertyModelT_impl.hh:749
ACG::SceneGraph::PICK_VERTEX
picks verices (may not be implemented for all nodes)
Definition: PickTarget.hh:82
OVMPropertyModel::pickModeChanged
virtual void pickModeChanged(const std::string &_mode)
Handles changing of pick mode.
Definition: OVMPropertyModelT_impl.hh:148
OVMPropertyModel::combine
virtual void combine()
Combines two properties.
Definition: OVMPropertyModelT_impl.hh:363
PluginFunctions::pickMode
const std::string pickMode()
Get the current Picking mode.
Definition: PluginFunctions.cc:575
OVMPropertyModel::getSaveFilenameFilter
virtual QString getSaveFilenameFilter(unsigned int propId)
Returns the filename filter for saving.
Definition: OVMPropertyModelT_impl.hh:318