Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_DEFORMATION_MODIFIERS_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_DEFORMATION_MODIFIERS_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_matrix3x3.h>
00013 #include <OpenTissue/core/math/math_constants.h>
00014
00015 #include <cassert>
00016 #include <cmath>
00017
00018 namespace OpenTissue
00019 {
00020 namespace mesh
00021 {
00022
00023 template<typename mesh_type,typename vector3_type>
00024 void translate(mesh_type & mesh,vector3_type const & translation)
00025 {
00026 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00027 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00028 for(;v!=end;++v)
00029 v->m_coord += translation;
00030 }
00031
00032 template<typename mesh_type,typename matrix3x3_type>
00033 void rotate(mesh_type & mesh,matrix3x3_type const & R)
00034 {
00035 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00036 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00037 for(;v!=end;++v)
00038 v->m_coord = R*v->m_coord;
00039 }
00040
00041 template<typename mesh_type,typename real_type>
00042 void uniform_scale(mesh_type & mesh,real_type const & s)
00043 {
00044 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00045 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00046 for(;v!=end;++v)
00047 v->m_coord = v->m_coord*s;
00048 }
00049
00050 template<typename mesh_type,typename real_type>
00051 void scale(mesh_type & mesh,real_type const & sx,real_type const & sy,real_type const & sz)
00052 {
00053 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00054 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00055 for(;v!=end;++v)
00056 {
00057 v->m_coord(0) = v->m_coord(0)*sx;
00058 v->m_coord(1) = v->m_coord(1)*sy;
00059 v->m_coord(2) = v->m_coord(2)*sz;
00060 }
00061 }
00062
00063 template<typename mesh_type,typename vector3_type>
00064 void scale(mesh_type & mesh,vector3_type const & s) { mesh::scale(mesh,s(0),s(1),s(2)); }
00065
00066 template<typename mesh_type,typename vector3_type, typename real_type>
00067 void twist(mesh_type & mesh,vector3_type const & direction, real_type const & pitch)
00068 {
00069 OpenTissue::math::Matrix3x3<real_type> R;
00070 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00071 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00072 for(;v!=end;++v)
00073 {
00074 real_type projection = v->m_coord * direction;
00075 real_type radian = projection/pitch;
00076 R = Ru(radian,direction);
00077 v->m_coord = R * v->m_coord;
00078 }
00079 }
00080
00081 template<typename mesh_type,typename vector3_type, typename real_type>
00082 void bend(mesh_type & mesh,vector3_type const & axis,vector3_type const & direction, real_type const & radius)
00083 {
00084 OpenTissue::math::Matrix3x3<real_type> R;
00085 real_type circum = 2*math::detail::pi<real_type>()*radius;
00086 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00087 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00088 for(;v!=end;++v)
00089 {
00090 real_type projection = v->m_coord * direction;
00091 real_type radian = projection/circum;
00092 R = Ru(radian,axis);
00093 v->m_coord = R * v->m_coord;
00094 }
00095 }
00096
00097 template<typename mesh_type,typename vector3_type, typename real_type>
00098 void spherical_bend(mesh_type & mesh,vector3_type const & normal, real_type const & radius)
00099 {
00100 OpenTissue::math::Matrix3x3<real_type> R;
00101 real_type circum = 2*math::detail::pi<real_type>()*radius;
00102 vector3_type axis1,axis2;
00103
00104 orthonormal_vectors(axis1,axis2,normal);
00105
00106 typename mesh_type::vertex_iterator end = mesh.vertex_end();
00107 typename mesh_type::vertex_iterator v = mesh.vertex_begin();
00108 for(;v!=end;++v)
00109 {
00110 real_type proj1 = v->m_coord*axis1;
00111 real_type proj2 = v->m_coord*axis2;
00112 real_type length = std::sqrt(proj1*proj1 + proj2*proj2);
00113 real_type radian = length/circum;
00114 vector3_type u = normalize(v->m_coord % normal);
00115 R = Ru(radian,u);
00116 v->m_coord = R * v->m_coord;
00117 }
00118 }
00119
00120 }
00121 }
00122
00123
00124 #endif