00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_MAKE_UNIT_H 00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_MAKE_UNIT_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/containers/mesh/common/util/mesh_compute_mesh_center.h> 00013 #include <OpenTissue/core/containers/mesh/common/util/mesh_compute_mesh_minimum_coord.h> 00014 #include <OpenTissue/core/containers/mesh/common/util/mesh_compute_mesh_maximum_coord.h> 00015 #include <OpenTissue/core/containers/mesh/common/util/mesh_deformation_modifiers.h> 00016 00017 #include <cassert> 00018 #include <cmath> 00019 00020 namespace OpenTissue 00021 { 00022 namespace mesh 00023 { 00024 00031 template<typename mesh_type> 00032 void make_unit(mesh_type & mesh) 00033 { 00034 typedef typename mesh_type::math_types math_types; 00035 typedef typename math_types::value_traits value_traits; 00036 typedef typename math_types::vector3_type vector3_type; 00037 //typedef typename math_types::real_type real_type; 00038 00039 00040 vector3_type min_coord; 00041 vector3_type max_coord; 00042 vector3_type center; 00043 vector3_type range; 00044 vector3_type s(1.0,1.0,1.0); 00045 00046 mesh::compute_mesh_center(mesh,center); 00047 mesh::compute_mesh_minimum_coord(mesh,min_coord); 00048 mesh::compute_mesh_maximum_coord(mesh,max_coord); 00049 00050 range = max_coord - min_coord; 00051 typename vector3_type::value_type max_range = std::max(range(0),std::max(range(1),range(2))); 00052 if(range(0)) 00053 s(0) = 1.0/max_range; 00054 if(range(1)) 00055 s(1) = 1.0/max_range; 00056 if(range(2)) 00057 s(2) = 1.0/max_range; 00058 mesh::translate(mesh,-center); 00059 mesh::scale(mesh, s); 00060 //translate(mesh,center); 00061 } 00062 00063 } // namespace mesh 00064 } // namespace OpenTissue 00065 00066 //OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_MAKE_UNIT_H 00067 #endif