~diresu/blender/blender-command-port

« back to all changes in this revision

Viewing changes to intern/bsp/intern/BSP_CSGMesh.h

  • Committer: theeth
  • Date: 2008-10-14 16:52:04 UTC
  • Revision ID: vcs-imports@canonical.com-20081014165204-r32w2gm6s0osvdhn
copy back trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: BSP_CSGMesh.h 14444 2008-04-16 22:40:48Z hos $
 
3
 * ***** BEGIN GPL LICENSE BLOCK *****
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software Foundation,
 
17
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
18
 *
 
19
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 
20
 * All rights reserved.
 
21
 *
 
22
 * The Original Code is: all of this file.
 
23
 *
 
24
 * Contributor(s): none yet.
 
25
 *
 
26
 * ***** END GPL LICENSE BLOCK *****
 
27
 */
 
28
 
 
29
#ifndef NAN_INCLUDED_BSP_CSGMesh_h
 
30
#define NAN_INCLUDED_BSP_CSGMesh_h
 
31
 
 
32
#include "BSP_MeshPrimitives.h"
 
33
#include "MEM_SmartPtr.h"
 
34
#include "MEM_RefCountPtr.h"
 
35
#include "MEM_NonCopyable.h"
 
36
#include "../extern/CSG_BooleanOps.h"
 
37
 
 
38
 
 
39
class MT_Plane3;
 
40
 
 
41
class BSP_CSGMesh : 
 
42
        public MEM_NonCopyable, 
 
43
        public MEM_RefCountable
 
44
{
 
45
 
 
46
public :
 
47
 
 
48
        static
 
49
                BSP_CSGMesh *
 
50
        New(
 
51
        );
 
52
 
 
53
                bool
 
54
        SetVertices(
 
55
                std::vector<BSP_MVertex> *verts
 
56
        );
 
57
 
 
58
                void
 
59
        AddPolygon(
 
60
                const int * verts,
 
61
                int num_verts
 
62
        );      
 
63
 
 
64
        // assumes that the face already has a plane equation
 
65
                void
 
66
        AddPolygon(
 
67
                const BSP_MFace &face
 
68
        );
 
69
 
 
70
 
 
71
        // Allocate and build the mesh edges.
 
72
        ////////////////////////////////////
 
73
 
 
74
                bool
 
75
        BuildEdges(
 
76
        );
 
77
 
 
78
        // Clean the mesh of edges. and edge pointers
 
79
        // This removes the circular connectivity information
 
80
        /////////////////////////////////////////////
 
81
 
 
82
                void
 
83
        DestroyEdges(
 
84
        );
 
85
 
 
86
        // return a new seperate copy of the 
 
87
        // mesh allocated on the heap.
 
88
 
 
89
                BSP_CSGMesh *
 
90
        NewCopy(
 
91
        ) const;
 
92
        
 
93
 
 
94
        // Reverse the winding order of every polygon 
 
95
        // in the mesh and swap the planes around.
 
96
 
 
97
                void
 
98
        Invert(
 
99
        );
 
100
 
 
101
 
 
102
        // geometry access
 
103
        //////////////////
 
104
 
 
105
                std::vector<BSP_MVertex> &
 
106
        VertexSet(
 
107
        ) const ;               
 
108
 
 
109
                std::vector<BSP_MFace> &
 
110
        FaceSet(
 
111
        ) const ;
 
112
 
 
113
                std::vector<BSP_MEdge> &
 
114
        EdgeSet(
 
115
        ) const;
 
116
 
 
117
        ~BSP_CSGMesh(
 
118
        );
 
119
 
 
120
        // local geometry queries.
 
121
        /////////////////////////
 
122
 
 
123
        // face queries
 
124
        ///////////////
 
125
 
 
126
                void
 
127
        FaceVertices(
 
128
                const BSP_FaceInd & f,
 
129
                std::vector<BSP_VertexInd> &output
 
130
        );
 
131
        
 
132
                void
 
133
        FaceEdges(
 
134
                const BSP_FaceInd & f,
 
135
                std::vector<BSP_EdgeInd> &output
 
136
        );      
 
137
 
 
138
        // edge queries
 
139
        ///////////////
 
140
 
 
141
                void
 
142
        EdgeVertices(
 
143
                const BSP_EdgeInd & e,
 
144
                std::vector<BSP_VertexInd> &output
 
145
        );
 
146
 
 
147
                void
 
148
        EdgeFaces(
 
149
                const BSP_EdgeInd & e,
 
150
                std::vector<BSP_FaceInd> &output
 
151
        );
 
152
 
 
153
        // vertex queries
 
154
        /////////////////
 
155
 
 
156
                void
 
157
        VertexEdges(
 
158
                const BSP_VertexInd & v,
 
159
                std::vector<BSP_EdgeInd> &output
 
160
        );
 
161
        
 
162
                void
 
163
        VertexFaces(
 
164
                const BSP_VertexInd & v,
 
165
                std::vector<BSP_FaceInd> &output
 
166
        );
 
167
 
 
168
        // Returns the edge index of the edge from v1 to v2. 
 
169
        // Does this by searching the edge sets of v1 - but not v2.
 
170
        // If you are paranoid you should check both and make sure the 
 
171
        // indices are the same. If the edge doe not exist edgeInd is empty.
 
172
 
 
173
                BSP_EdgeInd
 
174
        FindEdge(
 
175
                const BSP_VertexInd &v1,
 
176
                const BSP_VertexInd &v2
 
177
        ) const;
 
178
 
 
179
 
 
180
        /**
 
181
         * Sanity checkers
 
182
         */
 
183
 
 
184
        // make sure the edge faces have a pointer to f
 
185
 
 
186
                bool
 
187
        SC_Face(
 
188
                BSP_FaceInd f
 
189
        );
 
190
 
 
191
        /**
 
192
         * Return the face plane equation
 
193
         */
 
194
 
 
195
                MT_Plane3
 
196
        FacePlane(
 
197
                const BSP_FaceInd &fi
 
198
        )const;
 
199
 
 
200
 
 
201
        /**
 
202
         * Recompute Face plane equations.
 
203
         * essential if you have been messing with the object.
 
204
         */
 
205
 
 
206
                void
 
207
        ComputeFacePlanes(
 
208
        );
 
209
                
 
210
        /**
 
211
         * Count the number of trinagles in the mesh.
 
212
         * This is not the same as the number of polygons.
 
213
         */
 
214
 
 
215
                int
 
216
        CountTriangles(
 
217
        ) const;
 
218
 
 
219
private :
 
220
        
 
221
                void
 
222
        InsertEdge(
 
223
                const BSP_VertexInd &v1,
 
224
                const BSP_VertexInd &v2,
 
225
                const BSP_FaceInd &f,
 
226
                std::vector<BSP_EdgeInd> &new_edges
 
227
        );
 
228
 
 
229
                
 
230
        // Private to insure heap instantiation.
 
231
 
 
232
        BSP_CSGMesh(
 
233
        );
 
234
 
 
235
        std::vector<BSP_MVertex> *m_verts;
 
236
        std::vector<BSP_MFace>   *m_faces;
 
237
        std::vector<BSP_MEdge>   *m_edges;
 
238
 
 
239
        MT_Vector3 m_bbox_min;
 
240
        MT_Vector3 m_bbox_max;
 
241
 
 
242
};
 
243
 
 
244
 
 
245
#endif
 
246