00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef opengl_CRenderizable_H 00029 #define opengl_CRenderizable_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 #include <mrpt/utils/CSerializable.h> 00033 00034 #include <mrpt/synch/CCriticalSection.h> 00035 #include <mrpt/math/lightweight_geom_data.h> 00036 00037 namespace mrpt 00038 { 00039 namespace poses { class CPose3D; class CPoint3D; class CPoint2D; } 00040 namespace utils { class CStringList; } 00041 00042 namespace opengl 00043 { 00044 class COpenGLViewport; 00045 class CSetOfObjects; 00046 00047 // This must be added to any CSerializable derived class: 00048 DEFINE_SERIALIZABLE_PRE( CRenderizable ) 00049 00050 /** The base class of 3D objects that can be directly rendered through OpenGL. 00051 * In this class there are a set of common properties to all 3D objects, mainly: 00052 * - A name (m_name): A name that can be optionally asigned to objects for easing its reference. 00053 * - 6D coordinates (x,y,z,yaw,pitch,roll), relative to the "current" reference framework. By default, any object is referenced to global scene coordinates. 00054 * - A RGB color: This field will be used in simple elements (points, lines, text,...) but is ignored in more complex objects that carry their own color information (triangle sets,...) 00055 * See the main class opengl::COpenGLScene 00056 * \sa opengl::COpenGLScene, mrpt::opengl 00057 */ 00058 class MRPTDLLIMPEXP CRenderizable : public mrpt::utils::CSerializable 00059 { 00060 DEFINE_VIRTUAL_SERIALIZABLE( CRenderizable ) 00061 00062 friend class mrpt::opengl::COpenGLViewport; 00063 friend class mrpt::opengl::CSetOfObjects; 00064 00065 protected: 00066 std::string m_name; 00067 bool m_show_name; 00068 double m_color_R,m_color_G,m_color_B,m_color_A; //!< Color components in the range [0,1] 00069 double m_x,m_y,m_z; //!< Translation relative to parent coordinate origin. 00070 double m_yaw,m_pitch,m_roll; //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00071 float m_scale_x, m_scale_y, m_scale_z; //!< Scale components to apply to the object (default=1) 00072 00073 public: 00074 void setName(const std::string &n) { m_name=n; } //!< Changes the name of the object 00075 std::string getName() const { return m_name; } //!< Returns the name of the object 00076 00077 void enableShowName(bool showName=true) { m_show_name=showName; } //!< Enables or disables showing the name of the object as a label when rendering 00078 00079 static void renderTextBitmap( const char *str, void *fontStyle ); 00080 00081 /** Default constructor: 00082 */ 00083 CRenderizable() : 00084 m_name(), 00085 m_show_name(false), 00086 m_color_R(1),m_color_G(1),m_color_B(1),m_color_A(1), 00087 m_x(0),m_y(0),m_z(0), 00088 m_yaw(0),m_pitch(0),m_roll(0), 00089 m_scale_x(1), m_scale_y(1), m_scale_z(1) 00090 { 00091 } 00092 00093 virtual ~CRenderizable() { } 00094 00095 /** Interface for the stlplus smart pointer class. */ 00096 inline CRenderizable * clone() const 00097 { 00098 return static_cast<CRenderizable*>( this->duplicate() ); 00099 } 00100 00101 /** This virtual method in the base class performs common tasks like coordinates transformation,color,... 00102 */ 00103 virtual void render() const = 0; 00104 00105 void setPose( const mrpt::poses::CPose3D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00106 void setPose( const mrpt::math::TPose3D &o ); //!< Set the 3D pose from a mrpt::math::TPose3D object 00107 void setPose( const mrpt::poses::CPoint3D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00108 void setPose( const mrpt::poses::CPoint2D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00109 00110 mrpt::math::TPose3D getPose() const; //!< Returns the 3D pose of the object 00111 00112 /** Changes the location of the object, keeping untouched the orientation */ 00113 void setLocation(double x,double y,double z) { m_x=x; m_y=y; m_z=z; } 00114 00115 /** Changes the location of the object, keeping untouched the orientation */ 00116 void setLocation(const mrpt::math::TPoint3D &p ) { m_x=p.x; m_y=p.y; m_z=p.z; } 00117 00118 double getPoseX() const { return m_x; } //!< Translation relative to parent coordinate origin. 00119 double getPoseY() const { return m_y; } //!< Translation relative to parent coordinate origin. 00120 double getPoseZ() const { return m_z; } //!< Translation relative to parent coordinate origin. 00121 double getPoseYaw() const { return m_yaw; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00122 double getPosePitch() const { return m_pitch; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00123 double getPoseRoll() const { return m_roll; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00124 00125 double getColorR() const { return m_color_R; } //!< Color components in the range [0,1] 00126 double getColorG() const { return m_color_G; } //!< Color components in the range [0,1] 00127 double getColorB() const { return m_color_B; } //!< Color components in the range [0,1] 00128 double getColorA() const { return m_color_A; } //!< Color components in the range [0,1] 00129 00130 virtual void setColorR(const double r) {m_color_R=r;} //!<Color components in the range [0,1] 00131 virtual void setColorG(const double g) {m_color_G=g;} //!<Color components in the range [0,1] 00132 virtual void setColorB(const double b) {m_color_B=b;} //!<Color components in the range [0,1] 00133 virtual void setColorA(const double a) {m_color_A=a;} //!<Color components in the range [0,1] 00134 00135 inline void setScale(float s) { m_scale_x=m_scale_y=m_scale_z = s; } //!< Scale to apply to the object, in all three axes (default=1) 00136 inline void setScale(float sx,float sy,float sz) { m_scale_x=sx; m_scale_y=sy; m_scale_z = sz; } //!< Scale to apply to the object in each axis (default=1) 00137 inline float getScaleX() const { return m_scale_x; } //!< Get the current scaling factor in one axis 00138 inline float getScaleY() const { return m_scale_y; } //!< Get the current scaling factor in one axis 00139 inline float getScaleZ() const { return m_scale_z; } //!< Get the current scaling factor in one axis 00140 00141 00142 inline mrpt::utils::TColorf getColor() const { return mrpt::utils::TColorf(m_color_R,m_color_G,m_color_B,m_color_A); } //!< Returns the object color property as a TColorf 00143 virtual void setColor( const mrpt::utils::TColorf &c) { m_color_R = c.R; m_color_G=c.G; m_color_B=c.B;m_color_A=c.A; } //!< Changes the default object color 00144 00145 00146 /** 00147 * Simulation of ray-trace, given a pose. Returns true if the ray effectively collisions with the object (returning the distance to the origin of the ray in "dist"), or false in other case. "dist" variable yields undefined behaviour when false is returned 00148 */ 00149 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const; 00150 00151 /** Set the color components of this object (R,G,B,Alpha, in the range 0-1) */ 00152 virtual void setColor( double R, double G, double B, double A=1); 00153 00154 protected: 00155 /** Checks glGetError and throws an exception if an error situation is found */ 00156 static void checkOpenGLError(); 00157 00158 void writeToStreamRender(utils::CStream &out) const; 00159 void readFromStreamRender(utils::CStream &in); 00160 00161 /** Returns the lowest, free texture name. */ 00162 static unsigned int getNewTextureNumber(); 00163 static void releaseTextureName(unsigned int i); 00164 00165 }; 00166 /** 00167 * Applies a CPose3D transformation to the object. Note that this method doesn't <i>set</i> the pose to the given value, but <i>combines</i> it with the existing one. 00168 * \sa setPose 00169 */ 00170 MRPTDLLIMPEXP CRenderizablePtr & operator<<(CRenderizablePtr &r,const mrpt::poses::CPose3D &p); 00171 00172 } // end namespace 00173 00174 } // End of namespace 00175 00176 00177 #endif
Page generated by Doxygen 1.6.1 for MRPT 0.7.1 SVN: at Tue Dec 22 08:29:35 CET 2009 |