00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2010 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 #include <mrpt/opengl/link_pragmas.h> 00038 00039 namespace mrpt 00040 { 00041 namespace poses { class CPose3D; class CPoint3D; class CPoint2D; } 00042 namespace utils { class CStringList; } 00043 00044 namespace opengl 00045 { 00046 class COpenGLViewport; 00047 class CSetOfObjects; 00048 00049 // This must be added to any CSerializable derived class: 00050 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CRenderizable, mrpt::utils::CSerializable, OPENGL_IMPEXP ) 00051 00052 /** The base class of 3D objects that can be directly rendered through OpenGL. 00053 * In this class there are a set of common properties to all 3D objects, mainly: 00054 * - A name (m_name): A name that can be optionally asigned to objects for easing its reference. 00055 * - 6D coordinates (x,y,z,yaw,pitch,roll), relative to the "current" reference framework. By default, any object is referenced to global scene coordinates. 00056 * - 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,...) 00057 * See the main class opengl::COpenGLScene 00058 * \sa opengl::COpenGLScene, mrpt::opengl 00059 */ 00060 class OPENGL_IMPEXP CRenderizable : public mrpt::utils::CSerializable 00061 { 00062 DEFINE_VIRTUAL_SERIALIZABLE( CRenderizable ) 00063 00064 friend class mrpt::opengl::COpenGLViewport; 00065 friend class mrpt::opengl::CSetOfObjects; 00066 00067 protected: 00068 std::string m_name; 00069 bool m_show_name; 00070 double m_color_R,m_color_G,m_color_B,m_color_A; //!< Color components in the range [0,1] 00071 double m_x,m_y,m_z; //!< Translation relative to parent coordinate origin. 00072 double m_yaw,m_pitch,m_roll; //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00073 float m_scale_x, m_scale_y, m_scale_z; //!< Scale components to apply to the object (default=1) 00074 bool m_visible; //!< Is the object visible? (default=true) 00075 00076 public: 00077 void setName(const std::string &n) { m_name=n; } //!< Changes the name of the object 00078 std::string getName() const { return m_name; } //!< Returns the name of the object 00079 00080 inline bool isVisible() const /** Is the object visible? \sa setVisibility */ { return m_visible; } 00081 inline void setVisibility(bool visible=true) /** Set object visibility (default=true) \sa isVisible */ { m_visible=visible; } 00082 00083 void enableShowName(bool showName=true) { m_show_name=showName; } //!< Enables or disables showing the name of the object as a label when rendering 00084 00085 static void renderTextBitmap( const char *str, void *fontStyle ); 00086 00087 /** Default constructor: */ 00088 CRenderizable(); 00089 virtual ~CRenderizable() { } 00090 00091 /** Interface for the stlplus smart pointer class. */ 00092 inline CRenderizable * clone() const 00093 { 00094 return static_cast<CRenderizable*>( this->duplicate() ); 00095 } 00096 00097 /** This virtual method in the base class performs common tasks like coordinates transformation,color,... 00098 */ 00099 virtual void render() const = 0; 00100 00101 void setPose( const mrpt::poses::CPose3D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00102 void setPose( const mrpt::math::TPose3D &o ); //!< Set the 3D pose from a mrpt::math::TPose3D object 00103 void setPose( const mrpt::poses::CPoint3D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00104 void setPose( const mrpt::poses::CPoint2D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00105 00106 mrpt::math::TPose3D getPose() const; //!< Returns the 3D pose of the object 00107 00108 /** Changes the location of the object, keeping untouched the orientation */ 00109 void setLocation(double x,double y,double z) { m_x=x; m_y=y; m_z=z; } 00110 00111 /** Changes the location of the object, keeping untouched the orientation */ 00112 void setLocation(const mrpt::math::TPoint3D &p ) { m_x=p.x; m_y=p.y; m_z=p.z; } 00113 00114 double getPoseX() const { return m_x; } //!< Translation relative to parent coordinate origin. 00115 double getPoseY() const { return m_y; } //!< Translation relative to parent coordinate origin. 00116 double getPoseZ() const { return m_z; } //!< Translation relative to parent coordinate origin. 00117 double getPoseYaw() const { return m_yaw; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00118 double getPosePitch() const { return m_pitch; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00119 double getPoseRoll() const { return m_roll; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00120 00121 double getColorR() const { return m_color_R; } //!< Color components in the range [0,1] 00122 double getColorG() const { return m_color_G; } //!< Color components in the range [0,1] 00123 double getColorB() const { return m_color_B; } //!< Color components in the range [0,1] 00124 double getColorA() const { return m_color_A; } //!< Color components in the range [0,1] 00125 00126 virtual void setColorR(const double r) {m_color_R=r;} //!<Color components in the range [0,1] 00127 virtual void setColorG(const double g) {m_color_G=g;} //!<Color components in the range [0,1] 00128 virtual void setColorB(const double b) {m_color_B=b;} //!<Color components in the range [0,1] 00129 virtual void setColorA(const double a) {m_color_A=a;} //!<Color components in the range [0,1] 00130 00131 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) 00132 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) 00133 inline float getScaleX() const { return m_scale_x; } //!< Get the current scaling factor in one axis 00134 inline float getScaleY() const { return m_scale_y; } //!< Get the current scaling factor in one axis 00135 inline float getScaleZ() const { return m_scale_z; } //!< Get the current scaling factor in one axis 00136 00137 00138 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 00139 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 00140 00141 00142 /** 00143 * 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 00144 */ 00145 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const; 00146 00147 /** Set the color components of this object (R,G,B,Alpha, in the range 0-1) */ 00148 virtual void setColor( double R, double G, double B, double A=1); 00149 00150 protected: 00151 /** Checks glGetError and throws an exception if an error situation is found */ 00152 static void checkOpenGLError(); 00153 /** Can be used by derived classes to draw a triangle with a normal vector computed automatically - to be called within a glBegin()-glEnd() block. */ 00154 static void renderTriangleWithNormal( const mrpt::math::TPoint3D &p1,const mrpt::math::TPoint3D &p2,const mrpt::math::TPoint3D &p3 ); 00155 00156 void writeToStreamRender(utils::CStream &out) const; 00157 void readFromStreamRender(utils::CStream &in); 00158 00159 /** Returns the lowest, free texture name. */ 00160 static unsigned int getNewTextureNumber(); 00161 static void releaseTextureName(unsigned int i); 00162 00163 }; 00164 /** 00165 * 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. 00166 * \sa setPose 00167 */ 00168 OPENGL_IMPEXP CRenderizablePtr & operator<<(CRenderizablePtr &r,const mrpt::poses::CPose3D &p); 00169 00170 } // end namespace 00171 00172 } // End of namespace 00173 00174 00175 #endif
| Page generated by Doxygen 1.6.1 for MRPT 0.9.0 SVN: at Mon Jun 7 06:47:58 UTC 2010 |
