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