Branch data Line data Source code
1 : : #include "moab/Tree.hpp"
2 : : #include "moab/Range.hpp"
3 : : #include "moab/Interface.hpp"
4 : :
5 : : #include <limits>
6 : :
7 : : namespace moab
8 : : {
9 : 11 : ErrorCode Tree::parse_common_options( FileOptions& options )
10 : : {
11 : : double tmp_dbl;
12 : : int tmp_int;
13 : : // MAX_PER_LEAF: max entities per leaf; default = 6
14 [ + - ]: 11 : ErrorCode rval = options.get_int_option( "MAX_PER_LEAF", tmp_int );
15 [ + - ][ + - ]: 11 : if( MB_SUCCESS == rval ) maxPerLeaf = std::max( tmp_int, 1 );
16 : :
17 : : // MAX_DEPTH: max depth of the tree; default = 30
18 [ + - ]: 11 : rval = options.get_int_option( "MAX_DEPTH", tmp_int );
19 [ + + ]: 11 : if( MB_SUCCESS == rval ) maxDepth = tmp_int;
20 [ - + ]: 11 : if( maxDepth < 1 ) maxDepth = std::numeric_limits< unsigned >::max();
21 : :
22 : : // MIN_WIDTH: minimum width of box, used like a tolerance; default = 1.0e-10
23 [ + - ]: 11 : rval = options.get_real_option( "MIN_WIDTH", tmp_dbl );
24 [ - + ]: 11 : if( MB_SUCCESS == rval ) minWidth = tmp_dbl;
25 : :
26 : : // MESHSET_FLAGS: flags passed into meshset creation for tree nodes; should be a value from
27 : : // ENTITY_SET_PROPERTY (see Types.hpp); default = MESHSET_SET
28 [ + - ]: 11 : rval = options.get_int_option( "MESHSET_FLAGS", tmp_int );
29 [ - + ][ # # ]: 11 : if( MB_SUCCESS == rval && 0 <= tmp_int )
30 : 0 : meshsetFlags = (unsigned)tmp_int;
31 [ - + ]: 11 : else if( 0 > tmp_int )
32 : 0 : return MB_FAILURE;
33 : :
34 : : // CLEAN_UP: if false, do not delete tree sets upon tree class destruction; default = true
35 : : bool tmp_bool;
36 [ + - ]: 11 : rval = options.get_toggle_option( "CLEAN_UP", true, tmp_bool );
37 [ + - ][ - + ]: 11 : if( MB_SUCCESS == rval && !tmp_bool ) cleanUp = false;
38 : :
39 : : // TAG_NAME: tag name to store tree information on tree nodes; default = "AKDTree"
40 [ + - ]: 11 : std::string tmp_str;
41 [ + - ]: 11 : rval = options.get_str_option( "TAG_NAME", tmp_str );
42 [ - + ][ # # ]: 11 : if( MB_SUCCESS == rval ) boxTagName = tmp_str;
43 : :
44 : 11 : return MB_SUCCESS;
45 : : }
46 : :
47 : 1 : ErrorCode Tree::find_all_trees( Range& results )
48 : : {
49 [ + - ]: 1 : Tag tag = get_box_tag();
50 [ + - ][ + - ]: 1 : ErrorCode rval = moab()->get_entities_by_type_and_tag( 0, MBENTITYSET, &tag, 0, 1, results );
51 [ + - ][ + - ]: 1 : if( MB_SUCCESS != rval || results.empty() ) return rval;
[ - + ][ - + ]
52 [ + - ][ + - ]: 1 : std::vector< BoundBox > boxes( results.size() );
53 [ + - ][ + - ]: 1 : rval = moab()->tag_get_data( tag, results, &boxes[0] );
[ + - ]
54 [ - + ]: 1 : if( MB_SUCCESS != rval ) return rval;
55 [ + - ][ + - ]: 2 : for( std::vector< BoundBox >::iterator vit = boxes.begin(); vit != boxes.end(); ++vit )
[ + + ]
56 [ + - ][ + - ]: 1 : boundBox.update( *vit );
57 : :
58 [ + - ][ + - ]: 1 : if( results.size() == 1 ) myRoot = *results.begin();
[ + - ][ + - ]
59 : :
60 : 1 : return MB_SUCCESS;
61 : : }
62 : :
63 : 30 : ErrorCode Tree::create_root( const double box_min[3], const double box_max[3], EntityHandle& root_handle )
64 : : {
65 [ + - ]: 30 : ErrorCode rval = mbImpl->create_meshset( meshsetFlags, root_handle );
66 [ - + ]: 30 : if( MB_SUCCESS != rval ) return rval;
67 : :
68 : 30 : myRoot = root_handle;
69 : :
70 : : double box_tag[6];
71 [ + + ]: 120 : for( int i = 0; i < 3; i++ )
72 : : {
73 : 90 : box_tag[i] = box_min[i];
74 : 90 : box_tag[3 + i] = box_max[i];
75 : : }
76 [ + - ][ + - ]: 30 : rval = mbImpl->tag_set_data( get_box_tag(), &root_handle, 1, box_tag );
77 [ - + ]: 30 : if( MB_SUCCESS != rval ) return rval;
78 : :
79 [ + - ]: 30 : boundBox.bMin = box_min;
80 [ + - ]: 30 : boundBox.bMax = box_max;
81 : :
82 : 30 : return MB_SUCCESS;
83 : : }
84 : :
85 : 30 : ErrorCode Tree::delete_tree_sets()
86 : : {
87 [ - + ]: 30 : if( !myRoot ) return MB_SUCCESS;
88 : :
89 : : ErrorCode rval;
90 [ + - ][ + - ]: 60 : std::vector< EntityHandle > children, dead_sets, current_sets;
[ + - ]
91 [ + - ]: 30 : current_sets.push_back( myRoot );
92 [ + + ]: 7460 : while( !current_sets.empty() )
93 : : {
94 [ + - ]: 7430 : EntityHandle set = current_sets.back();
95 [ + - ]: 7430 : current_sets.pop_back();
96 [ + - ]: 7430 : dead_sets.push_back( set );
97 [ + - ]: 7430 : rval = mbImpl->get_child_meshsets( set, children );
98 [ - + ]: 7430 : if( MB_SUCCESS != rval ) return rval;
99 [ + - ][ + - ]: 7430 : std::copy( children.begin(), children.end(), std::back_inserter( current_sets ) );
100 : 7430 : children.clear();
101 : : }
102 : :
103 [ + - ]: 30 : rval = mbImpl->tag_delete_data( boxTag, &myRoot, 1 );
104 [ - + ]: 30 : if( MB_SUCCESS != rval ) return rval;
105 : :
106 [ + - ][ + - ]: 30 : rval = mbImpl->delete_entities( &dead_sets[0], dead_sets.size() );
107 [ - + ]: 30 : if( MB_SUCCESS != rval ) return rval;
108 : :
109 : 30 : myRoot = 0;
110 : :
111 : 60 : return MB_SUCCESS;
112 : : }
113 : :
114 [ + - ][ + - ]: 228 : } // namespace moab
|