SkeletonObjectInfoPlugin.cc 9.14 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
 
Jan Möbius committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
*                                                                            *
\*===========================================================================*/

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

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


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

Matthias Möller's avatar
Matthias Möller committed
59

Jan Möbius's avatar
 
Jan Möbius committed
60 61 62 63 64 65 66 67 68 69 70 71 72 73
#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>

74
#include <cfloat>
Jan Möbius's avatar
 
Jan Möbius committed
75

76 77 78 79 80 81
#if QT_VERSION >= 0x050000 
#include <QtWidgets>
#else
#include <QtGui>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
82 83 84 85
//== IMPLEMENTATION ==========================================================

void InfoSkeletonObjectPlugin::initializePlugin() {

86 87 88 89
  if ( OpenFlipper::Options::gui()) {
    // Create info dialog
    info_ = new InfoDialog();
  }
Jan Möbius's avatar
 
Jan Möbius committed
90 91 92 93 94

}

/// initialize the plugin
void InfoSkeletonObjectPlugin::pluginsInitialized() {
Matthias Möller's avatar
Matthias Möller committed
95 96
	//set the slot descriptions
	setDescriptions();
Jan Möbius's avatar
 
Jan Möbius committed
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 230 231 232 233 234 235 236 237 238 239 240 241

}

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

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;
    }
}

Matthias Möller's avatar
Matthias Möller committed
242 243 244
#if QT_VERSION < 0x050000
  Q_EXPORT_PLUGIN2( infoskeletonobjectplugin , InfoSkeletonObjectPlugin );
#endif
Jan Möbius's avatar
 
Jan Möbius committed
245