Developer Documentation
OVMPropertyVisualizer.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 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
51 
52 #ifndef OVM_PROPERTY_VISUALIZER_HH
53 #define OVM_PROPERTY_VISUALIZER_HH
54 
55 #include "../PropertyVisualizer.hh"
56 
57 #include <ObjectTypes/VolumeMeshObject/VolumeMeshObject.hh>
58 
59 #include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
60 
61 #include <ObjectTypes/VolumeMeshObject/VolumeMeshDrawModesContainer.hh>
62 
63 #include <iostream>
64 
65 template <typename MeshT>
66 class OVMPropertyVisualizer: public PropertyVisualizer{
67 
68 public:
69  OVMPropertyVisualizer(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo)
70  : PropertyVisualizer(_propertyInfo),
71  mesh(_mesh),
72  mObjectID(objectID),
73  drawModes()
74  {}
75 
76  virtual ~OVMPropertyVisualizer(){ clear(); }
77 
79  virtual void visualize(bool _setDrawMode, QWidget* _widget);
80 
87  virtual void removeProperty(){ emit log("Removing properties not yet implemented for OpenVolumeMeshs."); }
88 
90  virtual void duplicateProperty(){ /*implemented by subclass*/}
91 
93  virtual void clear();
94 
95  virtual QString getPropertyText(unsigned int index)=0;
96 
98  unsigned int getClosestPrimitiveId(unsigned int _face, ACG::Vec3d &_hitPoint);
99 
100 protected:
101  MeshT* mesh;
102 
103  virtual void visualizeFaceProp(bool _setDrawMode = true);
104  virtual void visualizeEdgeProp(bool _setDrawMode = true);
105  virtual void visualizeHalfedgeProp(bool _setDrawMode = true);
106  virtual void visualizeVertexProp(bool _setDrawMode = true);
107  virtual void visualizeCellProp(bool _setDrawMode = true);
108  virtual void visualizeHalffaceProp(bool _setDrawMode = true);
109 
110  template<typename PropType>
111  void duplicateProperty_stage1();
112 
113  OpenMesh::Vec4f convertColor(QColor color);
114 
115  template <typename InnerType>
116  QString getPropertyText_(unsigned int index);
117 
118  virtual void setCellPropertyFromText(unsigned int index, QString text);
119  virtual void setFacePropertyFromText(unsigned int index, QString text);
120  virtual void setHalffacePropertyFromText(unsigned int index, QString text);
121  virtual void setEdgePropertyFromText(unsigned int index, QString text);
122  virtual void setHalfedgePropertyFromText(unsigned int index, QString text);
123  virtual void setVertexPropertyFromText(unsigned int index, QString text);
124 
125  virtual void setPropertyFromText(unsigned int index, QString text);
126 
127  virtual int getEntityCount();
128 
129  virtual QString getHeader();
130 
131  unsigned int getClosestCellId(unsigned int _face, ACG::Vec3d& _hitPoint);
132  unsigned int getClosestFaceId(unsigned int _face, ACG::Vec3d& _hitPoint);
133  unsigned int getClosestHalffaceId(unsigned int _face, ACG::Vec3d& _hitPoint);
134  unsigned int getClosestEdgeId(unsigned int _face, ACG::Vec3d& _hitPoint);
135  unsigned int getClosestHalfedgeId(unsigned int _face, ACG::Vec3d& _hitPoint);
136  unsigned int getClosestVertexId(unsigned int _face, ACG::Vec3d& _hitPoint);
137 
138  int mObjectID;
139 
141 
142 private:
143 
144  template<typename Property>
145  class CopyProperty
146  {
147  public:
148  CopyProperty(Property& p1, const Property& p2, MeshT*& mesh) :
149  p1(p1), p2(p2), mesh(mesh) {}
150 
151  template<typename PrimitiveHandleT>
152  inline void operator() (const PrimitiveHandleT &pr) {
153  p1[pr] = p2[pr];
154  }
155 
156  private:
157  Property &p1;
158  const Property &p2;
159  MeshT*& mesh;
160  };
161 };
162 
163 #define CALLS_TO_VISUALIZE_PROP(Classname, Template, PropType) \
164 template <Template> \
165 void Classname::visualizeCellProp(bool _setDrawMode) \
166 {\
167  OpenVolumeMesh::CellPropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
168  visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->cells_begin(), OVMPropertyVisualizer<MeshT>::mesh->cells_end());\
169  if (_setDrawMode)\
170  {\
171  VolumeMeshObject<MeshT>* object;\
172  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
173  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.cellsColoredPerCell);\
174  }\
175 }\
176 template <Template>\
177 void Classname::visualizeFaceProp(bool _setDrawMode)\
178 {\
179  OpenVolumeMesh::FacePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
180  visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->faces_begin(), OVMPropertyVisualizer<MeshT>::mesh->faces_end());\
181  if (_setDrawMode)\
182  {\
183  VolumeMeshObject<MeshT>* object;\
184  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
185  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.facesColoredPerFace);\
186  }\
187 }\
188 template <Template>\
189 void Classname::visualizeHalffaceProp(bool _setDrawMode)\
190 {\
191  OpenVolumeMesh::HalfFacePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
192  visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin(), OVMPropertyVisualizer<MeshT>::mesh->halffaces_end());\
193  if (_setDrawMode)\
194  {\
195  VolumeMeshObject<MeshT>* object;\
196  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
197  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halffacesColoredPerHalfface);\
198  }\
199 }\
200 template <Template>\
201 void Classname::visualizeEdgeProp(bool _setDrawMode)\
202 {\
203  OpenVolumeMesh::EdgePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_edge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
204  visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->edges_begin(), OVMPropertyVisualizer<MeshT>::mesh->edges_end());\
205  if (_setDrawMode)\
206  {\
207  VolumeMeshObject<MeshT>* object;\
208  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
209  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.edgesColoredPerEdge);\
210  }\
211 }\
212 template <Template>\
213 void Classname::visualizeHalfedgeProp(bool _setDrawMode)\
214 {\
215  OpenVolumeMesh::HalfEdgePropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfedge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
216  visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin(), OVMPropertyVisualizer<MeshT>::mesh->halfedges_end());\
217  if (_setDrawMode)\
218  {\
219  VolumeMeshObject<MeshT>* object;\
220  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
221  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halfedgesColoredPerHalfedge);\
222  }\
223 }\
224 template <Template>\
225 void Classname::visualizeVertexProp(bool _setDrawMode)\
226 {\
227  OpenVolumeMesh::VertexPropertyT<PropType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_vertex_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());\
228  visualizeProp(prop, OVMPropertyVisualizer<MeshT>::mesh->vertices_begin(), OVMPropertyVisualizer<MeshT>::mesh->vertices_end());\
229  if (_setDrawMode)\
230  {\
231  VolumeMeshObject<MeshT>* object;\
232  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);\
233  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.verticesColored);\
234  }\
235 }\
236 
237 
238 #if defined(INCLUDE_TEMPLATES) && !defined(OVM_PROPERTY_VISUALIZER_CC)
239 #include "OVMPropertyVisualizerT.cc"
240 #endif
241 
242 #endif /* OVM_PROPERTY_VISUALIZER_HH */
243 
244 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
This class provides easy access to DrawModes supported by OpenVolumeMesh.
virtual void visualize(bool _setDrawMode, QWidget *_widget)
Visualizes the property.
virtual void removeProperty()
Removes the property.
virtual void setPropertyFromText(unsigned int index, QString text)=0
Returns the value of a property in text form.
Cellection of information about a property.
Definition: Utils.hh:115
This class vizualizes a property.
virtual QString getHeader()=0
Returns the header for saving.
virtual int getEntityCount()=0
Returns the number of entities.
virtual QString getPropertyText(unsigned int i)=0
Returns the value of a property in text form.
virtual void duplicateProperty()
Duplicates the property.
virtual void clear()
Clears the property visualization.