Blender  V2.59
LOD_MeshBounds.h
Go to the documentation of this file.
00001 /*
00002  * $Id: LOD_MeshBounds.h 35147 2011-02-25 10:47:28Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #ifndef NAN_INCLUDED_MeshBounds_h
00035 #define NAN_INCLUDED_MeshBounds_h
00036 
00037 #include "MEM_SmartPtr.h"
00038 #include "LOD_MeshPrimitives.h"
00039 #include "LOD_ManMesh2.h"
00040 #include "MT_assert.h"
00041 
00042 // simple class to compute the mesh bounds of a manifold mesh,
00043 
00044 class LOD_MeshBounds {
00045 
00046 public :
00047         static
00048                 LOD_MeshBounds *
00049         New(
00050         ){
00051 
00052                 MEM_SmartPtr<LOD_MeshBounds> output(new LOD_MeshBounds());              
00053                 return output.Release();
00054         }
00055 
00056                 void
00057         ComputeBounds(
00058                 const LOD_ManMesh2 * mesh
00059         ){
00060                 MT_assert(mesh!=NULL);
00061                 MT_assert(mesh->VertexSet().size() > 0);
00062 
00063                 const std::vector<LOD_Vertex> &verts = mesh->VertexSet(); 
00064                 
00065                 m_min = verts[0].pos;
00066                 m_max = verts[0].pos;
00067 
00068                 // iterate through the verts
00069 
00070                 int t;
00071                 const int size = verts.size();
00072 
00073                 for (t=1; t< size ; ++t) {
00074 
00075                         UpdateBounds(verts[t].pos,m_min,m_max);
00076                 }
00077         }
00078                                 
00079                 MT_Vector3
00080         Min(
00081         ) const {
00082                 return m_min;
00083         }
00084 
00085                 MT_Vector3
00086         Max(
00087         ) const {
00088                 return m_max;
00089         }
00090 
00091 private :
00092 
00093                 void
00094         UpdateBounds(
00095                 MT_Vector3 vertex,
00096                 MT_Vector3& min,
00097                 MT_Vector3& max
00098         ) {
00099                 if (vertex.x() < min.x()) {
00100                         min.x() = vertex.x();
00101                 } else
00102                 if (vertex.x() > max.x()) {
00103                         max.x()= vertex.x();
00104                 }
00105 
00106                 if (vertex.y() < min.y()) {
00107                         min.y() = vertex.y();
00108                 } else
00109                 if (vertex.y() > max.y()) {
00110                         max.y()= vertex.y();
00111                 }
00112 
00113                 if (vertex.z() < min.z()) {
00114                         min.z() = vertex.z();
00115                 } else
00116                 if (vertex.z() > max.z()) {
00117                         max.z()= vertex.z();
00118                 }
00119         }
00120 
00121         LOD_MeshBounds(
00122         ) :
00123                 m_min(0,0,0),
00124                 m_max(0,0,0)
00125         {
00126         };
00127                         
00128         MT_Vector3 m_min;
00129         MT_Vector3 m_max;
00130 
00131 };
00132 
00133 #endif
00134