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