Developer Documentation
OVMPropertyVisualizerVectorT_impl.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 
45 #define OVM_PROPERTY_VISUALIZER_VECTOR_CC
46 
47 #include <ACG/Utils/ColorConversion.hh>
48 #include "OVMPropertyVisualizerVector.hh"
49 
50 
51 template <typename MeshT, typename VectorT>
53  : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
54 {
55  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
56  VectorWidget* w = new VectorWidget();
57  w->paramVector->setTitle(QString("3D Vector Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
58  PropertyVisualizer::widget = w;
59 
60  BaseObjectData *bod;
61  PluginFunctions::getObject(objectID, bod);
62  lineNode = new ACG::SceneGraph::LineNode(ACG::SceneGraph::LineNode::LineSegmentsMode, bod->manipulatorNode());
63  w->vectors_edges_rb->hide();
64  this->connect(w->lineWidth, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
65  [this](double value) {lineNode->set_line_width(value);});
66 }
67 
68 template <typename MeshT, typename VectorT>
70 {
71  lineNode->clear();
73 }
74 
75 template <typename MeshT, typename VectorT>
77 {
78  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<VectorT>();
79 }
80 
81 template<typename MeshT, typename VectorT>
82 template<typename PropType, typename EntityIterator>
83 void OVMPropertyVisualizerVector<MeshT,VectorT>::visualizeVectorAsColorForEntity(PropType prop, EntityIterator e_begin, EntityIterator e_end, bool normalized) {
84  if (!prop)
85  throw VizException("Getting PropHandle from mesh for selected property failed.");
88  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it) {
89  ACG::Vec3d v = convert_to_acg(prop[*e_it]);
90  if (normalized)
91  v = v.normalized() * 0.5 + ACG::Vec3d(0.5);
92  else
93  v = v.min(ACG::Vec3d(1, 1, 1)).max(ACG::Vec3d(0, 0, 0));
94  object->colors()[*e_it] = ACG::Vec4f(v[0], v[1], v[2], 1.0);
95  }
96 }
97 
98 template <typename MeshT, typename VectorT>
100 {
101  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
102  if (w->vectors_colors_rb->isChecked())
103  {
105  visualizeVectorAsColorForEntity(prop,
106  OVMPropertyVisualizer<MeshT>::mesh->cells_begin(),
108  w->normalize_colors->isChecked());
109  if (_setDrawMode)
110  {
111  VolumeMeshObject<MeshT>* object;
113  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.cellsColoredPerCell);
114  }
115  }
116  else visualizeCellPropAsStrokes();
117 }
118 
119 template <typename MeshT, typename VectorT>
121 {
122  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
123  if (w->vectors_colors_rb->isChecked())
124  {
126  visualizeVectorAsColorForEntity(prop,
127  OVMPropertyVisualizer<MeshT>::mesh->faces_begin(),
129  w->normalize_colors->isChecked());
130  if (_setDrawMode)
131  {
132  VolumeMeshObject<MeshT>* object;
134  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.facesColoredPerFace);
135  }
136  }
137  else visualizeFacePropAsStrokes();
138 }
139 
140 
141 template <typename MeshT, typename VectorT>
143 {
144  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
145  if (w->vectors_colors_rb->isChecked())
146  {
148  visualizeVectorAsColorForEntity(prop,
149  OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin(),
150  OVMPropertyVisualizer<MeshT>::mesh->halffaces_end(),
151  w->normalize_colors->isChecked());
152  if (_setDrawMode)
153  {
154  VolumeMeshObject<MeshT>* object;
156  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halffacesColoredPerHalfface);
157  }
158  }
159  else visualizeHalffacePropAsStrokes();
160 }
161 
162 template <typename MeshT, typename VectorT>
164 {
165  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
166  if (w->vectors_colors_rb->isChecked())
167  {
169  visualizeVectorAsColorForEntity(prop,
170  OVMPropertyVisualizer<MeshT>::mesh->edges_begin(),
172  w->normalize_colors->isChecked());
173  if (_setDrawMode)
174  {
175  VolumeMeshObject<MeshT>* object;
177  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.edgesColoredPerEdge);
178  }
179  }
180  else visualizeEdgePropAsStrokes();
181 }
182 
183 template <typename MeshT, typename VectorT>
185 {
186  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
187  if (w->vectors_colors_rb->isChecked())
188  {
190  visualizeVectorAsColorForEntity(prop,
191  OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin(),
192  OVMPropertyVisualizer<MeshT>::mesh->halfedges_end(),
193  w->normalize_colors->isChecked());
194  if (_setDrawMode)
195  {
196  VolumeMeshObject<MeshT>* object;
198  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.halfedgesColoredPerHalfedge);
199  }
200  }
201  else visualizeHalfedgePropAsStrokes();
202 }
203 
204 template <typename MeshT, typename VectorT>
206 {
207  VectorWidget* w = (VectorWidget*)PropertyVisualizer::widget;
208  if (w->vectors_colors_rb->isChecked())
209  {
211  visualizeVectorAsColorForEntity(prop,
212  OVMPropertyVisualizer<MeshT>::mesh->vertices_begin(),
213  OVMPropertyVisualizer<MeshT>::mesh->vertices_end(),
214  w->normalize_colors->isChecked());
215  if (_setDrawMode)
216  {
217  VolumeMeshObject<MeshT>* object;
219  object->setObjectDrawMode(OVMPropertyVisualizer<MeshT>::drawModes.verticesColored);
220  }
221  }
222  else visualizeVertexPropAsStrokes();
223 }
224 
225 template <typename MeshT, typename VectorT>
227 {
228  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
229 
230  lineNode->clear();
231 
232  ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
233 
234  OpenVolumeMesh::FacePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_face_property<VectorT>(PropertyVisualizer::propertyInfo.propName());
235 
236  if ( !prop )
237  return;
238 
240  for (OpenVolumeMesh::FaceIter f_it = f_begin; f_it != f_end; ++f_it){
241 
242  ACG::Vec3d center(0.0, 0.0, 0.0);
243  int vCount = 0;
244 
246  for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = OVMPropertyVisualizer<MeshT>::mesh->hfv_iter(hfh); hfv_it; ++hfv_it){
247  vCount++;
248  center += OVMPropertyVisualizer<MeshT>::mesh->vertex(*hfv_it);
249  }
250 
251  center /= vCount;
252 
253  ACG::Vec3d v = convert_to_acg(prop[*f_it]);
254 
255  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
256  v.normalize();
257 
258  if(vectorWidget->scale->isChecked())
259  v *= vectorWidget->scaleBox->value();
260 
261  lineNode->add_line( center, (center+v) );
262  lineNode->add_color(color);
263  }
264 }
265 
266 template <typename MeshT, typename VectorT>
268 {
269  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
270 
271  lineNode->clear();
272 
273  ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
274 
276  if ( !prop )
277  return;
278 
280  for (OpenVolumeMesh::EdgeIter e_it = e_begin; e_it != e_end; ++e_it){
281 
283  ACG::Vec3d v1 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.from_vertex());
284  ACG::Vec3d v2 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.to_vertex());
285  ACG::Vec3d start = 0.5*(v1+v2);
286 
287  ACG::Vec3d v = convert_to_acg(prop[*e_it]);
288 
289  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
290  v.normalize();
291 
292 
293 
294  if(vectorWidget->scale->isChecked())
295  v *= vectorWidget->scaleBox->value();
296 
297  lineNode->add_line( start, (start+v) );
298  lineNode->add_color(color);
299  }
300 }
301 
302 template <typename MeshT, typename VectorT>
304 {
305  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
306 
307  lineNode->clear();
308 
309  ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
310 
312  if ( !prop )
313  return;
314 
315  OpenVolumeMesh::HalfEdgeIter he_begin(OVMPropertyVisualizer<MeshT>::mesh->halfedges_begin()), he_end(OVMPropertyVisualizer<MeshT>::mesh->halfedges_end());
316  for (OpenVolumeMesh::HalfEdgeIter he_it = he_begin; he_it != he_end; ++he_it){
317 
319 
320  ACG::Vec3d v1 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.from_vertex());
321  ACG::Vec3d v2 = OVMPropertyVisualizer<MeshT>::mesh->vertex(edge.to_vertex());
322  ACG::Vec3d start = (2.0*v1+v2)/3.0;
323 
324  ACG::Vec3d v = convert_to_acg(prop[*he_it]);
325 
326  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
327  v.normalize();
328 
329  if(vectorWidget->scale->isChecked())
330  v *= vectorWidget->scaleBox->value();
331 
332  lineNode->add_line( start, (start+v) );
333  lineNode->add_color(color);
334  }
335 }
336 
337 template <typename MeshT, typename VectorT>
339 {
340  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
341 
342  lineNode->clear();
343 
344  ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
345 
347  if ( !prop )
348  return;
349 
351  for (OpenVolumeMesh::VertexIter v_it = v_begin; v_it != v_end; ++v_it){
352 
353  ACG::Vec3d start = OVMPropertyVisualizer<MeshT>::mesh->vertex(*v_it);
354 
355  ACG::Vec3d v = convert_to_acg(prop[*v_it]);
356 
357  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
358  v.normalize();
359 
360  if(vectorWidget->scale->isChecked())
361  v *= vectorWidget->scaleBox->value();
362 
363  lineNode->add_line( start, (start+v) );
364  lineNode->add_color(color);
365  }
366 }
367 
368 template <typename MeshT, typename VectorT>
370 {
371  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
372 
373  lineNode->clear();
374 
375  ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
376 
377  OpenVolumeMesh::CellPropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_cell_property<VectorT>(PropertyVisualizer::propertyInfo.propName());
378 
379  if ( !prop )
380  return;
381 
383  for (OpenVolumeMesh::CellIter c_it = c_begin; c_it != c_end; ++c_it){
384 
385  // Compute cell's center
386  ACG::Vec3d center(0.0, 0.0, 0.0);
387  unsigned int vCount = OVMPropertyVisualizer<MeshT>::mesh->n_vertices_in_cell(*c_it);
388  for(OpenVolumeMesh::CellVertexIter cv_it = OVMPropertyVisualizer<MeshT>::mesh->cv_iter(*c_it); cv_it.valid(); ++cv_it) {
389  center += OVMPropertyVisualizer<MeshT>::mesh->vertex(*cv_it) / (double)vCount;
390  }
391 
392  ACG::Vec3d v = convert_to_acg(prop[*c_it]);
393 
394  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
395  v.normalize();
396 
397  if(vectorWidget->scale->isChecked())
398  v *= vectorWidget->scaleBox->value();
399 
400  lineNode->add_line( center, (center+v) );
401  lineNode->add_color(color);
402  }
403 }
404 
405 template <typename MeshT, typename VectorT>
407 {
408  VectorWidget* vectorWidget = static_cast<VectorWidget*>(PropertyVisualizer::widget);
409 
410  lineNode->clear();
411 
412  ACG::Vec4f color = ACG::to_Vec4f(vectorWidget->lineColor->color());
413 
414  OpenVolumeMesh::HalfFacePropertyT<VectorT> prop = OVMPropertyVisualizer<MeshT>::mesh->template request_halfface_property<VectorT>(PropertyVisualizer::propertyInfo.propName());
415 
416  if ( !prop )
417  return;
418 
419  OpenVolumeMesh::HalfFaceIter hf_begin(OVMPropertyVisualizer<MeshT>::mesh->halffaces_begin()), hf_end(OVMPropertyVisualizer<MeshT>::mesh->halffaces_end());
420  for (OpenVolumeMesh::HalfFaceIter hf_it = hf_begin; hf_it != hf_end; ++hf_it){
421 
422  ACG::Vec3d center(0.0, 0.0, 0.0);
423  int vCount = 0;
424 
425  for (OpenVolumeMesh::HalfFaceVertexIter hfv_it = OVMPropertyVisualizer<MeshT>::mesh->hfv_iter(*hf_it); hfv_it; ++hfv_it){
426  vCount++;
427  center += OVMPropertyVisualizer<MeshT>::mesh->vertex(*hfv_it);
428  }
429 
430  center /= vCount;
431 
432  ACG::Vec3d v = convert_to_acg(prop[*hf_it]);
433 
434  if (vectorWidget->normalize->isChecked() && v.sqrnorm() > 1e-12)
435  v.normalize();
436 
437  if(vectorWidget->scale->isChecked())
438  v *= vectorWidget->scaleBox->value();
439 
440  lineNode->add_line( center, (center+v) );
441  lineNode->add_color(color);
442  }
443 }
444 
445 template <typename MeshT, typename VectorT>
447 {
448  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<VectorT>(index);
449 }
450 
451 
452 template <typename MeshT, typename VectorT>
453 void OVMPropertyVisualizerVector<MeshT,VectorT>::setCellPropertyFromText(unsigned int index, QString text)
454 {
456 
457  OpenVolumeMesh::CellPropertyT<VectorT> prop = mesh->template request_cell_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
458  if ( !prop )
459  {
460  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
461  return;
462  }
463 
464  OpenVolumeMesh::CellHandle ch(index);
465 
466  prop[ch] = this->template strToVec3<VectorT>(text);
467 }
468 
469 template <typename MeshT, typename VectorT>
470 void OVMPropertyVisualizerVector<MeshT,VectorT>::setFacePropertyFromText(unsigned int index, QString text)
471 {
473 
474  OpenVolumeMesh::FacePropertyT<VectorT> prop = mesh->template request_face_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
475  if ( !prop )
476  {
477  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
478  return;
479  }
480 
481  OpenVolumeMesh::FaceHandle fh(index);
482 
483  prop[fh] = this->template strToVec3<VectorT>(text);
484 }
485 
486 template <typename MeshT, typename VectorT>
488 {
490 
491  OpenVolumeMesh::HalfFacePropertyT<VectorT> prop = mesh->template request_halfface_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
492  if ( !prop )
493  {
494  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
495  return;
496  }
497 
499 
500  prop[hfh] = this->template strToVec3<VectorT>(text);
501 }
502 
503 template <typename MeshT, typename VectorT>
504 void OVMPropertyVisualizerVector<MeshT,VectorT>::setEdgePropertyFromText(unsigned int index, QString text)
505 {
507 
508  OpenVolumeMesh::EdgePropertyT<VectorT> prop = mesh->template request_edge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
509  if ( !prop )
510  {
511  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
512  return;
513  }
514 
515  OpenVolumeMesh::EdgeHandle eh(index);
516 
517  prop[eh] = this->template strToVec3<VectorT>(text);
518 }
519 
520 template <typename MeshT, typename VectorT>
522 {
524 
525  OpenVolumeMesh::HalfEdgePropertyT<VectorT> prop = mesh->template request_halfedge_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
526  if ( !prop )
527  {
528  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
529  return;
530  }
531 
533 
534  prop[heh] = this->template strToVec3<VectorT>(text);
535 }
536 
537 template <typename MeshT, typename VectorT>
539 {
541 
542  OpenVolumeMesh::VertexPropertyT<VectorT> prop = mesh->template request_vertex_property<VectorT>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
543  if ( !prop )
544  {
545  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
546  return;
547  }
548 
550 
551  prop[vh] = this->template strToVec3<VectorT>(text);
552 }
553 
virtual void clear()
Clears a property.
void duplicateProperty() override
Duplicates a property.
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:138
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:464
Scalar min() const
return the minimal component
Definition: Vector11T.hh:531
QtTranslationManipulatorNode * manipulatorNode()
Cellection of information about a property.
Definition: Utils.hh:109
void clear() override
Clears a property.
decltype(std::declval< S >() *std::declval< S >()) sqrnorm() const
compute squared euclidean norm
Definition: Vector11T.hh:421
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
Definition: Vector11T.hh:453
QString getPropertyText(unsigned int index) override
Returns the value of a property in text form.
VectorT< double, 3 > Vec3d
Definition: VectorT.hh:121