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
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
62 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
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
83 void InfoSkeletonObjectPlugin::pluginsInitialized() {
84 //set the slot descriptions
85 setDescriptions();
86
87 }
88
89 //-----------------------------------------------------------------------------
90
91 DataType InfoSkeletonObjectPlugin::supportedDataTypes() {
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
212 ACG::SceneGraph::PickTarget target = ACG::SceneGraph::PICK_ANYTHING;
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
InfoSkeletonObjectPlugin
Plugin to visualize information about objects in the scene.
Definition: SkeletonObjectInfoPlugin.hh:81
JointT::begin
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT.cc:181
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: BaseNode.hh:99
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:255
BaseObjectData
Definition: BaseObjectData.hh:105
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
InfoSkeletonObjectPlugin::name
QString name()
Name of the Plugin.
Definition: SkeletonObjectInfoPlugin.hh:128
ACG::SceneGraph::PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
PluginFunctions::getObject
bool getObject(int _identifier, BSplineCurveObject *&_object)
Definition: PluginFunctionsBSplineCurve.cc:75
SkeletonT::referencePose
Pose * referencePose()
Returns a pointer to the reference pose.
Definition: SkeletonT.cc:761
SkeletonT::animation
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
Definition: SkeletonT.cc:858
InfoDialog
Definition: infoDialog.hh:59
JointT::end
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT.cc:192
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
SkeletonT::begin
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Definition: SkeletonT.cc:714
InfoSkeletonObjectPlugin::supportedDataTypes
DataType supportedDataTypes()
Get data type for information requests.
Definition: SkeletonObjectInfoPlugin.cc:91
BaseObject
Definition: BaseObject.hh:94
JointT::parent
Joint * parent()
Returns the parent joint.
Definition: JointT.cc:162
OpenMesh::VectorT
Definition: Vector11T.hh:83
SkeletonT::animationCount
unsigned int animationCount()
Returns the number of animations stored in this skeleton.
Definition: SkeletonT.cc:971
SkeletonT
Definition: JointT.hh:56
PoseT::globalTranslation
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Definition: PoseT.cc:233
LOGINFO
Definition: LoggingInterface.hh:105
JointT::id
unsigned int id()
returns the joint id
Definition: JointT.cc:103
InfoSkeletonObjectPlugin::pluginsInitialized
void pluginsInitialized()
initialize the plugin
Definition: SkeletonObjectInfoPlugin.cc:83
InfoSkeletonObjectPlugin::setDescriptions
void setDescriptions()
set scripting slot descriptions
Definition: SkeletonObjectInfoScripting.cc:58
InfoSkeletonObjectPlugin::slotInformationRequested
void slotInformationRequested(const QPoint _clickedPoint, DataType _type)
Show information dialog on clicked object.
Definition: SkeletonObjectInfoPlugin.cc:207
PluginFunctions::scenegraphPick
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Definition: PluginFunctions.cc:482
JointT::size
size_t size()
Returns the number of children.
Definition: JointT.cc:203
PluginFunctions.hh
DataType
Predefined datatypes.
Definition: DataTypes.hh:96
DATA_SKELETON
#define DATA_SKELETON
Definition: Skeleton.hh:70
SkeletonT::animationName
const std::string & animationName(unsigned int _index)
Returns the name of the animation with the given index.
Definition: SkeletonT.cc:984
PluginFunctions::getPickedObject
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Definition: PluginFunctions.cc:263
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
BaseObjectData::picked
virtual bool picked(uint _node_idx)
detect if the node has been picked
Definition: BaseObjectData.cc:313