Blender V2.61 - r43446

BSP_CSGMesh.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #ifndef NAN_INCLUDED_BSP_CSGMesh_h
00034 #define NAN_INCLUDED_BSP_CSGMesh_h
00035 
00036 #include "BSP_MeshPrimitives.h"
00037 #include "MEM_SmartPtr.h"
00038 #include "MEM_RefCountPtr.h"
00039 #include "MEM_NonCopyable.h"
00040 #include "../extern/CSG_BooleanOps.h"
00041 
00042 
00043 class MT_Plane3;
00044 
00045 class BSP_CSGMesh : 
00046     public MEM_NonCopyable, 
00047     public MEM_RefCountable
00048 {
00049 
00050 public :
00051 
00052     static
00053         BSP_CSGMesh *
00054     New(
00055     );
00056 
00057         bool
00058     SetVertices(
00059         std::vector<BSP_MVertex> *verts
00060     );
00061 
00062         void
00063     AddPolygon(
00064         const int * verts,
00065         int num_verts
00066     );  
00067 
00068     // assumes that the face already has a plane equation
00069         void
00070     AddPolygon(
00071         const BSP_MFace &face
00072     );
00073 
00074 
00075     // Allocate and build the mesh edges.
00077 
00078         bool
00079     BuildEdges(
00080     );
00081 
00082     // Clean the mesh of edges. and edge pointers
00083     // This removes the circular connectivity information
00085 
00086         void
00087     DestroyEdges(
00088     );
00089 
00090     // return a new separate copy of the 
00091     // mesh allocated on the heap.
00092 
00093         BSP_CSGMesh *
00094     NewCopy(
00095     ) const;
00096     
00097 
00098     // Reverse the winding order of every polygon 
00099     // in the mesh and swap the planes around.
00100 
00101         void
00102     Invert(
00103     );
00104 
00105 
00106     // geometry access
00108 
00109         std::vector<BSP_MVertex> &
00110     VertexSet(
00111     ) const ;       
00112 
00113         std::vector<BSP_MFace> &
00114     FaceSet(
00115     ) const ;
00116 
00117         std::vector<BSP_MEdge> &
00118     EdgeSet(
00119     ) const;
00120 
00121     ~BSP_CSGMesh(
00122     );
00123 
00124     // local geometry queries.
00126 
00127     // face queries
00129 
00130         void
00131     FaceVertices(
00132         const BSP_FaceInd & f,
00133         std::vector<BSP_VertexInd> &output
00134     );
00135     
00136         void
00137     FaceEdges(
00138         const BSP_FaceInd & f,
00139         std::vector<BSP_EdgeInd> &output
00140     );  
00141 
00142     // edge queries
00144 
00145         void
00146     EdgeVertices(
00147         const BSP_EdgeInd & e,
00148         std::vector<BSP_VertexInd> &output
00149     );
00150 
00151         void
00152     EdgeFaces(
00153         const BSP_EdgeInd & e,
00154         std::vector<BSP_FaceInd> &output
00155     );
00156 
00157     // vertex queries
00159 
00160         void
00161     VertexEdges(
00162         const BSP_VertexInd & v,
00163         std::vector<BSP_EdgeInd> &output
00164     );
00165     
00166         void
00167     VertexFaces(
00168         const BSP_VertexInd & v,
00169         std::vector<BSP_FaceInd> &output
00170     );
00171 
00172     // Returns the edge index of the edge from v1 to v2. 
00173     // Does this by searching the edge sets of v1 - but not v2.
00174     // If you are paranoid you should check both and make sure the 
00175     // indices are the same. If the edge doe not exist edgeInd is empty.
00176 
00177         BSP_EdgeInd
00178     FindEdge(
00179         const BSP_VertexInd &v1,
00180         const BSP_VertexInd &v2
00181     ) const;
00182 
00183 
00188     // make sure the edge faces have a pointer to f
00189 
00190         bool
00191     SC_Face(
00192         BSP_FaceInd f
00193     );
00194 
00199         MT_Plane3
00200     FacePlane(
00201         const BSP_FaceInd &fi
00202     )const;
00203 
00204 
00210         void
00211     ComputeFacePlanes(
00212     );
00213         
00219         int
00220     CountTriangles(
00221     ) const;
00222 
00223 private :
00224     
00225         void
00226     InsertEdge(
00227         const BSP_VertexInd &v1,
00228         const BSP_VertexInd &v2,
00229         const BSP_FaceInd &f,
00230         std::vector<BSP_EdgeInd> &new_edges
00231     );
00232 
00233         
00234     // Private to insure heap instantiation.
00235 
00236     BSP_CSGMesh(
00237     );
00238 
00239     std::vector<BSP_MVertex> *m_verts;
00240     std::vector<BSP_MFace>   *m_faces;
00241     std::vector<BSP_MEdge>   *m_edges;
00242 
00243     MT_Vector3 m_bbox_min;
00244     MT_Vector3 m_bbox_max;
00245 
00246 };
00247 
00248 
00249 #endif
00250