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_CSetOfTexturedTriangles_H 00029 #define opengl_CSetOfTexturedTriangles_H 00030 00031 #include <mrpt/opengl/CRenderizable.h> 00032 #include <mrpt/utils/CImage.h> 00033 00034 namespace mrpt 00035 { 00036 namespace opengl 00037 { 00038 class MRPTDLLIMPEXP CSetOfTexturedTriangles; 00039 00040 // This must be added to any CSerializable derived class: 00041 DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE( CSetOfTexturedTriangles, CRenderizable ) 00042 00043 /** A set of textured triangles. 00044 * This class can be used to draw any solid, arbitrarily complex object with textures. 00045 * \sa opengl::COpenGLScene 00046 */ 00047 class MRPTDLLIMPEXP CSetOfTexturedTriangles : public CRenderizable 00048 { 00049 DEFINE_SERIALIZABLE( CSetOfTexturedTriangles ) 00050 00051 public: 00052 /** Triangle vertex. This structure encapsulates the vertex coordinates and the image pixels. 00053 */ 00054 struct MRPTDLLIMPEXP TVertex 00055 { 00056 /** Default constructor. 00057 */ 00058 TVertex( ) : 00059 m_x(0.0), m_y(0.0), m_z(0.0), m_u(0), m_v(0) { } 00060 /** Constructor. 00061 */ 00062 TVertex(float x, float y, float z, unsigned int u, unsigned int v) : 00063 m_x(x), m_y(y), m_z(z), m_u(u), m_v(v) { } 00064 /** 3D vertex coordinates. 00065 */ 00066 float m_x, m_y, m_z; 00067 /** 2D texture coordinates. Notice that the texture coordinates are 2D pixels!!! 00068 */ 00069 unsigned int m_u, m_v; 00070 }; 00071 00072 /** Triangle. This structure encapsulates the triangle vertices. 00073 */ 00074 struct MRPTDLLIMPEXP TTriangle 00075 { 00076 /** Default constructor. 00077 */ 00078 TTriangle( ) : 00079 m_v1(), m_v2(), m_v3() { } 00080 /** Constructor. 00081 */ 00082 TTriangle(TVertex v1, TVertex v2, TVertex v3) : 00083 m_v1(v1), m_v2(v2), m_v3(v3) { } 00084 /** Vertices. 00085 */ 00086 TVertex m_v1, m_v2, m_v3; 00087 }; 00088 00089 protected: 00090 mutable bool m_init, 00091 m_transparency; 00092 mutable unsigned int m_glTextureName; 00093 mutable mrpt::utils::CImage m_textureImage, 00094 m_textureAlpha; 00095 mutable unsigned int r_width, 00096 r_height; 00097 00098 /** VERY IMPORTANT: If you use a multi-thread application, you MUST call this from the same thread that will later destruct the object in order to the OpenGL texture memory to be correctly deleted. 00099 * Calling this method more than once has no effects. If you user one thread, this method will be automatically called when rendering, so there is no need to explicitly call it. 00100 */ 00101 void loadTextureInOpenGL() const; 00102 00103 /** Triangle array. */ 00104 std::vector<TTriangle> m_triangles; 00105 00106 public: 00107 void clearTriangles( ) { m_triangles.clear(); } 00108 size_t getTrianglesCount( ) const { return m_triangles.size(); } 00109 void getTriangle( size_t idx, TTriangle &t ) const { ASSERT_(idx<m_triangles.size()); t = m_triangles[idx]; } 00110 void insertTriangle( const TTriangle &t ) { m_triangles.push_back(t); } 00111 00112 /** Render 00113 */ 00114 void render( ) const; 00115 00116 /** Ray Trace 00117 */ 00118 virtual bool traceRay( const mrpt::poses::CPose3D &o,double &dist ) const; 00119 00120 /** Assigns a texture and a transparency image, and enables transparency (If the images are not 2^N x 2^M, they will be internally filled to its dimensions to be powers of two) 00121 */ 00122 void assignImage( 00123 const mrpt::utils::CImage& image, 00124 const mrpt::utils::CImage& alpha ); 00125 00126 /** Assigns a texture image, and disable transparency. 00127 */ 00128 void assignImage( 00129 const mrpt::utils::CImage& image ); 00130 00131 /** Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of the whole image, just copies a pointer. 00132 */ 00133 void assignImage_fast( 00134 mrpt::utils::CImage& image, 00135 mrpt::utils::CImage& alpha ); 00136 00137 /** Similar to assignImage, but the passed images will be returned as empty: it avoids making a copy of the whole image, just copies a pointer. 00138 */ 00139 void assignImage_fast( 00140 mrpt::utils::CImage& image ); 00141 00142 private: 00143 /** Constructor 00144 */ 00145 CSetOfTexturedTriangles( ) : 00146 m_init(false), 00147 m_transparency(false), 00148 m_glTextureName(0), 00149 m_triangles() 00150 { 00151 } 00152 00153 /** Private, virtual destructor: only can be deleted from smart pointers */ 00154 virtual ~CSetOfTexturedTriangles(); 00155 }; 00156 00157 } // end namespace 00158 00159 } // End of namespace 00160 00161 #endif
| Page generated by Doxygen 1.6.2 for MRPT 0.8.1 SVN:exported at Mon Feb 15 22:01:07 UTC 2010 |
