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