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