Blender V2.61 - r43446

BSP_MeshPrimitives.cpp

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 #include "BSP_MeshPrimitives.h"
00034 
00035 #include "MT_assert.h"
00036 #include "BSP_CSGException.h"
00037 #include <algorithm>
00038 
00039 using namespace std;
00040 
00041 BSP_MVertex::
00042 BSP_MVertex(
00043 ) :
00044     m_pos (MT_Point3()),
00045     m_select_tag (false),
00046     m_open_tag (0)
00047 {
00048 };
00049 
00050 BSP_MVertex::
00051 BSP_MVertex(
00052     const MT_Point3 & pos
00053 ) :
00054     m_pos(pos),
00055     m_select_tag (false),
00056     m_open_tag (0)
00057 {
00058 };
00059 
00060 
00061     bool
00062 BSP_MVertex::
00063 RemoveEdge(
00064     BSP_EdgeInd e
00065 ){
00066     vector<BSP_EdgeInd>::iterator result = find(m_edges.begin(),m_edges.end(),e);
00067     if (result == m_edges.end()) {
00068         return false;
00069     }
00070     BSP_EdgeInd last = m_edges.back();
00071     m_edges.pop_back();
00072     if (m_edges.empty()) return true;
00073 
00074     *result = last;
00075     return true;    
00076 }   
00077 
00078     void
00079 BSP_MVertex::
00080 AddEdge(
00081     BSP_EdgeInd e
00082 ){
00083     m_edges.push_back(e);
00084 }
00085 
00086     void
00087 BSP_MVertex::
00088 SwapEdge(
00089     BSP_EdgeInd e_old,
00090     BSP_EdgeInd e_new
00091 ){
00092     vector<BSP_EdgeInd>::iterator result = 
00093         find(m_edges.begin(),m_edges.end(),e_old);
00094     if (result == m_edges.end()) {
00095         BSP_CSGException e(e_mesh_error);
00096         throw(e);
00097         MT_assert(false);
00098     }
00099     
00100     *result = e_new;
00101 }
00102 
00103     bool
00104 BSP_MVertex::
00105 SelectTag(
00106 ) const{
00107     return m_select_tag;
00108 }
00109 
00110     void
00111 BSP_MVertex::
00112 SetSelectTag(
00113     bool tag    
00114 ){
00115     m_select_tag = tag;
00116 }
00117 
00118     int
00119 BSP_MVertex::
00120 OpenTag(
00121 ) const {
00122     return m_open_tag;
00123 }
00124 
00125     void
00126 BSP_MVertex::
00127 SetOpenTag(
00128     int tag
00129 ){
00130     m_open_tag = tag;
00131 }
00132 
00133 
00138 BSP_MEdge::
00139 BSP_MEdge(
00140 ){
00141     m_verts[0] = m_verts[1] = BSP_VertexInd::Empty();
00142 }
00143     
00144     bool 
00145 BSP_MEdge::
00146 operator == (
00147     BSP_MEdge & rhs
00148 ){
00149     // edges are the same if their vertex indices are the 
00150     // same!!! Other properties are not checked 
00151 
00152     int matches = 0;
00153 
00154     if (this->m_verts[0] == rhs.m_verts[0]) {
00155         ++matches;
00156     }
00157     if (this->m_verts[1] == rhs.m_verts[0]) {
00158         ++matches;
00159     }
00160     if (this->m_verts[0] == rhs.m_verts[1]) {
00161         ++matches;
00162     }
00163     if (this->m_verts[1] == rhs.m_verts[1]) {
00164         ++matches;
00165     }
00166     
00167     if (matches >= 2) {
00168         return true;
00169     }
00170     return false;
00171 }
00172 
00173     void
00174 BSP_MEdge::
00175 SwapFace(
00176     BSP_FaceInd old_f,
00177     BSP_FaceInd new_f
00178 ){
00179     vector<BSP_FaceInd>::iterator result = 
00180         find(m_faces.begin(),m_faces.end(),old_f);
00181     if (result == m_faces.end()) {
00182         BSP_CSGException e(e_mesh_error);
00183         throw(e);
00184         MT_assert(false);
00185     }
00186     
00187     *result = new_f;
00188 }
00189 
00190     BSP_VertexInd
00191 BSP_MEdge::
00192 OpVertex(
00193     BSP_VertexInd vi
00194 ) const {
00195     if (vi == m_verts[0]) return m_verts[1];
00196     if (vi == m_verts[1]) return m_verts[0];
00197     MT_assert(false);
00198     BSP_CSGException e(e_mesh_error);
00199     throw(e);
00200 
00201     return BSP_VertexInd::Empty();
00202 }
00203 
00204     bool
00205 BSP_MEdge::
00206 SelectTag(
00207 ) const {
00208     return bool(m_verts[1].Tag() & 0x1);
00209 }
00210     void
00211 BSP_MEdge::
00212 SetSelectTag(
00213     bool tag    
00214 ){
00215     m_verts[1].SetTag(int(tag));
00216 }
00217 
00218     int
00219 BSP_MEdge::
00220 OpenTag(
00221 ) const {
00222     return m_verts[0].Tag();
00223 }
00224 
00225     void
00226 BSP_MEdge::
00227 SetOpenTag(
00228     int tag
00229 ) {
00230     // Note conversion from int to unsigned int!!!!!
00231     m_verts[0].SetTag(tag);
00232 }
00233     
00234 
00240 BSP_MFace::
00241 BSP_MFace(
00242 ):
00243     m_open_tag(-1),
00244     m_orig_face(0)
00245 {
00246     // nothing to do
00247 }
00248 
00249     void
00250 BSP_MFace::
00251 Invert(
00252 ){
00253 
00254     // TODO replace reverse as I think some compilers
00255     // do not support the STL routines employed.
00256 
00257     reverse(
00258         m_verts.begin(),
00259         m_verts.end()
00260     );
00261 
00262     // invert the normal
00263     m_plane.Invert();
00264 }
00265 
00266     bool
00267 BSP_MFace::
00268 SelectTag(
00269 ) const {
00270     return bool(m_verts[1].Tag() & 0x1);
00271 }   
00272 
00273     void
00274 BSP_MFace::
00275 SetSelectTag(
00276     bool tag    
00277 ){
00278     m_verts[1].SetTag(int(tag));
00279 };  
00280 
00281     int
00282 BSP_MFace::
00283 OpenTag(
00284 ) const {
00285     return m_open_tag;
00286 }
00287 
00288     void
00289 BSP_MFace::
00290 SetOpenTag(
00291     int tag
00292 ){
00293     // Note conversion from int to unsigned int!!!!!
00294     m_open_tag = tag;
00295 }
00296 
00297 
00298