|
Blender
V2.59
|
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 "BOP_BSPTree.h" 00034 #include <vector> 00035 #include <iostream> 00036 using namespace std; 00037 00041 BOP_BSPTree::BOP_BSPTree() 00042 { 00043 m_root = NULL; 00044 m_bspBB = NULL; 00045 } 00046 00050 BOP_BSPTree::~BOP_BSPTree() 00051 { 00052 if (m_root!=NULL) delete m_root; 00053 if (m_bspBB!=NULL) delete m_bspBB; 00054 } 00055 00061 void BOP_BSPTree::addMesh(BOP_Mesh* mesh, BOP_Faces& facesList) 00062 { 00063 for (BOP_IT_Faces it = facesList.begin(); it != facesList.end(); ++it) { 00064 addFace( mesh, *it ); 00065 } 00066 00067 } 00068 00075 void BOP_BSPTree::addFace(BOP_Mesh* mesh, BOP_Face* face) 00076 { 00077 addFace(mesh->getVertex(face->getVertex(0))->getPoint(), 00078 mesh->getVertex(face->getVertex(1))->getPoint(), 00079 mesh->getVertex(face->getVertex(2))->getPoint(), 00080 face->getPlane()); 00081 } 00082 00090 void BOP_BSPTree::addFace(const MT_Point3& p1, 00091 const MT_Point3& p2, 00092 const MT_Point3& p3, 00093 const MT_Plane3& plane) 00094 { 00095 if (m_root == NULL) 00096 m_root = new BOP_BSPNode(plane); 00097 else { 00098 BOP_BSPPoints pts; 00099 00100 pts.push_back(p1); 00101 pts.push_back(p2); 00102 pts.push_back(p3); 00103 00104 m_root->addFace(pts,plane); 00105 } 00106 00107 // update bounding box 00108 m_bbox.add(p1); 00109 m_bbox.add(p2); 00110 m_bbox.add(p3); 00111 } 00112 00121 BOP_TAG BOP_BSPTree::classifyFace(const MT_Point3& p1, 00122 const MT_Point3& p2, 00123 const MT_Point3& p3, 00124 const MT_Plane3& plane) const 00125 { 00126 if ( m_root != NULL ) 00127 return m_root->classifyFace(p1, p2, p3, plane); 00128 else 00129 return OUT; 00130 } 00131 00140 BOP_TAG BOP_BSPTree::filterFace(const MT_Point3& p1, 00141 const MT_Point3& p2, 00142 const MT_Point3& p3, 00143 BOP_Face* face) 00144 { 00145 if ( m_bspBB != NULL ) { 00146 return m_bspBB->classifyFace(p1,p2,p3,face->getPlane()); 00147 } 00148 else 00149 return UNCLASSIFIED; 00150 } 00151 00160 BOP_TAG BOP_BSPTree::simplifiedClassifyFace(const MT_Point3& p1, 00161 const MT_Point3& p2, 00162 const MT_Point3& p3, 00163 const MT_Plane3& plane) const 00164 { 00165 if ( m_root != NULL ) 00166 return m_root->simplifiedClassifyFace(p1, p2, p3, plane); 00167 else 00168 return OUT; 00169 } 00170 00175 unsigned int BOP_BSPTree::getDeep() const 00176 { 00177 if ( m_root != NULL ) 00178 return m_root->getDeep(); 00179 else 00180 return 0; 00181 } 00182 00186 void BOP_BSPTree::print() 00187 { 00188 if ( m_root != NULL ) 00189 m_root->print( 0 ); 00190 } 00191