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
56 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
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
73 void InfoSkeletonObjectPlugin::pluginsInitialized() {
74 //set the slot descriptions
75 setDescriptions();
76
77 }
78
79 //-----------------------------------------------------------------------------
80
81 DataType InfoSkeletonObjectPlugin::supportedDataTypes() {
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
202 ACG::SceneGraph::PickTarget target = ACG::SceneGraph::PICK_ANYTHING;
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
PluginFunctions::scenegraphPick
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
Definition: PluginFunctions.cc:480
BaseObject::getObjectinfo
virtual QString getObjectinfo()
Get all Info for the Object as a string.
Definition: BaseObject.cc:244
SkeletonT::end
Iterator end()
Compare an iterator with the return value of this method to test if it is done.
Definition: SkeletonT_impl.hh:719
BaseObjectData::picked
virtual bool picked(uint _node_idx)
detect if the node has been picked
Definition: BaseObjectData.cc:311
JointT::id
size_t id() const
returns the joint id
Definition: JointT_impl.hh:97
JointT::size
size_t size() const
Returns the number of children.
Definition: JointT_impl.hh:197
InfoSkeletonObjectPlugin::name
QString name()
Name of the Plugin.
Definition: SkeletonObjectInfoPlugin.hh:120
InfoSkeletonObjectPlugin::pluginsInitialized
void pluginsInitialized()
initialize the plugin
Definition: SkeletonObjectInfoPlugin.cc:73
SkeletonT::jointCount
size_t jointCount()
Returns the number of joints.
Definition: SkeletonT_impl.hh:695
BaseObject
Definition: BaseObject.hh:82
PluginFunctions::getObject
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
Definition: PluginFunctions.cc:296
SkeletonT::joint
Joint * joint(const size_t &_index)
Returns the joint with the given index.
Definition: SkeletonT_impl.hh:636
DATA_SKELETON
#define DATA_SKELETON
Definition: Skeleton.hh:64
OpenMesh::VectorT
Definition: Vector11T.hh:83
PoseT
A general pose, used to store the frames of the animation.
Definition: PoseT.hh:58
OpenMesh::VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition: Vector11T.hh:568
DataType
Predefined datatypes.
Definition: DataTypes.hh:83
PluginFunctions.hh
InfoSkeletonObjectPlugin::setDescriptions
void setDescriptions()
set scripting slot descriptions
Definition: SkeletonObjectInfoScripting.cc:52
SkeletonT::begin
Iterator begin()
Iterator over joints of the skeletal tree in TOP-DOWN order (from root to leafs)
Definition: SkeletonT_impl.hh:708
JointT::end
ChildIter end()
Returns the end iterator for the joints children.
Definition: JointT_impl.hh:186
ACG::SceneGraph::PickTarget
PickTarget
What target to use for picking.
Definition: PickTarget.hh:73
JointT
Represents a single joint in the skeleton.
Definition: JointT.hh:60
SkeletonT::referencePose
Pose * referencePose()
Returns a pointer to the reference pose.
Definition: SkeletonT_impl.hh:755
ACG::SceneGraph::PICK_ANYTHING
pick any of the prior targets (should be implemented for all nodes)
Definition: PickTarget.hh:84
InfoDialog
Definition: infoDialog.hh:46
PluginFunctions::skeleton
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.
Definition: PluginFunctionsSkeleton.cc:80
OpenMesh::VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition: Vector11T.hh:540
BaseObject::name
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:730
SkeletonT::animationName
const std::string & animationName(size_t _index)
Returns the name of the animation with the given index.
Definition: SkeletonT_impl.hh:978
BaseObjectData
Definition: BaseObjectData.hh:102
SkeletonT::Iterator
Iterator class for the skeleton.
Definition: SkeletonT.hh:82
InfoSkeletonObjectPlugin::slotInformationRequested
void slotInformationRequested(const QPoint _clickedPoint, DataType _type)
Show information dialog on clicked object.
Definition: SkeletonObjectInfoPlugin.cc:197
SkeletonT::animation
Animation * animation(std::string _name)
Returns a pointer to the animation to the given name.
Definition: SkeletonT_impl.hh:852
JointT::parent
Joint * parent()
Returns the parent joint.
Definition: JointT_impl.hh:156
SkeletonT::animationCount
size_t animationCount()
Returns the number of animations stored in this skeleton.
Definition: SkeletonT_impl.hh:965
SkeletonT
Definition: JointT.hh:50
PluginFunctions::getPickedObject
bool getPickedObject(const size_t _node_idx, BaseObjectData *&_object)
Get the picked mesh.
Definition: PluginFunctions.cc:261
InfoSkeletonObjectPlugin::supportedDataTypes
DataType supportedDataTypes()
Get data type for information requests.
Definition: SkeletonObjectInfoPlugin.cc:81
PoseT::globalTranslation
Vector globalTranslation(unsigned int _joint)
Returns the global translation vector.
Definition: PoseT_impl.hh:227
JointT::begin
ChildIter begin()
Returns an iterator on the joints children.
Definition: JointT_impl.hh:175
LOGINFO
Definition: LoggingInterface.hh:94