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