Developer Documentation
OVMPropertyVisualizerIntegerT_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 OVM_PROPERTY_VISUALIZER_ITEGER_CC
45 
46 #include "OVMPropertyVisualizerInteger.hh"
47 #include <ACG/Utils/ColorConversion.hh>
48 #include <ACG/Utils/LinearTwoColorCoder.hh>
49 
50 template <typename MeshT, typename T>
51 OVMPropertyVisualizerInteger<MeshT,T>::OVMPropertyVisualizerInteger(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo, bool isUnsigned)
52  : OVMPropertyVisualizer<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  mNumericLimitMax = std::numeric_limits<T>::max();
67  mNumericLimitMin = std::numeric_limits<T>::min();
68 
69 }
70 
71 template <typename MeshT, typename T>
72 template <typename PropType, typename EntityIterator>
73 void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
74 {
75  if (!prop) return;
76 
77  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
78 
79  ACG::Vec4f colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
80 
81  std::map< int, ACG::Vec4f> randomColor;
82 
83  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
84  randomColor[ integerWidget->intMapBlackValue->value() ] = ACG::Vec4f(0.0, 0.0, 0.0, 0.0);
85 
86  T min = mNumericLimitMax;
87  T max = mNumericLimitMin;
88 
89  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it)
90  {
91  T value = prop[*e_it];
92  min = std::min( min, value);
93  max = std::max( max, value);
94  }
95 
96  if( integerWidget->intFixedRange->isChecked())
97  {
98  min = integerWidget->intFixedRangeMin->value();
99  max = integerWidget->intFixedRangeMax->value();
100  }
101  else
102  {
103  integerWidget->intFixedRangeMin->setValue(min);
104  integerWidget->intFixedRangeMax->setValue(max);
105  }
106 
107  auto cc = integerWidget->buildColorCoder();
108 
109  unsigned int range = max - min;
110  VolumeMeshObject<MeshT>* object;
112 
113  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it)
114  {
115  if (range == 0)
116  object->colors()[*e_it] = colorMin;
117  else {
118  T value = prop[*e_it];
119  double pos = (value - min) / (double) range;
120  ACG::Vec4f color;
121  if ( integerWidget->intRandom->isChecked() )
122  {
123  // TODO: build appropriate subclass of IColorCoder for this purpose
124  if ( randomColor.find( value ) == randomColor.end() )
125  {
126  color = mColorGenerator.generateNextColor();
127  color[3] = 1.0;
128  randomColor[ value ] = color;
129  }
130  color = randomColor[ value ];
131  }
132  else
133  {
134  color = cc->color_float4(pos);
135  }
136 
137  object->colors()[*e_it] = color;
138  }
139  }
140 }
141 #define KOMMA ,
142 CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger<MeshT KOMMA T>, typename MeshT KOMMA typename T, T)
143 #undef KOMMA
144 
145 template <typename MeshT, typename T>
147 {
148  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<T>();
149 }
150 
151 template <typename MeshT, typename T>
153 {
154  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<T>(index);
155 }
156 
157 template <typename MeshT, typename T>
158 void OVMPropertyVisualizerInteger<MeshT, T>::setCellPropertyFromText(unsigned int index, QString text)
159 {
161 
162  OpenVolumeMesh::CellPropertyT<int> prop = mesh->template request_cell_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
163  if ( !prop )
164  {
165  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
166  return;
167  }
168 
169  OpenVolumeMesh::CellHandle ch(index);
170 
171  prop[ch] = this->strToInt(text);
172 }
173 
174 template <typename MeshT, typename T>
175 void OVMPropertyVisualizerInteger<MeshT, T>::setFacePropertyFromText(unsigned int index, QString text)
176 {
178 
179  OpenVolumeMesh::FacePropertyT<int> prop = mesh->template request_face_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
180  if ( !prop )
181  {
182  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
183  return;
184  }
185 
186  OpenVolumeMesh::FaceHandle fh(index);
187 
188  prop[fh] = this->strToInt(text);
189 }
190 
191 template <typename MeshT, typename T>
192 void OVMPropertyVisualizerInteger<MeshT, T>::setHalffacePropertyFromText(unsigned int index, QString text)
193 {
195 
196  OpenVolumeMesh::HalfFacePropertyT<int> prop = mesh->template request_halfface_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
197  if ( !prop )
198  {
199  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
200  return;
201  }
202 
204 
205  prop[hfh] = this->strToInt(text);
206 }
207 
208 template <typename MeshT, typename T>
209 void OVMPropertyVisualizerInteger<MeshT, T>::setEdgePropertyFromText(unsigned int index, QString text)
210 {
212 
213  OpenVolumeMesh::EdgePropertyT<int> prop = mesh->template request_edge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
214  if ( !prop )
215  {
216  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
217  return;
218  }
219 
220  OpenVolumeMesh::EdgeHandle eh(index);
221 
222  prop[eh] = this->strToInt(text);
223 }
224 
225 template <typename MeshT, typename T>
226 void OVMPropertyVisualizerInteger<MeshT, T>::setHalfedgePropertyFromText(unsigned int index, QString text)
227 {
229 
230  OpenVolumeMesh::HalfEdgePropertyT<int> prop = mesh->template request_halfedge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
231  if ( !prop )
232  {
233  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
234  return;
235  }
236 
238 
239  prop[heh] = this->strToInt(text);
240 }
241 
242 template <typename MeshT, typename T>
243 void OVMPropertyVisualizerInteger<MeshT, T>::setVertexPropertyFromText(unsigned int index, QString text)
244 {
246 
247  OpenVolumeMesh::VertexPropertyT<int> prop = mesh->template request_vertex_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
248  if ( !prop )
249  {
250  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
251  return;
252  }
253 
255 
256  prop[vh] = this->strToInt(text);
257 }
258 
259 template <typename MeshT, typename T>
260 std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerInteger<MeshT, T>::buildColorCoder()
261 {
262  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
263  return integerWidget->buildColorCoder();
264 }
265 
void duplicateProperty() override
Duplicates a property.
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:138
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
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.
Cellection of information about a property.
Definition: Utils.hh:109