Developer Documentation
Loading...
Searching...
No Matches
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#include "SkeletonObjectInfoPlugin.hh"
45
46#include <limits>
47
48//-----------------------------------------------------------------------------
53{
54 emit setSlotDescription("jointCount(int)",tr("get total number of joints for a given skeleton"),
55 QStringList(tr("skeletontID")), QStringList(tr("id of a skeleton")));
56
57 emit setSlotDescription("branchCount(int)",tr("get total number of branches for a given skeleton"),
58 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
59
60 emit setSlotDescription("leafCount(int)",tr("get total number of leaves for a given skeleton"),
61 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
62
63
64
65 emit setSlotDescription("boundingBoxMin(int)",tr("get minimum point of the axis-aligned bounding box"),
66 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
67
68 emit setSlotDescription("boundingBoxMax(int)",tr("get maximum point of the axis-aligned bounding box"),
69 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
70
71 emit setSlotDescription("boundingBoxSize(int)",tr("get the size of the axis-aligned bounding box"),
72 QStringList(tr("skeletonID")), QStringList(tr("id of a skeleton")));
73
74
75 emit setSlotDescription("boneLength(int,int)",tr("Get the length of a bone from given joint to his parent"),
76 QString(tr("SkeletonID,jointID")).split(","),
77 QString(tr("id of the skeleton, id of the joint")).split(","));
78
79 emit setSlotDescription("minBoneLength(int)",tr("Get the minimal bone length of a skeleton"),
80 QStringList(tr("SkeletonID")), QStringList(tr("id of the skeleton")));
81
82 emit setSlotDescription("maxBoneLength(int)",tr("Get the maximal bone length of a skeleton"),
83 QStringList(tr("SkeletonID")), QStringList(tr("id of the skeleton")));
84
85 emit setSlotDescription("meanBoneLength(int)",tr("Get the mean bone length of a skeleton"),
86 QStringList(tr("SkeletonID")), QStringList(tr("id of the skeleton")));
87}
88
89//-----------------------------------------------------------------------------
90
97{
98 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
99 if ( !skeleton )
100 {
101 emit log(LOGERR, tr("Unable to get skeleton"));
102 return -1;
103 }
104
105 return skeleton->jointCount();
106}
107
108//-----------------------------------------------------------------------------
109
116{
117 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
118 if ( !skeleton )
119 {
120 emit log(LOGERR, tr("Unable to get skeleton"));
121 return -1;
122 }
123
124 int result = 0;
125 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
126 if (iter->size() > 1)
127 ++result;
128
129 return result;
130//safsdf
131}
132
133//-----------------------------------------------------------------------------
134
141{
142 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
143 if ( !skeleton )
144 {
145 emit log(LOGERR, tr("Unable to get skeleton"));
146 return -1;
147 }
148
149 int result = 0;
150 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
151 if (iter->size() == 0)
152 ++result;
153
154 return result;
155}
156
157//-----------------------------------------------------------------------------
158
165{
166 SkeletonObject* skeleton = PluginFunctions::skeletonObject(_skeletonID);
167 if ( !skeleton )
168 {
169 emit log(LOGERR, tr("Unable to get skeleton"));
170 return Vector();
171 }
172
173 Vector min,max;
174 skeleton->skeletonNode()->boundingBox(min,max);
175 return min;
176}
177
178//-----------------------------------------------------------------------------
179
186{
187 SkeletonObject* skeleton = PluginFunctions::skeletonObject(_skeletonID);
188 if ( !skeleton )
189 {
190 emit log(LOGERR, tr("Unable to get skeleton"));
191 return Vector();
192 }
193
194 Vector min,max;
195 skeleton->skeletonNode()->boundingBox(min,max);
196 return max;
197}
198
199//-----------------------------------------------------------------------------
200
207{
208 SkeletonObject* skeleton = PluginFunctions::skeletonObject(_skeletonID);
209 if ( !skeleton )
210 {
211 emit log(LOGERR, tr("Unable to get skeleton"));
212 return Vector();
213 }
214
215 Vector min,max;
216 skeleton->skeletonNode()->boundingBox(min,max);
217 return (max - min);
218}
219
220//-----------------------------------------------------------------------------
227double InfoSkeletonObjectPlugin::boneLength(int _skeletonID, int _jointID)
228{
229 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
230 if ( !skeleton )
231 {
232 emit log(LOGERR, tr("Unable to get skeleton"));
233 return (-1.0);
234 }
235
236 Skeleton::Joint* parent = skeleton->joint(_jointID)->parent();
237 if (!parent)
238 {
239 emit log(LOGERR, tr ("Unable to get parent joint"));
240 return (-1.0);
241 }
242
243 unsigned int parentID = parent->id();
244
245 //length of bones is defined in the reference pose and cannot be modified in any animation
246 Skeleton::Pose* pose = skeleton->referencePose();
247
248 return (pose->globalTranslation(_jointID) - pose->globalTranslation(parentID)).length();
249}
250
251//-----------------------------------------------------------------------------
252
259{
260 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
261 if ( !skeleton )
262 {
263 emit log(LOGERR, tr("Unable to get skeleton"));
264 return -1;
265 }
266
267
268 double min = std::numeric_limits<double>::max();
269 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
270 {
271 if (!iter->isRoot())
272 {
273 double length = boneLength(_skeletonID,iter->id());
274 if (length < min)
275 min = length;
276 }
277 }
278 return min;
279}
280
281//-----------------------------------------------------------------------------
282
289{
290 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
291 if ( !skeleton )
292 {
293 emit log(LOGERR, tr("Unable to get skeleton"));
294 return -1;
295 }
296
297
298 double max = std::numeric_limits<double>::min();
299 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
300 {
301 if (!iter->isRoot())
302 {
303 double length = boneLength(_skeletonID,iter->id());
304 if (length > max)
305 max = length;
306 }
307 }
308 return max;
309}
310
311//-----------------------------------------------------------------------------
312
319{
320 Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
321 if ( !skeleton )
322 {
323 emit log(LOGERR, tr("Unable to get skeleton"));
324 return -1;
325 }
326
327
328 double sum = 0;
329 unsigned int count = 0;
330 for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
331 {
332 if (!iter->isRoot())
333 {
334 sum += boneLength(_skeletonID,iter->id());
335 ++count;
336 }
337 }
338
339 return (sum/static_cast<double>(count));
340}
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Definition DataTypes.hh:176
@ LOGERR
double boneLength(int _skeletonID, int _jointID)
get the length of a bone
Vector boundingBoxSize(int _skeletonID)
get the size of the bounding box
double meanBoneLength(int _skeletonID)
get the mean bone length
double minBoneLength(int _skeletonID)
get the minimal bone length
Vector boundingBoxMin(int _skeletonID)
get minumum bounding box point
void setDescriptions()
set scripting slot descriptions
int jointCount(int _skeletonID)
get total number of joints for a given skeleton
Vector boundingBoxMax(int _skeletonID)
get maximum bounding box point
int leafCount(int _skeletonID)
get total number of leaves for a given skeleton
double maxBoneLength(int _skeletonID)
get the maximal bone length
int branchCount(int _skeletonID)
get total number of branches for a given skeleton
Represents a single joint in the skeleton.
Definition JointT.hh:61
size_t id() const
returns the joint id
Joint * parent()
Returns the parent joint.
A general pose, used to store the frames of the animation.
Definition PoseT.hh:59
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Iterator class for the skeleton.
Definition SkeletonT.hh:83
Pose * referencePose()
Returns a pointer to the reference pose.
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
size_t jointCount()
Returns the number of joints.
Joint * joint(const size_t &_index)
Returns the joint with the given index.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.