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