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