SkeletonObjectInfoPlugin.cc 8.42 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

//=============================================================================
//
//  CLASS InfoMeshObjectPlugin - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

#include <QtGui>

#include "SkeletonObjectInfoPlugin.hh"

#include <iostream>
#include <ACG/GL/GLState.hh>
#include <QStringList>
#include <QLocale>

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <MeshTools/MeshInfoT.hh>
#include <OpenFlipper/common/BaseObject.hh>
#include <ACG/Geometry/Algorithms.hh>

#include <Math_Tools/Math_Tools.hh>

#include <float.h>

//== IMPLEMENTATION ==========================================================

void InfoSkeletonObjectPlugin::initializePlugin() {

  // Create info dialog
  info_ = new InfoDialog();

}

/// initialize the plugin
void InfoSkeletonObjectPlugin::pluginsInitialized() {

}

//-----------------------------------------------------------------------------

DataType InfoSkeletonObjectPlugin::supportedDataTypes() {
    return DataType(DATA_SKELETON);
}

//-----------------------------------------------------------------------------

void InfoSkeletonObjectPlugin::printSkeletonInfo( Skeleton* _skeleton,  unsigned int _objectId, unsigned int _index, ACG::Vec3d& _hitPoint ) {

  QLocale locale;
  QString name;

  // name
  BaseObject* obj = 0;
  if ( PluginFunctions::getObject(_objectId, obj) )
    info_->generalBox->setTitle( tr("General object information for %1").arg( obj->name() ) );



  // ID
  info_->id->setText( locale.toString(_objectId) );
  // Joints
  info_->joints->setText( locale.toString( _skeleton->jointCount() ) );


  // animation list with animation names and the frame count
  info_->comboBoxAnimations->clear();
  QString animationInfo;
  unsigned int aniCount = _skeleton->animationCount();

  for (unsigned int i = 0; i < aniCount; ++i) {
    std::string aniName = _skeleton->animationName(i);
    animationInfo = "Name: " + QString(aniName.c_str())
                     + " : Frames: " + locale.toString(_skeleton->animation(aniName)->frameCount());
    info_->comboBoxAnimations->addItem(animationInfo);
  }


  // Clicked:
  info_->jointHandle->setText( locale.toString( _index  ) );

  QString adjacentHandles;

  // Check if we have a parent joint
  if ( _skeleton->joint(_index)->parent() !=0 ) {
    adjacentHandles = adjacentHandles + "Parent: " + locale.toString( _skeleton->joint(_index)->parent()->id()  ) + " ;";
  }

  // Check for children
  if ( _skeleton->joint(_index)->size() != 0 ) {

    adjacentHandles = adjacentHandles + "Children:";

    for ( Skeleton::Joint::ChildIter it = _skeleton->joint(_index)->begin(); it != _skeleton->joint(_index)->end(); ++it) {
        Skeleton::Joint *joint = *it;

        adjacentHandles = adjacentHandles + " " + locale.toString(joint->id());
      }
  }



  info_->adjacentJointsHandles->setText(adjacentHandles);


  Skeleton::Point bbMin( FLT_MAX,  FLT_MAX,  FLT_MAX);
  Skeleton::Point bbMax(-FLT_MAX, -FLT_MAX, -FLT_MAX);
  Skeleton::Point cog(0.0,0.0,0.0);

  Skeleton::Pose* pose = _skeleton->referencePose();
  for (Skeleton::Iterator it = _skeleton->begin(); it != _skeleton->end(); ++it) {
    Skeleton::Joint *joint = *it;

    Skeleton::Point p = pose->globalTranslation(joint->id());

    cog += p;

    bbMin.minimize(p);
    bbMax.maximize(p);

  }

  //Bounding Box Size
  Skeleton::Point diff = bbMax-bbMin;

  info_->bbMinX->setText( QString::number(bbMin[0],'f') );
  info_->bbMinY->setText( QString::number(bbMin[1],'f') );
  info_->bbMinZ->setText( QString::number(bbMin[2],'f') );

  info_->bbMaxX->setText( QString::number(bbMax[0],'f') );
  info_->bbMaxY->setText( QString::number(bbMax[1],'f') );
  info_->bbMaxZ->setText( QString::number(bbMax[2],'f') );

  info_->bbSizeX->setText( QString::number(diff[0],'f') );
  info_->bbSizeY->setText( QString::number(diff[1],'f') );
  info_->bbSizeZ->setText( QString::number(diff[2],'f') );


  //COG
  cog = cog / _skeleton->jointCount() ;

  info_->cogX->setText( QString::number(cog[0],'f') );
  info_->cogY->setText( QString::number(cog[1],'f') );
  info_->cogZ->setText( QString::number(cog[2],'f') );

  //hitpoint
  info_->pointX->setText( QString::number( _hitPoint[0],'f' ) );
  info_->pointY->setText( QString::number( _hitPoint[1],'f' ) );
  info_->pointZ->setText( QString::number( _hitPoint[2],'f' ) );

  info_->setWindowFlags(info_->windowFlags() | Qt::WindowStaysOnTopHint);

  info_->show();
}

//----------------------------------------------------------------------------------------------

void InfoSkeletonObjectPlugin::slotInformationRequested(const QPoint _clickedPoint, DataType _type) {

    // Only respond on skeleton objects
    if( _type != DATA_SKELETON ) return;

    ACG::SceneGraph::PickTarget target = ACG::SceneGraph::PICK_ANYTHING;

    unsigned int   node_idx, target_idx;
    ACG::Vec3d     hit_point;

    if (PluginFunctions::scenegraphPick(target, _clickedPoint, node_idx, target_idx, &hit_point)) {
      BaseObjectData* object;

      if ( PluginFunctions::getPickedObject(node_idx, object) ) {

         emit log( LOGINFO , object->getObjectinfo() );

         if ( object->picked(node_idx) && object->dataType(DATA_SKELETON) )
            printSkeletonInfo( PluginFunctions::skeleton(object) , object->id(), target_idx, hit_point );

      } else return;
    }
}


Q_EXPORT_PLUGIN2( infoskeletonobjectplugin , InfoSkeletonObjectPlugin );