33 #ifndef __INCLUDE_MIST_MESH__
34 #define __INCLUDE_MIST_MESH__
37 #ifndef __INCLUDE_MIST_CONF_H__
38 #include "../config/mist_conf.h"
41 #ifndef __INCLUDE_MIST_VECTOR__
42 #include "../vector.h"
53 template <
class T,
class VTX >
54 inline void register_vertex( std::vector< vector3< T > > &list, std::vector< vector3< VTX > > &vlist,
const vector3< T > &a,
const vector3< T > &b,
const vector3< T > &c )
56 typedef vector3< T > vector_type;
57 typedef vector3< VTX > vertex_index;
58 typedef typename std::vector< vector_type >::size_type size_type;
60 const double eps = 1.0e-12;
61 typename vertex_index::value_type index[ 3 ] = { 0, 0, 0 };
62 vector_type vertex[ 3 ] = { a, b, c };
64 for( size_type j = 0 ; j < 3 ; j++ )
66 const vector_type &v = vertex[ j ];
68 for( ; i < list.size( ) ; i++ )
70 const vector_type &p = list[ i ];
71 if( ( p - v ).length( ) < eps )
78 if( i == list.size( ) )
85 vlist.push_back( vertex_index( index[ 0 ], index[ 1 ], index[ 2 ] ) );
90 template <
class T,
class VTX >
91 inline void divide_triangle( std::vector< vector3< T > > &list, std::vector< vector3< VTX > > &vlist,
const vector3< T > v1,
const vector3< T > v2,
const vector3< T > v3,
size_t __division_num__ )
93 typedef vector3< T > vector_type;
95 vector_type v12 = ( v1 + v2 ).unit( );
96 vector_type v23 = ( v2 + v3 ).unit( );
97 vector_type v31 = ( v3 + v1 ).unit( );
99 if( __division_num__ == 1 )
101 register_vertex( list, vlist, v1, v12, v31 );
102 register_vertex( list, vlist, v12, v2, v23 );
103 register_vertex( list, vlist, v31, v23, v3 );
104 register_vertex( list, vlist, v31, v12, v23 );
108 divide_triangle( list, vlist, v1, v12, v31, __division_num__ - 1 );
109 divide_triangle( list, vlist, v12, v2, v23, __division_num__ - 1 );
110 divide_triangle( list, vlist, v31, v23, v3, __division_num__ - 1 );
111 divide_triangle( list, vlist, v31, v12, v23, __division_num__ - 1 );
129 inline std::vector< vector3< double > >
balloon(
size_t number_of_division )
133 typedef std::vector< vector_type > position_list;
134 typedef std::vector< vertex_index > vertex_list;
135 typedef position_list::size_type size_type;
137 const double BX = 0.525731112119133606;
138 const double BZ = 0.850650808352039932;
140 vector_type vtx20[ 12 ] = {
141 vector_type( -BX, 0, BZ ), vector_type( BX, 0, BZ ), vector_type( -BX, 0, -BZ ), vector_type( BX, 0, -BZ ),
142 vector_type( 0, BZ, BX ), vector_type( 0, BZ, -BX ), vector_type( 0, -BZ, BX ), vector_type( 0, -BZ, -BX ),
143 vector_type( BZ, BX, 0 ), vector_type( -BZ, BX, 0 ), vector_type( BZ, -BX, 0 ), vector_type( -BZ, -BX, 0 )
146 vertex_index ivtx20[ 20 ] = {
147 vertex_index( 0, 1, 4 ), vertex_index( 0, 4, 9 ), vertex_index( 9, 4, 5 ), vertex_index( 4, 8, 5 ), vertex_index( 4, 1, 8 ),
148 vertex_index( 8, 1, 10 ), vertex_index( 8, 10, 3 ), vertex_index( 5, 8, 3 ), vertex_index( 5, 3, 2 ), vertex_index( 2, 3, 7 ),
149 vertex_index( 7, 3, 10 ), vertex_index( 7, 10, 6 ), vertex_index( 7, 6, 11 ), vertex_index( 11, 6, 0 ), vertex_index( 0, 6, 1 ),
150 vertex_index( 6, 10, 1 ), vertex_index( 9, 11, 0 ), vertex_index( 9, 2, 11 ), vertex_index( 9, 5, 2 ), vertex_index( 7, 11, 2 )
154 vertex_list vlist, vtmp;
156 for( size_type i = 0; i < 20; i++ )
158 register_vertex( plist, vlist, vtx20[ ivtx20[ i ].x ], vtx20[ ivtx20[ i ].y ], vtx20[ ivtx20[ i ].z ] );
161 if( number_of_division > 0 )
165 for( size_type i = 0 ; i < vlist.size( ) ; i++ )
167 divide_triangle( plist, vtmp, plist[ vlist[ i ].x ], plist[ vlist[ i ].y ], plist[ vlist[ i ].z ], number_of_division );
181 inline std::vector< vector3< double > >
half_balloon(
size_t number_of_division )
184 typedef std::vector< vector_type > position_list;
185 typedef position_list::size_type size_type;
187 position_list plist =
balloon( number_of_division ), qlist;
188 const double eps = 1.0e-12;
190 qlist.reserve( plist.size( ) / 2 + 1 );
192 for( size_type i = 0 ; i < plist.size( ) ; i++ )
194 const vector_type &p = plist[ i ];
198 qlist.push_back( p );
200 else if( p.z > -eps )
204 qlist.push_back( p );
206 else if( p.y > -eps && p.x > 0 )
208 qlist.push_back( p );
225 #endif // __INCLUDE_MIST_TIMER__