Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OMPropertyVisualizerIntegerT.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_INTEGER_CC
51 
52 #include "OMPropertyVisualizerInteger.hh"
53 
54 template <typename MeshT, typename T>
55 OMPropertyVisualizerInteger<MeshT, T>::OMPropertyVisualizerInteger(MeshT* _mesh, PropertyInfo _propertyInfo, bool isUnsigned)
56  : OMPropertyVisualizer<MeshT>(_mesh, _propertyInfo)
57 {
58  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
59  IntegerWidget* w = new IntegerWidget();
60  w->paramInt->setTitle(QString("Integer Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
61  PropertyVisualizer::widget = w;
62 
63  if (isUnsigned)
64  {
65  w->intAbsolute->setChecked(false); //because we already have unsigned integers wo don't have to calculate their absolute value
66  w->intAbsolute->setCheckable(false);
67  }
68 }
69 
70 template <typename MeshT,typename T>
72 {
73  return OMPropertyVisualizer<MeshT>::template getPropertyText_<T>(index);
74 }
75 
76 template <typename MeshT, typename T>
78 {
79  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
80  typename MeshT::Color colorMin, colorMax;
81 
82  colorMin = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMin->color());
83  colorMax = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMax->color());
84 
85  // color coder in [0,1]
86  ACG::ColorCoder cc;
87 
88  std::map< int, typename MeshT::Color> randomColor;
89 
90  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
91  randomColor[ integerWidget->intMapBlackValue->value() ] = typename MeshT::Color(0.0, 0.0, 0.0, 1.0);
92 
93  //TODO check if this also works if the property is Vec3d
95 
96  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
97  return;
98 
99  T max = std::numeric_limits<T>::min();
100  T min = std::numeric_limits<T>::max();
101 
102  for (typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
103  min = std::min( min, getValue(prop, f_it));
104  max = std::max( max, getValue(prop, f_it));
105  }
106 
107  // fixed range?
108  if( integerWidget->intFixedRange->isChecked())
109  {
110  min = integerWidget->intFixedRangeMin->value();
111  max = integerWidget->intFixedRangeMax->value();
112  }
113  else
114  {
115  integerWidget->intFixedRangeMin->setValue(min);
116  integerWidget->intFixedRangeMax->setValue(max);
117  }
118 
119  unsigned int range = max - min;
120 
121  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_face_colors() )
122  OMPropertyVisualizer<MeshT>::mesh->request_face_colors();
123 
124  for (typename MeshT::FaceIter f_it = OMPropertyVisualizer<MeshT>::mesh->faces_begin() ; f_it != OMPropertyVisualizer<MeshT>::mesh->faces_end() ; ++f_it){
125 
126  if (range == 0)
127  OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, colorMin);
128  else {
129 
130  double pos = (getValue(prop, f_it) - min) / (double) range;
131 
132  typename MeshT::Color color;
133 
134  if (integerWidget->intColorCoder->isChecked())
135  {
136  color = cc.color_float4(pos);
137  }
138  else if ( !integerWidget->intRandom->isChecked() ){
139 
140  color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
141  color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
142  color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
143  color[3] = 1.0;
144 
145  } else {
146 
147  if ( randomColor.find( getValue(prop, f_it) ) == randomColor.end() ){
148 
149  color = mColorGenerator.generateNextColor();
150  color[3] = 1.0;
151 
152  randomColor[ getValue(prop, f_it) ] = color;
153  }
154 
155  color = randomColor[ getValue(prop, f_it) ];
156  }
157 
158  OMPropertyVisualizer<MeshT>::mesh->set_color(*f_it, color);
159  }
160  }
161 
162  if (_setDrawMode)
164 }
165 
166 template <typename MeshT, typename T>
168 {
169  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
170  typename MeshT::Color colorMin, colorMax;
171 
172  colorMin = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMin->color());
173  colorMax = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMax->color());
174 
175  // color coder in [0,1]
176  ACG::ColorCoder cc;
177 
178  std::map< int, typename MeshT::Color> randomColor;
179 
180  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
181  randomColor[ integerWidget->intMapBlackValue->value() ] = typename MeshT::Color(0.0, 0.0, 0.0, 1.0);
182 
183  //TODO check if this also works if the property is Vec3d
185 
186  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
187  return;
188 
189  T max = std::numeric_limits<T>::min();
190  T min = std::numeric_limits<T>::max();
191 
192  for (typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
193  min = std::min( min, getValue(prop, e_it));
194  max = std::max( max, getValue(prop, e_it));
195  }
196 
197  // fixed range?
198  if( integerWidget->intFixedRange->isChecked())
199  {
200  min = integerWidget->intFixedRangeMin->value();
201  max = integerWidget->intFixedRangeMax->value();
202  }
203  else
204  {
205  integerWidget->intFixedRangeMin->setValue(min);
206  integerWidget->intFixedRangeMax->setValue(max);
207  }
208 
209  unsigned int range = max - min;
210 
211  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_edge_colors() )
212  OMPropertyVisualizer<MeshT>::mesh->request_edge_colors();
213 
214  for (typename MeshT::EdgeIter e_it = OMPropertyVisualizer<MeshT>::mesh->edges_begin() ; e_it != OMPropertyVisualizer<MeshT>::mesh->edges_end() ; ++e_it){
215 
216  if (range == 0)
217  OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, colorMin);
218  else {
219 
220  double pos = (getValue(prop, e_it) - min) / (double) range;
221 
222  typename MeshT::Color color;
223 
224  if (integerWidget->intColorCoder->isChecked())
225  {
226  color = cc.color_float4(pos);
227  }
228  else if ( !integerWidget->intRandom->isChecked() ){
229 
230  color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
231  color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
232  color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
233  color[3] = 1.0;
234 
235  } else {
236 
237  if ( randomColor.find( getValue(prop, e_it) ) == randomColor.end() ){
238 
239  color = mColorGenerator.generateNextColor();
240  color[3] = 1.0;
241 
242  randomColor[ getValue(prop, e_it) ] = color;
243  }
244 
245  color = randomColor[ getValue(prop, e_it) ];
246  }
247 
248  OMPropertyVisualizer<MeshT>::mesh->set_color(*e_it, color);
249  }
250  }
251 
252  if (_setDrawMode)
254 
255 }
256 
257 template <typename MeshT, typename T>
259 {
260  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
261  typename MeshT::Color colorMin, colorMax;
262 
263  colorMin = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMin->color());
264  colorMax = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMax->color());
265 
266  // color coder in [0,1]
267  ACG::ColorCoder cc;
268 
269  std::map< int, typename MeshT::Color> randomColor;
270 
271  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
272  randomColor[ integerWidget->intMapBlackValue->value() ] = typename MeshT::Color(0.0, 0.0, 0.0, 1.0);
273 
274  //TODO check if this also works if the property is Vec3d
276 
277  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
278  return;
279 
280  T max = std::numeric_limits<T>::min();
281  T min = std::numeric_limits<T>::max();
282 
283  for (typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
284  min = std::min( min, getValue(prop, he_it));
285  max = std::max( max, getValue(prop, he_it));
286  }
287 
288  // fixed range?
289  if( integerWidget->intFixedRange->isChecked())
290  {
291  min = integerWidget->intFixedRangeMin->value();
292  max = integerWidget->intFixedRangeMax->value();
293  }
294  else
295  {
296  integerWidget->intFixedRangeMin->setValue(min);
297  integerWidget->intFixedRangeMax->setValue(max);
298  }
299 
300  unsigned int range = max - min;
301 
302  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_halfedge_colors() )
303  OMPropertyVisualizer<MeshT>::mesh->request_halfedge_colors();
304 
305  for (typename MeshT::HalfedgeIter he_it = OMPropertyVisualizer<MeshT>::mesh->halfedges_begin() ; he_it != OMPropertyVisualizer<MeshT>::mesh->halfedges_end() ; ++he_it){
306 
307  if (range == 0)
308  OMPropertyVisualizer<MeshT>::mesh->set_color(*he_it, colorMin);
309  else {
310 
311  double pos = (getValue(prop, he_it) - min) / (double) range;
312 
313  typename MeshT::Color color;
314 
315  if (integerWidget->intColorCoder->isChecked())
316  {
317  color = cc.color_float4(pos);
318  }
319  else if ( !integerWidget->intRandom->isChecked() ){
320 
321  color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
322  color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
323  color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
324  color[3] = 1.0;
325 
326  } else {
327 
328  if ( randomColor.find( getValue(prop, he_it) ) == randomColor.end() ){
329 
330  color = mColorGenerator.generateNextColor();
331  color[3] = 1.0;
332 
333  randomColor[ getValue(prop, he_it) ] = color;
334  }
335 
336  color = randomColor[ getValue(prop, he_it) ];
337  }
338 
339  OMPropertyVisualizer<MeshT>::mesh->set_color(*he_it, color);
340  }
341  }
342 
343  if (_setDrawMode)
345 }
346 
347 template <typename MeshT, typename T>
349 {
350  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
351  typename MeshT::Color colorMin, colorMax;
352 
353  colorMin = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMin->color());
354  colorMax = OMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMax->color());
355 
356  // color coder in [0,1]
357  ACG::ColorCoder cc;
358 
359  std::map< int, typename MeshT::Color> randomColor;
360 
361  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
362  randomColor[ integerWidget->intMapBlackValue->value() ] = typename MeshT::Color(0.0, 0.0, 0.0, 1.0);
363 
364  //TODO check if this also works if the property is Vec3d
366 
367  if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
368  return;
369 
370  T max = std::numeric_limits<T>::min();
371  T min = std::numeric_limits<T>::max();
372 
373  for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
374  min = std::min( min, getValue(prop, v_it));
375  max = std::max( max, getValue(prop, v_it));
376  }
377 
378  // fixed range?
379  if( integerWidget->intFixedRange->isChecked())
380  {
381  min = integerWidget->intFixedRangeMin->value();
382  max = integerWidget->intFixedRangeMax->value();
383  }
384  else
385  {
386  integerWidget->intFixedRangeMin->setValue(min);
387  integerWidget->intFixedRangeMax->setValue(max);
388  }
389 
390  unsigned int range = max - min;
391 
392  if ( ! OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
393  OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
394 
395  for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
396 
397  if (range == 0)
398  OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, colorMin);
399  else {
400 
401  double pos = (getValue(prop, v_it) - min) / (double) range;
402 
403  typename MeshT::Color color;
404 
405  if (integerWidget->intColorCoder->isChecked())
406  {
407  color = cc.color_float4(pos);
408  }
409  else if ( !integerWidget->intRandom->isChecked() ){
410 
411  color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
412  color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
413  color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
414  color[3] = 1.0;
415 
416  }
417  else
418  {
419 
420  if ( randomColor.find( getValue(prop, v_it) ) == randomColor.end() ){
421 
422  color = mColorGenerator.generateNextColor();
423  color[3] = 1.0;
424 
425  randomColor[ getValue(prop, v_it) ] = color;
426  }
427 
428  color = randomColor[ getValue(prop, v_it) ];
429  }
430 
431  OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, color);
432  }
433  }
434 
435  if (_setDrawMode)
437 
438 }
439 
440 template <typename MeshT, typename T>
441 void OMPropertyVisualizerInteger<MeshT, T>::setFacePropertyFromText(unsigned int index, QString text)
442 {
444  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
445 
446  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
447  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
448 
449 
450  typename MeshT::FaceHandle fh = mesh->face_handle(index);
451 
452  T dummy = 0;
453  mesh->property(prop, fh) = this->strToT(text, dummy);
454 }
455 
456 template <typename MeshT, typename T>
457 void OMPropertyVisualizerInteger<MeshT, T>::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  typename MeshT::EdgeHandle eh = mesh->edge_handle(index);
466 
467  T dummy = 0;
468  mesh->property(prop, eh) = this->strToT(text, dummy);
469 }
470 
471 template <typename MeshT, typename T>
472 void OMPropertyVisualizerInteger<MeshT, T>::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  T dummy = 0;
484  mesh->property(prop, heh) = this->strToT(text, dummy);
485 }
486 
487 template <typename MeshT, typename T>
488 void OMPropertyVisualizerInteger<MeshT, T>::setVertexPropertyFromText(unsigned int index, QString text)
489 {
491  MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
492 
493  if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
494  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
495 
496 
497  typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
498 
499  T dummy = 0;
500  mesh->property(prop, vh) = this->strToT(text, dummy);
501 }
502 
503 template<typename MeshT, typename T>
505 {
506  OMPropertyVisualizer<MeshT>::template removeProperty_stage1<T>();
507 }
508 
509 template<typename MeshT, typename T>
511 {
512  OMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<T>();
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
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
virtual void duplicateProperty()
Duplicates the property.
virtual void removeProperty()
Removes the property.
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
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