Developer Documentation

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OMPropertyVisualizerVectorFieldDifferenceT.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
51 #define OM_PROPERTY_VISUALIZER_VECTOR_FIELD_DIFFERENCE_CC
52
53 #include "OMPropertyVisualizerVectorFieldDifference.hh"
54
55 template <typename MeshT>
56 OMPropertyVisualizerVectorFieldDifference<MeshT>::OMPropertyVisualizerVectorFieldDifference(MeshT* _mesh, PropertyInfo _propertyInfo1, PropertyInfo _propertyInfo2)
57 : OMPropertyVisualizer<MeshT>(_mesh, _propertyInfo1),
58 propertyInfo2(_propertyInfo2)
59 {
60 if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
61 VectorFieldDifferenceWidget* w = new VectorFieldDifferenceWidget();
62 w->paramVectorFieldDifference->setTitle(QString("3D Vector Field Difference Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
63 PropertyVisualizer::widget = w;
64 }
65
66 template <typename MeshT>
67 QString OMPropertyVisualizerVectorFieldDifference<MeshT>::getPropertyText(unsigned int index)
68 {
69 return "";
70 }
71
72 namespace OMPVVFD{ //OMPVVFD = OpenMeshProeprtyVisualizerVectorFieldDifference
73
74 template<typename MeshT>
75 float scalarFn_norm_of_diff(const typename MeshT::Point &a, const typename MeshT::Point &b) {
76 return (a - b).norm();
77 }
78
79 template<typename MeshT>
80 float scalarFn_diff_of_norms(const typename MeshT::Point &a, const typename MeshT::Point &b) {
81 return std::fabs(a.norm() - b.norm());
82 }
83
84 template<typename MeshT>
85 float scalarFn_4_symm_diff(const typename MeshT::Point &a, const typename MeshT::Point &b) {
86 double alpha = std::acos((a|b) / a.norm() / b.norm());
87 alpha -= std::floor((alpha + M_PI_4) / M_PI_2) * M_PI_2;
88 return std::fabs(alpha);
89 }
90
91
92 template<typename Mesh, typename Prop1, typename Prop2, float (*ScalarFn)(const typename Prop1::value_type &, const typename Prop2::value_type &)>
93 class ScalarAssigner {
94 public:
95 ScalarAssigner(const Mesh &mesh, const Prop1 &prop1, const Prop2 &prop2) :
96 mesh(mesh), prop1(prop1), prop2(prop2) { }
97
98 template<typename Handle>
99 float operator() (const Handle &handle) const {
100 return ScalarFn(mesh.property(prop1, handle), mesh.property(prop2, handle));
101 }
102
103 protected:
104 const Mesh &mesh;
105 const Prop1 &prop1;
106 const Prop2 &prop2;
107 };
108
109 template<typename MeshT, typename IteratorT, typename PropHandleType, float (*ScalarFn)(const typename MeshT::Point &, const typename MeshT::Point &)>
110 void colorElements(MeshT *mesh, const PropertyInfo &p1,
111 const PropertyInfo &p2,
112 IteratorT primitivesBegin, IteratorT primitivesEnd) {
113 PropHandleType prop1, prop2;
114 if (!mesh->get_property_handle(prop1, p1.propName())) return;
115 if (!mesh->get_property_handle(prop2, p2.propName())) return;
116
117 std::vector<float> scalars;
118 std::transform(primitivesBegin, primitivesEnd, std::back_inserter(scalars),
119 ScalarAssigner<MeshT, PropHandleType, PropHandleType, ScalarFn >(*mesh, prop1, prop2));
120
121 const float min = *std::min_element(scalars.begin(), scalars.end());
122 const float max = *std::max_element(scalars.begin(), scalars.end());
123
124 ACG::ColorCoder colCod(min,max,false);
125 for (std::vector<float>::iterator i = scalars.begin(); i != scalars.end(); ++i)
126 mesh->set_color(*(primitivesBegin++),colCod(*i));
127 }
128
129 }
130
131 template <typename MeshT>
132 void OMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeFaceProp(bool _setDrawMode)
133 {
134 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
135 const PropertyInfo p1 = PropertyVisualizer::propertyInfo;
136 const PropertyInfo p2 = propertyInfo2;
137 VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
138 if (!mesh->has_face_colors())
139 mesh->request_face_colors();
140
141 if (w->vecFieldDiff_4symm_rb->isChecked())
142 OMPVVFD::colorElements<MeshT, typename MeshT::FaceIter, OpenMesh::FPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_4_symm_diff<MeshT> >(mesh, p1, p2, mesh->faces_begin(), mesh->faces_end());
143 if (w->vecFieldDiff_diff_norm_rb->isChecked())
144 OMPVVFD::colorElements<MeshT, typename MeshT::FaceIter, OpenMesh::FPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_diff_of_norms<MeshT> >(mesh, p1, p2, mesh->faces_begin(), mesh->faces_end());
145 if (w->vecFieldDiff_norm_diff_rb->isChecked())
146 OMPVVFD::colorElements<MeshT, typename MeshT::FaceIter, OpenMesh::FPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_norm_of_diff<MeshT> >(mesh, p1, p2, mesh->faces_begin(), mesh->faces_end());
147
148 if (_setDrawMode)
149 PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED);
150 }
151
152 template <typename MeshT>
153 void OMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeEdgeProp(bool _setDrawMode)
154 {
155 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
156 const PropertyInfo p1 = PropertyVisualizer::propertyInfo;
157 const PropertyInfo p2 = propertyInfo2;
158 VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
159 if (!mesh->has_edge_colors())
160 mesh->request_edge_colors();
161
162 if (w->vecFieldDiff_4symm_rb->isChecked())
163 OMPVVFD::colorElements<MeshT, typename MeshT::EdgeIter, OpenMesh::EPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_4_symm_diff<MeshT> >(mesh, p1, p2, mesh->edges_begin(), mesh->edges_end());
164 if (w->vecFieldDiff_diff_norm_rb->isChecked())
165 OMPVVFD::colorElements<MeshT, typename MeshT::EdgeIter, OpenMesh::EPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_diff_of_norms<MeshT> >(mesh, p1, p2, mesh->edges_begin(), mesh->edges_end());
166 if (w->vecFieldDiff_norm_diff_rb->isChecked())
167 OMPVVFD::colorElements<MeshT, typename MeshT::EdgeIter, OpenMesh::EPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_norm_of_diff<MeshT> >(mesh, p1, p2, mesh->edges_begin(), mesh->edges_end());
168
169 if (_setDrawMode)
170 PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::EDGES_COLORED);
171 }
172
173 template <typename MeshT>
174 void OMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeHalfedgeProp(bool _setDrawMode)
175 {
176 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
177 const PropertyInfo p1 = PropertyVisualizer::propertyInfo;
178 const PropertyInfo p2 = propertyInfo2;
179 VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
180 if (!mesh->has_halfedge_colors())
181 mesh->request_halfedge_colors();
182
183 if (w->vecFieldDiff_4symm_rb->isChecked())
184 OMPVVFD::colorElements<MeshT, typename MeshT::HalfedgeIter, OpenMesh::HPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_4_symm_diff<MeshT> >(mesh, p1, p2, mesh->halfedges_begin(), mesh->halfedges_end());
185 if (w->vecFieldDiff_diff_norm_rb->isChecked())
186 OMPVVFD::colorElements<MeshT, typename MeshT::HalfedgeIter, OpenMesh::HPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_diff_of_norms<MeshT> >(mesh, p1, p2, mesh->halfedges_begin(), mesh->halfedges_end());
187 if (w->vecFieldDiff_norm_diff_rb->isChecked())
188 OMPVVFD::colorElements<MeshT, typename MeshT::HalfedgeIter, OpenMesh::HPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_norm_of_diff<MeshT> >(mesh, p1, p2, mesh->halfedges_begin(), mesh->halfedges_end());
189
190 if (_setDrawMode)
191 PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::HALFEDGES_COLORED);
192 }
193
194 template <typename MeshT>
195 void OMPropertyVisualizerVectorFieldDifference<MeshT>::visualizeVertexProp(bool _setDrawMode)
196 {
197 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
198 const PropertyInfo p1 = PropertyVisualizer::propertyInfo;
199 const PropertyInfo p2 = propertyInfo2;
200 VectorFieldDifferenceWidget* w = static_cast<VectorFieldDifferenceWidget*>(PropertyVisualizer::widget);
201 if (!mesh->has_vertex_colors())
202 mesh->request_vertex_colors();
203
204 if (w->vecFieldDiff_4symm_rb->isChecked())
205 OMPVVFD::colorElements<MeshT, typename MeshT::VertexIter, OpenMesh::VPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_4_symm_diff<MeshT> >(mesh, p1, p2, mesh->vertices_begin(), mesh->vertices_end());
206 if (w->vecFieldDiff_diff_norm_rb->isChecked())
207 OMPVVFD::colorElements<MeshT, typename MeshT::VertexIter, OpenMesh::VPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_diff_of_norms<MeshT> >(mesh, p1, p2, mesh->vertices_begin(), mesh->vertices_end());
208 if (w->vecFieldDiff_norm_diff_rb->isChecked())
209 OMPVVFD::colorElements<MeshT, typename MeshT::VertexIter, OpenMesh::VPropHandleT<typename MeshT::Point>, OMPVVFD::scalarFn_norm_of_diff<MeshT> >(mesh, p1, p2, mesh->vertices_begin(), mesh->vertices_end());
210
211 if (_setDrawMode)
212 PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED);
213 }
OpenMesh::HPropHandleT
Definition: Property.hh:501
ACG::SceneGraph::DrawModes::EDGES_COLORED
DrawMode EDGES_COLORED
draw edges with colors (without shading)
Definition: DrawModes.cc:83
PluginFunctions::setDrawMode
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
Definition: PluginFunctions.cc:435
OMPropertyVisualizerVectorFieldDifference::getPropertyText
virtual QString getPropertyText(unsigned int index)
Returns the value of a property in text form.
Definition: OMPropertyVisualizerVectorFieldDifferenceT.cc:67
OpenMesh::EPropHandleT
Definition: Property.hh:515
OpenMesh::TriMesh_ArrayKernelT< CustomTraits >
OpenMesh::VPropHandleT
Definition: Property.hh:487
OMPropertyVisualizerVectorFieldDifference
Definition: OMPropertyVisualizerVectorFieldDifference.hh:66
ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:91
ACG::ColorCoder
Class for generating nice colors for doubles.
Definition: ColorCoder.hh:75
OMPropertyVisualizer
Definition: OMPropertyVisualizer.hh:61
ACG::SceneGraph::DrawModes::SOLID_FACES_COLORED
DrawMode SOLID_FACES_COLORED
draw colored, but not lighted faces using face colors
Definition: DrawModes.cc:90
OpenMesh::FPropHandleT
Definition: Property.hh:529
PropertyInfo
Cellection of information about a property.
Definition: Utils.hh:115
VectorFieldDifferenceWidget
Definition: VectorFieldDifferenceWidget.hh:62
ACG::SceneGraph::DrawModes::HALFEDGES_COLORED
DrawMode HALFEDGES_COLORED
draw halfedges with colors (without shading)
Definition: DrawModes.cc:109
OMPVVFD::ScalarAssigner
Definition: OMPropertyVisualizerVectorFieldDifferenceT.cc:93
OMPVVFD
Definition: OMPropertyVisualizerVectorFieldDifferenceT.cc:72