Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 #include <mrpt/utils/TColor.h>
00034
00035 #include <mrpt/poses/CPose3D.h>
00036
00037 #include <mrpt/synch/CCriticalSection.h>
00038 #include <mrpt/math/lightweight_geom_data.h>
00039
00040 #include <mrpt/opengl/opengl_fonts.h>
00041
00042 #include <mrpt/opengl/link_pragmas.h>
00043
00044 namespace mrpt
00045 {
00046 namespace poses { class CPoint3D; class CPoint2D; }
00047 namespace utils { class CStringList; }
00048
00049 namespace opengl
00050 {
00051 class COpenGLViewport;
00052 class CSetOfObjects;
00053
00054
00055
00056 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE( CRenderizable, mrpt::utils::CSerializable, OPENGL_IMPEXP )
00057
00058
00059 typedef std::deque<CRenderizablePtr> CListOpenGLObjects;
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 class OPENGL_IMPEXP CRenderizable : public mrpt::utils::CSerializable
00071 {
00072 DEFINE_VIRTUAL_SERIALIZABLE( CRenderizable )
00073
00074 friend class mrpt::opengl::COpenGLViewport;
00075 friend class mrpt::opengl::CSetOfObjects;
00076
00077 protected:
00078 std::string m_name;
00079 bool m_show_name;
00080 mrpt::utils::TColor m_color;
00081 mrpt::poses::CPose3D m_pose;
00082 float m_scale_x, m_scale_y, m_scale_z;
00083 bool m_visible;
00084
00085 public:
00086
00087
00088
00089 void setName(const std::string &n) { m_name=n; }
00090 const std::string &getName() const { return m_name; }
00091
00092 inline bool isVisible() const { return m_visible; }
00093 inline void setVisibility(bool visible=true) { m_visible=visible; }
00094
00095 inline void enableShowName(bool showName=true) { m_show_name=showName; }
00096 inline bool isShowNameEnabled() const { return m_show_name; }
00097
00098 CRenderizable& setPose( const mrpt::poses::CPose3D &o );
00099 CRenderizable& setPose( const mrpt::math::TPose3D &o );
00100 CRenderizable& setPose( const mrpt::poses::CPoint3D &o );
00101 CRenderizable& setPose( const mrpt::poses::CPoint2D &o );
00102
00103 mrpt::math::TPose3D getPose() const;
00104
00105 inline const mrpt::poses::CPose3D & getPoseRef() const { return m_pose; }
00106
00107
00108 inline CRenderizable& setLocation(double x,double y,double z) { m_pose.x(x); m_pose.y(y); m_pose.z(z); return *this; }
00109
00110
00111 inline CRenderizable& setLocation(const mrpt::math::TPoint3D &p ) { m_pose.x(p.x); m_pose.y(p.y); m_pose.z(p.z); return *this; }
00112
00113 inline double getPoseX() const { return m_pose.x(); }
00114 inline double getPoseY() const { return m_pose.y(); }
00115 inline double getPoseZ() const { return m_pose.z(); }
00116 inline double getPoseYaw() const { return mrpt::utils::RAD2DEG(m_pose.yaw()); }
00117 inline double getPosePitch() const { return mrpt::utils::RAD2DEG(m_pose.pitch()); }
00118 inline double getPoseRoll() const { return mrpt::utils::RAD2DEG(m_pose.roll()); }
00119 inline double getPoseYawRad() const { return m_pose.yaw(); }
00120 inline double getPosePitchRad() const { return m_pose.pitch(); }
00121 inline double getPoseRollRad() const { return m_pose.roll(); }
00122
00123 inline double getColorR() const { return m_color.R/255.; }
00124 inline double getColorG() const { return m_color.G/255.; }
00125 inline double getColorB() const { return m_color.B/255.; }
00126 inline double getColorA() const { return m_color.A/255.; }
00127
00128 inline uint8_t getColorR_u8() const { return m_color.R; }
00129 inline uint8_t getColorG_u8() const { return m_color.G; }
00130 inline uint8_t getColorB_u8() const { return m_color.B; }
00131 inline uint8_t getColorA_u8() const { return m_color.A; }
00132
00133 CRenderizable& setColorR(const double r) {return setColorR_u8(static_cast<uint8_t>(255*r));}
00134 CRenderizable& setColorG(const double g) {return setColorG_u8(static_cast<uint8_t>(255*g));}
00135 CRenderizable& setColorB(const double b) {return setColorB_u8(static_cast<uint8_t>(255*b));}
00136 CRenderizable& setColorA(const double a) {return setColorA_u8(static_cast<uint8_t>(255*a));}
00137
00138 virtual CRenderizable& setColorR_u8(const uint8_t r) {m_color.R=r; return *this;}
00139 virtual CRenderizable& setColorG_u8(const uint8_t g) {m_color.G=g; return *this;}
00140 virtual CRenderizable& setColorB_u8(const uint8_t b) {m_color.B=b; return *this;}
00141 virtual CRenderizable& setColorA_u8(const uint8_t a) {m_color.A=a; return *this;}
00142
00143 inline CRenderizable& setScale(float s) { m_scale_x=m_scale_y=m_scale_z = s; return *this; }
00144 inline CRenderizable& setScale(float sx,float sy,float sz) { m_scale_x=sx; m_scale_y=sy; m_scale_z = sz; return *this; }
00145 inline float getScaleX() const { return m_scale_x; }
00146 inline float getScaleY() const { return m_scale_y; }
00147 inline float getScaleZ() const { return m_scale_z; }
00148
00149
00150 inline mrpt::utils::TColorf getColor() const { return mrpt::utils::TColorf(m_color); }
00151 CRenderizable& setColor( const mrpt::utils::TColorf &c)
00152 {
00153 return setColor_u8(mrpt::utils::TColor(c.R*255.f,c.G*255.f,c.B*255.f,c.A*255.f));
00154 }
00155
00156
00157 inline CRenderizable& setColor( double R, double G, double B, double A=1) { return setColor_u8(R*255,G*255,B*255,A*255); }
00158
00159 inline const mrpt::utils::TColor &getColor_u8() const { return m_color; }
00160
00161 virtual CRenderizable& setColor_u8( const mrpt::utils::TColor &c);
00162
00163
00164 inline CRenderizable& setColor_u8( uint8_t R, uint8_t G, uint8_t B, uint8_t A=255) { return setColor_u8(mrpt::utils::TColor(R,G,B,A)); }
00165
00166
00167
00168
00169
00170 CRenderizable();
00171 virtual ~CRenderizable();
00172
00173
00174 inline CRenderizable * clone() const
00175 {
00176 return static_cast<CRenderizable*>( this->duplicate() );
00177 }
00178
00179
00180
00181 virtual void render() const = 0;
00182
00183
00184
00185 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00186
00187
00188
00189 static void renderTextBitmap( const char *str, void *fontStyle );
00190
00191
00192
00193
00194 static int textBitmapWidth(
00195 const std::string &str,
00196 mrpt::opengl::TOpenGLFont font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24 );
00197
00198
00199
00200
00201
00202
00203 static void renderTextBitmap(
00204 int screen_x,
00205 int screen_y,
00206 const std::string &str,
00207 float color_r=1,
00208 float color_g=1,
00209 float color_b=1,
00210 mrpt::opengl::TOpenGLFont font = mrpt::opengl::MRPT_GLUT_BITMAP_TIMES_ROMAN_24
00211 );
00212
00213 protected:
00214
00215 static void checkOpenGLError();
00216
00217 void writeToStreamRender(utils::CStream &out) const;
00218 void readFromStreamRender(utils::CStream &in);
00219
00220
00221 static unsigned int getNewTextureNumber();
00222 static void releaseTextureName(unsigned int i);
00223
00224 };
00225
00226
00227
00228
00229 OPENGL_IMPEXP CRenderizablePtr & operator<<(CRenderizablePtr &r,const mrpt::poses::CPose3D &p);
00230
00231 }
00232
00233 }
00234
00235
00236 #include <mrpt/opengl/gl_utils.h>
00237
00238
00239 #endif