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