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