Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMeshBuilder.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_geom_geMeshBuilder_h
00020 #define freecloth_geom_geMeshBuilder_h
00021 
00022 #ifndef freecloth_geom_package_h
00023 #include <freecloth/geom/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_resmgt_rcShdPtr_h
00027 #include <freecloth/resmgt/rcShdPtr.h>
00028 #endif
00029 
00030 #ifndef freecloth_geom_geMesh_h
00031 #include <freecloth/geom/geMesh.h>
00032 #endif
00033 
00034 FREECLOTH_NAMESPACE_START
00035 
00036 ////////////////////////////////////////////////////////////////////////////////
00037 // FORWARD DECLARATIONS
00038 //
00039 
00040 template <class T> class RCShdPtr;
00041 
00042 ////////////////////////////////////////////////////////////////////////////////
00043 /*!
00044  * \class GeMeshBuilder freecloth/geom/geMeshBuilder.h
00045  * \brief Class to construct a GeMesh object.
00046  *
00047  * Vertices, texture vertices and faces can be added, and the mesh will be
00048  * created with a final call to createMesh().
00049  *
00050  * For added efficiency, the prealloc* routines can be called before the
00051  * add* routines to reserve space for vertices, texture vertices or faces.
00052  *
00053  * During construction, vertices and texture vertices are given temporary
00054  * IDs and can be retrieved from the partially constructed mesh.
00055  *
00056  * \pattern Builder
00057  */
00058 class GeMeshBuilder : public GeMeshTypes {
00059 
00060 public:
00061 
00062     // ----- types and enumerations -----
00063 
00064     //! ConstIterator for faces.
00065     typedef GeMesh::FaceConstIterator FaceConstIterator;
00066     
00067     // ----- member functions -----
00068     
00069     GeMeshBuilder();
00070 
00071     //! Reserve space for the given number of vertices.
00072     void preallocVertices( UInt32 );
00073     //! Reserve space for the given number of texture vertices.
00074     void preallocTextureVertices( UInt32 );
00075     //! Reserve space for the given number of faces.
00076     void preallocFaces( UInt32 nb );
00077 
00078     //! Add a vertex to the mesh. Returns the id of the new vertex.
00079     VertexId addVertex( const VertexType& );
00080     //! Add the range [beginIt,endIt). Returns the id of the first vertex.
00081     VertexId addVertices(
00082         VertexConstIterator const& beginIt,
00083         VertexConstIterator const& endIt
00084     );
00085     //! Retrieve number of vertices added to mesh so far.
00086     UInt32 getNbVertices() const;
00087     //! Retrieve a vertex that has already been added.
00088     const VertexType& getVertex( VertexId ) const; 
00089 
00090     //! Add a texture vertex to the mesh. Returns the id of the new texture
00091     //! vertex.
00092     TextureVertexId addTextureVertex( const TextureVertexType& );
00093     //! Add the range [beginIt,endIt). Returns the id of the first texture
00094     //! vertex.
00095     TextureVertexId addTextureVertices(
00096         TextureVertexConstIterator const& beginIt,
00097         TextureVertexConstIterator const& endIt
00098     );
00099     //! Retrieve number of texture vertices added to mesh so far.
00100     UInt32 getNbTextureVertices() const;
00101     //! Retrieve a texture vertex that has already been added.
00102     const TextureVertexType& getTextureVertex( TextureVertexId ) const;
00103 
00104     //! Add a face to the mesh. Returns the id of the new face.
00105     FaceId addFace(
00106         VertexId v1, VertexId v2, VertexId v3,
00107         TextureVertexId tv1, TextureVertexId tv2, TextureVertexId tv3
00108     );
00109     //! Add a face to the mesh. Returns the id of the new face.
00110     FaceId addFace(
00111         VertexId vids[ GeMesh::FaceType::NB_VERTICES ],
00112         TextureVertexId tvids[ GeMesh::FaceType::NB_VERTICES ]
00113     );
00114     //! Add the range [beginIt,endIt). Returns the id of the first face.
00115     FaceId addFaces(
00116         FaceConstIterator const& beginIt,
00117         FaceConstIterator const& endIt
00118     );
00119     //! Retrieve number of faces added to mesh so far.
00120     UInt32 getNbFaces() const;
00121 
00122     //! Creates a GeMesh object using the vertices, texture vertices and
00123     //! faces added to the builder so far. Returns a pointer to the built
00124     //! GeMesh object.
00125     //!
00126     //! Subsequently, resets the builder in preparation for the construction
00127     //! of a new GeMesh object.
00128     RCShdPtr<GeMesh> createMesh();
00129 
00130 
00131 private:
00132 
00133     // ----- member functions -----
00134 
00135     //! Disallowed.
00136     GeMeshBuilder( const GeMeshBuilder& );
00137     //! Disallowed.
00138     GeMeshBuilder& operator=( const GeMeshBuilder& );
00139 
00140     // ----- data members -----
00141     
00142     RCShdPtr<GeMesh>        _meshPtr;
00143 };
00144 
00145 FREECLOTH_NAMESPACE_END
00146 #endif

Generated on Wed Apr 23 15:58:52 2003 for Freecloth by doxygen1.3-rc3