15 #include <tr1/unordered_map>
18 #ifndef COMMON_TREE_HPP
19 #define COMMON_TREE_HPP
27 template <
typename T,
typename Stream >
30 typedef typename T::const_iterator Iterator;
32 for( Iterator i = v.begin(); i != v.end(); ++i )
35 if( i + 1 != v.end() )
40 out <<
" ]" << std::endl;
44 template <
typename T >
48 for( T i = begin; i != end; ++i )
50 std::cout << ( *i )->second.second.to_ulong();
56 std::cout <<
" ]" << std::endl;
60 template <
typename _Box,
typename _Po
int >
63 for( std::size_t i = 0; i < box.min.size(); ++i )
65 if( p[i] < ( box.min[i] - tol ) || p[i] > ( box.max[i] ) + tol )
73 template <
typename _Box >
76 for( std::size_t i = 0; i < a.min.size(); ++i )
78 if( b.min[i] < ( a.min[i] - tol ) )
82 if( b.max[i] > ( a.max[i] + tol ) )
92 template <
typename T >
96 typedef T first_argument_type;
97 typedef T second_argument_type;
98 typedef T result_type;
100 T operator()(
const T a,
const T b )
const
102 return ( a + b ) / 2.0;
107 template <
typename Vector >
110 typedef typename Vector::value_type Unit;
112 std::transform( max.begin(), max.end(),
center.begin(),
center.begin(), Compute_center< Unit >() );
115 template <
typename Box >
121 template <
typename T =
float >
129 template <
typename Iterator >
130 Box(
const Iterator begin,
const Iterator end ) :
max( begin, end ),
min( begin, end )
143 template <
typename T >
154 template <
typename T1,
typename T2 >
164 template <
typename U,
typename V >
170 template <
typename Entities,
typename Iterator >
173 entities.reserve( std::distance( begin, end ) );
174 for( Iterator i = begin; i != end; ++i )
176 entities.push_back( std::make_pair( ( *i )->second.first, ( *i )->first ) );
180 template <
typename Coordinate,
typename Coordinate_iterator >
183 typedef typename Coordinate::iterator Iterator;
184 for( Iterator i = max.begin(); i != max.end(); ++i, ++j )
186 *i = std::max( *i, *j );
190 template <
typename Coordinate,
typename Coordinate_iterator >
193 typedef typename Coordinate::iterator Iterator;
194 for( Iterator i = min.begin(); i != min.end(); ++i, ++j )
196 *i = std::min( *i, *j );
200 template <
typename Box >
205 #ifdef COMMON_TREE_DEBUG
208 std::cout << a << b << std::endl;
213 template <
typename Entity_map,
typename Ordering >
216 entity_ordering.reserve( entity_map.size() );
217 typedef typename Entity_map::iterator Map_iterator;
218 for( Map_iterator i = entity_map.begin(); i != entity_map.end(); ++i )
220 entity_ordering.push_back( i );
228 template <
typename Entity_handles,
typename Element_map,
typename Bounding_box,
typename Moab >
234 typedef typename Element_map::mapped_type Box_data;
235 typedef typename Entity_handles::value_type Entity_handle;
236 typedef typename Entity_handles::iterator Entity_handles_iterator;
237 typedef typename Box_data::first_type::value_type Unit;
238 typedef typename std::vector< Unit > Coordinates;
239 typedef typename Coordinates::iterator Coordinate_iterator;
241 for( Entity_handles_iterator i = elements.begin(); i != elements.end(); ++i )
245 int num_vertices = 0;
247 const Entity_handle* vertex_handle;
248 moab.get_connectivity( *i, vertex_handle, num_vertices );
249 Coordinates coordinate( DIM * num_vertices, 0.0 );
250 moab.get_coords( vertex_handle, num_vertices, &coordinate[0] );
251 Bounding_box box( coordinate.begin(), coordinate.begin() + 3 );
252 if( i == elements.begin() )
256 for( Coordinate_iterator j = coordinate.begin() + DIM; j != coordinate.end(); j += DIM )
262 map.insert( std::make_pair( *i, Box_data( box ) ) );