Developer Documentation
OMPropertyVisualizerDoubleT.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_DOUBLE_CC
51 
52 #include "OMPropertyVisualizerDouble.hh"
53 
54 template <typename MeshT>
56  : OMPropertyVisualizer<MeshT>(_mesh, _propertyInfo)
57 {
58  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
59  DoubleWidget* w = new DoubleWidget();
60  w->paramDouble->setTitle(QString("Double Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
61  PropertyVisualizer::widget = w;
62 }
63 
64 template <typename MeshT>
66 {
67  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
68  typename MeshT::Color colorMin, colorMax;
69 
70  colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
71  colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
72 
73  // color coder in [0,1]
74  ACG::ColorCoder cc;
75 
77 
78  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
79  return;
80 
81  double min, max;
82 
83  if ( doubleWidget->doubleAbsolute->isChecked() ){
84  min = FLT_MAX;
85  max = 0.0;
86  } else {
87  min = FLT_MAX;
88  max = FLT_MIN;
89  }
90 
91  for (typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
92  if ( doubleWidget->doubleAbsolute->isChecked() ){
93  min = std::min( min, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it)));
94  max = std::max( max, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it)));
95  } else {
96  min = std::min( min, OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
97  max = std::max( max, OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it));
98  }
99  }
100 
101  // fixed range?
102  if( doubleWidget->doubleFixedRange->isChecked())
103  {
104  min = doubleWidget->doubleFixedRangeMin->value();
105  max = doubleWidget->doubleFixedRangeMax->value();
106  }
107  else
108  {
109  doubleWidget->doubleFixedRangeMin->setValue(min);
110  doubleWidget->doubleFixedRangeMax->setValue(max);
111  }
112 
113  double range = max - min;
114 
115  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_face_colors() )
116  OMPropertyVisualizer<MeshT>::mesh->request_face_colors();
117 
118  for (typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
119 
120  if (range == 0.0)
121  OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, colorMin);
122  else
123  {
124  double v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *f_it);
125 
126  // absolut value?
127  if ( doubleWidget->doubleAbsolute->isChecked())
128  v = fabs(v);
129 
130  // clamping
131  v = std::max(min,v);
132  v = std::min(max,v);
133 
134  double t = (v-min)/range;
135 
136  typename MeshT::Color color;
137 
138  if( doubleWidget->doubleColorCoder->isChecked())
139  color = cc.color_float4(t);
140  else
141  color = (colorMin)*(1.0-t) + (colorMax)*t;
142 
143  // set color
144  OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, color);
145  }
146  }
147 
148  if (_setDrawMode)
150 }
151 
152 template <typename MeshT>
154 {
155  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
156  typename MeshT::Color colorMin, colorMax;
157 
158  colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
159  colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
160 
161  // color coder in [0,1]
162  ACG::ColorCoder cc;
163 
164 
165 
166  //TODO check if this also works if the property is Vec3d
168 
169  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
170  return;
171 
172  double min, max;
173 
174  if ( doubleWidget->doubleAbsolute->isChecked() ){
175  min = FLT_MAX;
176  max = 0.0;
177  } else {
178  min = FLT_MAX;
179  max = FLT_MIN;
180  }
181 
182  for (typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
183  if ( doubleWidget->doubleAbsolute->isChecked() ){
184  min = std::min( min, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it)));
185  max = std::max( max, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it)));
186  } else {
187  min = std::min( min, OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it));
188  max = std::max( max, OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it));
189  }
190  }
191 
192  // fixed range?
193  if( doubleWidget->doubleFixedRange->isChecked())
194  {
195  min = doubleWidget->doubleFixedRangeMin->value();
196  max = doubleWidget->doubleFixedRangeMax->value();
197  }
198  else
199  {
200  doubleWidget->doubleFixedRangeMin->setValue(min);
201  doubleWidget->doubleFixedRangeMax->setValue(max);
202  }
203 
204 
205  double range = max - min;
206 
207  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
208  OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
209 
210  for (typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
211 
212  if (range == 0.0)
213  OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, colorMin);
214  else {
215 
216  double v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *e_it);
217 
218  // absolut value?
219  if ( doubleWidget->doubleAbsolute->isChecked())
220  v = fabs(v);
221 
222  // clamping
223  v = std::max(min,v);
224  v = std::min(max,v);
225 
226  double t = (v-min)/range;
227 
228  typename MeshT::Color color;
229 
230  if( doubleWidget->doubleColorCoder->isChecked())
231  color = cc.color_float4(t);
232  else
233  color = (colorMin)*(1.0-t) + (colorMax)*t;
234 
235  // set color
236  OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, color);
237  }
238  }
239 
240 
241  if (_setDrawMode)
243 
244 }
245 
246 template <typename MeshT>
248 {
249  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
250  typename MeshT::Color colorMin, colorMax;
251 
252  colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
253  colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
254 
255  // color coder in [0,1]
256  ACG::ColorCoder cc;
257 
258 
259  //TODO check if this also works if the property is Vec3d
261 
262  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
263  return;
264 
265  double min, max;
266 
267  if ( doubleWidget->doubleAbsolute->isChecked() ){
268  min = FLT_MAX;
269  max = 0.0;
270  } else {
271  min = FLT_MAX;
272  max = FLT_MIN;
273  }
274 
275  for (typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
276  if ( doubleWidget->doubleAbsolute->isChecked() ){
277  min = std::min( min, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it)));
278  max = std::max( max, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it)));
279  } else {
280  min = std::min( min, OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it));
281  max = std::max( max, OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it));
282  }
283  }
284 
285  // fixed range?
286  if( doubleWidget->doubleFixedRange->isChecked())
287  {
288  min = doubleWidget->doubleFixedRangeMin->value();
289  max = doubleWidget->doubleFixedRangeMax->value();
290  }
291  else
292  {
293  doubleWidget->doubleFixedRangeMin->setValue(min);
294  doubleWidget->doubleFixedRangeMax->setValue(max);
295  }
296 
297  double range = max - min;
298 
299  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
300  OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
301 
302  for (typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
303 
304  if (range == 0.0)
305  OMPropertyVisualizer<MeshT>::mesh->set_color(*he_it, colorMin);
306  else {
307 
308  double v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *he_it);
309 
310  // absolut value?
311  if ( doubleWidget->doubleAbsolute->isChecked())
312  v = fabs(v);
313 
314  // clamping
315  v = std::max(min,v);
316  v = std::min(max,v);
317 
318  double t = (v-min)/range;
319 
320  typename MeshT::Color color;
321 
322  if( doubleWidget->doubleColorCoder->isChecked())
323  color = cc.color_float4(t);
324  else {
325  color = (colorMin)*(1.0-t) + (colorMax)*t;
326  }
327 
328  // set color
329  OMPropertyVisualizer<MeshT>::mesh->set_color(*he_it, color);
330  }
331  }
332  if (_setDrawMode)
334 }
335 
336 template <typename MeshT>
338 {
339  DoubleWidget* doubleWidget = static_cast<DoubleWidget*>(PropertyVisualizer::widget);
340  typename MeshT::Color colorMin, colorMax;
341 
342  colorMin = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMin->color());
343  colorMax = OMPropertyVisualizer<MeshT>::convertColor(doubleWidget->doubleMax->color());
344 
345  // color coder in [0,1]
346  ACG::ColorCoder cc;
347 
348  //TODO check if this also works if the property is Vec3d
350 
351  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
352  return;
353 
354  double min, max;
355 
356  if ( doubleWidget->doubleAbsolute->isChecked() ){
357  min = FLT_MAX;
358  max = 0.0;
359  } else {
360  min = FLT_MAX;
361  max = FLT_MIN;
362  }
363 
364  for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
365  if ( doubleWidget->doubleAbsolute->isChecked() ){
366  min = std::min( min, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it)));
367  max = std::max( max, fabs(OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it)));
368  } else {
369  min = std::min( min, OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it));
370  max = std::max( max, OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it));
371  }
372  }
373 
374  // fixed range?
375  if( doubleWidget->doubleFixedRange->isChecked())
376  {
377  min = doubleWidget->doubleFixedRangeMin->value();
378  max = doubleWidget->doubleFixedRangeMax->value();
379  }
380  else
381  {
382  doubleWidget->doubleFixedRangeMin->setValue(min);
383  doubleWidget->doubleFixedRangeMax->setValue(max);
384  }
385 
386  const double range = max - min;
387 
388  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
389  OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
390 
391  for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
392 
393  if (range == 0.0)
394  OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, colorMin);
395  else {
396 
397  double v = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
398 
399  // absolut value?
400  if ( doubleWidget->doubleAbsolute->isChecked())
401  v = fabs(v);
402 
403  // clamping
404  v = std::max(min,v);
405  v = std::min(max,v);
406 
407  double t = (v-min)/range;
408 
409  typename MeshT::Color color;
410 
411  if( doubleWidget->doubleColorCoder->isChecked())
412  color = cc.color_float4(t);
413  else {
414  color = (colorMin)*(1.0-t) + (colorMax)*t;
415  }
416 
417  // set color
418  OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, color);
419  }
420  }
421 
422  if (_setDrawMode)
424 }
425 
426 template <typename MeshT>
427 void OMPropertyVisualizerDouble<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
428 {
430  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
431 
432  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
433  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
434 
435 
436  typename MeshT::FaceHandle fh = mesh->face_handle(index);
437 
438  mesh->property(prop, fh) = this->strToDouble(text);
439 }
440 
441 template <typename MeshT>
442 void OMPropertyVisualizerDouble<MeshT>::setEdgePropertyFromText(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::EdgeHandle eh = mesh->edge_handle(index);
452 
453  mesh->property(prop, eh) = this->strToDouble(text);
454 }
455 
456 template <typename MeshT>
457 void OMPropertyVisualizerDouble<MeshT>::setHalfedgePropertyFromText(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::HalfedgeHandle heh = mesh->halfedge_handle(index);
467 
468  mesh->property(prop, heh) = this->strToDouble(text);
469 }
470 
471 template <typename MeshT>
472 void OMPropertyVisualizerDouble<MeshT>::setVertexPropertyFromText(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::VertexHandle vh = mesh->vertex_handle(index);
482 
483  mesh->property(prop, vh) = this->strToDouble(text);
484 }
485 
486 
487 template<typename MeshT>
489 {
490  OMPropertyVisualizer<MeshT>::template removeProperty_stage1<double>();
491 }
492 
493 template<typename MeshT>
495 {
496  OMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<double>();
497 }
498 
virtual void removeProperty()
Removes the property.
Cellection of information about a property.
Definition: Utils.hh:115
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:109
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:90
virtual void duplicateProperty()
Duplicates the property.
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:83
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:88
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
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .