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