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