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  this->connect(w->computeHistogramButton, &QPushButton::clicked,
70  [this, w](){this->template showHistogram<T>(w->histogram);});
71 
72 }
73 
74 template <typename MeshT, typename T>
75 template <typename PropType, typename HandleIterable>
76 void OVMPropertyVisualizerInteger<MeshT, T>::visualizeProp(PropType prop, HandleIterable handles)
77 {
78  if (!prop) return;
79 
80  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
81 
82  ACG::Vec4f colorMin = ACG::to_Vec4f(integerWidget->intMin->color());
83 
84  std::map< int, ACG::Vec4f> randomColor;
85 
86  if ( integerWidget->intRandom->isChecked() && integerWidget->intMapBlack->isChecked() )
87  randomColor[ integerWidget->intMapBlackValue->value() ] = ACG::Vec4f(0.0, 0.0, 0.0, 0.0);
88 
89  T min = mNumericLimitMax;
90  T max = mNumericLimitMin;
91 
92  for (const auto &h: handles)
93  {
94  T value = prop[h];
95  min = std::min( min, value);
96  max = std::max( max, value);
97  }
98 
99  if( integerWidget->intFixedRange->isChecked())
100  {
101  min = integerWidget->intFixedRangeMin->value();
102  max = integerWidget->intFixedRangeMax->value();
103  }
104  else
105  {
106  integerWidget->intFixedRangeMin->setValue(min);
107  integerWidget->intFixedRangeMax->setValue(max);
108  }
109 
110  auto cc = integerWidget->buildColorCoder();
111 
112  unsigned int range = max - min;
113  VolumeMeshObject<MeshT>* object;
115 
116  for (const auto &h: handles)
117  {
118  if (range == 0)
119  object->colors()[h] = colorMin;
120  else {
121  T value = prop[h];
122  double pos = (value - min) / (double) range;
123  ACG::Vec4f color;
124  if ( integerWidget->intRandom->isChecked() )
125  {
126  // TODO: build appropriate subclass of IColorCoder for this purpose
127  if ( randomColor.find( value ) == randomColor.end() )
128  {
129  color = mColorGenerator.generateNextColor();
130  color[3] = 1.0;
131  randomColor[ value ] = color;
132  }
133  color = randomColor[ value ];
134  }
135  else
136  {
137  color = cc->color_float4(pos);
138  }
139 
140  object->colors()[h] = color;
141  }
142  }
143 }
144 #define KOMMA ,
145 CALLS_TO_VISUALIZE_PROP(OVMPropertyVisualizerInteger<MeshT KOMMA T>, typename MeshT KOMMA typename T, T)
146 #undef KOMMA
147 
148 template <typename MeshT, typename T>
150 {
151  OVMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<T>();
152 }
153 
154 template <typename MeshT, typename T>
156 {
157  return OVMPropertyVisualizer<MeshT>::template getPropertyText_<T>(index);
158 }
159 
160 template <typename MeshT, typename T>
161 void OVMPropertyVisualizerInteger<MeshT, T>::setCellPropertyFromText(unsigned int index, QString text)
162 {
164 
165  OpenVolumeMesh::CellPropertyT<int> prop = mesh->template request_cell_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
166  if ( !prop )
167  {
168  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
169  return;
170  }
171 
172  OpenVolumeMesh::CellHandle ch(index);
173 
174  prop[ch] = this->strToInt(text);
175 }
176 
177 template <typename MeshT, typename T>
178 void OVMPropertyVisualizerInteger<MeshT, T>::setFacePropertyFromText(unsigned int index, QString text)
179 {
181 
182  OpenVolumeMesh::FacePropertyT<int> prop = mesh->template request_face_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
183  if ( !prop )
184  {
185  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
186  return;
187  }
188 
189  OpenVolumeMesh::FaceHandle fh(index);
190 
191  prop[fh] = this->strToInt(text);
192 }
193 
194 template <typename MeshT, typename T>
195 void OVMPropertyVisualizerInteger<MeshT, T>::setHalffacePropertyFromText(unsigned int index, QString text)
196 {
198 
199  OpenVolumeMesh::HalfFacePropertyT<int> prop = mesh->template request_halfface_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
200  if ( !prop )
201  {
202  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
203  return;
204  }
205 
207 
208  prop[hfh] = this->strToInt(text);
209 }
210 
211 template <typename MeshT, typename T>
212 void OVMPropertyVisualizerInteger<MeshT, T>::setEdgePropertyFromText(unsigned int index, QString text)
213 {
215 
216  OpenVolumeMesh::EdgePropertyT<int> prop = mesh->template request_edge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
217  if ( !prop )
218  {
219  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
220  return;
221  }
222 
223  OpenVolumeMesh::EdgeHandle eh(index);
224 
225  prop[eh] = this->strToInt(text);
226 }
227 
228 template <typename MeshT, typename T>
229 void OVMPropertyVisualizerInteger<MeshT, T>::setHalfedgePropertyFromText(unsigned int index, QString text)
230 {
232 
233  OpenVolumeMesh::HalfEdgePropertyT<int> prop = mesh->template request_halfedge_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
234  if ( !prop )
235  {
236  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
237  return;
238  }
239 
241 
242  prop[heh] = this->strToInt(text);
243 }
244 
245 template <typename MeshT, typename T>
246 void OVMPropertyVisualizerInteger<MeshT, T>::setVertexPropertyFromText(unsigned int index, QString text)
247 {
249 
250  OpenVolumeMesh::VertexPropertyT<int> prop = mesh->template request_vertex_property<int>(OVMPropertyVisualizer<MeshT>::propertyInfo.propName());
251  if ( !prop )
252  {
253  emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
254  return;
255  }
256 
258 
259  prop[vh] = this->strToInt(text);
260 }
261 
262 template <typename MeshT, typename T>
263 std::unique_ptr<ACG::IColorCoder> OVMPropertyVisualizerInteger<MeshT, T>::buildColorCoder()
264 {
265  IntegerWidget* integerWidget = static_cast<IntegerWidget*>(PropertyVisualizer::widget);
266  return integerWidget->buildColorCoder();
267 }
268 
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