Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OMPropertyVisualizerVectorT.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 #define OM_PROPERTY_VISUALIZER_VECTOR_CC
51 
52 #include "OMPropertyVisualizerVector.hh"
53 
54 template <typename MeshT>
56  : OMPropertyVisualizer<MeshT>(_mesh, _propertyInfo)
57 {
58  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
59  VectorWidget* w = new VectorWidget();
60  w->paramVector->setTitle(QString("3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
61  PropertyVisualizer::widget = w;
62 
63  lineNode = new ACG::SceneGraph::LineNode( ACG::SceneGraph::LineNode::LineSegmentsMode, dynamic_cast < ACG::SceneGraph::SeparatorNode* >( PluginFunctions::getRootNode() ) );
64 
65  if (!_propertyInfo.isFaceProp())
66  {
67  w->vectors_edges_rb->hide();
68  }
69 
70 }
71 
72 template <typename MeshT>
74 {
75  lineNode->clear();
77 }
78 
79 template <typename MeshT>
81 {
82  return OMPropertyVisualizer<MeshT>::template getPropertyText_<typename MeshT::Point>(index);
83 }
84 
85 
86 namespace {
87 
88 template<typename PROPTYPE, typename MeshT, typename ENTITY_IT, typename PROPINFO_TYPE>
89 void visualizeVectorAsColorForEntity(MeshT *mesh, const ENTITY_IT e_begin, const ENTITY_IT e_end,
90  const PROPINFO_TYPE &propinfo) {
91  PROPTYPE prop;
92  if (!mesh->get_property_handle(prop, propinfo.propName()))
93  throw VizException("Getting PropHandle from mesh for selected property failed.");
94  for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
95  typename MeshT::Point v = mesh->property(prop, *e_it).normalized() * .5 + typename MeshT::Point(.5, .5, .5);
96  mesh->set_color(*e_it, typename MeshT::Color(v[0], v[1], v[2], 1.0));
97  }
98 }
99 
100 template<typename PROPTYPE, typename MeshT, typename ENTITY_IT, typename PROPINFO_TYPE>
101 void visualizeVectorLengthAsColorForEntity(
102  MeshT *mesh, const ENTITY_IT e_begin, const ENTITY_IT e_end,
103  const PROPINFO_TYPE &propinfo) {
104  PROPTYPE prop;
105  if (!mesh->get_property_handle(prop, propinfo.propName()))
106  throw VizException("Getting PropHandle from mesh for selected "
107  "property failed.");
108 
109  double min = std::numeric_limits<double>::infinity();
110  double max = -std::numeric_limits<double>::infinity();
111 
112  for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
113  const double val = mesh->property(prop, *e_it).norm();
114  min = std::min(min, val);
115  max = std::max(max, val);
116  }
117 
118  ACG::ColorCoder color_coder(min, max);
119 
120  for (ENTITY_IT e_it = e_begin; e_it != e_end; ++e_it) {
121  mesh->set_color(*e_it, color_coder(mesh->property(prop, *e_it).norm()));
122  }
123 }
124 
125 }
126 
127 template <typename MeshT>
129 {
130  VectorWidget* const w = (VectorWidget*)PropertyVisualizer::widget;
131  if (w->vectors_edges_rb->isChecked()) {
132  visualizeFacePropOnEdges();
133  } else if (w->vectors_colors_rb->isChecked() ||
134  w->vectors_length_color_rb->isChecked()) {
135  if ( !OMPropertyVisualizer<MeshT>::mesh->has_face_colors() )
136  OMPropertyVisualizer<MeshT>::mesh->request_face_colors();
137 
138  if (w->vectors_colors_rb->isChecked()) {
139  visualizeVectorAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
141  OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
142  OMPropertyVisualizer<MeshT>::mesh->faces_end(),
143  PropertyVisualizer::propertyInfo);
144  } else {
145  visualizeVectorLengthAsColorForEntity<OpenMesh::FPropHandleT<typename MeshT::Point> >(
146  OMPropertyVisualizer<MeshT>::mesh,
147  OMPropertyVisualizer<MeshT>::mesh->faces_begin(),
148  OMPropertyVisualizer<MeshT>::mesh->faces_end(),
149  PropertyVisualizer::propertyInfo);
150  }
151  if (_setDrawMode)
153  }
154  else visualizeFacePropAsStrokes();
155 }
156 
157 template <typename MeshT>
159 {
160  VectorWidget* const w = (VectorWidget*)PropertyVisualizer::widget;
161  if (w->vectors_colors_rb->isChecked() ||
162  w->vectors_length_color_rb->isChecked()) {
163  if ( !OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
164  OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
165  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
166  if ( !mesh->has_edge_colors() )
167  mesh->request_edge_colors();
168  if (w->vectors_colors_rb->isChecked()) {
169  visualizeVectorAsColorForEntity<
171  mesh,
172  mesh->edges_begin(),
173  mesh->edges_end(),
174  PropertyVisualizer::propertyInfo);
175  } else {
176  visualizeVectorLengthAsColorForEntity<
178  mesh,
179  mesh->edges_begin(),
180  mesh->edges_end(),
181  PropertyVisualizer::propertyInfo);
182  }
183  if (_setDrawMode)
185  }
186  else visualizeEdgePropAsStrokes();
187 }
188 
189 template <typename MeshT>
191 {
192  VectorWidget* const w = (VectorWidget*)PropertyVisualizer::widget;
193  if (w->vectors_colors_rb->isChecked() ||
194  w->vectors_length_color_rb->isChecked()) {
195  if ( !OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
196  OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
197  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
198  if ( ! mesh->has_halfedge_colors() )
199  mesh->request_halfedge_colors();
200 
201  if (w->vectors_colors_rb->isChecked()) {
202  visualizeVectorAsColorForEntity<
204  mesh,
205  mesh->halfedges_begin(),
206  mesh->halfedges_end(),
207  PropertyVisualizer::propertyInfo);
208  } else {
209  visualizeVectorLengthAsColorForEntity<
211  mesh,
212  mesh->halfedges_begin(),
213  mesh->halfedges_end(),
214  PropertyVisualizer::propertyInfo);
215  }
216 
217  if (_setDrawMode)
220  }
221  else visualizeHalfedgePropAsStrokes();
222 }
223 
224 template <typename MeshT>
226 {
227  VectorWidget* const w = (VectorWidget*)PropertyVisualizer::widget;
228  if (w->vectors_colors_rb->isChecked() ||
229  w->vectors_length_color_rb->isChecked()) {
230  if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
231  OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
232 
233  if (w->vectors_colors_rb->isChecked()) {
234  visualizeVectorAsColorForEntity<
236  OMPropertyVisualizer<MeshT>::mesh,
237  OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
238  OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
239  PropertyVisualizer::propertyInfo);
240  } else {
241  visualizeVectorLengthAsColorForEntity<
243  OMPropertyVisualizer<MeshT>::mesh,
244  OMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
245  OMPropertyVisualizer<MeshT>::mesh->vertices_end(),
246  PropertyVisualizer::propertyInfo);
247  }
248  if (_setDrawMode)
251  }
252  else visualizeVertexPropAsStrokes();
253 }
254 
255 template <typename MeshT>
257 
258  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
259  MeshT* _mesh = OMPropertyVisualizer<MeshT>::mesh;
260 
261 
262  const double thresh_1 = w->vectors_edges_alpha->value();
263  const double thresh_2 = std::min(thresh_1, w->vectors_edges_alpha->value());
264 
266  if (!_mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName()))
267  throw VizException("Getting PropHandle from mesh for selected property failed.");
268 
269  if (!_mesh->has_edge_colors())
270  _mesh->request_edge_colors();
271  const ACG::Vec4f cold(0, 0, 0, 1.0), hot(0, 1, 0, 1.0), degen(1, 1, 0, 1.0);
272  for (typename MeshT::EdgeIter e_it = _mesh->edges_begin(), e_end = _mesh->edges_end();
273  e_it != e_end; ++e_it) {
274  typename MeshT::Point p1 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 0)));
275  typename MeshT::Point p2 = _mesh->property(prop, _mesh->face_handle(_mesh->halfedge_handle(*e_it, 1)));
276 
277  ACG::Vec4f color;
278 
279  const char degenerate = ((p1.sqrnorm() < 1e-6) ? 1 : 0) | ((p2.sqrnorm() < 1e-6) ? 2 : 0);
280  if (degenerate == 3) {
281  color = cold;
282  } else if (degenerate == 0) {
283  p1.normalize(); p2.normalize();
284  const double alpha = std::min(1.0, std::abs(p1 | p2));
285  if (alpha < thresh_1)
286  color = hot;
287  else if (alpha > thresh_2)
288  color = cold;
289  else {
290  const double beta = (alpha - thresh_1) / (thresh_2 - thresh_1);
291  color = cold * beta + hot * (1.0 - beta);
292  }
293  } else {
294  color = degen;
295  }
296  _mesh->set_color(*e_it, color);
297  }
299 }
300 
301 template <typename MeshT>
303  {
304  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
305 
306  lineNode->clear();
307 
308  typename MeshT::Color color = OMPropertyVisualizer<MeshT>::convertColor(vectorWidget->lineColor->color());
309 
311 
312  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
313  return;
314 
315  for (typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
316 
317  typename MeshT::Point center(0.0, 0.0, 0.0);
318  int vCount = 0;
319 
320  for (typename MeshT::FaceVertexIter fv_it(*(OMPropertyVisualizer<MeshT>::mesh),*f_it); fv_it.is_valid(); ++fv_it){
321  vCount++;
322  center += OMPropertyVisualizer<MeshT>::mesh->point(*fv_it);
323  }
324 
325  center /= vCount;
326 
327  typename MeshT::Point v = (OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
328 
329  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
330  v.normalize();
331 
332  if(vectorWidget->scale->isChecked())
333  v *= vectorWidget->scaleBox->value();
334 
335  lineNode->add_line( center, (center+v) );
336  lineNode->add_color(color);
337  }
338 }
339 
340 template <typename MeshT>
342 {
343  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
344 
345  lineNode->clear();
346 
347  typename MeshT::Color color = OMPropertyVisualizer<MeshT>::convertColor(vectorWidget->lineColor->color());
348 
349  //TODO check if this also works if the property is Vec3f
351 
352  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
353  return;
354 
355  for (typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
356 
357  typename MeshT::HalfedgeHandle hh = OMPropertyVisualizer<MeshT>::mesh->halfedge_handle( *e_it, 0 );
358 
359  typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( hh );
360  typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( hh );
361 
362  typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
363  typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it);
364 
365  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
366  v.normalize();
367 
368  if(vectorWidget->scale->isChecked())
369  v *= vectorWidget->scaleBox->value();
370 
371  lineNode->add_line( v1, (v1+v) );
372  lineNode->add_color(color);
373  }
374 }
375 
376 template <typename MeshT>
378 {
379  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
380 
381  lineNode->clear();
382 
383  typename MeshT::Color color = OMPropertyVisualizer<MeshT>::convertColor(vectorWidget->lineColor->color());
384 
385  //TODO check if this also works if the property is Vec3f
387 
388  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
389  return;
390 
391  for (typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
392 
393  typename MeshT::VertexHandle vh0 = OMPropertyVisualizer<MeshT>::mesh->from_vertex_handle( *he_it );
394  typename MeshT::VertexHandle vh1 = OMPropertyVisualizer<MeshT>::mesh->to_vertex_handle( *he_it );
395 
396  typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point(vh0) + 0.5 * (OMPropertyVisualizer<MeshT>::mesh->point(vh1) - OMPropertyVisualizer<MeshT>::mesh->point(vh0));
397  typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it);
398 
399  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
400  v.normalize();
401 
402  if(vectorWidget->scale->isChecked())
403  v *= vectorWidget->scaleBox->value();
404 
405  lineNode->add_line( v1, (v1+v) );
406  lineNode->add_color(color);
407  }
408 }
409 
410 template <typename MeshT>
412 {
413  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
414 
415  lineNode->clear();
416 
417  typename MeshT::Color color = OMPropertyVisualizer<MeshT>::convertColor(vectorWidget->lineColor->color());
418 
419  //TODO check if this also works if the property is Vec3f
421 
422  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
423  return;
424 
425  for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
426 
427  typename MeshT::Point v1 = OMPropertyVisualizer<MeshT>::mesh->point( *v_it );
428  typename MeshT::Point v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
429 
430  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
431  v.normalize();
432 
433  if(vectorWidget->scale->isChecked())
434  v *= vectorWidget->scaleBox->value();
435 
436  lineNode->add_line( v1, (v1+v) );
437  lineNode->add_color(color);
438  }
439 }
440 
441 template <typename MeshT>
442 void OMPropertyVisualizerVector<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
443 {
445  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
446 
447  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
448  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
449 
450 
451  typename MeshT::FaceHandle fh = mesh->face_handle(index);
452 
453  mesh->property(prop, fh) = this->strToVec3d(text);
454 }
455 
456 template <typename MeshT>
457 void OMPropertyVisualizerVector<MeshT>::setEdgePropertyFromText(unsigned int index, QString text)
458 {
460  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
461 
462  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
463  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
464 
465 
466  typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
467 
468  mesh->property(prop, eh) = this->strToVec3d(text);
469 }
470 
471 template <typename MeshT>
472 void OMPropertyVisualizerVector<MeshT>::setHalfedgePropertyFromText(unsigned int index, QString text)
473 {
475  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
476 
477  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
478  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
479 
480 
481  typename MeshT::HalfedgeHandle heh = mesh->halfedge_handle(index);
482 
483  mesh->property(prop, heh) = this->strToVec3d(text);
484 }
485 
486 template <typename MeshT>
487 void OMPropertyVisualizerVector<MeshT>::setVertexPropertyFromText(unsigned int index, QString text)
488 {
490  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
491 
492  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
493  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
494 
495 
496  typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
497 
498  mesh->property(prop, vh) = this->strToVec3d(text);
499 }
500 
501 
502 template<typename MeshT>
504 {
505  OMPropertyVisualizer<MeshT>::template removeProperty_stage1<typename MeshT::Point>();
506 }
507 
508 template<typename MeshT>
510 {
511  OMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<typename MeshT::Point>();
512 }
513 
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:83
virtual void removeProperty()
Removes the property.
virtual void duplicateProperty()
Duplicates the property.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
DrawMode SOLID_FLAT_SHADED
draw flat shaded faces (requires face normals)
Definition: DrawModes.cc:87
virtual void clear()
Clears the property.
virtual void clear()
Clears the property.
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:91
Class for generating nice colors for doubles.
Definition: ColorCoder.hh:75
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:90
Cellection of information about a property.
Definition: Utils.hh:115
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:109