balloon.h
説明を見る。
1 //
2 // Copyright (c) 2003-2011, MIST Project, Nagoya University
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the name of the Nagoya University nor the names of its contributors
16 // may be used to endorse or promote products derived from this software
17 // without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 
33 #ifndef __INCLUDE_MIST_MESH__
34 #define __INCLUDE_MIST_MESH__
35 
36 
37 #ifndef __INCLUDE_MIST_CONF_H__
38 #include "../config/mist_conf.h"
39 #endif
40 
41 #ifndef __INCLUDE_MIST_VECTOR__
42 #include "../vector.h"
43 #endif
44 
45 
46 #include <vector>
47 #include <cmath>
48 
49 
50 // mist名前空間の始まり
52 
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 )
55 {
56  typedef vector3< T > vector_type;
57  typedef vector3< VTX > vertex_index;
58  typedef typename std::vector< vector_type >::size_type size_type;
59 
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 };
63 
64  for( size_type j = 0 ; j < 3 ; j++ )
65  {
66  const vector_type &v = vertex[ j ];
67  size_type i = 0;
68  for( ; i < list.size( ) ; i++ )
69  {
70  const vector_type &p = list[ i ];
71  if( ( p - v ).length( ) < eps )
72  {
73  index[ j ] = i;
74  break;
75  }
76  }
77 
78  if( i == list.size( ) )
79  {
80  index[ j ] = i;
81  list.push_back( v );
82  }
83  }
84 
85  vlist.push_back( vertex_index( index[ 0 ], index[ 1 ], index[ 2 ] ) );
86 }
87 
88 
89 /* 三角形を4等分する */
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__ )
92 {
93  typedef vector3< T > vector_type;
94 
95  vector_type v12 = ( v1 + v2 ).unit( );
96  vector_type v23 = ( v2 + v3 ).unit( );
97  vector_type v31 = ( v3 + v1 ).unit( );
98 
99  if( __division_num__ == 1 )
100  {
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 );
105  }
106  else
107  {
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 );
112  }
113 }
114 
122 
129 inline std::vector< vector3< double > > balloon( size_t number_of_division )
130 {
131  typedef vector3< double > vector_type;
132  typedef vector3< size_t > vertex_index;
133  typedef std::vector< vector_type > position_list;
134  typedef std::vector< vertex_index > vertex_list;
135  typedef position_list::size_type size_type;
136 
137  const double BX = 0.525731112119133606;
138  const double BZ = 0.850650808352039932;
139 
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 )
144  };
145 
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 )
151  };
152 
153  position_list plist;
154  vertex_list vlist, vtmp;
155 
156  for( size_type i = 0; i < 20; i++ )
157  {
158  register_vertex( plist, vlist, vtx20[ ivtx20[ i ].x ], vtx20[ ivtx20[ i ].y ], vtx20[ ivtx20[ i ].z ] );
159  }
160 
161  if( number_of_division > 0 )
162  {
163  vertex_list vtmp;
164 
165  for( size_type i = 0 ; i < vlist.size( ) ; i++ )
166  {
167  divide_triangle( plist, vtmp, plist[ vlist[ i ].x ], plist[ vlist[ i ].y ], plist[ vlist[ i ].z ], number_of_division );
168  }
169  }
170 
171  return( plist );
172 }
173 
174 
181 inline std::vector< vector3< double > > half_balloon( size_t number_of_division )
182 {
183  typedef vector3< double > vector_type;
184  typedef std::vector< vector_type > position_list;
185  typedef position_list::size_type size_type;
186 
187  position_list plist = balloon( number_of_division ), qlist;
188  const double eps = 1.0e-12;
189 
190  qlist.reserve( plist.size( ) / 2 + 1 );
191 
192  for( size_type i = 0 ; i < plist.size( ) ; i++ )
193  {
194  const vector_type &p = plist[ i ];
195 
196  if( p.z > 0 )
197  {
198  qlist.push_back( p );
199  }
200  else if( p.z > -eps )
201  {
202  if( p.y > 0 )
203  {
204  qlist.push_back( p );
205  }
206  else if( p.y > -eps && p.x > 0 )
207  {
208  qlist.push_back( p );
209  }
210  }
211  }
212 
213  return( qlist );
214 }
215 
216 
218 // メッシュ抽出グループの終わり
219 
220 
221 // mist名前空間の終わり
222 _MIST_END
223 
224 
225 #endif // __INCLUDE_MIST_TIMER__
226 

Generated on Wed Nov 12 2014 19:44:13 for MIST by doxygen 1.8.1.2