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 
56 template <typename MeshT, typename T>
57 OVMPropertyVisualizerInteger<MeshT,T>::OVMPropertyVisualizerInteger(MeshT* _mesh, int objectID, PropertyInfo _propertyInfo, bool isUnsigned)
58  : OVMPropertyVisualizer<MeshT>(_mesh, objectID, _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  mNumericLimitMax = std::numeric_limits<T>::max();
73  mNumericLimitMin = std::numeric_limits<T>::min();
74 
75 }
76 
77 template <typename MeshT, typename T>
78 template <typename PropType, typename EntityIterator>
79 void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, EntityIterator e_begin, EntityIterator e_end)
80 {
81  if (!prop) return;
82 
83  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
84  ACG::Vec4f colorMin, colorMax;
85 
86  colorMin = OVMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMin->color());
87  colorMax = OVMPropertyVisualizer<MeshT>::convertColor(integerWidget->intMax->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  ACG::ColorCoder cc;
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->intColorCoder->isChecked())
130  {
131  color = cc.color_float4(pos);
132  }
133  else
134  if ( !integerWidget->intRandom->isChecked() )
135  {
136  color[0] = colorMin[0] * (1-pos) + pos * colorMax[0];
137  color[1] = colorMin[1] * (1-pos) + pos * colorMax[1];
138  color[2] = colorMin[2] * (1-pos) + pos * colorMax[2];
139  color[3] = 1.0;
140  }
141  else
142  {
143  if ( randomColor.find( value ) == randomColor.end() )
144  {
145  color = mColorGenerator.generateNextColor();
146  color[3] = 1.0;
147  randomColor[ value ] = color;
148  }
149  color = randomColor[ value ];
150  }
151 
152  object->colors()[*e_it] = color;
153  }
154  }
155 
156 }
157 #define KOMMA ,
158 CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger<MeshT KOMMA T>, typename MeshT KOMMA typename T, T)
159 #undef KOMMA
160 
161 template <typename MeshT, typename T>
162 void OVMPropertyVisualizerInteger<MeshT, T>::duplicateProperty()
163 {
164  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<T>();
165 }
166 
167 template <typename MeshT, typename T>
168 QString OVMPropertyVisualizerInteger<MeshT, T>::getPropertyText(unsigned int index)
169 {
170  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<T>(index);
171 }
172 
173 template <typename MeshT, typename T>
174 void OVMPropertyVisualizerInteger<MeshT, T>::setCellPropertyFromText(unsigned int index, QString text)
175 {
176  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
177 
178  OpenVolumeMesh::CellPropertyT<int> prop = mesh->template request_cell_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
179  if ( !prop )
180  {
181  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
182  return;
183  }
184 
185  OpenVolumeMesh::CellHandle ch(index);
186 
187  prop[ch] = this->strToInt(text);
188 }
189 
190 template <typename MeshT, typename T>
191 void OVMPropertyVisualizerInteger<MeshT, T>::setFacePropertyFromText(unsigned int index, QString text)
192 {
193  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
194 
195  OpenVolumeMesh::FacePropertyT<int> prop = mesh->template request_face_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
196  if ( !prop )
197  {
198  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
199  return;
200  }
201 
202  OpenVolumeMesh::FaceHandle fh(index);
203 
204  prop[fh] = this->strToInt(text);
205 }
206 
207 template <typename MeshT, typename T>
208 void OVMPropertyVisualizerInteger<MeshT, T>::setHalffacePropertyFromText(unsigned int index, QString text)
209 {
210  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
211 
212  OpenVolumeMesh::HalfFacePropertyT<int> prop = mesh->template request_halfface_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
213  if ( !prop )
214  {
215  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
216  return;
217  }
218 
220 
221  prop[hfh] = this->strToInt(text);
222 }
223 
224 template <typename MeshT, typename T>
225 void OVMPropertyVisualizerInteger<MeshT, T>::setEdgePropertyFromText(unsigned int index, QString text)
226 {
227  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
228 
229  OpenVolumeMesh::EdgePropertyT<int> prop = mesh->template request_edge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
230  if ( !prop )
231  {
232  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
233  return;
234  }
235 
236  OpenVolumeMesh::EdgeHandle eh(index);
237 
238  prop[eh] = this->strToInt(text);
239 }
240 
241 template <typename MeshT, typename T>
242 void OVMPropertyVisualizerInteger<MeshT, T>::setHalfedgePropertyFromText(unsigned int index, QString text)
243 {
244  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
245 
246  OpenVolumeMesh::HalfEdgePropertyT<int> prop = mesh->template request_halfedge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
247  if ( !prop )
248  {
249  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
250  return;
251  }
252 
254 
255  prop[heh] = this->strToInt(text);
256 }
257 
258 template <typename MeshT, typename T>
259 void OVMPropertyVisualizerInteger<MeshT, T>::setVertexPropertyFromText(unsigned int index, QString text)
260 {
261  MeshT* mesh = OVMPropertyVisualizer<MeshT>::mesh;
262 
263  OpenVolumeMesh::VertexPropertyT<int> prop = mesh->template request_vertex_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
264  if ( !prop )
265  {
266  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
267  return;
268  }
269 
271 
272  prop[vh] = this->strToInt(text);
273 }
274 
275 #endif /* ENABLE_OPENVOLUMEMESH_SUPPORT */
bool getObject(int _identifier, BSplineCurveObject *&_object)
VectorT< float, 4 > Vec4f
Definition: VectorT.hh:144
ACG::Vec4f color_float4(float _v) const
color coding
Definition: ColorCoder.cc:119
Class for generating nice colors for doubles.
Definition: ColorCoder.hh:75
Property classes for the different entity types.
Cellection of information about a property.
Definition: Utils.hh:115