Main MRPT website > C++ reference
MRPT logo

CBox.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  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_CBox_H
00029 #define opengl_CBox_H
00030 
00031 #include <mrpt/opengl/CRenderizableDisplayList.h>
00032 #include <mrpt/math/lightweight_geom_data.h>
00033 
00034 namespace mrpt  {
00035 namespace opengl        {
00036 
00037         // This must be added to any CSerializable derived class:
00038         DEFINE_SERIALIZABLE_PRE_CUSTOM_BASE_LINKAGE(CBox,CRenderizableDisplayList, OPENGL_IMPEXP)
00039         
00040         /** A solid or wireframe box in 3D, defined by 6 rectangular faces parallel to the planes X, Y and Z (note that the object can be translated and rotated afterwards as any other CRenderizable object using the "object pose" in the base class).
00041           *
00042           * \sa opengl::COpenGLScene,opengl::CRenderizable
00043           *  
00044           *  <div align="center">
00045           *  <table border="0" cellspan="4" cellspacing="4" style="border-width: 1px; border-style: solid;">
00046           *   <tr> <td> mrpt::opengl::CBox </td> <td> \image html preview_CBox.png </td> </tr>
00047           *  </table>
00048           *  </div>
00049           *  
00050           */
00051         class OPENGL_IMPEXP CBox :public CRenderizableDisplayList       {
00052                 DEFINE_SERIALIZABLE(CBox)
00053 
00054         protected:
00055                 mrpt::math::TPoint3D    m_corner_min,m_corner_max;              //!< Corners coordinates
00056                 bool                                    m_wireframe;    //!< true: wireframe, false: solid
00057                 float                                   m_lineWidth;    //!< For wireframe only.
00058                 
00059         public:
00060                 /** Constructor returning a smart pointer to the newly created object. */
00061                 static CBoxPtr Create(const mrpt::math::TPoint3D &corner1, const mrpt::math::TPoint3D &corner2, bool  is_wireframe = false, float lineWidth = 1.0 )     
00062                 { 
00063                         return CBoxPtr(new CBox(corner1,corner2,is_wireframe,lineWidth)); 
00064                 }
00065                 
00066                 /** Render
00067                   * \sa mrpt::opengl::CRenderizable
00068                   */
00069                 void render_dl() const;
00070                 
00071                 /**
00072                   * Ray tracing.
00073                   * \sa mrpt::opengl::CRenderizable
00074                   */
00075                 virtual bool traceRay(const mrpt::poses::CPose3D &o,double &dist) const;
00076                 
00077                 inline void setLineWidth(float width) { m_lineWidth = width; CRenderizableDisplayList::notifyChange(); }
00078                 inline float getLineWidth() const { return m_lineWidth; }
00079                 
00080                 inline void setWireframe(bool is_wireframe=true) { m_wireframe = is_wireframe; CRenderizableDisplayList::notifyChange(); }
00081                 inline bool isWireframe() const { return m_wireframe; }
00082 
00083                 /** Set the position and size of the box, from two corners in 3D */
00084                 void setBoxCorners(const mrpt::math::TPoint3D &corner1, const mrpt::math::TPoint3D &corner2);
00085                 void getBoxCorners(mrpt::math::TPoint3D &corner1, mrpt::math::TPoint3D &corner2) const { corner1= m_corner_min; corner2 = m_corner_max; }
00086                 
00087 
00088         private:
00089                 /** Basic empty constructor. Set all parameters to default. */ 
00090                 CBox():m_corner_min(-1,-1,-1),m_corner_max(1,1,1),m_wireframe(false),m_lineWidth(1) { }
00091                 
00092                 /** Constructor with all the parameters  */ 
00093                 CBox(const mrpt::math::TPoint3D &corner1, const mrpt::math::TPoint3D &corner2, bool  is_wireframe = false, float lineWidth = 1.0) :
00094                         m_wireframe(is_wireframe) , m_lineWidth( lineWidth )
00095                 {
00096                         setBoxCorners(corner1,corner2);                 
00097                 }
00098                 
00099                 /** Destructor  */ 
00100                 virtual ~CBox() { }
00101                 
00102         };
00103 }
00104 }
00105 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:16:28 UTC 2011