Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OVMPropertyVisualizerT.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_VISUALIZER_CC
53
54 #ifdef ENABLE_OPENVOLUMEMESH_POLYHEDRAL_SUPPORT
55 #include <ObjectTypes/PolyhedralMesh/PolyhedralMesh.hh>
56 #endif
57 #ifdef ENABLE_OPENVOLUMEMESH_HEXAHEDRAL_SUPPORT
58 #include <ObjectTypes/HexahedralMesh/HexahedralMesh.hh>
59 #endif
60
61 #include "OVMPropertyVisualizer.hh"
62
63 template <typename MeshT>
64 template <typename InnerType>
65 QString OVMPropertyVisualizer<MeshT>::getPropertyText_(unsigned int index)
66 {
67 if (PropertyVisualizer::propertyInfo.isCellProp())
68 {
69 OpenVolumeMesh::CellPropertyT<InnerType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<InnerType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
70 return PropertyVisualizer::toStr(prop[OpenVolumeMesh::CellHandle(index)]);
71 }
72 else if (PropertyVisualizer::propertyInfo.isFaceProp())
73 {
74 OpenVolumeMesh::FacePropertyT<InnerType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<InnerType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
75 return PropertyVisualizer::toStr(prop[OpenVolumeMesh::FaceHandle(index)]);
76 }
77 else if (PropertyVisualizer::propertyInfo.isHalffaceProp())
78 {
79 OpenVolumeMesh::HalfFacePropertyT<InnerType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<InnerType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
80 return PropertyVisualizer::toStr(prop[OpenVolumeMesh::HalfFaceHandle(index)]);
81 }
82 else if (PropertyVisualizer::propertyInfo.isEdgeProp())
83 {
84 OpenVolumeMesh::EdgePropertyT<InnerType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_edge_property<InnerType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
85 return PropertyVisualizer::toStr(prop[OpenVolumeMesh::EdgeHandle(index)]);
86 }
87 else if (PropertyVisualizer::propertyInfo.isHalfedgeProp())
88 {
89 OpenVolumeMesh::HalfEdgePropertyT<InnerType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfedge_property<InnerType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
90 return PropertyVisualizer::toStr(prop[OpenVolumeMesh::HalfEdgeHandle(index)]);
91 }
92 else //if (propertyInfo.isVertexProp())
93 {
94 OpenVolumeMesh::VertexPropertyT<InnerType> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_vertex_property<InnerType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
95 return PropertyVisualizer::toStr(prop[OpenVolumeMesh::VertexHandle(index)]);
96 }
97 }
98
99 template <typename MeshT>
100 void OVMPropertyVisualizer<MeshT>::setPropertyFromText(unsigned int index, QString text)
101 {
102 if (propertyInfo.isCellProp())
103 setCellPropertyFromText(index, text);
104 else if (propertyInfo.isFaceProp())
105 setFacePropertyFromText(index, text);
106 else if (propertyInfo.isHalffaceProp())
107 setHalffacePropertyFromText(index, text);
108 else if (propertyInfo.isEdgeProp())
109 setEdgePropertyFromText(index, text);
110 else if (propertyInfo.isHalfedgeProp())
111 setHalfedgePropertyFromText(index, text);
112 else //if (propertyInfo.isVertexProp())
113 setVertexPropertyFromText(index, text);
114 }
115
116 template <typename MeshT>
117 int OVMPropertyVisualizer<MeshT>::getEntityCount()
118 {
119 if (propertyInfo.isCellProp())
120 return mesh->n_cells();
121 if (propertyInfo.isFaceProp())
122 return mesh->n_faces();
123 if (propertyInfo.isHalffaceProp())
124 return mesh->n_halffaces();
125 else if (propertyInfo.isEdgeProp())
126 return mesh->n_edges();
127 else if (propertyInfo.isHalfedgeProp())
128 return mesh->n_halfedges();
129 else //if (propertyInfo.isVertexProp())
130 return mesh->n_vertices();
131 }
132
133 template <typename MeshT>
134 QString OVMPropertyVisualizer<MeshT>::getHeader()
135 {
136 //Header: headerVersion, numberOfEntities, typeOfEntites, typeOfProperty, propertyName
137
138 QString header = QObject::tr("1"); //version
139 header.append(QObject::tr(", %1").arg(getEntityCount())); //number of entities
140 header.append(QObject::tr(", %1").arg(propertyInfo.entityType())); //type of entities
141 header.append(", ").append(propertyInfo.friendlyTypeName()); //type of property
142 header.append(", ").append(propertyInfo.propName().c_str()); // name of property
143 return header;
144 }
145
146 template <typename MeshT>
147 unsigned int OVMPropertyVisualizer<MeshT>::getClosestPrimitiveId(unsigned int _face, ACG::Vec3d& _hitPoint)
148 {
149 if (propertyInfo.isHalffaceProp())
150 return getClosestHalffaceId(_face, _hitPoint);
151 else// if (propertyInfo.isHalfedgeProp())
152 return getClosestHalfedgeId(_face, _hitPoint);
153 }
154
155 template <typename MeshT>
156 unsigned int OVMPropertyVisualizer<MeshT>::getClosestHalffaceId(unsigned int _face, ACG::Vec3d& _hitPoint)
157 {
158 ACG::Vec3d direction = PluginFunctions::viewingDirection();
159
160 OpenVolumeMesh::HalfFaceHandle hfh = mesh->halfface_handle(OpenVolumeMesh::FaceHandle(_face), 0);
161 OpenVolumeMesh::HalfFaceVertexIter hfv_it = mesh->hfv_iter(hfh);
162 ACG::Vec3d p1 = mesh->vertex(*(hfv_it+0));
163 ACG::Vec3d p2 = mesh->vertex(*(hfv_it+1));
164 ACG::Vec3d p3 = mesh->vertex(*(hfv_it+2));
165
166 ACG::Vec3d normal = (p2-p1)%(p3-p1);
167
168 if ((direction | normal) < 0)
169 return hfh.idx();
170 else
171 return mesh->halfface_handle(OpenVolumeMesh::FaceHandle(_face), 1).idx();
172 }
173
174 template <typename MeshT>
175 unsigned int OVMPropertyVisualizer<MeshT>::getClosestHalfedgeId(unsigned int _face, ACG::Vec3d& _hitPoint)
176 {
177 unsigned int halfface = getClosestHalffaceId(_face, _hitPoint);
178
179 OpenVolumeMesh::OpenVolumeMeshFace face = mesh->halfface(halfface);
180
181 const std::vector<OpenVolumeMesh::HalfEdgeHandle> & halfedges = face.halfedges();
182
183 double min_distance = DBL_MAX;
184 OpenVolumeMesh::HalfEdgeHandle closestHalfEdgeHandle;
185
186 for (std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator he_it = halfedges.begin(); he_it != halfedges.end(); ++he_it)
187 {
188 OpenVolumeMesh::OpenVolumeMeshEdge edge = OVMPropertyVisualizer<MeshT>::mesh->halfedge(*he_it);
189 ACG::Vec3d v1 = mesh->vertex(edge.from_vertex());
190 ACG::Vec3d v2 = mesh->vertex(edge.to_vertex());
191 ACG::Vec3d p = 0.5 * (v1+v2);
192 double distance = (p-_hitPoint).length();
193 if (distance < min_distance)
194 {
195 min_distance = distance;
196 closestHalfEdgeHandle = *he_it;
197 }
198
199 }
200
201 return closestHalfEdgeHandle.idx();
202 }
203
204
205 template <typename MeshT>
206 void OVMPropertyVisualizer<MeshT>::visualize(bool _setDrawMode, QWidget* _widget)
207 {
208 QWidget* tmp;
209 if (_widget)
210 {
211 tmp = widget;
212 widget = _widget;
213 }
214
215 if (propertyInfo.isCellProp())
216 visualizeCellProp(_setDrawMode);
217 else if (propertyInfo.isFaceProp())
218 visualizeFaceProp(_setDrawMode);
219 else if (propertyInfo.isHalffaceProp())
220 visualizeHalffaceProp(_setDrawMode);
221 else if (propertyInfo.isEdgeProp())
222 visualizeEdgeProp(_setDrawMode);
223 else if (propertyInfo.isHalfedgeProp())
224 visualizeHalfedgeProp(_setDrawMode);
225 else if (propertyInfo.isVertexProp())
226 visualizeVertexProp(_setDrawMode);
227
228 if (_widget)
229 {
230 widget = tmp;
231 }
232 }
233
234 template <typename MeshT>
235 OpenMesh::Vec4f OVMPropertyVisualizer<MeshT>::convertColor(const QColor _color){
236
237 OpenMesh::Vec4f color;
238
239 color[0] = _color.redF();
240 color[1] = _color.greenF();
241 color[2] = _color.blueF();
242 color[3] = _color.alphaF();
243
244 return color;
245 }
246
247 template <typename MeshT>
248 void OVMPropertyVisualizer<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
249 {
250 emit log(LOGERR, "Visualizing FaceProp not implemented");
251 }
252
253 template <typename MeshT>
254 void OVMPropertyVisualizer<MeshT>::visualizeEdgeProp(bool /*_setDrawMode*/)
255 {
256 emit log(LOGERR, "Visualizing EdgeProp not implemented");
257 }
258
259 template <typename MeshT>
260 void OVMPropertyVisualizer<MeshT>::visualizeHalfedgeProp(bool /*_setDrawMode*/)
261 {
262 emit log(LOGERR, "Visualizing HalfedgeProp not implemented");
263 }
264
265 template <typename MeshT>
266 void OVMPropertyVisualizer<MeshT>::visualizeVertexProp(bool /*_setDrawMode*/)
267 {
268 emit log(LOGERR, "Visualizing VertexProp not implemented");
269 }
270
271 template <typename MeshT>
272 void OVMPropertyVisualizer<MeshT>::visualizeCellProp(bool /*_setDrawMode*/)
273 {
274 emit log(LOGERR, "Visualizing CellProp not implemented");
275 }
276
277 template <typename MeshT>
278 void OVMPropertyVisualizer<MeshT>::visualizeHalffaceProp(bool /*_setDrawMode*/)
279 {
280 emit log(LOGERR, "Visualizing HalffaceProp not implemented");
281 }
282
283 template<typename MeshT>
284 template<typename PropType>
285 inline void OVMPropertyVisualizer<MeshT>::duplicateProperty_stage1() {
286 std::string newPropertyName;
287 for (int i = 1;; ++i) {
288 std::ostringstream oss;
289 oss << propertyInfo.propName() << " Copy " << i;
290 newPropertyName = oss.str();
291
292 if (propertyInfo.isCellProp())
293 {
294 if(!mesh->template cell_property_exists<PropType>(newPropertyName)) break;
295 }
296 else if (propertyInfo.isFaceProp())
297 {
298 if(!mesh->template face_property_exists<PropType>(newPropertyName)) break;
299 }
300 else if (propertyInfo.isHalffaceProp())
301 {
302 if(!mesh->template halfface_property_exists<PropType>(newPropertyName)) break;
303 }
304 else if (propertyInfo.isEdgeProp())
305 {
306 if(!mesh->template edge_property_exists<PropType>(newPropertyName)) break;
307 }
308 else if (propertyInfo.isHalfedgeProp())
309 {
310 if(!mesh->template halfedge_property_exists<PropType>(newPropertyName)) break;
311 }
312 else if (propertyInfo.isVertexProp())
313 {
314 if(!mesh->template vertex_property_exists<PropType>(newPropertyName)) break;
315 }
316 }
317
318 if (propertyInfo.isCellProp())
319 {
320 OpenVolumeMesh::CellPropertyT<PropType> prop = mesh->template request_cell_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
321 OpenVolumeMesh::CellPropertyT<PropType> newProp = mesh->template request_cell_property< PropType >(newPropertyName);
322 mesh->set_persistent(newProp, true);
323 std::for_each(mesh->cells_begin(), mesh->cells_end(), CopyProperty<OpenVolumeMesh::CellPropertyT<PropType> >(newProp, prop, mesh));
324 }
325 else if (propertyInfo.isFaceProp())
326 {
327 OpenVolumeMesh::FacePropertyT<PropType> prop = mesh->template request_face_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
328 OpenVolumeMesh::FacePropertyT<PropType> newProp = mesh->template request_face_property< PropType >(newPropertyName);
329 mesh->set_persistent(newProp, true);
330 std::for_each(mesh->faces_begin(), mesh->faces_end(), CopyProperty<OpenVolumeMesh::FacePropertyT<PropType> >(newProp, prop, mesh));
331 }
332 else if (propertyInfo.isHalffaceProp())
333 {
334 OpenVolumeMesh::HalfFacePropertyT<PropType> prop = mesh->template request_halfface_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
335 OpenVolumeMesh::HalfFacePropertyT<PropType> newProp = mesh->template request_halfface_property< PropType >(newPropertyName);
336 mesh->set_persistent(newProp, true);
337 std::for_each(mesh->halffaces_begin(), mesh->halffaces_end(), CopyProperty<OpenVolumeMesh::HalfFacePropertyT<PropType> >(newProp, prop, mesh));
338 }
339 else if (propertyInfo.isEdgeProp())
340 {
341 OpenVolumeMesh::EdgePropertyT<PropType> prop = mesh->template request_edge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
342 OpenVolumeMesh::EdgePropertyT<PropType> newProp = mesh->template request_edge_property< PropType >(newPropertyName);
343 mesh->set_persistent(newProp, true);
344 std::for_each(mesh->edges_begin(), mesh->edges_end(), CopyProperty<OpenVolumeMesh::EdgePropertyT<PropType> >(newProp, prop, mesh));
345 }
346 else if (propertyInfo.isHalfedgeProp())
347 {
348 OpenVolumeMesh::HalfEdgePropertyT<PropType> prop = mesh->template request_halfedge_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
349 OpenVolumeMesh::HalfEdgePropertyT<PropType> newProp = mesh->template request_halfedge_property< PropType >(newPropertyName);
350 mesh->set_persistent(newProp, true);
351 std::for_each(mesh->halfedges_begin(), mesh->halfedges_end(), CopyProperty<OpenVolumeMesh::HalfEdgePropertyT<PropType> >(newProp, prop, mesh));
352 }
353 else if (propertyInfo.isVertexProp())
354 {
355 OpenVolumeMesh::VertexPropertyT<PropType> prop = mesh->template request_vertex_property<PropType>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
356 OpenVolumeMesh::VertexPropertyT<PropType> newProp = mesh->template request_vertex_property< PropType >(newPropertyName);
357 mesh->set_persistent(newProp, true);
358 std::for_each(mesh->vertices_begin(), mesh->vertices_end(), CopyProperty<OpenVolumeMesh::VertexPropertyT<PropType> >(newProp, prop, mesh));
359 }
360 }
361
362 template <typename MeshT>
363 void OVMPropertyVisualizer<MeshT>::clear()
364 {
365 VolumeMeshObject<MeshT>* object;
366 PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
367
368 if (propertyInfo.isCellProp())
369 object->colors().clear_cell_colors();
370 else if (propertyInfo.isFaceProp())
371 object->colors().clear_face_colors();
372 else if (propertyInfo.isHalffaceProp())
373 object->colors().clear_halfface_colors();
374 else if (propertyInfo.isEdgeProp())
375 object->colors().clear_edge_colors();
376 else if (propertyInfo.isHalfedgeProp())
377 object->colors().clear_halfedge_colors();
378 else if (propertyInfo.isVertexProp())
379 object->colors().clear_vertex_colors();
380
381 object->setObjectDrawMode(drawModes.cellsFlatShaded);
382 }
383
384 template <typename MeshT>
385 void OVMPropertyVisualizer<MeshT>::setCellPropertyFromText(unsigned int /*index*/, QString /*text*/)
386 {
387 emit log(LOGERR, "Setting CellProp not implemented for this property type");
388 }
389
390 template <typename MeshT>
391 void OVMPropertyVisualizer<MeshT>::setFacePropertyFromText(unsigned int /*index*/, QString /*text*/)
392 {
393 emit log(LOGERR, "Setting FaceProp not implemented for this property type");
394 }
395
396 template <typename MeshT>
397 void OVMPropertyVisualizer<MeshT>::setHalffacePropertyFromText(unsigned int /*index*/, QString /*text*/)
398 {
399 emit log(LOGERR, "Setting HalffaceProp not implemented for this property type");
400 }
401
402 template <typename MeshT>
403 void OVMPropertyVisualizer<MeshT>::setEdgePropertyFromText(unsigned int /*index*/, QString /*text*/)
404 {
405 emit log(LOGERR, "Setting EdgeProp not implemented for this property type");
406 }
407
408 template <typename MeshT>
409 void OVMPropertyVisualizer<MeshT>::setHalfedgePropertyFromText(unsigned int /*index*/, QString /*text*/)
410 {
411 emit log(LOGERR, "Setting HalfedgeProp not implemented for this property type");
412 }
413
414 template <typename MeshT>
415 void OVMPropertyVisualizer<MeshT>::setVertexPropertyFromText(unsigned int /*index*/, QString /*text*/)
416 {
417 emit log(LOGERR, "Setting VertexProp not implemented for this property type");
418 }
419
420 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
OpenVolumeMesh::EdgeHandle
Definition: OpenVolumeMeshHandle.hh:99
OpenVolumeMesh::CellHandle
Definition: OpenVolumeMeshHandle.hh:101
OpenVolumeMesh::FaceHandle
Definition: OpenVolumeMeshHandle.hh:100
PolyhedralMesh.hh
LOGERR
Definition: LoggingInterface.hh:107
OpenVolumeMesh::OpenVolumeMeshEdge
Definition: BaseEntities.hh:52
OpenVolumeMesh::FacePropertyT
Definition: PropertyDefines.hh:108
PluginFunctions::viewingDirection
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up, int _viewer)
Set the viewing direction.
Definition: PluginFunctions.cc:691
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
OpenVolumeMesh::HalfFaceHandle
Definition: OpenVolumeMeshHandle.hh:103
VolumeMeshObject
Definition: VolumeMeshObject.hh:72
VolumeMeshObject::colors
const ColorAttrib & colors() const
return a pointer to the mesh
Definition: VolumeMeshObject.hh:138
OpenVolumeMesh::CellPropertyT
Definition: PropertyDefines.hh:128
OpenMesh::VectorT
Definition: Vector11T.hh:83
OpenVolumeMesh::EdgePropertyT
Definition: PropertyDefines.hh:88
OpenVolumeMesh::VertexPropertyT
Property classes for the different entity types.
Definition: PropertyDefines.hh:78
OpenVolumeMesh::HalfEdgeHandle
Definition: OpenVolumeMeshHandle.hh:102
OpenVolumeMesh::HalfEdgePropertyT
Definition: PropertyDefines.hh:98
OpenVolumeMesh::VertexHandle
Definition: OpenVolumeMeshHandle.hh:98
OpenVolumeMesh::OpenVolumeMeshFace
Definition: BaseEntities.hh:90
HexahedralMesh.hh
OpenVolumeMesh::HalfFacePropertyT
Definition: PropertyDefines.hh:118
OpenVolumeMesh::HalfFaceVertexIter
Definition: Iterators.hh:568