Developer Documentation
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 //-----------------------------------------------------------------------------
227 double 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  }
234 
235  Skeleton::Joint* parent = skeleton->joint(_jointID)->parent();
236  if (!parent)
237  {
238  emit log(LOGERR, tr ("Unable to get parent joint"));
239  }
240 
241  unsigned int parentID = parent->id();
242 
243  //length of bones is defined in the reference pose and cannot be modified in any animation
244  Skeleton::Pose* pose = skeleton->referencePose();
245 
246  return (pose->globalTranslation(_jointID) - pose->globalTranslation(parentID)).length();
247 }
248 
249 //-----------------------------------------------------------------------------
250 
257 {
258  Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
259  if ( !skeleton )
260  {
261  emit log(LOGERR, tr("Unable to get skeleton"));
262  return -1;
263  }
264 
265 
266  double min = std::numeric_limits<double>::max();
267  for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
268  {
269  if (!iter->isRoot())
270  {
271  double length = boneLength(_skeletonID,iter->id());
272  if (length < min)
273  min = length;
274  }
275  }
276  return min;
277 }
278 
279 //-----------------------------------------------------------------------------
280 
287 {
288  Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
289  if ( !skeleton )
290  {
291  emit log(LOGERR, tr("Unable to get skeleton"));
292  return -1;
293  }
294 
295 
296  double max = std::numeric_limits<double>::min();
297  for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
298  {
299  if (!iter->isRoot())
300  {
301  double length = boneLength(_skeletonID,iter->id());
302  if (length > max)
303  max = length;
304  }
305  }
306  return max;
307 }
308 
309 //-----------------------------------------------------------------------------
310 
317 {
318  Skeleton* skeleton = PluginFunctions::skeleton(_skeletonID);
319  if ( !skeleton )
320  {
321  emit log(LOGERR, tr("Unable to get skeleton"));
322  return -1;
323  }
324 
325 
326  double sum = 0;
327  unsigned int count = 0;
328  for (Skeleton::Iterator iter = skeleton->begin(); iter != skeleton->end(); ++iter)
329  {
330  if (!iter->isRoot())
331  {
332  sum += boneLength(_skeletonID,iter->id());
333  ++count;
334  }
335  }
336 
337  return (sum/static_cast<double>(count));
338 }
double boneLength(int _skeletonID, int _jointID)
get the length of a bone
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
size_t id() const
returns the joint id
Definition: JointT_impl.hh:97
size_t jointCount()
Returns the number of joints.
ACG::SceneGraph::SkeletonNodeT< Skeleton > * skeletonNode()
Returns the skeleton scenegraph node.
int branchCount(int _skeletonID)
get total number of branches for a given skeleton
Vector boundingBoxMax(int _skeletonID)
get maximum bounding box point
Joint * joint(const size_t &_index)
Returns the joint with the given index.
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
void setDescriptions()
set scripting slot descriptions
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
double minBoneLength(int _skeletonID)
get the minimal bone length
Vector boundingBoxMin(int _skeletonID)
get minumum bounding box point
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Definition: DataTypes.hh:176
Represents a single joint in the skeleton.
Definition: JointT.hh:60
Pose * referencePose()
Returns a pointer to the reference pose.
int jointCount(int _skeletonID)
get total number of joints for a given skeleton
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.
int leafCount(int _skeletonID)
get total number of leaves for a given skeleton
Vector boundingBoxSize(int _skeletonID)
get the size of the bounding box
double maxBoneLength(int _skeletonID)
get the maximal bone length
Iterator class for the skeleton.
Definition: SkeletonT.hh:82
double meanBoneLength(int _skeletonID)
get the mean bone length
Joint * parent()
Returns the parent joint.
Definition: JointT_impl.hh:156
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Definition: PoseT_impl.hh:227