Developer Documentation

OMPropertyVisualizerSkinWeightsT_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 #ifdef ENABLE_SKELETON_SUPPORT
46
47 #define OM_PROPERTY_VISUALIZER_SKIN_WEIGHTS_CC
48
49 #include "OMPropertyVisualizerSkinWeights.hh"
50
51 template <typename MeshT>
52 OMPropertyVisualizerSkinWeights<MeshT>::OMPropertyVisualizerSkinWeights(MeshT* _mesh, int _objectID, const PropertyInfo& _propertyInfo)
53 : OMPropertyVisualizer<MeshT>(_mesh, _objectID, _propertyInfo)
54 {
55 if (PropertyVisualizer::widget) delete PropertyVisualizer::widget;
56 SkinWeightsWidget* w = new SkinWeightsWidget();
57 w->paramSkinWeights->setTitle(QString("SkinWeights Parameters of ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
58 PropertyVisualizer::widget = w;
59 }
60
61 template <typename MeshT>
62 QString OMPropertyVisualizerSkinWeights<MeshT>::getPropertyText(unsigned int index)
63 {
64 return OMPropertyVisualizer<MeshT>::template getPropertyText_<BaseSkin::SkinWeights>(index);
65 }
66
67 template <typename MeshT>
68 void OMPropertyVisualizerSkinWeights<MeshT>::visualizeFaceProp(bool /*_setDrawMode*/)
69 {
70 OMPropertyVisualizer<MeshT>::log("Visualizing SkinWeights for faces not supported.");
71 }
72
73 template <typename MeshT>
74 void OMPropertyVisualizerSkinWeights<MeshT>::visualizeEdgeProp(bool /*_setDrawMode*/)
75 {
76 OMPropertyVisualizer<MeshT>::log("Visualizing SkinWeights for edges not supported.");
77 }
78
79 template <typename MeshT>
80 void OMPropertyVisualizerSkinWeights<MeshT>::visualizeHalfedgeProp(bool /*_setDrawMode*/)
81 {
82 OMPropertyVisualizer<MeshT>::log("Visualizing SkinWeights for halfedges not supported.");
83 }
84
85 template <typename MeshT>
86 void OMPropertyVisualizerSkinWeights<MeshT>::visualizeVertexProp(bool _setDrawMode)
87 {
88 SkinWeightsWidget* skinWeightsWidget = static_cast<SkinWeightsWidget*>(PropertyVisualizer::widget);
89
90 OpenMesh::VPropHandleT< BaseSkin::SkinWeights > prop;
91
92 if ( !OMPropertyVisualizer<MeshT>::mesh->get_property_handle(prop, OMPropertyVisualizer<MeshT>::propertyInfo.propName() ) )
93 return;
94
95 // Request vertex colors if required
96 if ( !OMPropertyVisualizer<MeshT>::mesh->has_vertex_colors() )
97 OMPropertyVisualizer<MeshT>::mesh->request_vertex_colors();
98
99 for (typename MeshT::VertexIter v_it = OMPropertyVisualizer<MeshT>::mesh->vertices_begin() ; v_it != OMPropertyVisualizer<MeshT>::mesh->vertices_end() ; ++v_it){
100
101 BaseSkin::SkinWeights weight = OMPropertyVisualizer<MeshT>::mesh->property(prop, *v_it);
102
103 double value = 0.0;
104 if ( weight.find( skinWeightsWidget->boneId->value() ) != weight.end() ) {
105 value = weight[skinWeightsWidget->boneId->value()];
106 }
107
108
109 typename MeshT::Color color(value,1.0-value,0.0,1.0);
110
111 // set color
112 OMPropertyVisualizer<MeshT>::mesh->set_color(*v_it, color);
113 }
114
115 if (_setDrawMode)
116 PluginFunctions::setDrawMode(ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED);
117 }
118
119 template<typename MeshT>
120 void OMPropertyVisualizerSkinWeights<MeshT>::removeProperty()
121 {
122 OMPropertyVisualizer<MeshT>::template removeProperty_stage1<BaseSkin::SkinWeights>();
123 }
124
125
126 template<typename MeshT>
127 void OMPropertyVisualizerSkinWeights<MeshT>::duplicateProperty()
128 {
129 OMPropertyVisualizer<MeshT>::template duplicateProperty_stage1<BaseSkin::SkinWeights>();
130 }
131
132 template<typename MeshT>
133 void OMPropertyVisualizerSkinWeights<MeshT>::setFacePropertyFromText(unsigned int index, QString text)
134 {
135 OMPropertyVisualizer<MeshT>::log("Setting SkinWeights for faces not supported.");
136 }
137
138 template<typename MeshT>
139 void OMPropertyVisualizerSkinWeights<MeshT>::setEdgePropertyFromText(unsigned int index, QString text)
140 {
141 OMPropertyVisualizer<MeshT>::log("Setting SkinWeights for edges not supported.");
142 }
143
144 template<typename MeshT>
145 void OMPropertyVisualizerSkinWeights<MeshT>::setHalfedgePropertyFromText(unsigned int index, QString text)
146 {
147 OMPropertyVisualizer<MeshT>::log("Setting SkinWeights for halfedges not supported.");
148 }
149
150 template<typename MeshT>
151 void OMPropertyVisualizerSkinWeights<MeshT>::setVertexPropertyFromText(unsigned int index, QString text)
152 {
153 OpenMesh::VPropHandleT< BaseSkin::SkinWeights > prop;
154 MeshT* mesh = OMPropertyVisualizer<MeshT>::mesh;
155
156 if ( !mesh->get_property_handle(prop, PropertyVisualizer::propertyInfo.propName() ) )
157 emit this->log(LOGERR, QObject::tr("Error: No property with name ").append(PropertyVisualizer::propertyInfo.propName().c_str()));
158
159 typename MeshT::VertexHandle vh = mesh->vertex_handle(index);
160
161 BaseSkin::SkinWeights sw;
162
163 text.remove(0,1);
164 text.remove(text.length()-1, 1);
165
166 QStringList slAll = text.split(")(");
167
168 for (QStringList::iterator it = slAll.begin(); it != slAll.end(); ++it)
169 {
170 QStringList slCurrent = it->split(",");
171 sw.insert(std::pair<int, double>(slCurrent.at(0).toInt(), slCurrent.at(1).toDouble()));
172 }
173
174 mesh->property(prop, vh) = sw;
175 }
176
177 #endif /* ENABLE_SKELETON_SUPPORT */
OpenMesh::Attributes::Color
Add colors to mesh item (vertices/faces/edges)
Definition: Attributes.hh:83
PluginFunctions::setDrawMode
void setDrawMode(const ACG::SceneGraph::DrawModes::DrawMode &_mode, int _viewer)
Set the draw Mode of a Viewer. .
Definition: PluginFunctions.cc:431
LOGERR
Definition: LoggingInterface.hh:96
ACG::SceneGraph::DrawModes::SOLID_POINTS_COLORED
DrawMode SOLID_POINTS_COLORED
draw colored, but not lighted faces using interpolated vertex colors
Definition: DrawModes.cc:85
SkinWeightsWidget
Definition: SkinWeightsWidget.hh:46
BaseSkin::SkinWeights
std::map< unsigned int, double > SkinWeights
Stores the joint weights per vertex.
Definition: BaseSkin.hh:94
PropertyInfo
Cellection of information about a property.
Definition: Utils.hh:109
OMPropertyVisualizer
Definition: OMPropertyVisualizer.hh:55
OpenMesh::VPropHandleT
Definition: Property.hh:482