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