Commit 912d973f authored by Jan Möbius's avatar Jan Möbius

Added coordinate system data type

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@11086 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 8a817856
/*===========================================================================*\
* *
* 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: 10926 $ *
* $Author: moebius $ *
* $Date: 2011-02-21 13:34:38 +0100 (Mo, 21 Feb 2011) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS CoordsysNode - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include <ObjectTypes/Coordsys/CoordinateSystemNode.hh>
#include <ACG/GL/gl.hh>
#include <iostream>
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
void
CoordinateSystemNode::
boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
{
//TODO!!
Vec3d topLeft = position_ + coordsysSize_ * ACG::Vec3d(1.0,1.0,1.0);
_bbMin.minimize( topLeft );
_bbMin.minimize( position_ );
_bbMax.maximize( topLeft );
_bbMax.maximize( position_ );
}
//----------------------------------------------------------------------------
DrawModes::DrawMode
CoordinateSystemNode::
availableDrawModes() const
{
return ( DrawModes::POINTS |
DrawModes::POINTS_SHADED |
DrawModes::POINTS_COLORED );
}
//----------------------------------------------------------------------------
void
CoordinateSystemNode::
drawCoordsys( GLState& _state) {
double topRadius = 0.1 * coordsysSize_;
double arrowLength = 0.4 * coordsysSize_;
double bodyRadius = 0.04 * coordsysSize_;
double bodyLength = 0.6 * coordsysSize_;
int slices = 10;
int stacks = 10;
int loops = 10;
double sphereRadius = 0.1 * coordsysSize_;
GLUquadricObj *quadric = gluNewQuadric();
// Origin
glColor3f(0.5, 0.5, 0.5);
gluSphere( quadric, sphereRadius, slices, stacks );
// X-Axis
glColor3f(1.0, 0.0, 0.0);
_state.push_modelview_matrix ();
_state.rotate (-90, 0, 1, 0);
_state.translate ( 0, 0, -bodyLength );
gluCylinder( quadric, bodyRadius, bodyRadius, bodyLength, slices, stacks );
gluDisk( quadric, 0, topRadius, slices, loops );
_state.translate ( 0, 0, -arrowLength );
gluCylinder( quadric, 0, topRadius, arrowLength, slices, stacks );
_state.pop_modelview_matrix ();
// Y-Axis
glColor3f(0.0, 1.0, 0.0);
_state.push_modelview_matrix ();
_state.rotate (90, 1, 0, 0);
_state.translate ( 0, 0, -bodyLength );
gluCylinder( quadric, bodyRadius, bodyRadius, bodyLength, slices, stacks );
gluDisk( quadric, 0, topRadius, slices, loops );
_state.translate ( 0, 0, -arrowLength );
gluCylinder( quadric, 0, topRadius, arrowLength, slices, stacks );
_state.pop_modelview_matrix ();
// Z-Axis
glColor3f(0.0, 0.0, 1.0);
_state.push_modelview_matrix ();
_state.rotate (180, 0, 1, 0);
_state.translate ( 0, 0, -bodyLength );
gluCylinder( quadric, bodyRadius, bodyRadius, bodyLength, slices, stacks );
gluDisk( quadric, 0, topRadius, slices, loops );
_state.translate ( 0, 0, -arrowLength );
gluCylinder( quadric, 0, topRadius, arrowLength, slices, stacks );
_state.pop_modelview_matrix ();
gluDeleteQuadric(quadric);
}
//============================================================================
void
CoordinateSystemNode::drawCoordsysPick( GLState& _state) {
double topRadius = 0.1 * coordsysSize_;
double arrowLength = 0.4 * coordsysSize_;
double bodyRadius = 0.04 * coordsysSize_;
double bodyLength = 0.6 * coordsysSize_;
int slices = 10;
int stacks = 10;
int loops = 10;
double sphereRadius = 0.1 * coordsysSize_;
GLUquadricObj *quadric = gluNewQuadric();
// Origin
_state.pick_set_name (1);
gluSphere( quadric, sphereRadius, slices, stacks );
// X-Axis
_state.pick_set_name (2);
_state.push_modelview_matrix ();
_state.rotate (-90, 0, 1, 0);
_state.translate ( 0, 0, -bodyLength );
gluCylinder( quadric, bodyRadius, bodyRadius, bodyLength, slices, stacks );
gluDisk( quadric, 0, topRadius, slices, loops );
_state.translate ( 0, 0, -arrowLength );
gluCylinder( quadric, 0, topRadius, arrowLength, slices, stacks );
_state.pop_modelview_matrix ();
// Y-Axis
_state.pick_set_name (3);
_state.push_modelview_matrix ();
_state.rotate (90, 1, 0, 0);
_state.translate ( 0, 0, -bodyLength );
gluCylinder( quadric, bodyRadius, bodyRadius, bodyLength, slices, stacks );
gluDisk( quadric, 0, topRadius, slices, loops );
_state.translate ( 0, 0, -arrowLength );
gluCylinder( quadric, 0, topRadius, arrowLength, slices, stacks );
_state.pop_modelview_matrix ();
// Z-Axis
_state.pick_set_name (4);
_state.push_modelview_matrix ();
_state.rotate (180, 0, 1, 0);
_state.translate ( 0, 0, -bodyLength );
gluCylinder( quadric, bodyRadius, bodyRadius, bodyLength, slices, stacks );
gluDisk( quadric, 0, topRadius, slices, loops );
_state.translate ( 0, 0, -arrowLength );
gluCylinder( quadric, 0, topRadius, arrowLength, slices, stacks );
_state.pop_modelview_matrix ();
gluDeleteQuadric(quadric);
}
//============================================================================
void
CoordinateSystemNode::
draw(GLState& _state , const DrawModes::DrawMode& /*_drawMode*/)
{
// Push Modelview-Matrix
_state.push_modelview_matrix();
Vec4f lastBaseColor = _state.base_color();
glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ) ;
glEnable(GL_COLOR_MATERIAL);
glShadeModel(GL_SMOOTH);
_state.translate(position_);
// Koordinatensystem zeichnen
drawCoordsys(_state);
glColor4fv(lastBaseColor.data());
// Reload old configuration
_state.pop_modelview_matrix();
}
void
CoordinateSystemNode::
position(const Vec3d& _pos)
{
position_ = _pos;
}
Vec3d
CoordinateSystemNode::
position() {
return position_;
}
void
CoordinateSystemNode::
size(const double _size) {
coordsysSize_ = _size;
}
double
CoordinateSystemNode::
size() {
return coordsysSize_;
}
void
CoordinateSystemNode::pick(GLState& _state, PickTarget _target)
{
if (_target == PICK_ANYTHING) {
_state.pick_set_maximum(5);
_state.pick_set_name(0);
// Push Modelview-Matrix
_state.push_modelview_matrix();
// Translate to current position of the coordsys
_state.translate(position_);
// Koordinatensystem zeichnen
drawCoordsysPick(_state);
// Reload old configuration
_state.pop_modelview_matrix();
}
}
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
/*===========================================================================*\
* *
* 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: 10926 $ *
* $Author: moebius $ *
* $Date: 2011-02-21 13:34:38 +0100 (Mo, 21 Feb 2011) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS PointNode
//
//=============================================================================
#ifndef ACG_COORDSYSNODE_HH
#define ACG_COORDSYSNODE_HH
//== INCLUDES =================================================================
#include <ACG/Scenegraph/BaseNode.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <vector>
//== NAMESPACES ===============================================================
namespace ACG {
namespace SceneGraph {
//== CLASS DEFINITION =========================================================
/** \class Node for displaying coordinate systems
CoordinateSystemNode renders A coordinate system.
**/
class ACGDLLEXPORT CoordinateSystemNode : public BaseNode
{
public:
/** default constructor
* @param _parent Define the parent Node this node gets attached to
* @param _name Name of this Node
*/
CoordinateSystemNode( BaseNode* _parent=0,
std::string _name="<TextNode>")
: BaseNode(_parent, _name),
coordsysSize_(1.0)
{};
/// destructor
~CoordinateSystemNode() {};
/// static name of this class
ACG_CLASSNAME(CoordinateSystemNode);
/// return available draw modes
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// draw Coordsys
void draw(GLState& _state, const DrawModes::DrawMode& _drawMode);
/// draw Coordsys for object picking
void pick(GLState& _state, PickTarget _target);
/// set position of the coordsys
void position(const Vec3d& _pos);
/// Get current position
Vec3d position();
/// set size of the coordsys ( Size is length of one of the axis )
void size(const double _size);
/// Get current size
double size();
private:
void drawCoordsys(GLState& _state);
void drawCoordsysPick(GLState& _state);
/// 3d position of the coordsys origin
Vec3d position_;
/// Size of the coordsys
double coordsysSize_;
};
//=============================================================================
} // namespace SceneGraph
} // namespace ACG
//=============================================================================
#endif // ACG_COORDSYSNODE_HH defined
//=============================================================================
/*===========================================================================*\
* *
* 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: 10745 $ *
* $LastChangedBy: moebius $ *
* $Date: 2011-01-26 10:23:50 +0100 (Mi, 26. Jan 2011) $ *
* *
\*===========================================================================*/
/**
* \file Coordsys.hh
* This File contains all required includes for using Coordinate systems
*/
#ifndef COORDSYS_INCLUDE_HH
#define COORDSYS_INCLUDE_HH
//== INCLUDES =================================================================
#define DATA_COORDSYS typeId("Coordsys")
#include <ObjectTypes/Coordsys/CoordsysObject.hh>
#include <ObjectTypes/Coordsys/PluginFunctionsCoordsys.hh>
#include <ObjectTypes/Coordsys/CoordsysTypes.hh>
#include <ACG/Scenegraph/CoordsysNode.hh>
//=============================================================================
#endif // COORDSYS_INCLUDE_HH defined
//=============================================================================
/*===========================================================================*\
* *
* 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: 10929 $ *
* $LastChangedBy: moebius $ *
* $Date: 2011-02-21 15:00:32 +0100 (Mo, 21 Feb 2011) $ *
* *
\*===========================================================================*/
//=============================================================================
//
// Plane Object
//
//=============================================================================
#define PLANEOBJECT_C
//== INCLUDES =================================================================
#include <OpenFlipper/common/Types.hh>
#include "Coordsys.hh"
//== DEFINES ==================================================================
//== TYPEDEFS =================================================================
//== CLASS DEFINITION =========================================================
/** Constructor for Coordinate system Objects. This object class gets a Separator Node giving
* the root node to which it should be connected. The Coordinate system is generated internally
* and all nodes for visualization will be added below the scenegraph node.\n
* You don't need to create an object of this type manually. Use
* the functions from LoadSaveInterface ( addEmpty() )
*/
CoordsysObject::CoordsysObject( ) :
BaseObjectData( ),
coordsysNode_(NULL)
{
setDataType(DATA_COORDSYS);
init();
}
//=============================================================================
/**
* Copy Constructor - generates a copy of the given object
*/
CoordsysObject::CoordsysObject(const CoordsysObject & _object) :
BaseObjectData(_object)
{
init(_object.coordsysNode_);
setName( name() );
}
/** Destructor for Coordsys Objects. The destructor deletes the Line and all
* Scenegraph nodes associated with the Coordinate System or the object.
*/
CoordsysObject::~CoordsysObject()
{
// Delete the data attached to this object ( this will remove all perObject data)
// Not the best way to do it but it will work.
// This is only necessary if people use references to the coordsys below and
// they do something with the coordsys in the destructor of their
// perObjectData.
deleteData();
// No need to delete the scenegraph Nodes as this will be managed by baseplugin
coordsysNode_ = NULL;
}
/** Cleanup Function for Coordsys Objects. Deletes the contents of the whole object and
* calls CoordsysObject::init afterwards.
*/
void CoordsysObject::cleanup() {
BaseObjectData::cleanup();
coordsysNode_ = NULL;
setDataType(DATA_COORDSYS);
setTypeIcon(DATA_COORDSYS,"CoordsysType.png");
init();
}
/**
* Generate a copy
*/
BaseObject* CoordsysObject::copy() {
CoordsysObject* object = new CoordsysObject(*this);
return dynamic_cast< BaseObject* >(object);
}
/** This function initalizes the coordsys object. It creates the scenegraph nodes.
*/
void CoordsysObject::init(CoordsysNode* _coordsys) {
if ( materialNode() == NULL)
std::cerr << "Error when creating Coordsys Object! materialNode is NULL!" << std::endl;
coordsysNode_ = new CoordsysNode( materialNode() , "NEW CoordsysNode");
if (_coordsys){
coordsysNode_->position( _coordsys->position() );
coordsysNode_->size( _coordsys->size() );
} else {
coordsysNode_->position( ACG::Vec3d(0.0, 0.0, 0.0) );
coordsysNode_->size( 1.0 );
}
}
// ===============================================================================
// Name/Path Handling
// ===============================================================================
/** Set the name of an object. All Scenegraph nodes are renamed too. It also calls
* BaseObjectData::setName.
*/
void CoordsysObject::setName( QString _name ) {
BaseObjectData::setName(_name);
std::string nodename = std::string("CoordsysNode for Coordinate system " + _name.toUtf8() );
coordsysNode_->name( nodename );
}
// ===============================================================================
// Visualization
// ===============================================================================
CoordsysNode* CoordsysObject::coordsysNode() {
return coordsysNode_;