Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OVMPropertyVisualizerIntegerT.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 #ifdef ENABLE_OPENVOLUMEMESH_SUPPORT
51 
52 #define OVM_PROPERTY_VISUALIZER_ITEGER_CC
53 
54 #include "OVMPropertyVisualizerInteger.hh"
55 #include <ACG/Utils/ColorConversion.hh>
56 #include <ACG/Utils/LinearTwoColorCoder.hh>
57 
58 template <typename MeshT, typename T>
59 OVMPropertyVisualizerInteger<MeshT,T>::OVMPropertyVisualizerInteger(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo, bool isUnsigned)
60  : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _propertyInfo)
61 {
62  if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
63  IntegerWidget* w = new IntegerWidget();
64  w->paramInt->setTitle(QString("Integer Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
65  PropertyVisualizer::widget = w;
66 
67  if (isUnsigned)
68  {
69  w->intAbsolute->setChecked(false); //because we already have unsigned integers wo don't have to calculate their absolute value
70  w->intAbsolute->setCheckable(false);
71  }
72 
73 
74  mNumericLimitMax = std::numeric_limits<T>::max();
75  mNumericLimitMin = std::numeric_limits<T>::min();
76 
77 }
78 
79 template <typename MeshT, typename T>
80 template <typename PropType, typename EntityIterator>
81 void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
82 {
83  if (!prop) return;
84 
85  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
86 
87  ACG::Vec4f colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
88 
89  std::map< int, ACG::Vec4f> randomColor;
90 
91  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
92  randomColor[ integerWidget->intMapBlackValue->value() ] = ACG::Vec4f(0.0, 0.0, 0.0, 0.0);
93 
94  T min = mNumericLimitMax;
95  T max = mNumericLimitMin;
96 
97  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it)
98  {
99  T value = prop[*e_it];
100  min = std::min( min, value);
101  max = std::max( max, value);
102  }
103 
104  if( integerWidget->intFixedRange->isChecked())
105  {
106  min = integerWidget->intFixedRangeMin->value();
107  max = integerWidget->intFixedRangeMax->value();
108  }
109  else
110  {
111  integerWidget->intFixedRangeMin->setValue(min);
112  integerWidget->intFixedRangeMax->setValue(max);
113  }
114 
115  auto cc = integerWidget->buildColorCoder();
116 
117  unsigned int range = max - min;
118  VolumeMeshObject<MeshT>* object;
119  PluginFunctions::getObject(OVMPropertyVisualizer<MeshT>::mObjectID, object);
120 
121  for (EntityIterator e_it = e_begin; e_it != e_end; ++e_it)
122  {
123  if (range == 0)
124  object->colors()[*e_it] = colorMin;
125  else {
126  T value = prop[*e_it];
127  double pos = (value - min) / (double) range;
128  ACG::Vec4f color;
129  if ( integerWidget->intRandom->isChecked() )
130  {
131  // TODO: build appropriate subclass of IColorCoder for this purpose
132  if ( randomColor.find( value ) == randomColor.end() )
133  {
134  color = mColorGenerator.generateNextColor();
135  color[3] = 1.0;
136  randomColor[ value ] = color;
137  }
138  color = randomColor[ value ];
139  }
140  else
141  {
142  color = cc->color_float4(pos);
143  }
144 
145  object->colors()[*e_it] = color;
146  }
147  }
148 }
149 #define KOMMA ,
150 CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger<MeshT KOMMA T>, typename MeshT KOMMA typename T, T)
151 #undef KOMMA
152 
153 template <typename MeshT, typename T>
154 void OVMPropertyVisualizerInteger<MeshT, T>::duplicateProperty()
155 {
156  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<T>();
157 }
158 
159 template <typename MeshT, typename T>
160 QString OVMPropertyVisualizerInteger<MeshT, T>::getPropertyText(unsigned int index)
161 {
162  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<T>(index);
163 }
164 
165 template <typename MeshT, typename T>
166 void OVMPropertyVisualizerInteger<MeshT, T>::setCellPropertyFromText(unsigned int index, QString text)
167 {
168  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
169 
170  OpenVolumeMesh::CellPropertyT<int> prop = mesh->template request_cell_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
171  if ( !prop )
172  {
173  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
174  return;
175  }
176 
177  OpenVolumeMesh::CellHandle ch(index);
178 
179  prop[ch] = this->strToInt(text);
180 }
181 
182 template <typename MeshT, typename T>
183 void OVMPropertyVisualizerInteger<MeshT, T>::setFacePropertyFromText(unsigned int index, QString text)
184 {
185  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
186 
187  OpenVolumeMesh::FacePropertyT<int> prop = mesh->template request_face_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
188  if ( !prop )
189  {
190  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
191  return;
192  }
193 
194  OpenVolumeMesh::FaceHandle fh(index);
195 
196  prop[fh] = this->strToInt(text);
197 }
198 
199 template <typename MeshT, typename T>
200 void OVMPropertyVisualizerInteger<MeshT, T>::setHalffacePropertyFromText(unsigned int index, QString text)
201 {
202  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
203 
204  OpenVolumeMesh::HalfFacePropertyT<int> prop = mesh->template request_halfface_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
205  if ( !prop )
206  {
207  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
208  return;
209  }
210 
212 
213  prop[hfh] = this->strToInt(text);
214 }
215 
216 template <typename MeshT, typename T>
217 void OVMPropertyVisualizerInteger<MeshT, T>::setEdgePropertyFromText(unsigned int index, QString text)
218 {
219  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
220 
221  OpenVolumeMesh::EdgePropertyT<int> prop = mesh->template request_edge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
222  if ( !prop )
223  {
224  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
225  return;
226  }
227 
228  OpenVolumeMesh::EdgeHandle eh(index);
229 
230  prop[eh] = this->strToInt(text);
231 }
232 
233 template <typename MeshT, typename T>
234 void OVMPropertyVisualizerInteger<MeshT, T>::setHalfedgePropertyFromText(unsigned int index, QString text)
235 {
236  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
237 
238  OpenVolumeMesh::HalfEdgePropertyT<int> prop = mesh->template request_halfedge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
239  if ( !prop )
240  {
241  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
242  return;
243  }
244 
246 
247  prop[heh] = this->strToInt(text);
248 }
249 
250 template <typename MeshT, typename T>
251 void OVMPropertyVisualizerInteger<MeshT, T>::setVertexPropertyFromText(unsigned int index, QString text)
252 {
253  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
254 
255  OpenVolumeMesh::VertexPropertyT<int> prop = mesh->template request_vertex_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
256  if ( !prop )
257  {
258  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
259  return;
260  }
261 
263 
264  prop[vh] = this->strToInt(text);
265 }
266 
267 template <typename MeshT, typename T>
268 std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerInteger<MeshT, T>::buildColorCoder()
269 {
270  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
271  return integerWidget->buildColorCoder();
272 }
273 
274 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
std::unique_ptr< ACG::IColorCoder > buildColorCoder()
Builds a color coder according to UI settings.
bool getObject(int _identifier, BSplineCurveObject *&_object)
Property classes for the different entity types.
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:144
Cellection of information about a property.
Definition: Utils.hh:115