Developer Documentation

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