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 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 bool m_visible; //!< Is the object visible? (default=true) 00073 00074 public: 00075 void setName(const std::string &n) { m_name=n; } //!< Changes the name of the object 00076 std::string getName() const { return m_name; } //!< Returns the name of the object 00077 00078 inline bool isVisible() const /** Is the object visible? \sa setVisibility */ { return m_visible; } 00079 inline void setVisibility(bool visible=true) /** Set object visibility (default=true) \sa isVisible */ { m_visible=visible; } 00080 00081 void enableShowName(bool showName=true) { m_show_name=showName; } //!< Enables or disables showing the name of the object as a label when rendering 00082 00083 static void renderTextBitmap( const char *str, void *fontStyle ); 00084 00085 /** Default constructor: */ 00086 CRenderizable(); 00087 virtual ~CRenderizable() { } 00088 00089 /** Interface for the stlplus smart pointer class. */ 00090 inline CRenderizable * clone() const 00091 { 00092 return static_cast<CRenderizable*>( this->duplicate() ); 00093 } 00094 00095 /** This virtual method in the base class performs common tasks like coordinates transformation,color,... 00096 */ 00097 virtual void render() const = 0; 00098 00099 void setPose( const mrpt::poses::CPose3D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00100 void setPose( const mrpt::math::TPose3D &o ); //!< Set the 3D pose from a mrpt::math::TPose3D object 00101 void setPose( const mrpt::poses::CPoint3D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00102 void setPose( const mrpt::poses::CPoint2D &o ); //!< Set the 3D pose from a mrpt::poses::CPose3D object 00103 00104 mrpt::math::TPose3D getPose() const; //!< Returns the 3D pose of the object 00105 00106 /** Changes the location of the object, keeping untouched the orientation */ 00107 void setLocation(double x,double y,double z) { m_x=x; m_y=y; m_z=z; } 00108 00109 /** Changes the location of the object, keeping untouched the orientation */ 00110 void setLocation(const mrpt::math::TPoint3D &p ) { m_x=p.x; m_y=p.y; m_z=p.z; } 00111 00112 double getPoseX() const { return m_x; } //!< Translation relative to parent coordinate origin. 00113 double getPoseY() const { return m_y; } //!< Translation relative to parent coordinate origin. 00114 double getPoseZ() const { return m_z; } //!< Translation relative to parent coordinate origin. 00115 double getPoseYaw() const { return m_yaw; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00116 double getPosePitch() const { return m_pitch; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00117 double getPoseRoll() const { return m_roll; } //!< Rotation relative to parent coordinate origin, in **DEGREES**. 00118 00119 double getColorR() const { return m_color_R; } //!< Color components in the range [0,1] 00120 double getColorG() const { return m_color_G; } //!< Color components in the range [0,1] 00121 double getColorB() const { return m_color_B; } //!< Color components in the range [0,1] 00122 double getColorA() const { return m_color_A; } //!< Color components in the range [0,1] 00123 00124 virtual void setColorR(const double r) {m_color_R=r;} //!<Color components in the range [0,1] 00125 virtual void setColorG(const double g) {m_color_G=g;} //!<Color components in the range [0,1] 00126 virtual void setColorB(const double b) {m_color_B=b;} //!<Color components in the range [0,1] 00127 virtual void setColorA(const double a) {m_color_A=a;} //!<Color components in the range [0,1] 00128 00129 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) 00130 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) 00131 inline float getScaleX() const { return m_scale_x; } //!< Get the current scaling factor in one axis 00132 inline float getScaleY() const { return m_scale_y; } //!< Get the current scaling factor in one axis 00133 inline float getScaleZ() const { return m_scale_z; } //!< Get the current scaling factor in one axis 00134 00135 00136 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 00137 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 00138 00139 00140 /** 00141 * 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 00142 */ 00143 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const; 00144 00145 /** Set the color components of this object (R,G,B,Alpha, in the range 0-1) */ 00146 virtual void setColor( double R, double G, double B, double A=1); 00147 00148 protected: 00149 /** Checks glGetError and throws an exception if an error situation is found */ 00150 static void checkOpenGLError(); 00151 00152 void writeToStreamRender(utils::CStream &out) const; 00153 void readFromStreamRender(utils::CStream &in); 00154 00155 /** Returns the lowest, free texture name. */ 00156 static unsigned int getNewTextureNumber(); 00157 static void releaseTextureName(unsigned int i); 00158 00159 }; 00160 /** 00161 * 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. 00162 * \sa setPose 00163 */ 00164 MRPTDLLIMPEXP CRenderizablePtr & operator<<(CRenderizablePtr &r,const mrpt::poses::CPose3D &p); 00165 00166 } // end namespace 00167 00168 } // End of namespace 00169 00170 00171 #endif
| Page generated by Doxygen 1.7.1 for MRPT 0.8.1 SVN:exported at Sun Sep 19 14:53:45 UTC 2010 |
