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
SkeletonObjectInfoScripting.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 #include "SkeletonObjectInfoPlugin.hh"
50 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
51
52 #include <limits>
53
54 //-----------------------------------------------------------------------------
58 void InfoSkeletonObjectPlugin::setDescriptions()
59 {
60 emit setSlotDescription("jointCount(int)",tr("get total number of joints for a given skeleton"),
61 QStringList(tr("skeletontID")), QStringList(tr("id of a skeleton")));
62
63 emit setSlotDescription("branchCount(int)",tr("get total number of branches for a given skeleton"),
64 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
65
66 emit setSlotDescription("leafCount(int)",tr("get total number of leaves for a given skeleton"),
67 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
68
69
70
71 emit setSlotDescription("boundingBoxMin(int)",tr("get minimum point of the axis-aligned bounding box"),
72 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
73
74 emit setSlotDescription("boundingBoxMax(int)",tr("get maximum point of the axis-aligned bounding box"),
75 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
76
77 emit setSlotDescription("boundingBoxSize(int)",tr("get the size of the axis-aligned bounding box"),
78 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
79
80
81 emit setSlotDescription("boneLength(int,int)",tr("Get the length of a bone from given joint to his parent"),
82 QString(tr("SkeletonID,jointID")).split(","),
83 QString(tr("id of the skeleton, id of the joint")).split(","));
84
85 emit setSlotDescription("minBoneLength(int)",tr("Get the minimal bone length of a skeleton"),
86 QStringList(tr("SkeletonID")), QStringList(tr("id of the skeleton")));
87
88 emit setSlotDescription("maxBoneLength(int)",tr("Get the maximal bone length of a skeleton"),
89 QStringList(tr("SkeletonID")), QStringList(tr("id of the skeleton")));
90
91 emit setSlotDescription("meanBoneLength(int)",tr("Get the mean bone length of a skeleton"),
92 QStringList(tr("SkeletonID")), QStringList(tr("id of the skeleton")));
93 }
94
95 //-----------------------------------------------------------------------------
96
102 int InfoSkeletonObjectPlugin::jointCount(int _skeletonID)
103 {
104 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
105 if ( !skeleton )
106 {
107 emit log(LOGERR, tr("Unable to get skeleton"));
108 return -1;
109 }
110
111 return skeleton->jointCount();
112 }
113
114 //-----------------------------------------------------------------------------
115
121 int InfoSkeletonObjectPlugin::branchCount(int _skeletonID)
122 {
123 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
124 if ( !skeleton )
125 {
126 emit log(LOGERR, tr("Unable to get skeleton"));
127 return -1;
128 }
129
130 int result = 0;
131 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
132 if (iter->size() > 1)
133 ++result;
134
135 return result;
136 //safsdf
137 }
138
139 //-----------------------------------------------------------------------------
140
146 int InfoSkeletonObjectPlugin::leafCount(int _skeletonID)
147 {
148 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
149 if ( !skeleton )
150 {
151 emit log(LOGERR, tr("Unable to get skeleton"));
152 return -1;
153 }
154
155 int result = 0;
156 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
157 if (iter->size() == 0)
158 ++result;
159
160 return result;
161 }
162
163 //-----------------------------------------------------------------------------
164
170 Vector InfoSkeletonObjectPlugin::boundingBoxMin(int _skeletonID)
171 {
172 SkeletonObject* skeleton = PluginFunctions::skeletonObject(_skeletonID);
173 if ( !skeleton )
174 {
175 emit log(LOGERR, tr("Unable to get skeleton"));
176 return Vector();
177 }
178
179 Vector min,max;
180 skeleton->skeletonNode()->boundingBox(min,max);
181 return min;
182 }
183
184 //-----------------------------------------------------------------------------
185
191 Vector InfoSkeletonObjectPlugin::boundingBoxMax(int _skeletonID)
192 {
193 SkeletonObject* skeleton = PluginFunctions::skeletonObject(_skeletonID);
194 if ( !skeleton )
195 {
196 emit log(LOGERR, tr("Unable to get skeleton"));
197 return Vector();
198 }
199
200 Vector min,max;
201 skeleton->skeletonNode()->boundingBox(min,max);
202 return max;
203 }
204
205 //-----------------------------------------------------------------------------
206
212 Vector InfoSkeletonObjectPlugin::boundingBoxSize(int _skeletonID)
213 {
214 SkeletonObject* skeleton = PluginFunctions::skeletonObject(_skeletonID);
215 if ( !skeleton )
216 {
217 emit log(LOGERR, tr("Unable to get skeleton"));
218 return Vector();
219 }
220
221 Vector min,max;
222 skeleton->skeletonNode()->boundingBox(min,max);
223 return (max - min);
224 }
225
226 //-----------------------------------------------------------------------------
233 double InfoSkeletonObjectPlugin::boneLength(int _skeletonID, int _jointID)
234 {
235 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
236 if ( !skeleton )
237 {
238 emit log(LOGERR, tr("Unable to get skeleton"));
239 }
240
241 Skeleton::Joint* parent = skeleton->joint(_jointID)->parent();
242 if (!parent)
243 {
244 emit log(LOGERR, tr ("Unable to get parent joint"));
245 }
246
247 unsigned int parentID = parent->id();
248
249 //length of bones is defined in the reference pose and cannot be modified in any animation
250 Skeleton::Pose* pose = skeleton->referencePose();
251
252 return (pose->globalTranslation(_jointID) - pose->globalTranslation(parentID)).length();
253 }
254
255 //-----------------------------------------------------------------------------
256
262 double InfoSkeletonObjectPlugin::minBoneLength(int _skeletonID)
263 {
264 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
265 if ( !skeleton )
266 {
267 emit log(LOGERR, tr("Unable to get skeleton"));
268 return -1;
269 }
270
271
272 double min = std::numeric_limits<double>::max();
273 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
274 {
275 if (!iter->isRoot())
276 {
277 double length = boneLength(_skeletonID,iter->id());
278 if (length < min)
279 min = length;
280 }
281 }
282 return min;
283 }
284
285 //-----------------------------------------------------------------------------
286
292 double InfoSkeletonObjectPlugin::maxBoneLength(int _skeletonID)
293 {
294 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
295 if ( !skeleton )
296 {
297 emit log(LOGERR, tr("Unable to get skeleton"));
298 return -1;
299 }
300
301
302 double max = std::numeric_limits<double>::min();
303 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
304 {
305 if (!iter->isRoot())
306 {
307 double length = boneLength(_skeletonID,iter->id());
308 if (length > max)
309 max = length;
310 }
311 }
312 return max;
313 }
314
315 //-----------------------------------------------------------------------------
316
322 double InfoSkeletonObjectPlugin::meanBoneLength(int _skeletonID)
323 {
324 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
325 if ( !skeleton )
326 {
327 emit log(LOGERR, tr("Unable to get skeleton"));
328 return -1;
329 }
330
331
332 double sum = 0;
333 unsigned int count = 0;
334 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
335 {
336 if (!iter->isRoot())
337 {
338 sum += boneLength(_skeletonID,iter->id());
339 ++count;
340 }
341 }
342
343 return (sum/static_cast<double>(count));
344 }
InfoSkeletonObjectPlugin::maxBoneLength
double maxBoneLength(int _skeletonID)
get the maximal bone length
Definition: SkeletonObjectInfoScripting.cc:292
PluginFunctions::skeletonObject
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
Definition: PluginFunctionsSkeleton.cc:105
LOGERR
Definition: LoggingInterface.hh:107
InfoSkeletonObjectPlugin::boundingBoxSize
Vector boundingBoxSize(int _skeletonID)
get the size of the bounding box
Definition: SkeletonObjectInfoScripting.cc:212
SkeletonT::referencePose
Pose * referencePose()
Returns a pointer to the reference pose.
Definition: SkeletonT.cc:761
SkeletonObject
Definition: SkeletonObject.hh:82
PoseT
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:68
SkeletonT::jointCount
unsigned int jointCount()
Returns the number of joints.
Definition: SkeletonT.cc:701
SkeletonT::end
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
Definition: SkeletonT.cc:725
SkeletonT::Iterator
Iterator class for the skeleton.
Definition: SkeletonT.hh:88
SkeletonT::joint
Joint * joint(const unsigned int &_index)
Returns the joint with the given index.
Definition: SkeletonT.cc:642
InfoSkeletonObjectPlugin::branchCount
int branchCount(int _skeletonID)
get total number of branches for a given skeleton
Definition: SkeletonObjectInfoScripting.cc:121
InfoSkeletonObjectPlugin::boundingBoxMin
Vector boundingBoxMin(int _skeletonID)
get minumum bounding box point
Definition: SkeletonObjectInfoScripting.cc:170
Vector
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Definition: DataTypes.hh:187
SkeletonT::begin
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Definition: SkeletonT.cc:714
JointT::parent
Joint * parent()
Returns the parent joint.
Definition: JointT.cc:162
OpenMesh::VectorT
Definition: Vector11T.hh:83
SkeletonT
Definition: JointT.hh:56
InfoSkeletonObjectPlugin::meanBoneLength
double meanBoneLength(int _skeletonID)
get the mean bone length
Definition: SkeletonObjectInfoScripting.cc:322
PoseT::globalTranslation
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Definition: PoseT.cc:233
JointT::id
unsigned int id()
returns the joint id
Definition: JointT.cc:103
InfoSkeletonObjectPlugin::boneLength
double boneLength(int _skeletonID, int _jointID)
get the length of a bone
Definition: SkeletonObjectInfoScripting.cc:233
InfoSkeletonObjectPlugin::boundingBoxMax
Vector boundingBoxMax(int _skeletonID)
get maximum bounding box point
Definition: SkeletonObjectInfoScripting.cc:191
InfoSkeletonObjectPlugin::setDescriptions
void setDescriptions()
set scripting slot descriptions
Definition: SkeletonObjectInfoScripting.cc:58
InfoSkeletonObjectPlugin::jointCount
int jointCount(int _skeletonID)
get total number of joints for a given skeleton
Definition: SkeletonObjectInfoScripting.cc:102
InfoSkeletonObjectPlugin::leafCount
int leafCount(int _skeletonID)
get total number of leaves for a given skeleton
Definition: SkeletonObjectInfoScripting.cc:146
InfoSkeletonObjectPlugin::minBoneLength
double minBoneLength(int _skeletonID)
get the minimal bone length
Definition: SkeletonObjectInfoScripting.cc:262
PluginFunctions.hh
PluginFunctions::skeleton
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.
Definition: PluginFunctionsSkeleton.cc:86
JointT
Represents a single joint in the skeleton.
Definition: JointT.hh:66
SkeletonObject::skeletonNode
ACG::SceneGraph::SkeletonNodeT< Skeleton > * skeletonNode()
Returns the skeleton scenegraph node.
Definition: SkeletonObject.cc:218