![]() |
Public API Reference |
00001 /* 00002 Copyright (C) 2003 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_POLYTREE_H__ 00020 #define __CS_POLYTREE_H__ 00021 00022 #include "csgeom/box.h" 00023 #include "csgeom/vector3.h" 00024 #include "csutil/array.h" 00025 00026 #define CS_POLYTREE_AXISINVALID -1 00027 #define CS_POLYTREE_AXISX 0 00028 #define CS_POLYTREE_AXISY 1 00029 #define CS_POLYTREE_AXISZ 2 00030 00031 struct iPolygonMesh; 00032 struct csMeshedPolygon; 00033 00037 class csPolygonTree 00038 { 00039 private: 00040 csBox3 bbox; // Bounding box of all polygons in this node. 00041 csArray<int> polygons; // Indices of polygons in this node. 00042 00043 csPolygonTree* child1; // If child1 is not 0 then child2 will 00044 csPolygonTree* child2; // also be not 0. 00045 00046 int split_axis; // One of CS_POLYTREE_AXIS? 00047 float split_location; // Where is the split? 00048 00049 void MakeLeaf (csArray<int>& polyidx); 00050 void CalculateBBox (csArray<int>& polyidx, iPolygonMesh* mesh); 00051 void Build (csArray<int>& polyidx, iPolygonMesh* mesh); 00052 00053 public: 00055 csPolygonTree (); 00057 ~csPolygonTree (); 00058 00060 void Clear (); 00061 00063 void Build (iPolygonMesh* mesh); 00064 00066 const csBox3& GetBoundingBox () const { return bbox; } 00067 00069 const csArray<int>& GetPolygons () const { return polygons; } 00070 00072 void IntersectBox (csArray<int>& polyidx, const csBox3& box); 00073 00075 void IntersectSphere (csArray<int>& polyidx, const csVector3& center, 00076 float sqradius); 00077 00079 void RemoveDoubles (csArray<int>& polyidx); 00080 }; 00081 00082 #endif // __CS_POLYTREE_H__ 00083