PlaneObject.cc

00001 //=============================================================================
00002 //
00003 //  MyTypes
00004 //
00005 //=============================================================================
00006 
00007 #define PLANEOBJECT_C
00008 
00009 //== INCLUDES =================================================================
00010 
00011 #include <OpenFlipper/common/Types.hh>
00012 #include "Plane.hh"
00013 
00014 //== DEFINES ==================================================================
00015 
00016 //== TYPEDEFS =================================================================
00017 
00018 //== CLASS DEFINITION =========================================================
00019 
00026 PlaneObject::PlaneObject( SeparatorNode* _rootNode ) :
00027   BaseObjectData(_rootNode ),
00028   planeNode_(NULL)
00029 {
00030   setDataType(DATA_PLANE);
00031   init();
00032 }
00033 
00034 //=============================================================================
00035 
00036 
00040 PlaneObject::PlaneObject(const PlaneObject & _object) :
00041   BaseObjectData(_object)
00042 {
00043 
00044     init(_object.planeNode_);
00045 
00046     setName( name() );
00047 }
00048 
00052 PlaneObject::~PlaneObject()
00053 {
00054   // Delete the data attached to this object ( this will remove all perObject data)
00055   // Not the best way to do it but it will work.
00056   // This is only necessary if people use references to the plane below and
00057   // they do something with the plane in the destructor of their
00058   // perObjectData.
00059   deleteData();
00060 
00061   // No need to delete the scenegraph Nodes as this will be managed by baseplugin
00062   planeNode_    = NULL;
00063 }
00064 
00068 void PlaneObject::cleanup() {
00069 
00070   BaseObjectData::cleanup();
00071 
00072   planeNode_   = NULL;
00073 
00074   setDataType(DATA_PLANE);
00075 
00076   init();
00077 
00078 }
00079 
00083 BaseObject* PlaneObject::copy() {
00084     PlaneObject* object = new PlaneObject(*this);
00085     return dynamic_cast< BaseObject* >(object);
00086 }
00087 
00090 void PlaneObject::init(PlaneNode* _plane) {
00091 
00092   if ( materialNode() == NULL)
00093     std::cerr << "Error when creating Plane Object! materialNode is NULL!" << std::endl;
00094 
00095   planeNode_ = new PlaneNode( materialNode() , "NEW PlaneNode");
00096 
00097   if (_plane){
00098     planeNode_->setPosition( _plane->position(), _plane->normal() );
00099     planeNode_->setSize( _plane->xDirection().norm(), _plane->yDirection().norm() );
00100   } else {
00101     planeNode_->setPosition( ACG::Vec3f(0.0, 0.0, 0.0), ACG::Vec3f(0.0, 1.0, 0.0) );
00102     planeNode_->setSize( 5.0, 5.0 );
00103   }
00104 }
00105 
00106 // ===============================================================================
00107 // Name/Path Handling
00108 // ===============================================================================
00109 
00113 void PlaneObject::setName( QString _name ) {
00114   BaseObjectData::setName(_name);
00115 
00116   std::string nodename = std::string("PlaneNode for Plane "     + _name.toUtf8() );
00117   planeNode_->name( nodename );
00118 }
00119 
00120 // ===============================================================================
00121 // Visualization
00122 // ===============================================================================
00123 
00124 PlaneNode* PlaneObject::planeNode() {
00125   return planeNode_;
00126 }
00127 
00128 // ===============================================================================
00129 // Object information
00130 // ===============================================================================
00131 
00137 QString PlaneObject::getObjectinfo() {
00138   QString output;
00139 
00140   output += "========================================================================\n";
00141   output += BaseObjectData::getObjectinfo();
00142 
00143   if ( dataType( DATA_PLANE ) )
00144     output += "Object Contains Plane : ";
00145 
00146   ACG::Vec3f pos = planeNode_->position();
00147   ACG::Vec3f nor = planeNode_->normal();
00148 
00149   output += " Position ( " + QString::number(pos[0]) + ", " + QString::number(pos[1]) + ", " + QString::number(pos[2]) + ")";
00150   output += " Normal ( " + QString::number(nor[0]) + ", " + QString::number(nor[1]) + ", " + QString::number(nor[2]) + ")";
00151 
00152   output += "========================================================================\n";
00153   return output;
00154 }
00155 
00156 // ===============================================================================
00157 // Picking
00158 // ===============================================================================
00159 
00166 bool PlaneObject::picked( uint _node_idx ) {
00167   return ( _node_idx == planeNode_->id() );
00168 }
00169 
00170 void PlaneObject::enablePicking( bool _enable ) {
00171   planeNode_->enablePicking( _enable );
00172 }
00173 
00174 bool PlaneObject::pickingEnabled() {
00175   return planeNode_->pickingEnabled();
00176 }
00177 
00178 //=============================================================================
00179 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .