Developer Documentation
SkeletonObjectInfoPlugin.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 //=============================================================================
45 //
46 // CLASS InfoMeshObjectPlugin - IMPLEMENTATION
47 //
48 //=============================================================================
49 
50 
51 //== INCLUDES =================================================================
52 
53 
54 #include "SkeletonObjectInfoPlugin.hh"
55 
57 #include <MeshTools/MeshInfoT.hh>
58 #include <ACG/Geometry/Algorithms.hh>
59 
60 
61 //== IMPLEMENTATION ==========================================================
62 
63 void InfoSkeletonObjectPlugin::initializePlugin() {
64 
65  if ( OpenFlipper::Options::gui()) {
66  // Create info dialog
67  info_ = new InfoDialog();
68  }
69 
70 }
71 
74  //set the slot descriptions
76 
77 }
78 
79 //-----------------------------------------------------------------------------
80 
82  return DataType(DATA_SKELETON);
83 }
84 
85 //-----------------------------------------------------------------------------
86 
87 void InfoSkeletonObjectPlugin::printSkeletonInfo( Skeleton* _skeleton, unsigned int _objectId, unsigned int _index, ACG::Vec3d& _hitPoint ) {
88 
89  QLocale locale;
90  QString name;
91 
92  // name
93  BaseObject* obj = 0;
94  if ( PluginFunctions::getObject(_objectId, obj) )
95  info_->generalBox->setTitle( tr("General object information for %1").arg( obj->name() ) );
96 
97 
98 
99  // ID
100  info_->id->setText( locale.toString(_objectId) );
101  // Joints
102  info_->joints->setText( QString::number( _skeleton->jointCount() ) );
103 
104 
105  // animation list with animation names and the frame count
106  info_->comboBoxAnimations->clear();
107  QString animationInfo;
108  unsigned int aniCount = _skeleton->animationCount();
109 
110  for (size_t i = 0; i < aniCount; ++i) {
111  std::string aniName = _skeleton->animationName(i);
112  animationInfo = "Name: " + QString(aniName.c_str())
113  + " : Frames: " + locale.toString(_skeleton->animation(aniName)->frameCount());
114  info_->comboBoxAnimations->addItem(animationInfo);
115  }
116 
117 
118  // Clicked:
119  info_->jointHandle->setText( locale.toString( _index ) );
120 
121  QString adjacentHandles;
122 
123  // Check if we have a parent joint
124  if ( _skeleton->joint(_index)->parent() !=0 ) {
125  adjacentHandles = adjacentHandles + "Parent: " + QString::number( _skeleton->joint(_index)->parent()->id() ) + " ;";
126  }
127 
128  // Check for children
129  if ( _skeleton->joint(_index)->size() != 0 ) {
130 
131  adjacentHandles = adjacentHandles + "Children:";
132 
133  for ( Skeleton::Joint::ChildIter it = _skeleton->joint(_index)->begin(); it != _skeleton->joint(_index)->end(); ++it) {
134  Skeleton::Joint *joint = *it;
135 
136  adjacentHandles = adjacentHandles + " " + QString::number(joint->id());
137  }
138  }
139 
140 
141 
142  info_->adjacentJointsHandles->setText(adjacentHandles);
143 
144 
145  Skeleton::Point bbMin( FLT_MAX, FLT_MAX, FLT_MAX);
146  Skeleton::Point bbMax(-FLT_MAX, -FLT_MAX, -FLT_MAX);
147  Skeleton::Point cog(0.0,0.0,0.0);
148 
149  Skeleton::Pose* pose = _skeleton->referencePose();
150  for (Skeleton::Iterator it = _skeleton->begin(); it != _skeleton->end(); ++it) {
151  Skeleton::Joint *joint = *it;
152 
153  Skeleton::Point p = pose->globalTranslation(joint->id());
154 
155  cog += p;
156 
157  bbMin.minimize(p);
158  bbMax.maximize(p);
159 
160  }
161 
162  //Bounding Box Size
163  Skeleton::Point diff = bbMax-bbMin;
164 
165  info_->bbMinX->setText( QString::number(bbMin[0],'f') );
166  info_->bbMinY->setText( QString::number(bbMin[1],'f') );
167  info_->bbMinZ->setText( QString::number(bbMin[2],'f') );
168 
169  info_->bbMaxX->setText( QString::number(bbMax[0],'f') );
170  info_->bbMaxY->setText( QString::number(bbMax[1],'f') );
171  info_->bbMaxZ->setText( QString::number(bbMax[2],'f') );
172 
173  info_->bbSizeX->setText( QString::number(diff[0],'f') );
174  info_->bbSizeY->setText( QString::number(diff[1],'f') );
175  info_->bbSizeZ->setText( QString::number(diff[2],'f') );
176 
177 
178  //COG
179  cog = cog / _skeleton->jointCount() ;
180 
181  info_->cogX->setText( QString::number(cog[0],'f') );
182  info_->cogY->setText( QString::number(cog[1],'f') );
183  info_->cogZ->setText( QString::number(cog[2],'f') );
184 
185  //hitpoint
186  info_->pointX->setText( QString::number( _hitPoint[0],'f' ) );
187  info_->pointY->setText( QString::number( _hitPoint[1],'f' ) );
188  info_->pointZ->setText( QString::number( _hitPoint[2],'f' ) );
189 
190  info_->setWindowFlags(info_->windowFlags() | Qt::WindowStaysOnTopHint);
191 
192  info_->show();
193 }
194 
195 //----------------------------------------------------------------------------------------------
196 
197 void InfoSkeletonObjectPlugin::slotInformationRequested(const QPoint _clickedPoint, DataType _type) {
198 
199  // Only respond on skeleton objects
200  if( _type != DATA_SKELETON ) return;
201 
203 
204  size_t node_idx, target_idx;
205  ACG::Vec3d hit_point;
206 
207  if (PluginFunctions::scenegraphPick(target, _clickedPoint, node_idx, target_idx, &hit_point)) {
208  BaseObjectData* object;
209 
210  if ( PluginFunctions::getPickedObject(node_idx, object) ) {
211 
212  emit log( LOGINFO , object->getObjectinfo() );
213 
214  if ( object->picked(node_idx) && object->dataType(DATA_SKELETON) )
215  printSkeletonInfo( PluginFunctions::skeleton(object) , object->id(), target_idx, hit_point );
216 
217  } else return;
218  }
219 }
220 
221 
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:563
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
#define DATA_SKELETON
Definition: Skeleton.hh:64
void pluginsInitialized()
initialize the plugin
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Definition: PoseT_impl.hh:227
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
DataType supportedDataTypes()
Get data type for information requests.
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT_impl.hh:186
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.
void slotInformationRequested(const QPoint _clickedPoint, DataType _type)
Show information dialog on clicked object.
void setDescriptions()
set scripting slot descriptions
QString name()
Name of the Plugin.
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
size_t animationCount()
Returns the number of animations stored in this skeleton.
Iterator class for the skeleton.
Definition: SkeletonT.hh:82
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
Joint * parent()
Returns the parent joint.
Definition: JointT_impl.hh:156
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)
Represents a single joint in the skeleton.
Definition: JointT.hh:60
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT_impl.hh:175
Predefined datatypes.
Definition: DataTypes.hh:83
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:535
size_t jointCount()
Returns the number of joints.
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
virtual bool picked(uint _node_idx)
detect if the node has been picked
Joint * joint(const size_t &_index)
Returns the joint with the given index.
size_t size() const
Returns the number of children.
Definition: JointT_impl.hh:197
size_t id() const
returns the joint id
Definition: JointT_impl.hh:97