Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_MAKE_PLANE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_MESH_COMMON_UTIL_MESH_MAKE_PLANE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <boost/multi_array.hpp>
00013
00014 namespace OpenTissue
00015 {
00016 namespace mesh
00017 {
00018
00024 template<typename mesh_type,typename real_type>
00025 bool make_plane(
00026 real_type dx
00027 , real_type dy
00028 , unsigned int X
00029 , unsigned int Y
00030 , mesh_type & mesh
00031 )
00032 {
00033 typedef typename mesh_type::math_types math_types;
00034 typedef typename math_types::value_traits value_traits;
00035 typedef typename math_types::vector3_type vector3_type;
00036
00037 typedef typename mesh_type::vertex_handle vertex_handle;
00038
00039 assert(X > 0 || !"At least one subdivision on x-axis");
00040 assert(Y > 0 || !"At least one subdivision on y-axis");
00041 assert(dx > static_cast<real_type>(0.0)|| !"x-axis spacing must be positive");
00042 assert(dy > static_cast<real_type>(0.0)|| !"y-axis spacing must be positive");
00043 unsigned int I = X + 1;
00044 assert(I>=2);
00045 unsigned int J = Y + 1;
00046 assert(J>=2);
00047 mesh.clear();
00048 boost::multi_array<vertex_handle, 2> grid(boost::extents[I][J]);
00049
00050 vector3_type coord;
00051 for(unsigned int j=0;j<J;++j)
00052 for(unsigned int i=0;i<I;++i)
00053 {
00054 coord(0) = static_cast<real_type>(i*dx - (X*dx/2.0));
00055 coord(1) = static_cast<real_type>(j*dy - (Y*dy/2.0));
00056 coord(2) = static_cast<real_type>(0.0);
00057 grid[i][j] = mesh.add_vertex(coord);
00058 typename mesh_type::vertex_iterator v = mesh.get_vertex_iterator(grid[i][j]);
00059 v->m_normal = vector3_type(0,0,1);
00060 v->m_u = 1.0*i/X;
00061 v->m_v = 1.0*j/Y;
00062 v->m_color = vector3_type( v->m_u, 0.0, v->m_v);
00063 }
00064 for(unsigned int j=0;j<Y;++j)
00065 for(unsigned int i=0;i<X;++i)
00066 {
00067 std::list<vertex_handle> handles;
00068
00069 handles.push_back( grid[ i][ j] );
00070 handles.push_back( grid[i+1][ j] );
00071 handles.push_back( grid[i+1][j+1] );
00072 handles.push_back( grid[ i][j+1] );
00073 mesh.add_face(handles.begin(),handles.end());
00074 }
00075 return true;
00076 }
00077
00078 }
00079 }
00080
00081
00082 #endif