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 #ifndef NAN_INCLUDED_MeshBounds_h 00034 #define NAN_INCLUDED_MeshBounds_h 00035 00036 #include "MEM_SmartPtr.h" 00037 #include "LOD_MeshPrimitives.h" 00038 #include "LOD_ManMesh2.h" 00039 #include "MT_assert.h" 00040 00041 // simple class to compute the mesh bounds of a manifold mesh, 00042 00043 class LOD_MeshBounds { 00044 00045 public : 00046 static 00047 LOD_MeshBounds * 00048 New( 00049 ){ 00050 00051 MEM_SmartPtr<LOD_MeshBounds> output(new LOD_MeshBounds()); 00052 return output.Release(); 00053 } 00054 00055 void 00056 ComputeBounds( 00057 const LOD_ManMesh2 * mesh 00058 ){ 00059 MT_assert(mesh!=NULL); 00060 MT_assert(mesh->VertexSet().size() > 0); 00061 00062 const std::vector<LOD_Vertex> &verts = mesh->VertexSet(); 00063 00064 m_min = verts[0].pos; 00065 m_max = verts[0].pos; 00066 00067 // iterate through the verts 00068 00069 int t; 00070 const int size = verts.size(); 00071 00072 for (t=1; t< size ; ++t) { 00073 00074 UpdateBounds(verts[t].pos,m_min,m_max); 00075 } 00076 } 00077 00078 MT_Vector3 00079 Min( 00080 ) const { 00081 return m_min; 00082 } 00083 00084 MT_Vector3 00085 Max( 00086 ) const { 00087 return m_max; 00088 } 00089 00090 private : 00091 00092 void 00093 UpdateBounds( 00094 MT_Vector3 vertex, 00095 MT_Vector3& min, 00096 MT_Vector3& max 00097 ) { 00098 if (vertex.x() < min.x()) { 00099 min.x() = vertex.x(); 00100 } else 00101 if (vertex.x() > max.x()) { 00102 max.x()= vertex.x(); 00103 } 00104 00105 if (vertex.y() < min.y()) { 00106 min.y() = vertex.y(); 00107 } else 00108 if (vertex.y() > max.y()) { 00109 max.y()= vertex.y(); 00110 } 00111 00112 if (vertex.z() < min.z()) { 00113 min.z() = vertex.z(); 00114 } else 00115 if (vertex.z() > max.z()) { 00116 max.z()= vertex.z(); 00117 } 00118 } 00119 00120 LOD_MeshBounds( 00121 ) : 00122 m_min(0,0,0), 00123 m_max(0,0,0) 00124 { 00125 }; 00126 00127 MT_Vector3 m_min; 00128 MT_Vector3 m_max; 00129 00130 }; 00131 00132 #endif 00133