Branch data Line data Source code
1 : : #include "moab/MOABConfig.h"
2 : : #include "iMesh_extensions.h"
3 : : #include "moab/Core.hpp"
4 : : #include "moab/Range.hpp"
5 : : #include "moab/CN.hpp"
6 : : #include "moab/MeshTopoUtil.hpp"
7 : : #include "moab/ScdInterface.hpp"
8 : : #include "moab/FileOptions.hpp"
9 : : #include "iMesh_MOAB.hpp"
10 : : #include "MBIter.hpp"
11 : : #include "MBTagConventions.hpp"
12 : : #define IS_BUILDING_MB
13 : : #include "Internals.hpp"
14 : : #undef IS_BUILDING_MB
15 : :
16 : : #ifdef MOAB_HAVE_MPI
17 : : #include "moab_mpi.h"
18 : : #include "moab/ParallelComm.hpp"
19 : : #endif
20 : :
21 : : #define STRINGIFY_( X ) #X
22 : : #define STRINGIFY( X ) STRINGIFY_( X )
23 : : #ifdef MOAB_HAVE_UNORDERED_MAP
24 : : #include STRINGIFY( MOAB_HAVE_UNORDERED_MAP )
25 : : #else
26 : : #include <map>
27 : : #endif
28 : :
29 : : #include <iostream>
30 : : #include <cassert>
31 : : #include <cctype>
32 : : #include <cstring>
33 : : #include <stdarg.h>
34 : : #include <stdio.h>
35 : : #define MIN( a, b ) ( a < b ? a : b )
36 : :
37 : : #ifdef _WIN32
38 : : #define snprintf( A, B, C, D ) _snprintf( ( A ), ( B ), ( C ), ( D ) )
39 : : #endif
40 : :
41 : : static ErrorCode create_int_ents( MBiMesh* mbimesh, Range& from_ents, const EntityHandle* in_set = 0 );
42 : : #define HANDLE_ARRAY_PTR( array ) reinterpret_cast< EntityHandle* >( array )
43 : : #define CONST_HANDLE_ARRAY_PTR( array ) reinterpret_cast< const EntityHandle* >( array )
44 : : #define TAG_HANDLE( handle ) reinterpret_cast< Tag >( handle )
45 : : #define CONST_TAG_HANDLE( handle ) static_cast< const Tag >( handle )
46 : : #define ENTITY_HANDLE( handle ) reinterpret_cast< EntityHandle >( handle )
47 : : #define CONST_ENTITY_HANDLE( handle ) reinterpret_cast< const EntityHandle >( handle )
48 : : #define CAST_TO_VOID( ptr ) reinterpret_cast< void* >( ptr )
49 : :
50 : : // map from MB's entity type to TSTT's entity topology
51 : : const iMesh_EntityTopology tstt_topology_table[] = {
52 : : iMesh_POINT, // MBVERTEX
53 : : iMesh_LINE_SEGMENT, // MBEDGE
54 : : iMesh_TRIANGLE, // MBTRI
55 : : iMesh_QUADRILATERAL, // MBQUAD
56 : : iMesh_POLYGON, // MBPOLYGON
57 : : iMesh_TETRAHEDRON, // MBTET
58 : : iMesh_PYRAMID, // MBPYRAMID
59 : : iMesh_PRISM, // MBPRISM
60 : : iMesh_ALL_TOPOLOGIES, // MBKNIFE
61 : : iMesh_HEXAHEDRON, // MBHEX
62 : : iMesh_POLYHEDRON, // MBPOLYHEDRON
63 : : iMesh_ALL_TOPOLOGIES, // MBENTITYSET
64 : : iMesh_ALL_TOPOLOGIES, // MBMAXTYPE
65 : : };
66 : :
67 : : // map from MB's entity type to TSTT's entity type
68 : : const iBase_EntityType tstt_type_table[] = {
69 : : iBase_VERTEX, // MBVERTEX
70 : : iBase_EDGE, // MBEDGE
71 : : iBase_FACE, // MBTRI
72 : : iBase_FACE, // MBQUAD
73 : : iBase_FACE, // MBPOLYGON
74 : : iBase_REGION, // MBTET
75 : : iBase_REGION, // MBPYRAMID
76 : : iBase_REGION, // MBPRISM
77 : : iBase_REGION, // MBKNIFE
78 : : iBase_REGION, // MBHEX
79 : : iBase_REGION, // MBPOLYHEDRON
80 : : iBase_ALL_TYPES, // MBENTITYSET
81 : : iBase_ALL_TYPES // MBMAXTYPE
82 : : };
83 : :
84 : : // map to MB's entity type from TSTT's entity topology
85 : : const EntityType mb_topology_table[] = { MBVERTEX, MBEDGE, MBPOLYGON, MBTRI, MBQUAD, MBPOLYHEDRON,
86 : : MBTET, MBHEX, MBPRISM, MBPYRAMID, MBMAXTYPE, MBMAXTYPE };
87 : :
88 : : // map from TSTT's tag types to MOAB's
89 : : const DataType mb_data_type_table[] = { MB_TYPE_OPAQUE, MB_TYPE_INTEGER, MB_TYPE_DOUBLE, MB_TYPE_HANDLE,
90 : : MB_TYPE_HANDLE };
91 : :
92 : : // map from MOAB's tag types to tstt's
93 : : const iBase_TagValueType tstt_data_type_table[] = { iBase_BYTES, iBase_INTEGER, iBase_DOUBLE, iBase_BYTES,
94 : : iBase_ENTITY_HANDLE };
95 : :
96 : : const iBase_ErrorType iBase_ERROR_MAP[MB_FAILURE + 1] = {
97 : : iBase_SUCCESS, // MB_SUCCESS = 0,
98 : : iBase_INVALID_ENTITY_HANDLE, // MB_INDEX_OUT_OF_RANGE,
99 : : iBase_INVALID_ENTITY_TYPE, // MB_TYPE_OUT_OF_RANGE,
100 : : iBase_MEMORY_ALLOCATION_FAILED, // MB_MEMORY_ALLOCATION_FAILED,
101 : : iBase_INVALID_ENTITY_HANDLE, // MB_ENTITY_NOT_FOUND,
102 : : iBase_NOT_SUPPORTED, // MB_MULTIPLE_ENTITIES_FOUND,
103 : : iBase_TAG_NOT_FOUND, // MB_TAG_NOT_FOUND,
104 : : iBase_FILE_NOT_FOUND, // MB_FILE_DOES_NOT_EXIST,
105 : : iBase_FILE_WRITE_ERROR, // MB_FILE_WRITE_ERROR,
106 : : iBase_NOT_SUPPORTED, // MB_NOT_IMPLEMENTED,
107 : : iBase_TAG_ALREADY_EXISTS, // MB_ALREADY_ALLOCATED,
108 : : iBase_FAILURE, // MB_VARIABLE_DATA_LENGTH,
109 : : iBase_FAILURE, // MB_INVALID_SIZE,
110 : : iBase_NOT_SUPPORTED, // MB_UNSUPPORTED_OPERATION,
111 : : iBase_INVALID_ARGUMENT, // MB_UNHANDLED_OPTION
112 : : iBase_INVALID_ENTITY_TYPE, // MB_STRUCTURED_MESH
113 : : iBase_FAILURE // MB_FAILURE};
114 : : };
115 : :
116 : : // Return data about a list of handles for use in check_handle_tag_type.
117 : : // Set output arguments to true if the list contains the corresponding
118 : : // type of handle. Leave them unmodified if it does not.
119 : 0 : static inline void ht_content_type( const std::vector< EntityHandle >& h, bool& saw_ent, bool& saw_set, bool& saw_root )
120 : : {
121 : 0 : std::vector< EntityHandle >::const_iterator i;
122 [ # # ][ # # ]: 0 : for( i = h.begin(); i != h.end(); ++i )
[ # # ]
123 : : {
124 [ # # ][ # # ]: 0 : if( *i == 0 )
125 : 0 : saw_root = true;
126 [ # # ][ # # ]: 0 : else if( TYPE_FROM_HANDLE( *i ) == MBENTITYSET )
[ # # ]
127 : 0 : saw_set = true;
128 : : else
129 : 0 : saw_ent = true;
130 : : }
131 : 0 : }
132 : :
133 : : // Scan all tag data to try to guess whether the MOAB tag with
134 : : // data of type MB_TYPE_HANDLE is iBase_ENTITY_HANDLE or
135 : : // iBase_ENTITY_SET_HANDLE.
136 : 0 : static ErrorCode check_handle_tag_type( Tag t, MBiMesh* mbi )
137 : : {
138 : 0 : Interface* mb = mbi->mbImpl;
139 : : ErrorCode rval;
140 : : int size;
141 : : DataType type;
142 [ # # ]: 0 : rval = mb->tag_get_data_type( t, type );
143 [ # # ]: 0 : if( MB_SUCCESS != rval ) return rval;
144 [ # # ]: 0 : if( MB_TYPE_HANDLE != type ) return MB_TYPE_OUT_OF_RANGE;
145 [ # # ]: 0 : rval = mb->tag_get_length( t, size );
146 [ # # ]: 0 : if( MB_SUCCESS != rval ) return rval;
147 [ # # ]: 0 : std::vector< EntityHandle > data( size );
148 : :
149 : : // check for global/mesh value
150 : 0 : bool saw_set = false, saw_ent = false, saw_root = false;
151 : 0 : EntityHandle root = 0;
152 [ # # ][ # # ]: 0 : rval = mb->tag_get_data( t, &root, 1, &data[0] );
153 [ # # ][ # # ]: 0 : if( MB_SUCCESS == rval ) ht_content_type( data, saw_ent, saw_set, saw_root );
154 : :
155 : : // check default value
156 [ # # ][ # # ]: 0 : rval = mb->tag_get_default_value( t, &data[0] );
157 [ # # ][ # # ]: 0 : if( MB_SUCCESS == rval ) ht_content_type( data, saw_ent, saw_set, saw_root );
158 : :
159 : : // check all tagged entities
160 [ # # ]: 0 : Range r;
161 [ # # ]: 0 : rval = mb->get_entities_by_type_and_tag( 0, MBMAXTYPE, &t, 0, 1, r );
162 [ # # ]: 0 : if( MB_SUCCESS != rval ) return rval;
163 [ # # ][ # # ]: 0 : for( Range::iterator i = r.begin(); i != r.end(); ++i )
[ # # ][ # # ]
[ # # ]
164 : : {
165 [ # # ][ # # ]: 0 : rval = mb->tag_get_data( t, &*i, 1, &data[0] );
[ # # ]
166 [ # # ]: 0 : if( MB_SUCCESS != rval ) return rval;
167 [ # # ]: 0 : ht_content_type( data, saw_ent, saw_set, saw_root );
168 : : }
169 : :
170 : : // If tag values were only entities, note type accordingly.
171 : : // Similarly if all are entity sets, note accordingly.
172 : : // Because root set (zero handle) is sometimes used to mean NULL
173 : : // rather than the actual root set, treat that specially. If
174 : : // all values are either root set or an entity handle, then
175 : : // treat as if all values were non-set handles.
176 [ # # ][ # # ]: 0 : if( saw_set && !saw_ent )
177 [ # # ]: 0 : mbi->note_set_handle_tag( t );
178 [ # # ][ # # ]: 0 : else if( !saw_set && saw_ent )
179 [ # # ]: 0 : mbi->note_ent_handle_tag( t );
180 [ # # ][ # # ]: 0 : else if( saw_root && !saw_ent )
181 [ # # ]: 0 : mbi->note_set_handle_tag( t );
182 : :
183 : 0 : return MB_SUCCESS;
184 : : }
185 : :
186 : 51 : static void remove_var_len_tags( Interface* mb, std::vector< Tag >& tags )
187 : : {
188 : : int size;
189 : 51 : size_t r, w = 0;
190 [ + + ]: 221 : for( r = 0; r < tags.size(); ++r )
191 [ + - ][ + - ]: 170 : if( MB_SUCCESS == mb->tag_get_length( tags[r], size ) ) tags[w++] = tags[r];
[ + + ][ + - ]
[ + - ]
192 [ + - ]: 51 : tags.resize( w );
193 : 51 : }
194 : :
195 : : // modify the adjacency table to match the ITAPS spec's expectations
196 : 0 : static void munge_adj_table( int* adjTable, int geom_dim )
197 : : {
198 : : // If geom_dim is 2, 3D adjacencies are unavailable. This may change!
199 [ # # ]: 0 : if( geom_dim == 2 )
200 : : {
201 [ # # ]: 0 : for( size_t i = 0; i < 16; ++i )
202 : : {
203 [ # # ][ # # ]: 0 : if( i % 4 == 3 || i >= 12 ) adjTable[i] = iBase_UNAVAILABLE;
204 : : }
205 : : }
206 : :
207 : : // Ensure that diagonal entries are only available/unavailable.
208 [ # # ]: 0 : for( size_t i = 0; i < 16; i += 5 )
209 : : {
210 [ # # ]: 0 : if( adjTable[i] != iBase_UNAVAILABLE ) adjTable[i] = iBase_AVAILABLE;
211 : : }
212 : 0 : }
213 : :
214 : : #ifdef __cplusplus
215 : : extern "C" {
216 : : #endif
217 : :
218 : : static void eatwhitespace( std::string& this_string );
219 : :
220 : 0 : void iMesh_getErrorType( iMesh_Instance instance, int* error_type )
221 : : {
222 [ # # ]: 0 : if( instance == NULL )
223 : 0 : *error_type = iBase_FAILURE;
224 : : else
225 : 0 : *error_type = MBIMESHI->lastErrorType;
226 : 0 : }
227 : :
228 : 5 : void iMesh_getDescription( iMesh_Instance instance, char* descr, int descr_len )
229 : : {
230 [ - + ]: 5 : if( instance == NULL ) { strcpy( descr, "iMesh_getDescription: Invalid instance" ); }
231 : : else
232 : : {
233 [ + - ]: 5 : unsigned int len = MIN( strlen( MBIMESHI->lastErrorDescription ), static_cast< unsigned int >( descr_len ) );
234 : 5 : strncpy( descr, MBIMESHI->lastErrorDescription, len );
235 : 5 : descr[len] = '\0';
236 : : }
237 : 5 : }
238 : :
239 : 55 : void iMesh_newMesh( const char* options, iMesh_Instance* instance, int* err, int options_len )
240 : : {
241 [ + - ]: 55 : std::string tmp_options = filter_options( options, options + options_len );
242 [ + - ][ + - ]: 110 : FileOptions opts( tmp_options.c_str() );
243 : :
244 : 55 : MBiMesh** mbi = reinterpret_cast< MBiMesh** >( instance );
245 : 55 : *mbi = NULL;
246 : :
247 [ + - ]: 55 : ErrorCode result = opts.get_null_option( "PARALLEL" );
248 [ - + ]: 55 : if( MB_SUCCESS == result )
249 : : {
250 : : #ifdef MOAB_HAVE_MPI
251 : 0 : int flag = 1;
252 [ # # ]: 0 : int retval = MPI_Initialized( &flag );
253 [ # # ][ # # ]: 0 : if( MPI_SUCCESS != retval || !flag )
254 : : {
255 : 0 : int argc = 0;
256 : 0 : char** argv = NULL;
257 : :
258 : : // mpi not initialized yet - initialize here
259 [ # # ]: 0 : retval = MPI_Init( &argc, &argv );
260 [ # # ]: 0 : assert( MPI_SUCCESS == retval );
261 : : }
262 [ # # ][ # # ]: 0 : *mbi = new( std::nothrow ) MBiMesh( NULL );
263 : : #else
264 : : // mError->set_last_error( "PARALLEL option not valid, this instance"
265 : : // " compiled for serial execution.\n" );
266 : : *mbi = new( std::nothrow ) MBiMesh( NULL );
267 : : *err = ( *mbi )->set_last_error( MB_NOT_IMPLEMENTED, "Not configured with parallel support" );
268 : : return;
269 : : #endif
270 : : }
271 : : else
272 : : {
273 [ + - ][ + - ]: 55 : *mbi = new( std::nothrow ) MBiMesh( NULL );
274 : : }
275 [ - + ]: 55 : if( NULL == *mbi )
276 : : {
277 : 0 : *err = iBase_FAILURE;
278 : 55 : return;
279 : : }
280 : :
281 [ + - ]: 110 : *err = iBase_SUCCESS;
282 : : }
283 : :
284 : 56 : void iMesh_dtor( iMesh_Instance instance, int* err )
285 : : {
286 [ + - ]: 56 : delete MBIMESHI;
287 : 56 : *err = iBase_SUCCESS;
288 : 56 : }
289 : :
290 : 25 : void iMesh_load( iMesh_Instance instance, const iBase_EntitySetHandle handle, const char* name, const char* options,
291 : : int* err, int name_len, int options_len )
292 : : {
293 : : // get filename, option & null-terminate
294 [ + - ]: 25 : std::string filename( name, name_len );
295 [ + - ]: 25 : eatwhitespace( filename );
296 : :
297 [ + - ]: 50 : std::string opts = filter_options( options, options + options_len );
298 : :
299 [ + - ]: 50 : Range orig_ents;
300 [ + - ][ - + ]: 25 : ErrorCode result = MOABI->get_entities_by_handle( 0, orig_ents );CHKERR( result, "Internal error" );
[ # # ]
301 : :
302 : 25 : const EntityHandle* file_set = 0;
303 [ + + ]: 25 : if( handle != 0 /*root_set*/ )
304 : : {
305 : 1 : const iBase_EntitySetHandle* ptr = &handle;
306 : 1 : file_set = reinterpret_cast< const EntityHandle* >( ptr );
307 : : }
308 : :
309 [ + - ]: 25 : result = MOABI->load_file( filename.c_str(), file_set, opts.c_str() );
310 : :
311 [ - + ][ # # ]: 25 : CHKERR( result, "iMesh_load:ERROR loading a mesh." );
312 : :
313 : : // create interior edges/faces if requested
314 [ + - ][ - + ]: 25 : if( MBIMESHI->AdjTable[5] || MBIMESHI->AdjTable[10] )
[ - + ]
315 : : {
316 [ # # ]: 0 : Range set_ents;
317 [ # # ][ # # ]: 0 : result = MOABI->get_entities_by_handle( 0, set_ents );CHKERR( result, "" );
[ # # ]
318 [ # # ][ # # ]: 0 : Range sets;
319 [ # # ][ # # ]: 0 : result = MOABI->get_entities_by_type( 0, MBENTITYSET, sets );CHKERR( result, "" );
[ # # ]
320 [ # # ][ # # ]: 0 : set_ents = subtract( set_ents, sets );
321 [ # # ][ # # ]: 0 : set_ents = subtract( set_ents, orig_ents );
322 [ # # ][ # # ]: 0 : result = create_int_ents( MBIMESHI, set_ents, file_set );CHKERR( result, "" );
[ # # ][ # # ]
323 : : }
324 [ + - ]: 50 : RETURN( iBase_SUCCESS );
325 : : }
326 : :
327 : 19 : void iMesh_save( iMesh_Instance instance, const iBase_EntitySetHandle handle, const char* name, const char* options,
328 : : int* err, const int name_len, int options_len )
329 : : {
330 : : // get filename & attempt to NULL-terminate
331 [ + - ]: 19 : std::string filename( name, name_len );
332 [ + - ]: 19 : eatwhitespace( filename );
333 [ + - ]: 38 : std::string opts = filter_options( options, options + options_len );
334 : :
335 : 19 : EntityHandle set = ENTITY_HANDLE( handle );
336 [ + - ]: 19 : ErrorCode result = MOABI->write_file( filename.c_str(), NULL, opts.c_str(), &set, 1 );
337 : :
338 [ - + ][ # # ]: 19 : CHKERR( result, "iMesh_save:ERROR saving a mesh." );
339 [ + - ]: 38 : RETURN( iBase_SUCCESS );
340 : : }
341 : :
342 : 55 : void iMesh_getRootSet( iMesh_Instance instance, iBase_EntitySetHandle* root_set, int* err )
343 : : {
344 : 55 : *root_set = 0;
345 : : // return CAST_TO_VOID(MOABI->get_root_set());
346 : 55 : RETURN( iBase_SUCCESS );
347 : : }
348 : :
349 : 3 : void iMesh_getGeometricDimension( iMesh_Instance instance, int* geom_dim, int* err )
350 : : {
351 : 3 : MOABI->get_dimension( *geom_dim );
352 : 3 : RETURN( iBase_SUCCESS );
353 : : }
354 : :
355 : 0 : void iMesh_setGeometricDimension( iMesh_Instance instance, int geom_dim, int* err )
356 : : {
357 [ # # ]: 0 : ErrorCode rval = MOABI->set_dimension( geom_dim );CHKERR( rval, "iMesh_setGeometricDimension: failed" );
358 : :
359 : 0 : RETURN( iBase_SUCCESS );
360 : : }
361 : :
362 : 1 : void iMesh_getDfltStorage( iMesh_Instance instance, int* order, int* err )
363 : : {
364 : 1 : *order = iBase_BLOCKED;
365 : 1 : RETURN( iBase_SUCCESS );
366 : : }
367 : :
368 : 0 : void iMesh_getAdjTable( iMesh_Instance instance, int** adjacency_table,
369 : : /*inout*/ int* adjacency_table_allocated,
370 : : /*out*/ int* adjacency_table_size, int* err )
371 : : {
372 : : int geom_dim;
373 [ # # ]: 0 : iMesh_getGeometricDimension( instance, &geom_dim, err );
374 : :
375 [ # # ][ # # ]: 0 : ALLOC_CHECK_ARRAY_NOFAIL( adjacency_table, 16 );
[ # # ]
376 : 0 : memcpy( *adjacency_table, MBIMESHI->AdjTable, 16 * sizeof( int ) );
377 : 0 : munge_adj_table( *adjacency_table, geom_dim );
378 [ # # ]: 0 : RETURN( iBase_SUCCESS );
379 : : }
380 : :
381 : 0 : void iMesh_setAdjTable( iMesh_Instance instance, int* adj_table,
382 : : /*inout*/ int adj_table_size, int* err )
383 : : {
384 [ # # ][ # # ]: 0 : if( 16 != adj_table_size ) { RETURN( iBase_INVALID_ARGUMENT ); }
385 : :
386 : : int geom_dim;
387 [ # # ]: 0 : iMesh_getGeometricDimension( instance, &geom_dim, err );
388 : :
389 : 0 : memcpy( MBIMESHI->AdjTable, adj_table, 16 * sizeof( int ) );
390 : 0 : munge_adj_table( adj_table, geom_dim );
391 [ # # ]: 0 : RETURN( iBase_SUCCESS );
392 : : }
393 : :
394 : 164 : void iMesh_getNumOfType( iMesh_Instance instance,
395 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
396 : : /*in*/ const int entity_type, int* num_type, int* err )
397 : : {
398 : 164 : iMesh_getNumOfTypeRec( instance, entity_set_handle, entity_type, false, num_type, err );
399 : 164 : }
400 : :
401 : 11 : void iMesh_getNumOfTopo( iMesh_Instance instance,
402 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
403 : : /*in*/ const int entity_topology, int* num_topo, int* err )
404 : : {
405 : 11 : iMesh_getNumOfTopoRec( instance, entity_set_handle, entity_topology, false, num_topo, err );
406 : 11 : }
407 : :
408 : 0 : void iMesh_optimize( iMesh_Instance instance, int* handles_invalidated, int* err )
409 : : {
410 : : // TODO: implement this for real
411 : 0 : *handles_invalidated = 0;
412 : 0 : RETURN( iBase_SUCCESS );
413 : : }
414 : :
415 : 183 : void iMesh_getEntities( iMesh_Instance instance,
416 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
417 : : /*in*/ const int entity_type,
418 : : /*in*/ const int entity_topology,
419 : : /*inout*/ iBase_EntityHandle** entity_handles,
420 : : /*inout*/ int* entity_handles_allocated,
421 : : /*out*/ int* entity_handles_size, int* err )
422 : : {
423 : : iMesh_getEntitiesRec( instance, entity_set_handle, entity_type, entity_topology, false, entity_handles,
424 : 183 : entity_handles_allocated, entity_handles_size, err );
425 : 183 : }
426 : :
427 : 58 : void iMesh_getVtxArrCoords( iMesh_Instance instance,
428 : : /*in*/ const iBase_EntityHandle* vertex_handles,
429 : : /*in*/ const int vertex_handles_size,
430 : : /*inout*/ int storage_order,
431 : : /*inout*/ double** coords,
432 : : /*inout*/ int* coords_allocated,
433 : : /*out*/ int* coords_size, int* err )
434 : : {
435 : : int geom_dim;
436 [ + - ]: 58 : MOABI->get_dimension( geom_dim );
437 : :
438 : : // make sure we can hold them all
439 [ + - ][ - + ]: 58 : ALLOC_CHECK_ARRAY( coords, geom_dim * vertex_handles_size );
440 : :
441 : : // now get all the coordinates
442 : : // coords will come back interleaved by default
443 : : ErrorCode result;
444 [ + + ]: 58 : if( storage_order == iBase_INTERLEAVED )
445 : : {
446 [ + - ]: 3 : if( 3 == geom_dim )
447 [ + - ]: 3 : { result = MOABI->get_coords( CONST_HANDLE_ARRAY_PTR( vertex_handles ), vertex_handles_size, *coords ); }
448 : : else
449 : : {
450 [ # # ]: 0 : std::vector< double > dum_coords( 3 * vertex_handles_size );
451 [ # # ][ # # ]: 0 : result = MOABI->get_coords( CONST_HANDLE_ARRAY_PTR( vertex_handles ), vertex_handles_size, &dum_coords[0] );
452 : :
453 [ # # ]: 0 : for( int i = 0; i < vertex_handles_size; i++ )
454 : : {
455 [ # # ]: 0 : for( int j = 0; j < geom_dim; j++ )
456 [ # # ]: 0 : ( *coords )[geom_dim * i + j] = dum_coords[3 * i + j];
457 : 3 : }
458 : : }
459 : : }
460 : : else
461 : : {
462 [ + - ]: 55 : std::vector< double > dum_coords( 3 * vertex_handles_size );
463 [ + - ][ + - ]: 55 : result = MOABI->get_coords( CONST_HANDLE_ARRAY_PTR( vertex_handles ), vertex_handles_size, &dum_coords[0] );CHKERR( result, "iMesh_getVtxArrCoords: problem getting vertex coords" );
[ - + ][ # # ]
464 : :
465 [ + + ][ + - ]: 110 : for( int i = 0; i < vertex_handles_size; i++ )
466 : : {
467 [ + + ]: 220 : for( int j = 0; j < geom_dim; j++ )
468 [ + - ]: 165 : ( *coords )[i + vertex_handles_size * j] = dum_coords[3 * i + j];
469 : 55 : }
470 : : }
471 : :
472 [ + - ]: 58 : KEEP_ARRAY( coords );
473 [ + - ]: 58 : RETURN( iBase_SUCCESS );
474 : : }
475 : :
476 : : /**
477 : : * Method: initEntArrIter[]
478 : : */
479 : 50 : void iMesh_initEntArrIter( iMesh_Instance instance,
480 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
481 : : /*in*/ const int requested_entity_type,
482 : : /*in*/ const int requested_entity_topology,
483 : : /*in*/ const int requested_array_size,
484 : : /*in*/ const int resilient,
485 : : /*out*/ iBase_EntityArrIterator* entArr_iterator, int* err )
486 : : {
487 : : iMesh_initEntArrIterRec( instance, entity_set_handle, requested_entity_type, requested_entity_topology,
488 : 50 : requested_array_size, resilient, false, entArr_iterator, err );
489 : 50 : }
490 : :
491 : : /**
492 : : * Method: getEntArrNextIter[]
493 : : */
494 : 52894 : void iMesh_getNextEntArrIter( iMesh_Instance instance,
495 : : /*in*/ iBase_EntityArrIterator entArr_iterator,
496 : : /*inout*/ iBase_EntityHandle** entity_handles,
497 : : /*inout*/ int* entity_handles_allocated,
498 : : /*out*/ int* entity_handles_size, int* has_data, int* err )
499 : : {
500 : : // check the size of the destination array
501 [ + - ][ + - ]: 52894 : ALLOC_CHECK_ARRAY_NOFAIL( entity_handles, entArr_iterator->array_size() );
[ - + ][ + - ]
502 : 52894 : entArr_iterator->get_entities( dynamic_cast< Core* >( MOABI ), (EntityHandle*)*entity_handles,
503 [ - + ][ + - ]: 52894 : *entity_handles_size );
504 : 52894 : *has_data = ( *entity_handles_size != 0 );
505 [ + - ]: 52894 : RETURN( iBase_SUCCESS );
506 : : }
507 : :
508 : : /**
509 : : * Method: resetEntArrIter[]
510 : : */
511 : 180 : void iMesh_resetEntArrIter( iMesh_Instance instance,
512 : : /*in*/ iBase_EntityArrIterator entArr_iterator, int* err )
513 : : {
514 [ - + ]: 180 : ErrorCode result = entArr_iterator->reset( MOABI );CHKERR( result, "Re-query of iterator data for iMesh_resetEntArrIter failed" );
515 : 180 : RETURN( iBase_SUCCESS );
516 : : }
517 : :
518 : 96 : void iMesh_endEntArrIter( iMesh_Instance instance,
519 : : /*in*/ iBase_EntityArrIterator entArr_iterator, int* err )
520 : : {
521 [ + - ]: 96 : delete entArr_iterator;
522 : 96 : RETURN( iBase_SUCCESS );
523 : : }
524 : :
525 : 4 : void iMesh_getEntArrTopo( iMesh_Instance instance,
526 : : /*in*/ const iBase_EntityHandle* entity_handles,
527 : : /*in*/ const int entity_handles_size,
528 : : /*inout*/ int** topology,
529 : : /*inout*/ int* topology_allocated,
530 : : /*out*/ int* topology_size, int* err )
531 : : {
532 : : // go through each entity and look up its type
533 [ + - ][ - + ]: 4 : ALLOC_CHECK_ARRAY_NOFAIL( topology, entity_handles_size );
[ + - ]
534 : :
535 [ + + ]: 4135 : for( int i = 0; i < entity_handles_size; i++ )
536 [ + - ]: 4131 : ( *topology )[i] = tstt_topology_table[MOABI->type_from_handle( ENTITY_HANDLE( entity_handles[i] ) )];
537 : :
538 : 4 : *topology_size = entity_handles_size;
539 : :
540 [ + - ]: 4 : RETURN( iBase_SUCCESS );
541 : : }
542 : :
543 : 3 : void iMesh_getEntArrType( iMesh_Instance instance,
544 : : /*in*/ const iBase_EntityHandle* entity_handles,
545 : : /*in*/ const int entity_handles_size,
546 : : /*inout*/ int** etype,
547 : : /*inout*/ int* etype_allocated,
548 : : /*out*/ int* etype_size, int* err )
549 : : {
550 : : // go through each entity and look up its type
551 [ + - ][ - + ]: 3 : ALLOC_CHECK_ARRAY_NOFAIL( etype, entity_handles_size );
[ + - ]
552 : :
553 [ + + ]: 1803 : for( int i = 0; i < entity_handles_size; i++ )
554 [ + - ]: 1800 : ( *etype )[i] = tstt_type_table[MOABI->type_from_handle( ENTITY_HANDLE( entity_handles[i] ) )];
555 : :
556 : 3 : *etype_size = entity_handles_size;
557 : :
558 [ + - ]: 3 : RETURN( iBase_SUCCESS );
559 : : }
560 : :
561 : 3022 : void iMesh_getEntArrAdj( iMesh_Instance instance,
562 : : /*in*/ const iBase_EntityHandle* entity_handles,
563 : : /*in*/ const int entity_handles_size,
564 : : /*in*/ const int entity_type_requested,
565 : : /*inout*/ iBase_EntityHandle** adjacentEntityHandles,
566 : : /*inout*/ int* adjacentEntityHandles_allocated,
567 : : /*out*/ int* adjacentEntityHandles_size,
568 : : /*inout*/ int** offset,
569 : : /*inout*/ int* offset_allocated,
570 : : /*out*/ int* offset_size, int* err )
571 : : {
572 : 3022 : ErrorCode result = MB_SUCCESS;
573 : :
574 [ + - ][ + + ]: 3022 : ALLOC_CHECK_ARRAY( offset, entity_handles_size + 1 );
575 : :
576 : 3021 : const EntityHandle* entity_iter = (const EntityHandle*)entity_handles;
577 : 3021 : const EntityHandle* const entity_end = entity_iter + entity_handles_size;
578 : 3021 : int* off_iter = *offset;
579 : 3021 : int prev_off = 0;
580 : :
581 [ + - ]: 6042 : std::vector< EntityHandle > conn_storage;
582 [ + - ]: 6042 : std::vector< EntityHandle > adj_ents;
583 : : const EntityHandle* connect;
584 : : int num_connect;
585 : :
586 : : EntityHandle* array; // ptr to working array of result handles
587 : : int array_alloc; // allocated size of 'array'
588 [ + + ][ - + ]: 3021 : const bool allocated_array = !*adjacentEntityHandles_allocated || !*adjacentEntityHandles;
589 [ + + ]: 3021 : if( allocated_array )
590 : : {
591 : 190 : array = 0;
592 : 190 : array_alloc = 0;
593 : : }
594 : : else
595 : : {
596 : 2831 : array = reinterpret_cast< EntityHandle* >( *adjacentEntityHandles );
597 : 2831 : array_alloc = *adjacentEntityHandles_allocated;
598 : : }
599 : :
600 [ + + ]: 12644 : for( ; entity_iter != entity_end; ++entity_iter )
601 : : {
602 : 9623 : *off_iter = prev_off;
603 : 9623 : off_iter++;
604 : :
605 [ + + ][ + - ]: 9623 : if( iBase_VERTEX == entity_type_requested && TYPE_FROM_HANDLE( *entity_iter ) != MBPOLYHEDRON )
[ + - ][ + + ]
606 : : {
607 [ + - ][ + - ]: 5964 : if( CN::Dimension( TYPE_FROM_HANDLE( *entity_iter ) ) == 0 ) continue;
[ - + ]
608 [ + - ]: 5964 : result = MOABI->get_connectivity( *entity_iter, connect, num_connect, false, &conn_storage );
609 [ - + ]: 5964 : if( MB_SUCCESS != result )
610 : : {
611 [ # # ]: 0 : if( allocated_array ) free( array );
612 [ # # ]: 0 : ERROR( result, "iMesh_getEntArrAdj: trouble getting adjacency list." );
613 : : }
614 : : }
615 [ + + ]: 3659 : else if( iBase_ALL_TYPES == entity_type_requested )
616 : : {
617 : 2 : adj_ents.clear();
618 [ + + ]: 10 : for( int dim = 0; dim < 4; ++dim )
619 : : {
620 [ + - ][ + - ]: 8 : if( CN::Dimension( TYPE_FROM_HANDLE( *entity_iter ) ) == dim ) continue;
[ + + ]
621 [ + - ]: 6 : result = MOABI->get_adjacencies( entity_iter, 1, dim, false, adj_ents, Interface::UNION );
622 [ - + ]: 6 : if( MB_SUCCESS != result )
623 : : {
624 [ # # ]: 0 : if( allocated_array ) free( array );
625 [ # # ]: 0 : ERROR( result, "iMesh_getEntArrAdj: trouble getting adjacency list." );
626 : : }
627 : : }
628 [ + - ]: 2 : connect = &adj_ents[0];
629 : 2 : num_connect = adj_ents.size();
630 : : }
631 : : else
632 : : {
633 [ + - ][ + - ]: 3657 : if( CN::Dimension( TYPE_FROM_HANDLE( *entity_iter ) ) == entity_type_requested ) continue;
[ - + ]
634 : 3657 : adj_ents.clear();
635 [ + - ]: 3657 : result = MOABI->get_adjacencies( entity_iter, 1, entity_type_requested, false, adj_ents );
636 [ - + ]: 3657 : if( MB_SUCCESS != result )
637 : : {
638 [ # # ]: 0 : if( allocated_array ) free( array );
639 [ # # ]: 0 : ERROR( result, "iMesh_getEntArrAdj: trouble getting adjacency list." );
640 : : }
641 [ + - ]: 3657 : connect = &adj_ents[0];
642 : 3657 : num_connect = adj_ents.size();
643 : : }
644 : :
645 [ + + ][ + - ]: 9623 : if( prev_off + num_connect <= array_alloc ) { std::copy( connect, connect + num_connect, array + prev_off ); }
646 [ + + ]: 191 : else if( allocated_array )
647 : : {
648 : : // if array is not allocated yet, guess at initial size
649 : : // as the number of adjacencies for the first entity times
650 : : // the number of input entities. This will result in a single
651 : : // exact allocation if one input entity or typical queries
652 : : // such as connectivity of a non-mixed mesh or regions adjacent
653 : : // to faces.
654 [ + + ]: 190 : if( !array_alloc )
655 : 189 : array_alloc = entity_handles_size * num_connect;
656 : : else
657 [ + - ]: 1 : array_alloc = std::max( array_alloc * 2, prev_off + num_connect );
658 : 190 : EntityHandle* new_array = (EntityHandle*)realloc( array, array_alloc * sizeof( EntityHandle ) );
659 [ - + ]: 190 : if( !new_array )
660 : : {
661 : 0 : free( array );
662 [ # # ]: 0 : RETURN( iBase_MEMORY_ALLOCATION_FAILED );
663 : : }
664 : : else
665 : 190 : array = new_array;
666 [ + - ]: 190 : std::copy( connect, connect + num_connect, array + prev_off );
667 : : }
668 : : // else do nothing. Will catch error later when comparing
669 : : // occupied to allocated sizes. Continue here because
670 : : // must pass back required size.
671 : :
672 : 9623 : prev_off += num_connect;
673 : : }
674 : 3021 : *off_iter = prev_off;
675 : 3021 : *adjacentEntityHandles_size = prev_off;
676 : :
677 [ + + ]: 3021 : if( *adjacentEntityHandles_size > array_alloc )
678 : : {
679 [ - + ]: 1 : if( allocated_array ) free( array );
680 [ + - ]: 1 : RETURN( iBase_BAD_ARRAY_SIZE );
681 : : }
682 [ + + ]: 3020 : else if( allocated_array )
683 : : {
684 : 190 : *adjacentEntityHandles = reinterpret_cast< iBase_EntityHandle* >( array );
685 : 190 : *adjacentEntityHandles_allocated = array_alloc;
686 : : }
687 : :
688 [ + - ]: 3020 : KEEP_ARRAY( offset );
689 [ + - ]: 6042 : RETURN( iBase_SUCCESS );
690 : : }
691 : :
692 : 0 : void iMesh_getEntArr2ndAdj( iMesh_Instance instance, iBase_EntityHandle const* entity_handles, int entity_handles_size,
693 : : int bridge_entity_type, int requested_entity_type, iBase_EntityHandle** adj_entity_handles,
694 : : int* adj_entity_handles_allocated, int* adj_entity_handles_size, int** offset,
695 : : int* offset_allocated, int* offset_size, int* err )
696 : : {
697 [ # # ][ # # ]: 0 : CHKENUM( bridge_entity_type, iBase_EntityType, iBase_INVALID_ENTITY_TYPE );
[ # # ]
698 [ # # ][ # # ]: 0 : CHKENUM( requested_entity_type, iBase_EntityType, iBase_INVALID_ENTITY_TYPE );
[ # # ]
699 : :
700 : 0 : ErrorCode result = MB_SUCCESS;
701 : :
702 [ # # ][ # # ]: 0 : ALLOC_CHECK_ARRAY( offset, entity_handles_size + 1 );
703 : :
704 : 0 : const EntityHandle* entity_iter = (const EntityHandle*)entity_handles;
705 : 0 : const EntityHandle* const entity_end = entity_iter + entity_handles_size;
706 : 0 : int* off_iter = *offset;
707 : 0 : int prev_off = 0;
708 : :
709 [ # # ]: 0 : std::vector< EntityHandle > all_adj_ents;
710 [ # # ]: 0 : MeshTopoUtil mtu( MOABI );
711 : :
712 : 0 : int min_bridge = iBase_VERTEX, max_bridge = iBase_REGION;
713 : 0 : int min_req = iBase_VERTEX, max_req = iBase_REGION;
714 [ # # ]: 0 : if( iBase_ALL_TYPES != bridge_entity_type ) min_bridge = max_bridge = bridge_entity_type;
715 [ # # ]: 0 : if( iBase_ALL_TYPES != requested_entity_type ) min_req = max_req = requested_entity_type;
716 : :
717 [ # # ]: 0 : for( ; entity_iter != entity_end; ++entity_iter )
718 : : {
719 : 0 : *off_iter = prev_off;
720 : 0 : off_iter++;
721 [ # # ]: 0 : Range adj_ents;
722 : :
723 [ # # ][ # # ]: 0 : int source = CN::Dimension( TYPE_FROM_HANDLE( *entity_iter ) );
724 [ # # ]: 0 : for( int bridge = min_bridge; bridge <= max_bridge; ++bridge )
725 : : {
726 [ # # ]: 0 : if( source == bridge ) continue;
727 [ # # ]: 0 : for( int requested = min_req; requested <= max_req; ++requested )
728 : : {
729 [ # # ]: 0 : if( bridge == requested ) continue;
730 [ # # ][ # # ]: 0 : result = mtu.get_bridge_adjacencies( *entity_iter, bridge, requested, adj_ents );CHKERR( result, "iMesh_getEntArr2ndAdj: trouble getting adjacency list." );
[ # # ]
731 : : }
732 : : }
733 : :
734 [ # # ][ # # ]: 0 : std::copy( adj_ents.begin(), adj_ents.end(), std::back_inserter( all_adj_ents ) );
[ # # ][ # # ]
735 [ # # ][ # # ]: 0 : prev_off += adj_ents.size();
736 : 0 : }
737 : 0 : *off_iter = prev_off;
738 : :
739 [ # # ][ # # ]: 0 : ALLOC_CHECK_ARRAY_NOFAIL( adj_entity_handles, all_adj_ents.size() );
[ # # ]
740 [ # # ]: 0 : memcpy( *adj_entity_handles, &all_adj_ents[0], sizeof( EntityHandle ) * all_adj_ents.size() );
741 : :
742 [ # # ]: 0 : KEEP_ARRAY( offset );
743 : :
744 : : // Return an error if the bridge and requested entity types are different
745 [ # # ][ # # ]: 0 : if( iBase_ALL_TYPES != bridge_entity_type && bridge_entity_type == requested_entity_type )
746 [ # # ]: 0 : ERROR( iBase_INVALID_ARGUMENT, "iMesh_getEntArr2ndAdj: bridge and "
747 : : "requested entity types must be different." );
748 : : else
749 [ # # ]: 0 : RETURN( iBase_SUCCESS );
750 : : }
751 : :
752 : 3 : void iMesh_getAdjEntIndices( iMesh_Instance instance,
753 : : /*in*/ iBase_EntitySetHandle entity_set_handle,
754 : : /*in*/ int entity_type_requestor,
755 : : /*in*/ int entity_topology_requestor,
756 : : /*in*/ int entity_type_requested,
757 : : /*inout*/ iBase_EntityHandle** entity_handles,
758 : : /*inout*/ int* entity_handles_allocated,
759 : : /*out*/ int* entity_handles_size,
760 : : /*inout*/ iBase_EntityHandle** adj_entity_handles,
761 : : /*inout*/ int* adj_entity_handles_allocated,
762 : : /*out*/ int* adj_entity_handles_size,
763 : : /*inout*/ int** adj_entity_indices,
764 : : /*inout*/ int* adj_entity_indices_allocated,
765 : : /*out*/ int* adj_entity_indices_size,
766 : : /*inout*/ int** offset,
767 : : /*inout*/ int* offset_allocated,
768 : : /*out*/ int* offset_size,
769 : : /*out*/ int* err )
770 : : {
771 : 3 : const int allocated_entity_handles = ( *entity_handles_allocated == 0 );
772 : 3 : const int allocated_indices = ( *adj_entity_indices_allocated == 0 );
773 : 3 : const int allocated_offset = ( *offset_allocated == 0 );
774 : :
775 : : // get source entities
776 : : iMesh_getEntities( instance, entity_set_handle, entity_type_requestor, entity_topology_requestor, entity_handles,
777 [ + - ]: 3 : entity_handles_allocated, entity_handles_size, err );
778 [ - + ]: 6 : if( iBase_SUCCESS != *err ) return;
779 : :
780 : : // get adjacencies
781 : 3 : iBase_EntityHandle* all_adj_handles = 0;
782 : 3 : int size = 0, alloc = 0;
783 : : iMesh_getEntArrAdj( instance, *entity_handles, *entity_handles_size, entity_type_requested, &all_adj_handles,
784 [ + - ]: 3 : &alloc, &size, offset, offset_allocated, offset_size, err );
785 [ - + ]: 3 : if( *err != iBase_SUCCESS )
786 : : {
787 [ # # ]: 0 : if( allocated_entity_handles )
788 : : {
789 : 0 : free( *entity_handles );
790 : 0 : *entity_handles = 0;
791 : 0 : *entity_handles_allocated = 0;
792 : : }
793 : 0 : return;
794 : : }
795 : :
796 : : // allocate or check size of adj_entity_indices
797 : 3 : *adj_entity_indices_size = size;
798 [ + - ]: 3 : if( allocated_indices )
799 : : {
800 : 3 : *adj_entity_indices = (int*)malloc( sizeof( iBase_EntityHandle ) * size );
801 [ - + ]: 3 : if( !*adj_entity_indices )
802 : 0 : *err = iBase_MEMORY_ALLOCATION_FAILED;
803 : : else
804 : 3 : *adj_entity_indices_allocated = size;
805 : : }
806 [ # # ]: 0 : else if( *adj_entity_indices_allocated < size )
807 : : {
808 : 0 : *err = iBase_BAD_ARRAY_DIMENSION;
809 : : }
810 [ - + ]: 3 : if( iBase_SUCCESS != *err )
811 : : {
812 : 0 : free( all_adj_handles );
813 [ # # ]: 0 : if( allocated_entity_handles )
814 : : {
815 : 0 : free( *entity_handles );
816 : 0 : *entity_handles = 0;
817 : 0 : *entity_handles_allocated = 0;
818 : : }
819 [ # # ]: 0 : if( allocated_offset )
820 : : {
821 : 0 : free( *offset );
822 : 0 : *offset = 0;
823 : 0 : *offset_allocated = 0;
824 : : }
825 : 0 : return;
826 : : }
827 : :
828 : : // Now create an array of unique sorted handles from all_adj_handles.
829 : : // We need to create a copy because we still need all_adj_handles. We
830 : : // will eventually need to copy the resulting unique list into
831 : : // adj_entity_handles, so if adj_entity_handles is already allocated and
832 : : // of sufficient size, use it rather than allocating another temporary.
833 : 3 : iBase_EntityHandle* unique_adj = 0;
834 [ - + ]: 3 : if( *adj_entity_handles_allocated >= size ) { unique_adj = *adj_entity_handles; }
835 : : else
836 : : {
837 : 3 : unique_adj = (iBase_EntityHandle*)malloc( sizeof( iBase_EntityHandle ) * size );
838 : : }
839 [ + - ]: 3 : std::copy( all_adj_handles, all_adj_handles + size, unique_adj );
840 [ + - ]: 3 : std::sort( unique_adj, unique_adj + size );
841 [ + - ]: 3 : *adj_entity_handles_size = std::unique( unique_adj, unique_adj + size ) - unique_adj;
842 : :
843 : : // If we created a temporary array for unique_adj rather than using
844 : : // already allocated space in adj_entity_handles, allocate adj_entity_handles
845 : : // and copy the unique handle list into it
846 [ + - ]: 3 : if( *adj_entity_handles != unique_adj )
847 : : {
848 [ + - ]: 3 : if( !*adj_entity_handles_allocated )
849 : : {
850 : : *adj_entity_handles =
851 : 3 : (iBase_EntityHandle*)malloc( sizeof( iBase_EntityHandle ) * *adj_entity_handles_size );
852 [ - + ]: 3 : if( !*adj_entity_handles )
853 : 0 : *err = iBase_MEMORY_ALLOCATION_FAILED;
854 : : else
855 : 3 : *adj_entity_handles_allocated = *adj_entity_handles_size;
856 : : }
857 [ # # ]: 0 : else if( *adj_entity_handles_allocated < *adj_entity_handles_size )
858 : 0 : *err = iBase_BAD_ARRAY_DIMENSION;
859 [ - + ]: 3 : if( iBase_SUCCESS != *err )
860 : : {
861 : 0 : free( unique_adj );
862 : 0 : free( all_adj_handles );
863 [ # # ]: 0 : if( allocated_entity_handles )
864 : : {
865 : 0 : free( *entity_handles );
866 : 0 : *entity_handles = 0;
867 : 0 : *entity_handles_allocated = 0;
868 : : }
869 [ # # ]: 0 : if( allocated_offset )
870 : : {
871 : 0 : free( *offset );
872 : 0 : *offset = 0;
873 : 0 : *offset_allocated = 0;
874 : : }
875 [ # # ]: 0 : if( allocated_indices )
876 : : {
877 : 0 : free( *adj_entity_indices );
878 : 0 : *adj_entity_indices = 0;
879 : 0 : *adj_entity_indices_allocated = 0;
880 : : }
881 : 0 : return;
882 : : }
883 : :
884 [ + - ]: 3 : std::copy( unique_adj, unique_adj + *adj_entity_handles_size, *adj_entity_handles );
885 : 3 : free( unique_adj );
886 : 3 : unique_adj = *adj_entity_handles;
887 : : }
888 : :
889 : : // convert from adjacency list to indices into unique_adj
890 [ + + ]: 12803 : for( int i = 0; i < *adj_entity_indices_size; ++i )
891 : 12800 : ( *adj_entity_indices )[i] =
892 [ + - ]: 12800 : std::lower_bound( unique_adj, unique_adj + *adj_entity_handles_size, all_adj_handles[i] ) - unique_adj;
893 : 3 : free( all_adj_handles );
894 : : }
895 : :
896 : 33 : void iMesh_createEntSet( iMesh_Instance instance,
897 : : /*in*/ const int isList,
898 : : /*out*/ iBase_EntitySetHandle* entity_set_created, int* err )
899 : : {
900 : : // create the entity set
901 : : EntityHandle meshset;
902 : : ErrorCode result;
903 : :
904 [ + + ]: 33 : if( isList )
905 [ + - ]: 16 : result = MOABI->create_meshset( MESHSET_ORDERED, meshset );
906 : : else
907 [ + - ]: 17 : result = MOABI->create_meshset( MESHSET_SET, meshset );
908 : :
909 [ - + ][ # # ]: 33 : CHKERR( result, "iMesh_createEntSet: ERROR creating a entityset instance" );
910 : :
911 : : // return EntitySet_Handle
912 : 33 : *entity_set_created = (iBase_EntitySetHandle)meshset;
913 [ + - ]: 33 : RETURN( iBase_SUCCESS );
914 : : }
915 : :
916 : 4 : void iMesh_destroyEntSet( iMesh_Instance instance,
917 : : /*in*/ iBase_EntitySetHandle entity_set, int* err )
918 : : {
919 : 4 : EntityHandle set = ENTITY_HANDLE( entity_set );
920 [ + - ][ - + ]: 4 : ErrorCode result = MOABI->delete_entities( &set, 1 );CHKERR( result, "iMesh_destroyEntSet: couldn't delete the set." );
[ # # ]
921 : :
922 [ + - ]: 4 : RETURN( iBase_SUCCESS );
923 : : }
924 : :
925 : 54 : void iMesh_isList( iMesh_Instance instance,
926 : : /*in*/ const iBase_EntitySetHandle entity_set, int* is_list, int* err )
927 : : {
928 : : unsigned int options;
929 [ + - ][ - + ]: 54 : ErrorCode result = MOABI->get_meshset_options( ENTITY_HANDLE( entity_set ), options );CHKERR( result, "iMesh_isList: couldn't query set." );
[ # # ]
930 [ + + ]: 54 : if( options & MESHSET_ORDERED )
931 : 25 : *is_list = true;
932 : : else
933 : 29 : *is_list = false;
934 : :
935 [ + - ]: 54 : RETURN( iBase_SUCCESS );
936 : : }
937 : :
938 : 18 : void iMesh_getNumEntSets( iMesh_Instance instance,
939 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
940 : : /*in*/ const int num_hops, int* num_sets, int* err )
941 : : {
942 : : ErrorCode rval =
943 [ + - ][ + - ]: 18 : MOABI->num_contained_meshsets( ENTITY_HANDLE( entity_set_handle ), num_sets, std::max( 0, num_hops + 1 ) );CHKERR( rval, "iMesh_entitysetGetNumberEntitySets:ERROR getting number of entitysets." );
[ - + ]
944 : :
945 : 18 : RETURN( iBase_SUCCESS );
946 : : }
947 : :
948 : 13 : void iMesh_getEntSets( iMesh_Instance instance,
949 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
950 : : /*in*/ const int num_hops,
951 : : /*inout*/ iBase_EntitySetHandle** contained_entset_handles,
952 : : /*inout*/ int* contained_entset_handles_allocated,
953 : : /*inout*/ int* contained_entset_handles_size, int* err )
954 : : {
955 [ + - ]: 13 : std::vector< EntityHandle > sets;
956 : : ErrorCode rval =
957 [ + - ][ + - ]: 13 : MOABI->get_contained_meshsets( ENTITY_HANDLE( entity_set_handle ), sets, std::max( num_hops + 1, 0 ) );CHKERR( rval, "iMesh_entitysetGetEntitySets: problem getting entities by type." );
[ - + ][ # # ]
958 [ + - ][ - + ]: 26 : ALLOC_CHECK_ARRAY_NOFAIL( contained_entset_handles, sets.size() );
[ + - ]
959 : :
960 [ + - ]: 13 : std::copy( sets.begin(), sets.end(), (EntityHandle*)*contained_entset_handles );
961 : 13 : *contained_entset_handles_size = sets.size();
962 [ + - ]: 26 : RETURN( iBase_SUCCESS );
963 : : }
964 : :
965 : 52 : void iMesh_addEntArrToSet( iMesh_Instance instance,
966 : : /*in*/ const iBase_EntityHandle* entity_handles,
967 : : /*in*/ int entity_handles_size,
968 : : /*in*/ iBase_EntitySetHandle entity_set, int* err )
969 : : {
970 : 52 : const EntityHandle* ents = CONST_HANDLE_ARRAY_PTR( entity_handles );
971 : 52 : ErrorCode result = MOABI->add_entities( ENTITY_HANDLE( entity_set ), ents, entity_handles_size );
972 : :
973 [ - + ]: 52 : CHKERR( result, "iMesh_addEntArrToSet:ERROR adding entities in EntitySet." );
974 : 52 : RETURN( iBase_SUCCESS );
975 : : }
976 : :
977 : 0 : void iMesh_addEntToSet( iMesh_Instance instance,
978 : : /*in*/ iBase_EntityHandle entity_handle,
979 : : /*in*/ iBase_EntitySetHandle entity_set, int* err )
980 : : {
981 : 0 : iMesh_addEntArrToSet( instance, &entity_handle, 1, entity_set, err );
982 : 0 : }
983 : :
984 : 2 : void iMesh_rmvEntArrFromSet( iMesh_Instance instance,
985 : : /*in*/ const iBase_EntityHandle* entity_handles,
986 : : /*in*/ int entity_handles_size,
987 : : /*in*/ iBase_EntitySetHandle entity_set, int* err )
988 : : {
989 : 2 : const EntityHandle* ents = CONST_HANDLE_ARRAY_PTR( entity_handles );
990 : :
991 : 2 : ErrorCode result = MOABI->remove_entities( ENTITY_HANDLE( entity_set ), ents, entity_handles_size );
992 : :
993 [ - + ]: 2 : CHKERR( result, "iMesh_rmvEntArrFromSet:ERROR removing entities in EntitySet." );
994 : 2 : RETURN( iBase_SUCCESS );
995 : : }
996 : :
997 : 0 : void iMesh_rmvEntFromSet( iMesh_Instance instance,
998 : : /*in*/ iBase_EntityHandle entity_handle,
999 : : /*in*/ iBase_EntitySetHandle entity_set, int* err )
1000 : : {
1001 : 0 : iMesh_rmvEntArrFromSet( instance, &entity_handle, 1, entity_set, err );
1002 : 0 : }
1003 : :
1004 : 73 : void iMesh_addEntSet( iMesh_Instance instance,
1005 : : /*in*/ iBase_EntitySetHandle entity_set_to_add,
1006 : : /*in*/ iBase_EntitySetHandle entity_set_handle, int* err )
1007 : : {
1008 [ + - ][ - + ]: 73 : if( !entity_set_to_add || !entity_set_handle )
1009 [ # # ]: 0 : ERROR( iBase_INVALID_ARGUMENT, "iMesh_addEntSet: ERROR invalid argument" );
1010 : :
1011 : 73 : EntityHandle to_add = ENTITY_HANDLE( entity_set_to_add );
1012 [ + - ]: 73 : ErrorCode result = MOABI->add_entities( ENTITY_HANDLE( entity_set_handle ), &to_add, 1 );
1013 : :
1014 [ - + ][ # # ]: 73 : CHKERR( result, "iMesh_addEntSet:ERROR adding entitysets." );
1015 [ + - ]: 73 : RETURN( iBase_SUCCESS );
1016 : : }
1017 : :
1018 : 1 : void iMesh_rmvEntSet( iMesh_Instance instance,
1019 : : /*in*/ iBase_EntitySetHandle entity_set_to_remove,
1020 : : /*in*/ iBase_EntitySetHandle entity_set_handle, int* err )
1021 : : {
1022 [ + - ][ - + ]: 1 : if( !entity_set_to_remove || !entity_set_handle )
1023 [ # # ]: 0 : ERROR( iBase_INVALID_ARGUMENT, "iMesh_rmvEntSet: ERROR invalid argument" );
1024 : :
1025 : 1 : EntityHandle to_remove = ENTITY_HANDLE( entity_set_to_remove );
1026 [ + - ]: 1 : ErrorCode result = MOABI->remove_entities( ENTITY_HANDLE( entity_set_handle ), &to_remove, 1 );
1027 : :
1028 [ - + ][ # # ]: 1 : CHKERR( result, "iMesh_rmvEntSet:ERROR removing entitysets in EntitySet." );
1029 [ + - ]: 1 : RETURN( iBase_SUCCESS );
1030 : : }
1031 : :
1032 : 2 : void iMesh_isEntContained( iMesh_Instance instance,
1033 : : /*in*/ iBase_EntitySetHandle containing_entity_set,
1034 : : /*in*/ iBase_EntityHandle contained_entity, int* is_contained, int* err )
1035 : : {
1036 : 2 : int junk1 = 1, junk2 = 1;
1037 : : iMesh_isEntArrContained( instance, containing_entity_set, &contained_entity, 1, &is_contained, &junk1, &junk2,
1038 [ + - ]: 2 : err );
1039 : 2 : }
1040 : :
1041 : 2 : void iMesh_isEntArrContained( iMesh_Instance instance,
1042 : : /*in*/ iBase_EntitySetHandle containing_set,
1043 : : /*in*/ const iBase_EntityHandle* entity_handles,
1044 : : /*in*/ int num_entity_handles,
1045 : : /*inout*/ int** is_contained,
1046 : : /*inout*/ int* is_contained_allocated,
1047 : : /*out*/ int* is_contained_size,
1048 : : /*out*/ int* err )
1049 : :
1050 : : {
1051 : 2 : EntityHandle set = ENTITY_HANDLE( containing_set );
1052 [ + - ][ - + ]: 2 : ALLOC_CHECK_ARRAY_NOFAIL( is_contained, num_entity_handles );
[ + - ]
1053 : 2 : *is_contained_size = num_entity_handles;
1054 : :
1055 [ + - ]: 2 : if( containing_set )
1056 : : {
1057 [ + + ]: 4 : for( int i = 0; i < num_entity_handles; ++i )
1058 : : {
1059 : 2 : EntityHandle h = ENTITY_HANDLE( entity_handles[i] );
1060 [ + - ]: 2 : ( *is_contained )[i] = MOABI->contains_entities( set, &h, 1 );
1061 : : }
1062 : : }
1063 : : else
1064 : : {
1065 [ # # ]: 0 : std::fill( *is_contained, ( *is_contained ) + num_entity_handles, 1 );
1066 : : }
1067 [ + - ]: 2 : RETURN( iBase_SUCCESS );
1068 : : }
1069 : :
1070 : 2 : void iMesh_isEntSetContained( iMesh_Instance instance,
1071 : : /*in*/ const iBase_EntitySetHandle containing_entity_set,
1072 : : /*in*/ const iBase_EntitySetHandle contained_entity_set, int* is_contained, int* err )
1073 : : {
1074 : : iMesh_isEntContained( instance, containing_entity_set,
1075 : 2 : reinterpret_cast< iBase_EntityHandle >( contained_entity_set ), is_contained, err );
1076 : 2 : }
1077 : :
1078 : 2 : void iMesh_addPrntChld( iMesh_Instance instance,
1079 : : /*inout*/ iBase_EntitySetHandle parent_entity_set,
1080 : : /*inout*/ iBase_EntitySetHandle child_entity_set, int* err )
1081 : : {
1082 : 2 : ErrorCode result = MOABI->add_parent_child( ENTITY_HANDLE( parent_entity_set ), ENTITY_HANDLE( child_entity_set ) );
1083 : :
1084 [ - + ]: 2 : if( result == MB_ENTITY_NOT_FOUND )
1085 [ - + ]: 2 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_addPrntChld: ERROR invalid entity set." );CHKERR( result, "iMesh_addPrntChld: ERROR addParentChild failed." );
1086 : 2 : RETURN( iBase_SUCCESS );
1087 : : }
1088 : :
1089 : 0 : void iMesh_rmvPrntChld( iMesh_Instance instance,
1090 : : /*inout*/ iBase_EntitySetHandle parent_entity_set,
1091 : : /*inout*/ iBase_EntitySetHandle child_entity_set, int* err )
1092 : : {
1093 : : ErrorCode result =
1094 : 0 : MOABI->remove_parent_child( ENTITY_HANDLE( parent_entity_set ), ENTITY_HANDLE( child_entity_set ) );
1095 : :
1096 [ # # ]: 0 : if( result == MB_ENTITY_NOT_FOUND )
1097 [ # # ]: 0 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_rmvPrntChld: ERROR invalid entity set." );CHKERR( result, "iMesh_rmvPrntChld: ERROR RemoveParentChild failed." );
1098 : 0 : RETURN( iBase_SUCCESS );
1099 : : }
1100 : :
1101 : 4 : void iMesh_isChildOf( iMesh_Instance instance,
1102 : : /*in*/ const iBase_EntitySetHandle parent_entity_set,
1103 : : /*in*/ const iBase_EntitySetHandle child_entity_set, int* is_child, int* err )
1104 : : {
1105 [ - + ][ # # ]: 4 : if( !child_entity_set ) ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_isChildOf: ERROR invalid entity set." );
1106 : :
1107 [ + - ]: 4 : std::vector< EntityHandle > children;
1108 : :
1109 [ + - ]: 4 : ErrorCode result = MOABI->get_child_meshsets( ENTITY_HANDLE( parent_entity_set ), children );
1110 : :
1111 [ - + ]: 4 : if( result == MB_ENTITY_NOT_FOUND )
1112 [ # # ][ - + ]: 4 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_rmvPrntChld: ERROR invalid entity set." );CHKERR( result, "iMesh_isChildOf: ERROR IsParentChildRelated failed." );
[ # # ]
1113 : :
1114 [ + - ][ + - ]: 4 : if( std::find( children.begin(), children.end(), ENTITY_HANDLE( child_entity_set ) ) != children.end() )
[ + + ]
1115 : 2 : *is_child = true;
1116 : :
1117 : : else
1118 : 2 : *is_child = false;
1119 : :
1120 [ + - ]: 4 : RETURN( iBase_SUCCESS );
1121 : : }
1122 : :
1123 : 2 : void iMesh_getNumChld( iMesh_Instance instance,
1124 : : /*in*/ const iBase_EntitySetHandle entity_set,
1125 : : /*in*/ const int num_hops, int* num_child, int* err )
1126 : : {
1127 : 2 : *num_child = 0;
1128 : 2 : ErrorCode result = MOABI->num_child_meshsets( ENTITY_HANDLE( entity_set ), num_child, num_hops + 1 );
1129 : :
1130 [ - + ]: 2 : if( result == MB_ENTITY_NOT_FOUND )
1131 [ - + ]: 2 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_getNumChld: ERROR invalid entity set." );CHKERR( result, "iMesh_getNumChld: ERROR GetNumChildren failed." );
1132 : :
1133 : 2 : RETURN( iBase_SUCCESS );
1134 : : }
1135 : :
1136 : 0 : void iMesh_getNumPrnt( iMesh_Instance instance,
1137 : : /*in*/ const iBase_EntitySetHandle entity_set,
1138 : : /*in*/ const int num_hops, int* num_parent, int* err )
1139 : : {
1140 : 0 : *num_parent = 0;
1141 : 0 : ErrorCode result = MOABI->num_parent_meshsets( ENTITY_HANDLE( entity_set ), num_parent, num_hops + 1 );
1142 : :
1143 [ # # ]: 0 : if( result == MB_ENTITY_NOT_FOUND )
1144 [ # # ]: 0 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_getNumPrnt: ERROR invalid entity set." );CHKERR( result, "iMesh_getNumPrnt: ERROR GetNumParents failed." );
1145 : 0 : RETURN( iBase_SUCCESS );
1146 : : }
1147 : :
1148 : 0 : void iMesh_getChldn( iMesh_Instance instance,
1149 : : /*in*/ const iBase_EntitySetHandle from_entity_set,
1150 : : /*in*/ const int num_hops,
1151 : : /*out*/ iBase_EntitySetHandle** entity_set_handles,
1152 : : /*out*/ int* entity_set_handles_allocated,
1153 : : /*out*/ int* entity_set_handles_size, int* err )
1154 : : {
1155 [ # # ]: 0 : std::vector< EntityHandle > children;
1156 : :
1157 [ # # ]: 0 : ErrorCode result = MOABI->get_child_meshsets( ENTITY_HANDLE( from_entity_set ), children, num_hops + 1 );
1158 : :
1159 [ # # ]: 0 : if( result == MB_ENTITY_NOT_FOUND )
1160 [ # # ][ # # ]: 0 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_getChldn: ERROR invalid entity set." );CHKERR( result, "ERROR getChildren failed." );
[ # # ]
1161 [ # # ][ # # ]: 0 : ALLOC_CHECK_ARRAY_NOFAIL( entity_set_handles, children.size() );
[ # # ]
1162 : :
1163 : 0 : EntityHandle* ents = HANDLE_ARRAY_PTR( *entity_set_handles );
1164 : : // use a memcpy for efficiency
1165 [ # # ]: 0 : memcpy( ents, &children[0], children.size() * sizeof( EntityHandle ) );
1166 : :
1167 [ # # ]: 0 : RETURN( iBase_SUCCESS );
1168 : : }
1169 : :
1170 : 2 : void iMesh_getPrnts( iMesh_Instance instance,
1171 : : /*in*/ const iBase_EntitySetHandle from_entity_set,
1172 : : /*in*/ const int num_hops,
1173 : : /*out*/ iBase_EntitySetHandle** entity_set_handles,
1174 : : /*out*/ int* entity_set_handles_allocated,
1175 : : /*out*/ int* entity_set_handles_size, int* err )
1176 : : {
1177 [ + - ]: 2 : std::vector< EntityHandle > parents;
1178 : :
1179 [ + - ]: 2 : ErrorCode result = MOABI->get_parent_meshsets( ENTITY_HANDLE( from_entity_set ), parents, num_hops + 1 );
1180 : :
1181 [ - + ]: 2 : if( result == MB_ENTITY_NOT_FOUND )
1182 [ # # ][ - + ]: 2 : ERROR( iBase_INVALID_ENTITYSET_HANDLE, "iMesh_getPrnts: ERROR invalid entity set." );CHKERR( result, "ERROR getParents failed." );
[ # # ]
1183 : :
1184 [ + - ][ - + ]: 4 : ALLOC_CHECK_ARRAY_NOFAIL( entity_set_handles, parents.size() );
[ + - ]
1185 : :
1186 : 2 : EntityHandle* ents = HANDLE_ARRAY_PTR( *entity_set_handles );
1187 : : // use a memcpy for efficiency
1188 [ + - ]: 2 : memcpy( ents, &parents[0], parents.size() * sizeof( EntityHandle ) );
1189 : :
1190 [ + - ]: 4 : RETURN( iBase_SUCCESS );
1191 : : }
1192 : :
1193 : 0 : void iMesh_setVtxArrCoords( iMesh_Instance instance,
1194 : : /*in*/ const iBase_EntityHandle* vertex_handles,
1195 : : /*in*/ const int vertex_handles_size,
1196 : : /*in*/ const int storage_order,
1197 : : /*in*/ const double* new_coords,
1198 : : /*in*/ const int new_coords_size, int* err )
1199 : : {
1200 [ # # ][ # # ]: 0 : CHKENUM( storage_order, iBase_StorageOrder, iBase_INVALID_ARGUMENT );
[ # # ]
1201 : :
1202 : : int geom_dim;
1203 [ # # ]: 0 : MOABI->get_dimension( geom_dim );
1204 [ # # ]: 0 : if( new_coords_size != geom_dim * vertex_handles_size )
1205 [ # # ]: 0 : { ERROR( iBase_INVALID_ARGUMENT, "iMesh_setVtxArrCoords: Didn't get the right # coordinates." ); }
1206 : :
1207 : 0 : ErrorCode result = MB_SUCCESS, tmp_result;
1208 [ # # ]: 0 : if( storage_order == iBase_INTERLEAVED )
1209 : : {
1210 [ # # ]: 0 : if( 3 == geom_dim )
1211 [ # # ]: 0 : { result = MOABI->set_coords( CONST_HANDLE_ARRAY_PTR( vertex_handles ), vertex_handles_size, new_coords ); }
1212 : : else
1213 : : {
1214 : 0 : const EntityHandle* verts = CONST_HANDLE_ARRAY_PTR( vertex_handles );
1215 : 0 : double dummy[3] = { 0, 0, 0 };
1216 [ # # ]: 0 : for( int i = 0; i < vertex_handles_size; i++ )
1217 : : {
1218 [ # # ]: 0 : for( int j = 0; j < geom_dim; j++ )
1219 : 0 : dummy[j] = new_coords[geom_dim * i + j];
1220 [ # # ]: 0 : tmp_result = MOABI->set_coords( &verts[i], 1, dummy );
1221 [ # # ]: 0 : if( MB_SUCCESS != tmp_result ) result = tmp_result;
1222 : : }
1223 : : }
1224 : : }
1225 : : else
1226 : : {
1227 : 0 : const EntityHandle* verts = CONST_HANDLE_ARRAY_PTR( vertex_handles );
1228 : 0 : double dummy[3] = { 0, 0, 0 };
1229 [ # # ]: 0 : for( int i = 0; i < vertex_handles_size; i++ )
1230 : : {
1231 [ # # ]: 0 : for( int j = 0; j < geom_dim; j++ )
1232 : 0 : dummy[j] = new_coords[i + vertex_handles_size * j];
1233 [ # # ]: 0 : tmp_result = MOABI->set_coords( &verts[i], 1, dummy );
1234 [ # # ]: 0 : if( MB_SUCCESS != tmp_result ) result = tmp_result;
1235 : : }
1236 : : }
1237 : :
1238 [ # # ][ # # ]: 0 : CHKERR( result, "iMesh_setVtxArrCoords: problem setting coordinates." );
1239 : :
1240 [ # # ]: 0 : RETURN( iBase_SUCCESS );
1241 : : }
1242 : :
1243 : 90 : void iMesh_createVtxArr( iMesh_Instance instance,
1244 : : /*in*/ const int num_verts,
1245 : : /*in*/ const int storage_order,
1246 : : /*in*/ const double* new_coords,
1247 : : /*in*/ const int new_coords_size,
1248 : : /*inout*/ iBase_EntityHandle** new_vertex_handles,
1249 : : /*inout*/ int* new_vertex_handles_allocated,
1250 : : /*inout*/ int* new_vertex_handles_size, int* err )
1251 : : {
1252 : : int geom_dim;
1253 [ + - ]: 90 : MOABI->get_dimension( geom_dim );
1254 [ - + ]: 90 : if( new_coords_size != geom_dim * num_verts )
1255 [ # # ]: 0 : { ERROR( iBase_INVALID_ARGUMENT, "iMesh_createVtxArr: Didn't get the right # coordinates." ); }
1256 : :
1257 : : // if there aren't any elements in the array, allocate it
1258 [ + - ][ - + ]: 90 : ALLOC_CHECK_ARRAY( new_vertex_handles, num_verts );
1259 : :
1260 : : // make the entities
1261 : 90 : EntityHandle* new_verts = HANDLE_ARRAY_PTR( *new_vertex_handles );
1262 : :
1263 [ + + ]: 90 : if( storage_order == iBase_INTERLEAVED )
1264 : : {
1265 [ + - ]: 63 : if( 3 == geom_dim )
1266 : : {
1267 [ + + ]: 296 : for( int i = 0; i < num_verts; i++ )
1268 : : {
1269 [ + - ][ - + ]: 233 : ErrorCode result = MOABI->create_vertex( &new_coords[3 * i], new_verts[i] );CHKERR( result, "iMesh_createVtxArr: couldn't create vertex." );
[ # # ]
1270 : : }
1271 : : }
1272 : : else
1273 : : {
1274 : 0 : double tmp[3] = { 0, 0, 0 };
1275 [ # # ]: 0 : for( int i = 0; i < num_verts; i++ )
1276 : : {
1277 [ # # ]: 0 : for( int j = 0; j < geom_dim; j++ )
1278 : 0 : tmp[j] = new_coords[geom_dim * i + j];
1279 [ # # ][ # # ]: 63 : ErrorCode result = MOABI->create_vertex( tmp, new_verts[i] );CHKERR( result, "iMesh_createVtxArr: couldn't create vertex." );
[ # # ]
1280 : : }
1281 : : }
1282 : : }
1283 : : else
1284 : : {
1285 : 27 : double tmp[3] = { 0, 0, 0 };
1286 [ + + ]: 54 : for( int i = 0; i < num_verts; i++ )
1287 : : {
1288 [ + + ]: 108 : for( int j = 0; j < geom_dim; j++ )
1289 : 81 : tmp[j] = new_coords[j * num_verts + i];
1290 : :
1291 [ + - ][ - + ]: 27 : ErrorCode result = MOABI->create_vertex( tmp, new_verts[i] );CHKERR( result, "iMesh_createVtxArr: couldn't create vertex." );
[ # # ]
1292 : : }
1293 : : }
1294 : :
1295 [ + - ]: 90 : KEEP_ARRAY( new_vertex_handles );
1296 [ + - ]: 90 : RETURN( iBase_SUCCESS );
1297 : : }
1298 : :
1299 : 38 : void iMesh_createEntArr( iMesh_Instance instance,
1300 : : /*in*/ const int new_entity_topology,
1301 : : /*in*/ const iBase_EntityHandle* lower_order_entity_handles,
1302 : : /*in*/ const int lower_order_entity_handles_size,
1303 : : /*out*/ iBase_EntityHandle** new_entity_handles,
1304 : : /*out*/ int* new_entity_handles_allocated,
1305 : : /*out*/ int* new_entity_handles_size,
1306 : : /*inout*/ int** status,
1307 : : /*inout*/ int* status_allocated,
1308 : : /*out*/ int* status_size, int* err )
1309 : : {
1310 : : // for now, throw an error if lower order entity handles aren't vertices
1311 [ + - ][ - + ]: 38 : if( iMesh_POINT > new_entity_topology || iMesh_SEPTAHEDRON < new_entity_topology )
1312 [ # # ]: 0 : { ERROR( iBase_INVALID_ARGUMENT, "iMesh_createEntArr: invalid topology." ); }
1313 : 38 : EntityType this_type = mb_topology_table[new_entity_topology];
1314 : 38 : int num_ents = 0, num_verts;
1315 : : const EntityHandle* lower_ents;
1316 [ + - ]: 38 : if( MBVERTEX != this_type )
1317 : : {
1318 [ + - ]: 38 : num_verts = CN::VerticesPerEntity( this_type );
1319 : 38 : num_ents = lower_order_entity_handles_size / num_verts;
1320 : 38 : lower_ents = CONST_HANDLE_ARRAY_PTR( lower_order_entity_handles );
1321 : : // check that we have the right number of lower order entity handles
1322 [ + - ][ - + ]: 38 : if( lower_order_entity_handles_size % CN::VerticesPerEntity( this_type ) != 0 )
1323 [ # # ]: 0 : { ERROR( iBase_INVALID_ENTITY_COUNT, "iMesh_createEntArr: wrong # vertices for this entity type." ); }
1324 : : }
1325 : : else
1326 : : {
1327 [ # # ]: 0 : ERROR( iBase_INVALID_ARGUMENT, "iMesh_createEntArr: can't create vertices with this "
1328 : : "function, use createVtxArr instead." );
1329 : : }
1330 : :
1331 [ - + ][ # # ]: 38 : if( num_ents == 0 ) { ERROR( iBase_INVALID_ENTITY_COUNT, "iMesh_createEntArr: called to create 0 entities." ); }
1332 : :
1333 : : // if there aren't any elements in the array, allocate it
1334 : :
1335 : : // This function is poorly defined. We have to return allocated
1336 : : // arrays even if we fail.
1337 [ + - ][ - + ]: 38 : ALLOC_CHECK_ARRAY_NOFAIL( new_entity_handles, num_ents );
[ + - ]
1338 [ + - ][ - + ]: 76 : ALLOC_CHECK_ARRAY_NOFAIL( status, num_ents );
[ + - ]
1339 : :
1340 : : // make the entities
1341 : 38 : EntityHandle* new_ents = HANDLE_ARRAY_PTR( *new_entity_handles );
1342 : :
1343 : 38 : ErrorCode tmp_result, result = MB_SUCCESS;
1344 : :
1345 [ + + ]: 114 : for( int i = 0; i < num_ents; i++ )
1346 : : {
1347 [ + - ]: 76 : tmp_result = MOABI->create_element( this_type, lower_ents, num_verts, new_ents[i] );
1348 [ - + ]: 76 : if( MB_SUCCESS != tmp_result )
1349 : : {
1350 : 0 : ( *status )[i] = iBase_CREATION_FAILED;
1351 : 0 : result = tmp_result;
1352 : : }
1353 : : else
1354 : 76 : ( *status )[i] = iBase_NEW;
1355 : :
1356 : 76 : lower_ents += num_verts;
1357 : : }
1358 : :
1359 [ - + ][ # # ]: 38 : CHKERR( result, "iMesh_createEntArr: couldn't create one of the entities." );
1360 : :
1361 : 38 : *new_entity_handles_size = num_ents;
1362 : 38 : *status_size = num_ents;
1363 : :
1364 [ + - ][ - + ]: 38 : if( MBIMESHI->AdjTable[5] || MBIMESHI->AdjTable[10] )
[ - + ]
1365 : : {
1366 [ # # ]: 0 : Range set_ents;
1367 : : std::copy( HANDLE_ARRAY_PTR( *new_entity_handles ),
1368 [ # # ][ # # ]: 0 : HANDLE_ARRAY_PTR( *new_entity_handles ) + *new_entity_handles_size, range_inserter( set_ents ) );
1369 [ # # ][ # # ]: 0 : result = create_int_ents( MBIMESHI, set_ents );CHKERR( result, "" );
[ # # ][ # # ]
1370 : : }
1371 : :
1372 [ + - ]: 76 : RETURN( iBase_SUCCESS );
1373 : : }
1374 : :
1375 : 0 : void iMesh_deleteEntArr( iMesh_Instance instance,
1376 : : /*in*/ const iBase_EntityHandle* entity_handles,
1377 : : /*in*/ const int entity_handles_size, int* err )
1378 : : {
1379 [ # # ]: 0 : if( 0 == entity_handles_size ) { RETURN( iBase_SUCCESS ); }
1380 : :
1381 [ # # ]: 0 : ErrorCode result = MOABI->delete_entities( CONST_HANDLE_ARRAY_PTR( entity_handles ), entity_handles_size );CHKERR( result, "iMesh_deleteEntArr: trouble deleting entities." );
1382 : :
1383 : 0 : RETURN( iBase_SUCCESS );
1384 : : }
1385 : :
1386 : 32 : void iMesh_createTag( iMesh_Instance instance,
1387 : : /*in*/ const char* tag_name,
1388 : : /*in*/ const int tag_size,
1389 : : /*in*/ const int tag_type,
1390 : : /*out*/ iBase_TagHandle* tag_handle, int* err, const int tag_name_size )
1391 : : {
1392 : 32 : iMesh_createTagWithOptions( instance, tag_name, NULL, tag_size, tag_type, tag_handle, err, tag_name_size, 0 );
1393 : 32 : }
1394 : :
1395 : 15 : void iMesh_destroyTag( iMesh_Instance instance,
1396 : : /*in*/ iBase_TagHandle tag_handle,
1397 : : /*in*/ const int forced, int* err )
1398 : : {
1399 : : // might need to check if it's used first
1400 [ + + ]: 15 : if( false == forced )
1401 : : {
1402 [ + - ]: 4 : Range ents;
1403 : : ErrorCode result;
1404 : 4 : Tag this_tag = TAG_HANDLE( tag_handle );
1405 [ + - ][ + + ]: 39 : for( EntityType this_type = MBVERTEX; this_type != MBMAXTYPE; this_type++ )
1406 : : {
1407 [ + - ][ - + ]: 39 : result = MOABI->get_entities_by_type_and_tag( 0, this_type, &this_tag, NULL, 1, ents, Interface::UNION );CHKERR( result, "iMesh_destroyTag: problem finding tag." );
[ # # ]
1408 [ + - ][ + + ]: 37 : if( !ents.empty() )
1409 : : {
1410 [ + - ]: 2 : ERROR( iBase_TAG_IN_USE, "iMesh_destroyTag: forced=false and entities"
1411 : : " are still assigned this tag." );
1412 : : }
1413 : : }
1414 : : // check if tag value is set on mesh
1415 : : const void* data_ptr;
1416 : 2 : EntityHandle root = 0;
1417 [ + - ]: 2 : result = MOABI->tag_get_by_ptr( this_tag, &root, 1, &data_ptr );
1418 [ + + ]: 2 : if( MB_SUCCESS == result )
1419 [ + - ][ + + ]: 4 : ERROR( iBase_TAG_IN_USE, "iMesh_destroyTag: forced=false and mesh"
1420 : 4 : " is still assigned this tag." );
1421 : : }
1422 : :
1423 : : // ok, good to go - either forced or no entities with this tag
1424 : 12 : ErrorCode result = MOABI->tag_delete( TAG_HANDLE( tag_handle ) );
1425 [ - + ][ # # ]: 12 : if( MB_SUCCESS != result && MB_TAG_NOT_FOUND != result ) ERROR( result, "iMesh_destroyTag: problem deleting tag." );
1426 : :
1427 [ + - ]: 12 : if( MB_SUCCESS == result ) MBIMESHI->note_tag_destroyed( TAG_HANDLE( tag_handle ) );
1428 : :
1429 : 15 : RETURN( iBase_ERROR_MAP[result] );
1430 : : }
1431 : :
1432 : 14 : void iMesh_getTagName( iMesh_Instance instance,
1433 : : /*in*/ const iBase_TagHandle tag_handle, char* out_data, int* err, int out_data_len )
1434 : : {
1435 [ + + ][ + - ]: 14 : static ::std::string name;
[ + - ][ # # ]
1436 [ - + ]: 14 : ErrorCode result = MOABI->tag_get_name( TAG_HANDLE( tag_handle ), name );CHKERR( result, "iMesh_getTagName: problem getting name." );
1437 : :
1438 : 14 : strncpy( out_data, name.c_str(), out_data_len );
1439 : 14 : RETURN( iBase_SUCCESS );
1440 : : }
1441 : :
1442 : 114 : void iMesh_getTagType( iMesh_Instance instance,
1443 : : /*in*/ const iBase_TagHandle tag_handle, int* value_type, int* err )
1444 : : {
1445 : : DataType this_type;
1446 [ + - ][ - + ]: 114 : ErrorCode result = MOABI->tag_get_data_type( TAG_HANDLE( tag_handle ), this_type );CHKERR( result, "iMesh_getTagType: problem getting type." );
[ # # ]
1447 : :
1448 [ + - ]: 114 : if( this_type != MB_TYPE_HANDLE )
1449 : 114 : *value_type = tstt_data_type_table[this_type];
1450 [ # # ][ # # ]: 0 : else if( MBIMESHI->is_set_handle_tag( TAG_HANDLE( tag_handle ) ) )
1451 : 0 : *value_type = iBase_ENTITY_SET_HANDLE;
1452 [ # # ][ # # ]: 0 : else if( MBIMESHI->is_ent_handle_tag( TAG_HANDLE( tag_handle ) ) )
1453 : 0 : *value_type = iBase_ENTITY_HANDLE;
1454 : : else
1455 : : {
1456 [ # # ][ # # ]: 0 : result = check_handle_tag_type( TAG_HANDLE( tag_handle ), MBIMESHI );CHKERR( result, "iMesh_getTagType: problem guessing handle tag subtype" );
[ # # ]
1457 [ # # ][ # # ]: 0 : if( MBIMESHI->is_set_handle_tag( TAG_HANDLE( tag_handle ) ) )
1458 : 0 : *value_type = iBase_ENTITY_SET_HANDLE;
1459 : : else
1460 : 0 : *value_type = iBase_ENTITY_HANDLE;
1461 : : }
1462 : :
1463 [ + - ]: 114 : RETURN( iBase_SUCCESS );
1464 : : }
1465 : :
1466 : 28 : void iMesh_getTagSizeValues( iMesh_Instance instance,
1467 : : /*in*/ const iBase_TagHandle tag_handle, int* tag_size_val, int* err )
1468 : : {
1469 [ - + ]: 28 : ErrorCode result = MOABI->tag_get_length( TAG_HANDLE( tag_handle ), *tag_size_val );CHKERR( result, "iMesh_getTagSize: problem getting size." );
1470 : :
1471 : 28 : RETURN( iBase_SUCCESS );
1472 : : }
1473 : :
1474 : 99 : void iMesh_getTagSizeBytes( iMesh_Instance instance,
1475 : : /*in*/ const iBase_TagHandle tag_handle, int* tag_size_bytes, int* err )
1476 : : {
1477 [ - + ]: 99 : ErrorCode result = MOABI->tag_get_bytes( TAG_HANDLE( tag_handle ), *tag_size_bytes );CHKERR( result, "iMesh_getTagSize: problem getting size." );
1478 : :
1479 : 99 : RETURN( iBase_SUCCESS );
1480 : : }
1481 : :
1482 : 52 : void iMesh_getTagHandle( iMesh_Instance instance,
1483 : : /*in*/ const char* tag_name, iBase_TagHandle* tag_handle, int* err, const int tag_name_len )
1484 : : {
1485 [ + - ]: 52 : std::string tmp_tagname( tag_name, tag_name_len );
1486 [ + - ]: 52 : eatwhitespace( tmp_tagname );
1487 : :
1488 [ + - ]: 52 : ErrorCode result = MOABI->tag_get_handle( tmp_tagname.c_str(), 0, MB_TYPE_OPAQUE, (Tag&)*tag_handle, MB_TAG_ANY );
1489 : :
1490 [ + + ]: 52 : if( MB_SUCCESS != result )
1491 : : {
1492 [ + - ]: 10 : std::string msg( "iMesh_getTagHandle: problem getting handle for tag named '" );
1493 [ + - ][ + - ]: 10 : msg += std::string( tag_name ) + std::string( "'" );
[ + - ][ + - ]
1494 : 10 : *tag_handle = 0;
1495 [ + - ]: 10 : ERROR( result, msg.c_str() );
1496 : : }
1497 : :
1498 : : // do not return variable-length tags through ITAPS API
1499 : : int size;
1500 [ + - ][ - + ]: 42 : if( MB_SUCCESS != MOABI->tag_get_length( TAG_HANDLE( *tag_handle ), size ) ) RETURN( iBase_TAG_NOT_FOUND );
[ # # ]
1501 : :
1502 [ + - ]: 52 : RETURN( iBase_SUCCESS );
1503 : : }
1504 : :
1505 : 0 : void iMesh_getAllIfaceTags( iMesh_Instance instance,
1506 : : /*inout*/ iBase_TagHandle** tag_handles,
1507 : : /*inout*/ int* tag_handles_allocated,
1508 : : /*out*/ int* tag_handles_size, int* err )
1509 : : {
1510 [ # # ]: 0 : std::vector< Tag > all_tags;
1511 : :
1512 [ # # ][ # # ]: 0 : ErrorCode result = MOABI->tag_get_tags( all_tags );CHKERR( result, "iMesh_getAllIfaceTags failed." );
[ # # ]
1513 : :
1514 [ # # ]: 0 : remove_var_len_tags( MOABI, all_tags );
1515 : :
1516 : : // now put those tag handles into sidl array
1517 [ # # ][ # # ]: 0 : ALLOC_CHECK_ARRAY_NOFAIL( tag_handles, all_tags.size() );
[ # # ]
1518 [ # # ]: 0 : memcpy( *tag_handles, &all_tags[0], all_tags.size() * sizeof( Tag ) );
1519 : 0 : *tag_handles_size = all_tags.size();
1520 : :
1521 [ # # ]: 0 : RETURN( iBase_SUCCESS );
1522 : : }
1523 : :
1524 : 134 : void iMesh_setEntSetData( iMesh_Instance instance,
1525 : : /*in*/ iBase_EntitySetHandle entity_set_handle,
1526 : : /*in*/ const iBase_TagHandle tag_handle,
1527 : : /*in*/ const void* tag_value,
1528 : : /*in*/ const int, int* err )
1529 : : {
1530 : : ErrorCode result;
1531 : :
1532 : 134 : EntityHandle set = ENTITY_HANDLE( entity_set_handle );
1533 [ + - ][ - + ]: 134 : result = MOABI->tag_set_data( TAG_HANDLE( tag_handle ), &set, 1, tag_value );CHKERR( result, "iMesh_setEntSetData: error" );
[ # # ]
1534 : :
1535 [ + - ]: 134 : RETURN( iBase_SUCCESS );
1536 : : }
1537 : :
1538 : 0 : void iMesh_setEntSetIntData( iMesh_Instance instance,
1539 : : /*in*/ iBase_EntitySetHandle entity_set,
1540 : : /*in*/ const iBase_TagHandle tag_handle,
1541 : : /*in*/ const int tag_value, int* err )
1542 : : {
1543 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_INTEGER );
[ # # ][ # # ]
[ # # ]
1544 : 0 : iMesh_setEntSetData( instance, entity_set, tag_handle, &tag_value, sizeof( int ), err );
1545 : : }
1546 : :
1547 : 0 : void iMesh_setEntSetDblData( iMesh_Instance instance,
1548 : : /*in*/ iBase_EntitySetHandle entity_set,
1549 : : /*in*/ const iBase_TagHandle tag_handle,
1550 : : /*in*/ const double tag_value, int* err )
1551 : : {
1552 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_DOUBLE );
[ # # ][ # # ]
[ # # ]
1553 : 0 : iMesh_setEntSetData( instance, entity_set, tag_handle, &tag_value, sizeof( double ), err );
1554 : : }
1555 : :
1556 : 0 : void iMesh_setEntSetEHData( iMesh_Instance instance,
1557 : : /*in*/ iBase_EntitySetHandle entity_set,
1558 : : /*in*/ const iBase_TagHandle tag_handle,
1559 : : /*in*/ const iBase_EntityHandle tag_value, int* err )
1560 : : {
1561 : : // XXX: decide how best to handle validating entity handles as tag data
1562 [ # # ][ # # ]: 0 : CHKNONEMPTY();
[ # # ][ # # ]
[ # # ]
1563 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1564 : 0 : iMesh_setEntSetData( instance, entity_set, tag_handle, &tag_value, sizeof( iBase_EntityHandle ), err );
1565 : : }
1566 : :
1567 : 0 : void iMesh_setEntSetESHData( iMesh_Instance instance,
1568 : : /*in*/ iBase_EntitySetHandle entity_set,
1569 : : /*in*/ const iBase_TagHandle tag_handle,
1570 : : /*in*/ const iBase_EntitySetHandle tag_value, int* err )
1571 : : {
1572 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_SET_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1573 : 0 : iMesh_setEntSetData( instance, entity_set, tag_handle, &tag_value, sizeof( iBase_EntitySetHandle ), err );
1574 : : }
1575 : :
1576 : 347 : void iMesh_getEntSetData( iMesh_Instance instance,
1577 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
1578 : : /*in*/ const iBase_TagHandle tag_handle,
1579 : : /*inout*/ void* tag_value,
1580 : : /*inout*/ int* tag_value_allocated,
1581 : : /*inout*/ int* tag_value_size, int* err )
1582 : : {
1583 : 347 : EntityHandle eh = ENTITY_HANDLE( entity_set_handle );
1584 : 347 : Tag tag = TAG_HANDLE( tag_handle );
1585 : :
1586 : : int tag_size;
1587 [ + - ][ - + ]: 347 : ErrorCode result = MOABI->tag_get_bytes( tag, tag_size );CHKERR( result, "iMesh_getEntSetData: couldn't get tag size." );
[ # # ]
1588 : :
1589 [ + - ][ - + ]: 347 : ALLOC_CHECK_TAG_ARRAY( tag_value, tag_size );
1590 : :
1591 [ + - ]: 347 : result = MOABI->tag_get_data( tag, &eh, 1, *static_cast< void** >( tag_value ) );
1592 : :
1593 [ - + ][ # # ]: 347 : CHKERR( result, "iMesh_getEntSetData didn't succeed." );
1594 [ + - ]: 347 : KEEP_ARRAY( tag_value );
1595 [ + - ]: 347 : RETURN( iBase_SUCCESS );
1596 : : }
1597 : :
1598 : 42 : void iMesh_getEntSetIntData( iMesh_Instance instance,
1599 : : /*in*/ const iBase_EntitySetHandle entity_set,
1600 : : /*in*/ const iBase_TagHandle tag_handle, int* out_data, int* err )
1601 : : {
1602 [ + - ][ - + ]: 84 : CHKTAGTYPE( tag_handle, iBase_INTEGER );
[ # # ][ - + ]
[ # # ]
1603 : 42 : void* tag_ptr = out_data;
1604 : 42 : int dum_size = sizeof( int );
1605 [ + - ]: 42 : iMesh_getEntSetData( instance, entity_set, tag_handle, &tag_ptr, &dum_size, &dum_size, err );
1606 : : }
1607 : :
1608 : 0 : void iMesh_getEntSetDblData( iMesh_Instance instance,
1609 : : /*in*/ const iBase_EntitySetHandle entity_set,
1610 : : /*in*/ const iBase_TagHandle tag_handle, double* out_data, int* err )
1611 : : {
1612 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_DOUBLE );
[ # # ][ # # ]
[ # # ]
1613 : 0 : void* tag_ptr = out_data;
1614 : 0 : int tag_size = sizeof( double );
1615 [ # # ]: 0 : iMesh_getEntSetData( instance, entity_set, tag_handle, &tag_ptr, &tag_size, &tag_size, err );
1616 : : }
1617 : :
1618 : 0 : void iMesh_getEntSetEHData( iMesh_Instance instance,
1619 : : /*in*/ const iBase_EntitySetHandle entity_set,
1620 : : /*in*/ const iBase_TagHandle tag_handle, iBase_EntityHandle* out_data, int* err )
1621 : : {
1622 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1623 : 0 : void* tag_ptr = out_data;
1624 : 0 : int tag_size = sizeof( EntityHandle );
1625 [ # # ]: 0 : iMesh_getEntSetData( instance, entity_set, tag_handle, &tag_ptr, &tag_size, &tag_size, err );
1626 : : }
1627 : :
1628 : 0 : void iMesh_getEntSetESHData( iMesh_Instance instance,
1629 : : /*in*/ const iBase_EntitySetHandle entity_set,
1630 : : /*in*/ const iBase_TagHandle tag_handle, iBase_EntitySetHandle* out_data, int* err )
1631 : : {
1632 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_SET_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1633 : 0 : void* tag_ptr = out_data;
1634 : 0 : int tag_size = sizeof( EntityHandle );
1635 [ # # ]: 0 : iMesh_getEntSetData( instance, entity_set, tag_handle, &tag_ptr, &tag_size, &tag_size, err );
1636 : : }
1637 : :
1638 : 5 : void iMesh_getAllEntSetTags( iMesh_Instance instance,
1639 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
1640 : : /*out*/ iBase_TagHandle** tag_handles,
1641 : : /*out*/ int* tag_handles_allocated,
1642 : : /*out*/ int* tag_handles_size, int* err )
1643 : : {
1644 : 5 : EntityHandle eh = ENTITY_HANDLE( entity_set_handle );
1645 [ + - ]: 5 : std::vector< Tag > all_tags;
1646 : :
1647 [ + - ][ - + ]: 5 : ErrorCode result = MOABI->tag_get_tags_on_entity( eh, all_tags );CHKERR( result, "iMesh_entitysetGetAllTagHandles failed." );
[ # # ]
1648 : :
1649 [ + - ]: 5 : remove_var_len_tags( MOABI, all_tags );
1650 : :
1651 : : // now put those tag handles into sidl array
1652 [ + - ][ - + ]: 10 : ALLOC_CHECK_ARRAY_NOFAIL( tag_handles, all_tags.size() );
[ + - ]
1653 [ + - ]: 5 : memcpy( *tag_handles, &all_tags[0], all_tags.size() * sizeof( Tag ) );
1654 : :
1655 : 5 : *tag_handles_size = (int)all_tags.size();
1656 [ + - ]: 10 : RETURN( iBase_SUCCESS );
1657 : : }
1658 : :
1659 : 44 : void iMesh_rmvEntSetTag( iMesh_Instance instance,
1660 : : /*in*/ iBase_EntitySetHandle entity_set_handle,
1661 : : /*in*/ const iBase_TagHandle tag_handle, int* err )
1662 : : {
1663 : 44 : EntityHandle set = ENTITY_HANDLE( entity_set_handle );
1664 [ + - ]: 44 : ErrorCode result = MOABI->tag_delete_data( TAG_HANDLE( tag_handle ), &set, 1 );
1665 : :
1666 : : // don't return an error if the tag simply wasn't set on the ent set
1667 [ - + ]: 44 : if( MB_TAG_NOT_FOUND == result )
1668 [ # # ]: 0 : RETURN( iBase_SUCCESS );
1669 : : else
1670 [ + - ]: 44 : RETURN( iBase_ERROR_MAP[result] );
1671 : : }
1672 : :
1673 : 0 : void iMesh_setVtxCoord( iMesh_Instance instance,
1674 : : /*in*/ iBase_EntityHandle vertex_handle,
1675 : : /*in*/ const double x, /*in*/ const double y,
1676 : : /*in*/ const double z, int* err )
1677 : :
1678 : : {
1679 : 0 : const double xyz[3] = { x, y, z };
1680 : : int geom_dim;
1681 [ # # ]: 0 : MOABI->get_dimension( geom_dim );
1682 : :
1683 [ # # ]: 0 : iMesh_setVtxArrCoords( instance, &vertex_handle, 1, iBase_BLOCKED, xyz, geom_dim, err );
1684 : 0 : }
1685 : :
1686 : 27 : void iMesh_createVtx( iMesh_Instance instance,
1687 : : /*in*/ const double x, /*in*/ const double y,
1688 : : /*in*/ const double z,
1689 : : /*out*/ iBase_EntityHandle* new_vertex_handle, int* err )
1690 : : {
1691 : 27 : int dum = 1;
1692 : 27 : const double xyz[3] = { x, y, z };
1693 : : int geom_dim;
1694 [ + - ]: 27 : MOABI->get_dimension( geom_dim );
1695 [ + - ]: 27 : iMesh_createVtxArr( instance, 1, iBase_BLOCKED, xyz, geom_dim, &new_vertex_handle, &dum, &dum, err );
1696 : 27 : }
1697 : :
1698 : 34 : void iMesh_createEnt( iMesh_Instance instance,
1699 : : /*in*/ const int new_entity_topology,
1700 : : /*in*/ const iBase_EntityHandle* lower_order_entity_handles,
1701 : : /*in*/ const int lower_order_entity_handles_size,
1702 : : /*out*/ iBase_EntityHandle* new_entity_handle,
1703 : : /*out*/ int* status, int* err )
1704 : : {
1705 [ - + ]: 34 : if( 0 == lower_order_entity_handles_size )
1706 [ # # ]: 0 : { ERROR( iBase_INVALID_ENTITY_COUNT, "iMesh_createEnt: need more than zero lower order entities." ); }
1707 : :
1708 : : // call directly to allow creation of higher-order entities
1709 : : // directly from connectivity
1710 : 34 : EntityType this_type = mb_topology_table[new_entity_topology];
1711 : : EntityHandle tmp_ent;
1712 : 34 : ErrorCode result = MOABI->create_element( this_type, CONST_HANDLE_ARRAY_PTR( lower_order_entity_handles ),
1713 [ + - ]: 34 : lower_order_entity_handles_size, tmp_ent );
1714 [ + - ]: 34 : if( MB_SUCCESS == result )
1715 : : {
1716 : 34 : *new_entity_handle = reinterpret_cast< iBase_EntityHandle >( tmp_ent );
1717 : 34 : *status = iBase_NEW;
1718 : :
1719 [ + - ][ - + ]: 34 : if( MBIMESHI->AdjTable[5] || MBIMESHI->AdjTable[10] )
[ - + ]
1720 : : {
1721 [ # # ]: 0 : Range set_ents;
1722 [ # # ]: 0 : set_ents.insert( tmp_ent );
1723 [ # # ]: 0 : create_int_ents( MBIMESHI, set_ents );
1724 : : }
1725 : :
1726 [ + - ]: 34 : RETURN( iBase_SUCCESS );
1727 : : }
1728 : : else
1729 : : {
1730 : 0 : *new_entity_handle = 0;
1731 : 0 : *status = iBase_CREATION_FAILED;
1732 [ # # ]: 34 : ERROR( result, "iMesh_createEnt: couldn't create entity" );
1733 : : }
1734 : : }
1735 : :
1736 : 0 : void iMesh_deleteEnt( iMesh_Instance instance,
1737 : : /*in*/ iBase_EntityHandle entity_handle, int* err )
1738 : : {
1739 : 0 : iMesh_deleteEntArr( instance, &entity_handle, 1, err );
1740 : 0 : }
1741 : :
1742 : 52 : void iMesh_getArrData( iMesh_Instance instance,
1743 : : /*in*/ const iBase_EntityHandle* entity_handles,
1744 : : /*in*/ const int entity_handles_size,
1745 : : /*in*/ const iBase_TagHandle tag_handle,
1746 : : /*inout*/ void* tag_values,
1747 : : /*inout*/ int* tag_values_allocated,
1748 : : /*out*/ int* tag_values_size, int* err )
1749 : : {
1750 [ + + ][ + - ]: 52 : if( 0 == entity_handles_size ) RETURN( iBase_SUCCESS );
1751 [ + - ][ - + ]: 49 : CHKNONEMPTY();
[ # # ][ - + ]
[ # # ]
1752 : :
1753 : 49 : const EntityHandle* ents = reinterpret_cast< const EntityHandle* >( entity_handles );
1754 : 49 : Tag tag = TAG_HANDLE( tag_handle );
1755 : :
1756 : : int tag_size;
1757 [ + - ]: 49 : ErrorCode result = MOABI->tag_get_bytes( tag, tag_size );
1758 [ - + ]: 49 : if( MB_SUCCESS != result )
1759 : : {
1760 : 0 : int nerr = -1;
1761 : : char tagn[64], msg[256];
1762 [ # # ]: 0 : iMesh_getTagName( instance, tag_handle, tagn, &nerr, sizeof( tagn ) );
1763 : : snprintf( msg, sizeof( msg ), "iMesh_getArrData: couldn't get size for tag \"%s\"",
1764 [ # # ]: 0 : nerr == 0 ? tagn : "unknown" );
1765 [ # # ]: 0 : ERROR( result, msg );
1766 : : }
1767 : :
1768 [ + - ][ - + ]: 49 : ALLOC_CHECK_TAG_ARRAY( tag_values, tag_size * entity_handles_size );
1769 : :
1770 [ + - ]: 49 : result = MOABI->tag_get_data( tag, ents, entity_handles_size, *static_cast< void** >( tag_values ) );
1771 : :
1772 [ + + ]: 49 : if( MB_SUCCESS != result )
1773 : : {
1774 [ + - ]: 5 : std::string message( "iMesh_getArrData: " );
1775 [ + - ]: 5 : if( MB_TAG_NOT_FOUND == result )
1776 [ + - ]: 5 : message += "tag not found";
1777 : : else
1778 [ # # ]: 0 : message += "failed";
1779 : :
1780 [ + - ]: 10 : std::string name;
1781 [ + - ][ + - ]: 5 : if( MB_SUCCESS == MOABI->tag_get_name( tag, name ) )
1782 : : {
1783 [ + - ]: 5 : message += "for tag \"";
1784 [ + - ]: 5 : message += name;
1785 [ + - ]: 5 : message += "\".";
1786 : : }
1787 [ + - ]: 10 : ERROR( result, message.c_str() );
1788 : : }
1789 : :
1790 [ + - ]: 44 : KEEP_ARRAY( tag_values );
1791 [ + - ]: 52 : RETURN( iBase_SUCCESS );
1792 : : }
1793 : :
1794 : 4 : void iMesh_getIntArrData( iMesh_Instance instance,
1795 : : /*in*/ const iBase_EntityHandle* entity_handles,
1796 : : /*in*/ const int entity_handles_size,
1797 : : /*in*/ const iBase_TagHandle tag_handle,
1798 : : /*inout*/ int** tag_values,
1799 : : /*inout*/ int* tag_values_allocated,
1800 : : /*out*/ int* tag_values_size, int* err )
1801 : : {
1802 [ + - ][ - + ]: 4 : CHKTAGTYPE( tag_handle, iBase_INTEGER );
[ # # ][ - + ]
[ # # ]
1803 : 4 : *tag_values_allocated *= sizeof( int );
1804 [ + - ]: 4 : if( tag_values_size != tag_values_allocated ) *tag_values_size *= sizeof( int );
1805 : : iMesh_getArrData( instance, entity_handles, entity_handles_size, tag_handle, tag_values, tag_values_allocated,
1806 : 4 : tag_values_size, err );
1807 : 4 : *tag_values_allocated /= sizeof( int );
1808 [ + - ]: 4 : if( tag_values_size != tag_values_allocated ) *tag_values_size /= sizeof( int );
1809 : : }
1810 : :
1811 : 0 : void iMesh_getDblArrData( iMesh_Instance instance,
1812 : : /*in*/ const iBase_EntityHandle* entity_handles,
1813 : : /*in*/ const int entity_handles_size,
1814 : : /*in*/ const iBase_TagHandle tag_handle,
1815 : : /*inout*/ double** tag_values,
1816 : : /*inout*/ int* tag_values_allocated,
1817 : : /*out*/ int* tag_values_size, int* err )
1818 : : {
1819 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_DOUBLE );
[ # # ][ # # ]
[ # # ]
1820 : 0 : *tag_values_allocated *= sizeof( double );
1821 [ # # ]: 0 : if( tag_values_size != tag_values_allocated ) *tag_values_size *= sizeof( double );
1822 : : iMesh_getArrData( instance, entity_handles, entity_handles_size, tag_handle, tag_values, tag_values_allocated,
1823 : 0 : tag_values_size, err );
1824 : 0 : *tag_values_allocated /= sizeof( double );
1825 [ # # ]: 0 : if( tag_values_size != tag_values_allocated ) *tag_values_size /= sizeof( double );
1826 : : }
1827 : :
1828 : 0 : void iMesh_getEHArrData( iMesh_Instance instance,
1829 : : /*in*/ const iBase_EntityHandle* entity_handles,
1830 : : /*in*/ const int entity_handles_size,
1831 : : /*in*/ const iBase_TagHandle tag_handle,
1832 : : /*inout*/ iBase_EntityHandle** tag_value,
1833 : : /*inout*/ int* tag_value_allocated,
1834 : : /*out*/ int* tag_value_size, int* err )
1835 : : {
1836 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1837 : 0 : *tag_value_allocated *= sizeof( iBase_EntityHandle );
1838 [ # # ]: 0 : if( tag_value_size != tag_value_allocated ) *tag_value_size *= sizeof( iBase_EntityHandle );
1839 : : iMesh_getArrData( instance, entity_handles, entity_handles_size, tag_handle,
1840 : 0 : reinterpret_cast< void** >( tag_value ), tag_value_allocated, tag_value_size, err );
1841 : 0 : *tag_value_allocated /= sizeof( iBase_EntityHandle );
1842 [ # # ]: 0 : if( tag_value_size != tag_value_allocated ) *tag_value_size /= sizeof( iBase_EntityHandle );
1843 : : }
1844 : :
1845 : 0 : void iMesh_getESHArrData( iMesh_Instance instance,
1846 : : /*in*/ const iBase_EntityHandle* entity_handles,
1847 : : /*in*/ const int entity_handles_size,
1848 : : /*in*/ const iBase_TagHandle tag_handle,
1849 : : /*inout*/ iBase_EntitySetHandle** tag_value,
1850 : : /*inout*/ int* tag_value_allocated,
1851 : : /*out*/ int* tag_value_size, int* err )
1852 : : {
1853 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_SET_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1854 : 0 : *tag_value_allocated *= sizeof( iBase_EntityHandle );
1855 [ # # ]: 0 : if( tag_value_size != tag_value_allocated ) *tag_value_size *= sizeof( iBase_EntityHandle );
1856 : : iMesh_getArrData( instance, entity_handles, entity_handles_size, tag_handle,
1857 : 0 : reinterpret_cast< void** >( tag_value ), tag_value_allocated, tag_value_size, err );
1858 : 0 : *tag_value_allocated /= sizeof( iBase_EntityHandle );
1859 [ # # ]: 0 : if( tag_value_size != tag_value_allocated ) *tag_value_size /= sizeof( iBase_EntityHandle );
1860 : : }
1861 : :
1862 : 100 : void iMesh_setArrData( iMesh_Instance instance,
1863 : : /*in*/ const iBase_EntityHandle* entity_handles,
1864 : : /*in*/ const int entity_handles_size,
1865 : : /*in*/ const iBase_TagHandle tag_handle,
1866 : : /*in*/ const void* tag_values,
1867 : : /*in*/ const int tag_values_size, int* err )
1868 : : {
1869 [ + + ][ + - ]: 100 : if( 0 == entity_handles_size ) RETURN( iBase_SUCCESS );
1870 [ + - ][ - + ]: 95 : CHKNONEMPTY();
[ # # ][ - + ]
[ # # ]
1871 : :
1872 : : int tag_size;
1873 [ + - ]: 95 : iMesh_getTagSizeBytes( instance, tag_handle, &tag_size, err );
1874 : : // Check err manually and just return if not iBase_SUCCESS to not step on
1875 : : // the error set in iMesh_getTagSizeBytes().
1876 [ - + ]: 95 : if( iBase_SUCCESS != *err ) return;
1877 : :
1878 [ - + ]: 95 : if( tag_values_size != ( tag_size * entity_handles_size ) )
1879 [ # # ]: 0 : { ERROR( iBase_BAD_ARRAY_SIZE, "iMesh_setArrData: bad tag_values_size passed." ); }
1880 : :
1881 : 95 : ErrorCode result = MOABI->tag_set_data( TAG_HANDLE( tag_handle ), CONST_HANDLE_ARRAY_PTR( entity_handles ),
1882 [ + - ][ - + ]: 95 : entity_handles_size, tag_values );CHKERR( result, "iMesh_setArrData didn't succeed." );
[ # # ]
1883 [ + - ]: 100 : RETURN( iBase_SUCCESS );
1884 : : }
1885 : :
1886 : 27 : void iMesh_setIntArrData( iMesh_Instance instance,
1887 : : /*in*/ const iBase_EntityHandle* entity_handles,
1888 : : /*in*/ const int entity_handles_size,
1889 : : /*in*/ const iBase_TagHandle tag_handle,
1890 : : /*in*/ const int* tag_values,
1891 : : /*in*/ const int tag_values_size, int* err )
1892 : : {
1893 [ + - ][ - + ]: 54 : CHKTAGTYPE( tag_handle, iBase_INTEGER );
[ # # ][ - + ]
[ # # ]
1894 : : iMesh_setArrData( instance, entity_handles, entity_handles_size, tag_handle,
1895 : 27 : reinterpret_cast< const char* >( tag_values ), sizeof( int ) * tag_values_size, err );
1896 : : }
1897 : :
1898 : 1 : void iMesh_setDblArrData( iMesh_Instance instance,
1899 : : /*in*/ const iBase_EntityHandle* entity_handles,
1900 : : /*in*/ const int entity_handles_size,
1901 : : /*in*/ const iBase_TagHandle tag_handle,
1902 : : /*in*/ const double* tag_values,
1903 : : /*in*/ const int tag_values_size, int* err )
1904 : : {
1905 [ + - ][ - + ]: 2 : CHKTAGTYPE( tag_handle, iBase_DOUBLE );
[ # # ][ - + ]
[ # # ]
1906 : : iMesh_setArrData( instance, entity_handles, entity_handles_size, tag_handle,
1907 : 1 : reinterpret_cast< const char* >( tag_values ), sizeof( double ) * tag_values_size, err );
1908 : : }
1909 : :
1910 : 0 : void iMesh_setEHArrData( iMesh_Instance instance,
1911 : : /*in*/ const iBase_EntityHandle* entity_handles,
1912 : : /*in*/ const int entity_handles_size,
1913 : : /*in*/ const iBase_TagHandle tag_handle,
1914 : : /*in*/ const iBase_EntityHandle* tag_values,
1915 : : /*in*/ const int tag_values_size, int* err )
1916 : : {
1917 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1918 : : iMesh_setArrData( instance, entity_handles, entity_handles_size, tag_handle,
1919 : : reinterpret_cast< const char* >( tag_values ), sizeof( iBase_EntityHandle ) * tag_values_size,
1920 : 0 : err );
1921 : : }
1922 : :
1923 : 0 : void iMesh_setESHArrData( iMesh_Instance instance,
1924 : : /*in*/ const iBase_EntityHandle* entity_handles,
1925 : : /*in*/ const int entity_handles_size,
1926 : : /*in*/ const iBase_TagHandle tag_handle,
1927 : : /*in*/ const iBase_EntitySetHandle* tag_values,
1928 : : /*in*/ const int tag_values_size, int* err )
1929 : : {
1930 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_SET_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1931 : : iMesh_setArrData( instance, entity_handles, entity_handles_size, tag_handle,
1932 : : reinterpret_cast< const char* >( tag_values ), sizeof( iBase_EntityHandle ) * tag_values_size,
1933 : 0 : err );
1934 : : }
1935 : :
1936 : 3 : void iMesh_rmvArrTag( iMesh_Instance instance,
1937 : : /*in*/ const iBase_EntityHandle* entity_handles,
1938 : : /*in*/ const int entity_handles_size,
1939 : : /*in*/ const iBase_TagHandle tag_handle, int* err )
1940 : : {
1941 [ - + ]: 3 : if( 0 == entity_handles_size ) RETURN( iBase_SUCCESS );
1942 [ + - ][ - + ]: 3 : CHKNONEMPTY();
[ # # ][ - + ]
[ # # ]
1943 : :
1944 : 3 : ErrorCode result = MOABI->tag_delete_data( TAG_HANDLE( tag_handle ), CONST_HANDLE_ARRAY_PTR( entity_handles ),
1945 : 3 : entity_handles_size );
1946 : :
1947 : : // don't return an error if the tag simply wasn't set on the entities
1948 [ - + ]: 3 : if( MB_TAG_NOT_FOUND == result )
1949 : 0 : RETURN( iBase_SUCCESS );
1950 : : else
1951 : 3 : RETURN( iBase_ERROR_MAP[result] );
1952 : : }
1953 : :
1954 : 0 : void iMesh_getData( iMesh_Instance instance,
1955 : : /*in*/ const iBase_EntityHandle entity_handle,
1956 : : /*in*/ const iBase_TagHandle tag_handle,
1957 : : /*out*/ void* tag_value,
1958 : : /*inout*/ int* tag_value_allocated,
1959 : : /*out*/ int* tag_value_size, int* err )
1960 : : {
1961 : 0 : iMesh_getArrData( instance, &entity_handle, 1, tag_handle, tag_value, tag_value_allocated, tag_value_size, err );
1962 : 0 : }
1963 : :
1964 : 18 : void iMesh_getIntData( iMesh_Instance instance,
1965 : : /*in*/ const iBase_EntityHandle entity_handle,
1966 : : /*in*/ const iBase_TagHandle tag_handle, int* out_data, int* err )
1967 : : {
1968 [ + - ][ - + ]: 36 : CHKTAGTYPE( tag_handle, iBase_INTEGER );
[ # # ][ - + ]
[ # # ]
1969 : 18 : void* val_ptr = out_data;
1970 : 18 : int val_size = sizeof( int );
1971 [ + - ]: 18 : iMesh_getArrData( instance, &entity_handle, 1, tag_handle, &val_ptr, &val_size, &val_size, err );
1972 : : }
1973 : :
1974 : 0 : void iMesh_getDblData( iMesh_Instance instance,
1975 : : /*in*/ const iBase_EntityHandle entity_handle,
1976 : : /*in*/ const iBase_TagHandle tag_handle, double* out_data, int* err )
1977 : : {
1978 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_DOUBLE );
[ # # ][ # # ]
[ # # ]
1979 : 0 : void* val_ptr = out_data;
1980 : 0 : int val_size = sizeof( double );
1981 [ # # ]: 0 : iMesh_getArrData( instance, &entity_handle, 1, tag_handle, &val_ptr, &val_size, &val_size, err );
1982 : : }
1983 : :
1984 : 0 : void iMesh_getEHData( iMesh_Instance instance,
1985 : : /*in*/ const iBase_EntityHandle entity_handle,
1986 : : /*in*/ const iBase_TagHandle tag_handle, iBase_EntityHandle* out_data, int* err )
1987 : : {
1988 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1989 : 0 : void* val_ptr = out_data;
1990 : 0 : int dum = sizeof( iBase_EntityHandle );
1991 [ # # ]: 0 : iMesh_getArrData( instance, &entity_handle, 1, tag_handle, &val_ptr, &dum, &dum, err );
1992 : : }
1993 : :
1994 : 0 : void iMesh_getESHData( iMesh_Instance instance,
1995 : : /*in*/ const iBase_EntityHandle entity_handle,
1996 : : /*in*/ const iBase_TagHandle tag_handle, iBase_EntitySetHandle* out_data, int* err )
1997 : : {
1998 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_SET_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
1999 : 0 : void* val_ptr = out_data;
2000 : 0 : int dum = sizeof( iBase_EntityHandle );
2001 [ # # ]: 0 : iMesh_getArrData( instance, &entity_handle, 1, tag_handle, &val_ptr, &dum, &dum, err );
2002 : : }
2003 : :
2004 : 0 : void iMesh_setData( iMesh_Instance instance,
2005 : : /*in*/ iBase_EntityHandle entity_handle,
2006 : : /*in*/ const iBase_TagHandle tag_handle,
2007 : : /*in*/ const void* tag_value,
2008 : : /*in*/ const int tag_value_size, int* err )
2009 : : {
2010 : 0 : iMesh_setArrData( instance, &entity_handle, 1, tag_handle, tag_value, tag_value_size, err );
2011 : 0 : }
2012 : :
2013 : 0 : void iMesh_setIntData( iMesh_Instance instance,
2014 : : /*in*/ iBase_EntityHandle entity_handle,
2015 : : /*in*/ const iBase_TagHandle tag_handle,
2016 : : /*in*/ const int tag_value, int* err )
2017 : : {
2018 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_INTEGER );
[ # # ][ # # ]
[ # # ]
2019 : : iMesh_setArrData( instance, &entity_handle, 1, tag_handle, reinterpret_cast< const char* >( &tag_value ),
2020 : 0 : sizeof( int ), err );
2021 : : }
2022 : :
2023 : 0 : void iMesh_setDblData( iMesh_Instance instance,
2024 : :
2025 : : /*in*/ iBase_EntityHandle entity_handle,
2026 : : /*in*/ const iBase_TagHandle tag_handle,
2027 : : /*in*/ const double tag_value, int* err )
2028 : : {
2029 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_DOUBLE );
[ # # ][ # # ]
[ # # ]
2030 : : iMesh_setArrData( instance, &entity_handle, 1, tag_handle, reinterpret_cast< const char* >( &tag_value ),
2031 : 0 : sizeof( double ), err );
2032 : : }
2033 : :
2034 : 0 : void iMesh_setEHData( iMesh_Instance instance,
2035 : : /*in*/ iBase_EntityHandle entity_handle,
2036 : : /*in*/ const iBase_TagHandle tag_handle,
2037 : : /*in*/ const iBase_EntityHandle tag_value, int* err )
2038 : : {
2039 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
2040 : : iMesh_setArrData( instance, &entity_handle, 1, tag_handle, reinterpret_cast< const char* >( &tag_value ),
2041 : 0 : sizeof( iBase_EntityHandle ), err );
2042 : : }
2043 : :
2044 : 0 : void iMesh_setESHData( iMesh_Instance instance,
2045 : : /*in*/ iBase_EntityHandle entity_handle,
2046 : : /*in*/ const iBase_TagHandle tag_handle,
2047 : : /*in*/ const iBase_EntitySetHandle tag_value, int* err )
2048 : : {
2049 [ # # ][ # # ]: 0 : CHKTAGTYPE( tag_handle, iBase_ENTITY_SET_HANDLE );
[ # # ][ # # ]
[ # # ][ # # ]
2050 : : iMesh_setArrData( instance, &entity_handle, 1, tag_handle, reinterpret_cast< const char* >( &tag_value ),
2051 : 0 : sizeof( iBase_EntityHandle ), err );
2052 : : }
2053 : :
2054 : 46 : void iMesh_getAllTags( iMesh_Instance instance,
2055 : : /*in*/ const iBase_EntityHandle entity_handle,
2056 : : /*inout*/ iBase_TagHandle** tag_handles,
2057 : : /*inout*/ int* tag_handles_allocated,
2058 : : /*out*/ int* tag_handles_size, int* err )
2059 : : {
2060 [ + - ]: 46 : std::vector< Tag > all_tags;
2061 : :
2062 [ + - ][ - + ]: 46 : ErrorCode result = MOABI->tag_get_tags_on_entity( ENTITY_HANDLE( entity_handle ), all_tags );CHKERR( result, "iMesh_getAllTags failed." );
[ # # ]
2063 : :
2064 [ + - ]: 46 : remove_var_len_tags( MOABI, all_tags );
2065 : :
2066 : : // now put those tag handles into sidl array
2067 [ + - ][ - + ]: 92 : ALLOC_CHECK_ARRAY_NOFAIL( tag_handles, all_tags.size() );
[ + - ]
2068 [ + - ]: 46 : memcpy( *tag_handles, &all_tags[0], all_tags.size() * sizeof( Tag ) );
2069 : 46 : *tag_handles_size = all_tags.size();
2070 : :
2071 [ + - ]: 92 : RETURN( iBase_SUCCESS );
2072 : : }
2073 : :
2074 : 0 : void iMesh_rmvTag( iMesh_Instance instance,
2075 : : /*in*/ iBase_EntityHandle entity_handle,
2076 : : /*in*/ const iBase_TagHandle tag_handle, int* err )
2077 : : {
2078 : 0 : iMesh_rmvArrTag( instance, &entity_handle, 1, tag_handle, err );
2079 : 0 : }
2080 : :
2081 : 46 : void iMesh_initEntIter( iMesh_Instance instance,
2082 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2083 : : /*in*/ const int requested_entity_type,
2084 : : /*in*/ const int requested_entity_topology,
2085 : : /*in*/ const int resilient,
2086 : : /*out*/ iBase_EntityIterator* entity_iterator, int* err )
2087 : : {
2088 : : iMesh_initEntArrIterRec( instance, entity_set_handle, requested_entity_type, requested_entity_topology, 1,
2089 : 46 : resilient, false, reinterpret_cast< iBase_EntityArrIterator* >( entity_iterator ), err );
2090 : 46 : }
2091 : :
2092 : 41402 : void iMesh_getNextEntIter( iMesh_Instance instance,
2093 : : /*in*/ iBase_EntityIterator entity_iterator,
2094 : : /*out*/ iBase_EntityHandle* entity_handle, int* is_end, int* err )
2095 : : {
2096 : 41402 : int eh_size = 1;
2097 : : iMesh_getNextEntArrIter( instance, reinterpret_cast< iBase_EntityArrIterator >( entity_iterator ), &entity_handle,
2098 [ + - ]: 41402 : &eh_size, &eh_size, is_end, err );
2099 : 41402 : }
2100 : :
2101 : 90 : void iMesh_resetEntIter( iMesh_Instance instance,
2102 : : /*in*/ iBase_EntityIterator entity_iterator, int* err )
2103 : : {
2104 : 90 : iMesh_resetEntArrIter( instance, reinterpret_cast< iBase_EntityArrIterator >( entity_iterator ), err );
2105 : 90 : }
2106 : :
2107 : 46 : void iMesh_endEntIter( iMesh_Instance instance,
2108 : : /*in*/ iBase_EntityIterator entity_iterator, int* err )
2109 : : {
2110 : 46 : iMesh_endEntArrIter( instance, reinterpret_cast< iBase_EntityArrIterator >( entity_iterator ), err );
2111 : 46 : }
2112 : :
2113 : 0 : void iMesh_getEntTopo( iMesh_Instance instance,
2114 : : /*in*/ const iBase_EntityHandle entity_handle, int* out_topo, int* err )
2115 : : {
2116 : 0 : *out_topo = tstt_topology_table[MOABI->type_from_handle( ENTITY_HANDLE( entity_handle ) )];
2117 : 0 : RETURN( iBase_SUCCESS );
2118 : : }
2119 : :
2120 : 0 : void iMesh_getEntType( iMesh_Instance instance,
2121 : : /*in*/ const iBase_EntityHandle entity_handle, int* out_type, int* err )
2122 : : {
2123 : 0 : *out_type = tstt_type_table[MOABI->type_from_handle( ENTITY_HANDLE( entity_handle ) )];
2124 : 0 : RETURN( iBase_SUCCESS );
2125 : : }
2126 : :
2127 : 55 : void iMesh_getVtxCoord( iMesh_Instance instance,
2128 : : /*in*/ const iBase_EntityHandle vertex_handle,
2129 : : /*out*/ double* x, /*out*/ double* y, /*out*/ double* z, int* err )
2130 : : {
2131 : 55 : int order = iBase_BLOCKED;
2132 : 55 : double xyz[3] = { 0 }, *tmp_xyz = xyz;
2133 : 55 : int dum = 3;
2134 : :
2135 [ + - ]: 55 : iMesh_getVtxArrCoords( instance, &vertex_handle, 1, order, &tmp_xyz, &dum, &dum, err );
2136 [ + - ]: 55 : if( iBase_SUCCESS == *err )
2137 : : {
2138 : 55 : *x = xyz[0];
2139 : 55 : *y = xyz[1];
2140 : 55 : *z = xyz[2];
2141 : : }
2142 : 55 : }
2143 : :
2144 : 2977 : void iMesh_getEntAdj( iMesh_Instance instance,
2145 : : /*in*/ const iBase_EntityHandle entity_handle,
2146 : : /*in*/ const int entity_type_requested,
2147 : : /*inout*/ iBase_EntityHandle** adj_entity_handles,
2148 : : /*inout*/ int* adj_entity_handles_allocated,
2149 : : /*out*/ int* adj_entity_handles_size, int* err )
2150 : : {
2151 : : int offsets[2];
2152 : 2977 : int* offsets_ptr = offsets;
2153 : 2977 : int offset_size, offset_allocated = 2;
2154 : :
2155 : : iMesh_getEntArrAdj( instance, &entity_handle, 1, entity_type_requested, adj_entity_handles,
2156 : : adj_entity_handles_allocated, adj_entity_handles_size, &offsets_ptr, &offset_allocated,
2157 [ + - ]: 2977 : &offset_size, err );
2158 : 2977 : }
2159 : :
2160 : 0 : void iMesh_getEnt2ndAdj( iMesh_Instance instance, iBase_EntityHandle entity_handle, int order_adjacent_key,
2161 : : int requested_entity_type, iBase_EntityHandle** adj_entities, int* adj_entities_allocated,
2162 : : int* adj_entities_size, int* err )
2163 : : {
2164 : : int offsets[2];
2165 : 0 : int* offsets_ptr = offsets;
2166 : 0 : int offset_size, offset_allocated = 2;
2167 : :
2168 : : iMesh_getEntArr2ndAdj( instance, &entity_handle, 1, order_adjacent_key, requested_entity_type, adj_entities,
2169 : : adj_entities_allocated, adj_entities_size, &offsets_ptr, &offset_allocated, &offset_size,
2170 [ # # ]: 0 : err );
2171 : 0 : }
2172 : :
2173 : 2 : void iMesh_subtract( iMesh_Instance instance,
2174 : : /*in*/ const iBase_EntitySetHandle entity_set_1,
2175 : : /*in*/ const iBase_EntitySetHandle entity_set_2,
2176 : : /*out*/ iBase_EntitySetHandle* result_entity_set, int* err )
2177 : : {
2178 : : EntityHandle temp_set;
2179 : 2 : EntityHandle set1 = ENTITY_HANDLE( entity_set_1 ), set2 = ENTITY_HANDLE( entity_set_2 );
2180 : :
2181 : 2 : int isList1 = 0, isList2 = 0;
2182 [ + - ]: 2 : iMesh_isList( instance, entity_set_1, &isList1, err );
2183 [ - + ]: 2 : if( *err != iBase_SUCCESS ) return;
2184 [ + - ]: 2 : iMesh_isList( instance, entity_set_2, &isList2, err );
2185 [ - + ]: 2 : if( *err != iBase_SUCCESS ) return;
2186 : :
2187 : : ErrorCode result;
2188 [ + + ][ + - ]: 2 : if( isList1 && isList2 )
2189 [ + - ]: 1 : result = MOABI->create_meshset( MESHSET_ORDERED, temp_set );
2190 : : else
2191 [ + - ]: 1 : result = MOABI->create_meshset( MESHSET_SET, temp_set );
2192 : :
2193 [ - + ][ # # ]: 2 : if( MB_SUCCESS != result ) ERROR( result, "iMesh_subtract: couldn't create result set." );
2194 : :
2195 : : // if the second set is the root set, the result is always the empty set
2196 [ + - ]: 2 : if( entity_set_2 )
2197 : : {
2198 [ - + ]: 2 : if( !entity_set_1 )
2199 : : {
2200 : : // subtracting from the root set, so get everything first...
2201 [ # # ]: 0 : Range entities;
2202 [ # # ]: 0 : result = MOABI->get_entities_by_handle( 0, entities );
2203 [ # # ][ # # ]: 0 : if( MB_SUCCESS == result ) result = MOABI->add_entities( temp_set, entities );
2204 : : // ...but not the newly-created set!
2205 [ # # ][ # # ]: 0 : if( MB_SUCCESS == result ) result = MOABI->remove_entities( temp_set, &temp_set, 1 );
2206 : : }
2207 : : else
2208 [ + - ]: 2 : result = MOABI->unite_meshset( temp_set, set1 );
2209 : :
2210 [ + - ][ + - ]: 2 : if( MB_SUCCESS == result ) result = MOABI->subtract_meshset( temp_set, set2 );
2211 : : }
2212 : :
2213 [ - + ][ # # ]: 2 : CHKERR( result, "iMesh_subtract: ERROR subtract failed." );
2214 : 2 : *result_entity_set = (iBase_EntitySetHandle)temp_set;
2215 : :
2216 [ + - ]: 2 : RETURN( iBase_SUCCESS );
2217 : : }
2218 : :
2219 : 2 : void iMesh_intersect( iMesh_Instance instance,
2220 : : /*in*/ const iBase_EntitySetHandle entity_set_1,
2221 : : /*in*/ const iBase_EntitySetHandle entity_set_2,
2222 : : /*out*/ iBase_EntitySetHandle* result_entity_set, int* err )
2223 : : {
2224 : : EntityHandle temp_set;
2225 : 2 : EntityHandle set1 = ENTITY_HANDLE( entity_set_1 ), set2 = ENTITY_HANDLE( entity_set_2 );
2226 : :
2227 : 2 : int isList1 = 0, isList2 = 0;
2228 [ + - ]: 2 : iMesh_isList( instance, entity_set_1, &isList1, err );
2229 [ - + ]: 2 : if( *err != iBase_SUCCESS ) return;
2230 [ + - ]: 2 : iMesh_isList( instance, entity_set_2, &isList2, err );
2231 [ - + ]: 2 : if( *err != iBase_SUCCESS ) return;
2232 : :
2233 : : ErrorCode result;
2234 [ + + ][ + - ]: 2 : if( isList1 && isList2 )
2235 [ + - ]: 1 : result = MOABI->create_meshset( MESHSET_ORDERED, temp_set );
2236 : : else
2237 [ + - ]: 1 : result = MOABI->create_meshset( MESHSET_SET, temp_set );
2238 : :
2239 [ - + ][ # # ]: 2 : if( MB_SUCCESS != result ) ERROR( result, "iMesh_intersect: couldn't create result set." );
2240 : :
2241 [ - + ][ # # ]: 2 : if( !entity_set_1 && !entity_set_2 )
2242 : : {
2243 : : // intersecting the root set with itself, so get everything...
2244 [ # # ]: 0 : Range entities;
2245 [ # # ]: 0 : result = MOABI->get_entities_by_handle( 0, entities );
2246 [ # # ][ # # ]: 0 : if( MB_SUCCESS == result ) result = MOABI->add_entities( temp_set, entities );
2247 : : // ...but not the newly-created set!
2248 [ # # ][ # # ]: 0 : if( MB_SUCCESS == result ) result = MOABI->remove_entities( temp_set, &temp_set, 1 );
2249 : : }
2250 [ - + ]: 2 : else if( !entity_set_1 )
2251 : : {
2252 [ # # ]: 0 : result = MOABI->unite_meshset( temp_set, set2 );
2253 : : }
2254 [ - + ]: 2 : else if( !entity_set_2 )
2255 : : {
2256 [ # # ]: 0 : result = MOABI->unite_meshset( temp_set, set1 );
2257 : : }
2258 : : else
2259 : : {
2260 [ + + ][ + - ]: 2 : if( isList1 && isList2 )
2261 : : {
2262 : : // ITAPS has very specific rules about the behavior of intersection on
2263 : : // list-type sets. Since MOAB doesn't (and likely will never) work
2264 : : // exactly this way, we implement our own algorithm here.
2265 : :
2266 : : #ifdef MOAB_HAVE_UNORDERED_MAP
2267 : : typedef MOAB_UNORDERED_MAP_NS::unordered_map< EntityHandle, size_t > lookup_t;
2268 : : #else
2269 : : typedef std::map< EntityHandle, size_t > lookup_t;
2270 : : #endif
2271 : :
2272 : : // First, build a lookup table for the second set.
2273 [ + - ]: 1 : lookup_t lookup;
2274 : : {
2275 [ + - ]: 1 : std::vector< EntityHandle > contents2;
2276 [ + - ][ - + ]: 1 : result = MOABI->get_entities_by_handle( set2, contents2 );CHKERR( result, "iMesh_intersect: ERROR intersect failed." );
[ # # ]
2277 : :
2278 [ + - ][ + - ]: 1201 : for( std::vector< EntityHandle >::iterator i = contents2.begin(); i != contents2.end(); ++i )
[ + + ][ + - ]
2279 : : {
2280 : : #ifdef MOAB_HAVE_UNORDERED_MAP
2281 [ + - ][ + - ]: 1200 : lookup_t::iterator j = lookup.find( *i );
2282 : : #else
2283 : : lookup_t::iterator j = lookup.lower_bound( *i );
2284 : : #endif
2285 [ + - ][ - + ]: 1200 : if( j != lookup.end() && j->first == *i )
[ # # ][ # # ]
[ # # ][ + - ]
[ - + # # ]
2286 [ # # ]: 0 : ++j->second;
2287 : : else
2288 [ + - ][ + - ]: 1200 : lookup.insert( j, lookup_t::value_type( *i, 1 ) );
[ + - ][ + - ]
2289 : 1 : }
2290 : : }
2291 : :
2292 : : // Then, iterate over the contents of the first set and check for
2293 : : // their existence in the second set.
2294 [ + - ][ + - ]: 2 : std::vector< EntityHandle > contents1;
2295 [ + - ][ - + ]: 1 : result = MOABI->get_entities_by_handle( set1, contents1 );CHKERR( result, "iMesh_intersect: ERROR intersect failed." );
[ # # ]
2296 : :
2297 : 1 : std::vector< EntityHandle >::iterator w = contents1.begin();
2298 [ + - ][ + - ]: 3001 : for( std::vector< EntityHandle >::iterator i = contents1.begin(); i != contents1.end(); ++i )
[ + + ]
2299 : : {
2300 [ + - ][ + - ]: 3000 : lookup_t::iterator j = lookup.find( *i );
2301 [ + - ][ + + ]: 3000 : if( j != lookup.end() && j->second )
[ + - ][ + + ]
[ + - ]
[ + + # # ]
2302 : : {
2303 [ + - ]: 1200 : --j->second;
2304 [ + - ][ + - ]: 1200 : *w = *i;
2305 [ + - ]: 1200 : ++w;
2306 : : }
2307 : : }
2308 : :
2309 [ + - ][ + - ]: 2 : result = MOABI->add_entities( temp_set, &contents1[0], w - contents1.begin() );
[ + - ][ + - ]
2310 : : }
2311 : : else
2312 : : {
2313 [ + - ]: 1 : result = MOABI->unite_meshset( temp_set, set1 );
2314 [ + - ][ + - ]: 1 : if( MB_SUCCESS == result ) result = MOABI->intersect_meshset( temp_set, set2 );
2315 : : }
2316 : : }
2317 : :
2318 [ - + ][ # # ]: 2 : CHKERR( result, "iMesh_intersect: ERROR intersect failed." );
2319 : 2 : *result_entity_set = (iBase_EntitySetHandle)temp_set;
2320 : :
2321 [ + - ]: 2 : RETURN( iBase_SUCCESS );
2322 : : }
2323 : :
2324 : 2 : void iMesh_unite( iMesh_Instance instance,
2325 : : /*in*/ const iBase_EntitySetHandle entity_set_1,
2326 : : /*in*/ const iBase_EntitySetHandle entity_set_2,
2327 : : /*out*/ iBase_EntitySetHandle* result_entity_set, int* err )
2328 : : {
2329 : : EntityHandle temp_set;
2330 : 2 : EntityHandle set1 = ENTITY_HANDLE( entity_set_1 ), set2 = ENTITY_HANDLE( entity_set_2 );
2331 : :
2332 : 2 : int isList1 = 0, isList2 = 0;
2333 [ + - ]: 2 : iMesh_isList( instance, entity_set_1, &isList1, err );
2334 [ - + ]: 2 : if( *err != iBase_SUCCESS ) return;
2335 [ + - ]: 2 : iMesh_isList( instance, entity_set_2, &isList2, err );
2336 [ - + ]: 2 : if( *err != iBase_SUCCESS ) return;
2337 : :
2338 : : ErrorCode result;
2339 [ + + ][ + - ]: 2 : if( isList1 && isList2 )
2340 [ + - ]: 1 : result = MOABI->create_meshset( MESHSET_ORDERED, temp_set );
2341 : : else
2342 [ + - ]: 1 : result = MOABI->create_meshset( MESHSET_SET, temp_set );
2343 : :
2344 [ - + ][ # # ]: 2 : if( MB_SUCCESS != result ) ERROR( result, "iMesh_unite: couldn't create result set." );
2345 : :
2346 [ + - ][ + - ]: 2 : if( entity_set_1 && entity_set_2 )
2347 : : {
2348 [ + - ]: 2 : result = MOABI->unite_meshset( temp_set, set1 );
2349 [ + - ][ + - ]: 2 : if( MB_SUCCESS == result ) result = MOABI->unite_meshset( temp_set, set2 );
2350 : : }
2351 : : else
2352 : : {
2353 : : // uniting with the root set, so get everything...
2354 [ # # ]: 0 : Range entities;
2355 [ # # ]: 0 : result = MOABI->get_entities_by_handle( 0, entities );
2356 [ # # ][ # # ]: 0 : if( MB_SUCCESS == result ) result = MOABI->add_entities( temp_set, entities );
2357 : : // ...but not the newly-created set!
2358 [ # # ][ # # ]: 0 : if( MB_SUCCESS == result ) result = MOABI->remove_entities( temp_set, &temp_set, 1 );
2359 : : }
2360 : :
2361 [ - + ][ # # ]: 2 : CHKERR( result, "iMesh_unite: ERROR unite failed." );
2362 : :
2363 : 2 : *result_entity_set = (iBase_EntitySetHandle)temp_set;
2364 : :
2365 [ + - ]: 2 : RETURN( iBase_SUCCESS );
2366 : : }
2367 : :
2368 : 183 : void iMesh_getEntitiesRec( iMesh_Instance instance,
2369 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2370 : : /*in*/ const int entity_type,
2371 : : /*in*/ const int entity_topology,
2372 : : /*in*/ const int recursive,
2373 : : /*out*/ iBase_EntityHandle** entity_handles,
2374 : : /*out*/ int* entity_handles_allocated,
2375 : : /*out*/ int* entity_handles_size,
2376 : : /*out*/ int* err )
2377 : : {
2378 [ + - ][ - + ]: 183 : CHKENUM( entity_type, iBase_EntityType, iBase_INVALID_ENTITY_TYPE );
[ # # ]
2379 [ + - ][ - + ]: 183 : CHKENUM( entity_topology, iMesh_EntityTopology, iBase_INVALID_ENTITY_TOPOLOGY );
[ # # ]
2380 : :
2381 : 183 : bool use_top = false;
2382 : : // initialize just to get rid of compiler warning
2383 : 183 : EntityType type = mb_topology_table[iMesh_ALL_TOPOLOGIES];
2384 [ + - ]: 183 : std::vector< EntityHandle > out_entities;
2385 : :
2386 [ + + ]: 183 : if( entity_topology != iMesh_ALL_TOPOLOGIES )
2387 : : {
2388 : 119 : type = mb_topology_table[entity_topology];
2389 : 119 : use_top = true;
2390 : :
2391 [ + + ]: 119 : if( entity_type != iBase_ALL_TYPES )
2392 : : {
2393 [ + - ][ + - ]: 39 : if( entity_topology != iMesh_SEPTAHEDRON && entity_type != CN::Dimension( type ) )
[ - + ][ - + ]
2394 [ # # ]: 0 : ERROR( iBase_BAD_TYPE_AND_TOPO, "type and topology are inconsistant" );
2395 : :
2396 : : // Special-case handling for septahedra since we don't support them
2397 [ - + ][ # # ]: 39 : else if( entity_topology == iMesh_SEPTAHEDRON && entity_type != iBase_REGION )
2398 [ # # ]: 0 : ERROR( iBase_BAD_TYPE_AND_TOPO, "type and topology are inconsistant" );
2399 : : }
2400 : : }
2401 : :
2402 : 183 : EntityHandle handle = ENTITY_HANDLE( entity_set_handle );
2403 : : ErrorCode result;
2404 : :
2405 [ + + ]: 183 : if( use_top )
2406 : : {
2407 [ + + ]: 119 : if( entity_topology == iMesh_SEPTAHEDRON )
2408 : 7 : result = MB_SUCCESS; // MOAB doesn't do septahedrons, so there are never any.
2409 : : else
2410 [ + - ]: 119 : result = MOABI->get_entities_by_type( handle, type, out_entities, recursive );
2411 : : }
2412 [ + + ]: 64 : else if( entity_type != iBase_ALL_TYPES )
2413 [ + - ]: 51 : result = MOABI->get_entities_by_dimension( handle, entity_type, out_entities, recursive );
2414 : : else
2415 [ + - ]: 13 : result = MOABI->get_entities_by_handle( handle, out_entities, recursive );
2416 : :
2417 [ - + ][ # # ]: 183 : CHKERR( result, "iMesh_GetEntities:ERROR getting entities." );
2418 : :
2419 : : // remove entity sets from the result list
2420 : 183 : std::vector< EntityHandle >::iterator iter, end_iter;
2421 [ + + ][ + + ]: 183 : if( iBase_ALL_TYPES == entity_type && iMesh_ALL_TOPOLOGIES == entity_topology )
2422 : : {
2423 [ + - ][ + - ]: 4183 : for( iter = out_entities.begin(); iter != out_entities.end() && TYPE_FROM_HANDLE( *iter ) != MBENTITYSET;
[ + + ][ + - ]
[ + - ][ + + ]
[ + - ]
[ + + # # ]
2424 : : ++iter )
2425 : : ;
2426 [ + - ][ + - ]: 41 : for( end_iter = iter; iter != out_entities.end(); ++iter )
[ + + ]
2427 [ + - ][ + - ]: 28 : if( TYPE_FROM_HANDLE( *iter ) != MBENTITYSET ) *( end_iter++ ) = *iter;
[ - + ][ # # ]
[ # # ][ # # ]
2428 [ + - ]: 13 : out_entities.erase( end_iter, out_entities.end() );
2429 : : }
2430 : :
2431 : 183 : int num_ents = out_entities.size();
2432 : :
2433 [ + - ][ + + ]: 365 : ALLOC_CHECK_ARRAY_NOFAIL( entity_handles, num_ents );
[ + - ]
2434 : :
2435 : 182 : int k = 0;
2436 : :
2437 : : // filter out entity sets here
2438 [ + - ][ + - ]: 76228 : for( iter = out_entities.begin(); iter != out_entities.end(); ++iter )
[ + + ]
2439 [ + - ]: 76046 : ( *entity_handles )[k++] = (iBase_EntityHandle)*iter;
2440 : :
2441 : : // now it's safe to set the size; set it to k, not out_entities.size(), to
2442 : : // account for sets which might have been removed
2443 : 182 : *entity_handles_size = k;
2444 : :
2445 [ + - ]: 365 : RETURN( iBase_SUCCESS );
2446 : : }
2447 : :
2448 : : /**\brief Get the number of entities with the specified type in the instance or set, recursive
2449 : : *
2450 : : * Get the number of entities with the specified type in the instance
2451 : : * or set. If recursive is passed in non-zero, includes entities in owned sets.
2452 : : * If entity set handle is zero, return information for instance,
2453 : : * otherwise for set. Value of entity type must be from the
2454 : : * iBase_EntityType enumeration. If iBase_ALL_TYPES is specified,
2455 : : * total number of entities (excluding entity sets) is returned.
2456 : : * \param instance iMesh instance handle
2457 : : * \param entity_set_handle Entity set being queried
2458 : : * \param entity_type Type of entity requested
2459 : : * \param recursive If non-zero, includes entities in owned sets too
2460 : : * \param num_type Pointer to number of entities, returned from function
2461 : : * \param *err Pointer to error type returned from function
2462 : : */
2463 : 164 : void iMesh_getNumOfTypeRec( iMesh_Instance instance,
2464 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2465 : : /*in*/ const int entity_type,
2466 : : /*in*/ const int recursive,
2467 : : /*out*/ int* num_type,
2468 : : /*out*/ int* err )
2469 : : {
2470 [ + - ][ - + ]: 164 : CHKENUM( entity_type, iBase_EntityType, iBase_INVALID_ENTITY_TYPE );
2471 : :
2472 : 164 : *num_type = 0;
2473 : : ErrorCode result;
2474 [ + + ]: 164 : if( entity_type == iBase_ALL_TYPES )
2475 : : {
2476 : 147 : result = MOABI->get_number_entities_by_handle( ENTITY_HANDLE( entity_set_handle ), *num_type, recursive );
2477 [ + - ][ + - ]: 147 : if( MB_SUCCESS == result && !recursive )
2478 : : {
2479 : 147 : int num_sets = 0;
2480 : 147 : result = MOABI->get_number_entities_by_type( ENTITY_HANDLE( entity_set_handle ), MBENTITYSET, num_sets,
2481 [ + - ]: 147 : recursive );
2482 : 147 : *num_type -= num_sets;
2483 : : }
2484 : : }
2485 : : else
2486 : : {
2487 : 17 : result = MOABI->get_number_entities_by_dimension( ENTITY_HANDLE( entity_set_handle ), entity_type, *num_type,
2488 : 17 : recursive );
2489 : : }
2490 : :
2491 [ - + ]: 164 : CHKERR( result, "iMesh_entitysetGetNumberEntityOfType: "
2492 : : "ERROR getting number of entities by type." );
2493 : :
2494 : 164 : RETURN( iBase_SUCCESS );
2495 : : }
2496 : :
2497 : : /**\brief Get the number of entities with the specified topology in the instance or set
2498 : : *
2499 : : * Get the number of entities with the specified topology in the instance
2500 : : * or set. If recursive is passed in non-zero, includes entities in owned sets.
2501 : : * If entity set handle is zero, return information for instance,
2502 : : * otherwise for set. Value of entity topology must be from the
2503 : : * iMesh_EntityTopology enumeration. If iMesh_ALL_TOPOLOGIES is specified,
2504 : : * total number of entities (excluding entity sets) is returned.
2505 : : * \param instance iMesh instance handle
2506 : : * \param entity_set_handle Entity set being queried
2507 : : * \param entity_topology Topology of entity requested
2508 : : * \param recursive If non-zero, includes entities in owned sets too
2509 : : * \param num_topo Pointer to number of entities, returned from function
2510 : : * \param *err Pointer to error type returned from function
2511 : : */
2512 : 11 : void iMesh_getNumOfTopoRec( iMesh_Instance instance,
2513 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2514 : : /*in*/ const int entity_topology,
2515 : : /*in*/ const int recursive,
2516 : : /*out*/ int* num_topo,
2517 : : /*out*/ int* err )
2518 : : {
2519 [ + - ][ - + ]: 11 : CHKENUM( entity_topology, iMesh_EntityTopology, iBase_INVALID_ENTITY_TOPOLOGY );
2520 : :
2521 [ + + ]: 11 : if( entity_topology == iMesh_SEPTAHEDRON )
2522 : : {
2523 : 1 : *num_topo = 0;
2524 : 1 : RETURN( iBase_SUCCESS );
2525 : : }
2526 : :
2527 : 10 : *num_topo = 0;
2528 : : ErrorCode result;
2529 [ - + ]: 10 : if( iMesh_ALL_TOPOLOGIES == entity_topology )
2530 : : {
2531 : 0 : result = MOABI->get_number_entities_by_handle( ENTITY_HANDLE( entity_set_handle ), *num_topo, recursive );
2532 : :
2533 [ # # ][ # # ]: 0 : if( !recursive && MB_SUCCESS == result )
2534 : : { // remove entity sets from count
2535 : : int num_sets;
2536 : 0 : result = MOABI->get_number_entities_by_type( ENTITY_HANDLE( entity_set_handle ), MBENTITYSET, num_sets,
2537 [ # # ]: 0 : recursive );
2538 : 0 : *num_topo -= num_sets;
2539 : : }
2540 : : }
2541 : : else
2542 : : {
2543 : 10 : result = MOABI->get_number_entities_by_type( ENTITY_HANDLE( entity_set_handle ),
2544 : 10 : mb_topology_table[entity_topology], *num_topo, recursive );
2545 : : }
2546 : :
2547 [ - + ]: 10 : CHKERR( result, "iMesh_entitysetGetNumberEntityOfTopology: ERROR getting "
2548 : : "number of entities by topology." );
2549 : 11 : RETURN( iBase_SUCCESS );
2550 : : }
2551 : :
2552 : : /**\brief Get entities with specified type, topology, tag(s) and (optionally) tag value(s)
2553 : : *
2554 : : * Get entities with the specified type, topology, tag(s), and optionally tag value(s).
2555 : : * If tag values pointer is input as zero, entities with specified tag(s) are returned,
2556 : : * regardless of their value.
2557 : : * \param instance iMesh instance handle
2558 : : * \param entity_set_handle Entity set being queried
2559 : : * \param entity_type Type of entities being requested
2560 : : * \param entity_topology Topology of entities being requested
2561 : : * \param tag_handles Array of tag handles
2562 : : * \param tag_vals Array of tag values (zero if values not requested)
2563 : : * \param num_tags_vals Number of tags and optionally values
2564 : : * \param recursive If non-zero, gets entities in owned sets too
2565 : : * \param *entity_handles Pointer to array of entity handles returned
2566 : : * from function
2567 : : * \param *entity_handles_allocated Pointer to allocated size of
2568 : : * entity_handles array
2569 : : * \param *entity_handles_size Pointer to occupied size of entity_handles array
2570 : : * \param *err Pointer to error type returned from function
2571 : : */
2572 : 0 : void iMesh_getEntsByTagsRec( iMesh_Instance instance,
2573 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2574 : : /*in*/ const int entity_type,
2575 : : /*in*/ const int entity_topology,
2576 : : /*in*/ const iBase_TagHandle* tag_handles,
2577 : : /*in*/ const char* const* tag_vals,
2578 : : /*in*/ const int num_tags_vals,
2579 : : /*in*/ const int recursive,
2580 : : /*out*/ iBase_EntityHandle** entity_handles,
2581 : : /*out*/ int* entity_handles_allocated,
2582 : : /*out*/ int* entity_handles_size,
2583 : : /*out*/ int* err )
2584 : : {
2585 [ # # ][ # # ]: 0 : CHKENUM( entity_type, iBase_EntityType, iBase_INVALID_ENTITY_TYPE );
[ # # ]
2586 [ # # ][ # # ]: 0 : CHKENUM( entity_topology, iMesh_EntityTopology, iBase_INVALID_ENTITY_TOPOLOGY );
[ # # ]
2587 : :
2588 : 0 : bool use_top = false;
2589 : : // initialize just to get rid of compiler warning
2590 : 0 : EntityType type = mb_topology_table[iMesh_ALL_TOPOLOGIES];
2591 [ # # ]: 0 : Range out_entities;
2592 : :
2593 [ # # ]: 0 : if( entity_topology != iMesh_ALL_TOPOLOGIES )
2594 : : {
2595 : 0 : type = mb_topology_table[entity_topology];
2596 : 0 : use_top = true;
2597 : :
2598 [ # # ]: 0 : if( entity_type != iBase_ALL_TYPES )
2599 : : {
2600 [ # # ][ # # ]: 0 : if( entity_topology != iMesh_SEPTAHEDRON && entity_type != CN::Dimension( type ) )
[ # # ][ # # ]
2601 [ # # ]: 0 : ERROR( iBase_BAD_TYPE_AND_TOPO, "type and topology are inconsistant" );
2602 : :
2603 : : // Special-case handling for septahedra since we don't support them
2604 [ # # ][ # # ]: 0 : else if( entity_topology == iMesh_SEPTAHEDRON && entity_type != iBase_REGION )
2605 [ # # ]: 0 : ERROR( iBase_BAD_TYPE_AND_TOPO, "type and topology are inconsistant" );
2606 : : }
2607 : : }
2608 : :
2609 : 0 : EntityHandle handle = ENTITY_HANDLE( entity_set_handle );
2610 : 0 : ErrorCode result = MB_SUCCESS;
2611 : :
2612 [ # # ]: 0 : if( use_top )
2613 : : {
2614 [ # # ]: 0 : if( entity_topology == iMesh_SEPTAHEDRON )
2615 : 0 : result = MB_SUCCESS; // MOAB doesn't do septahedrons, so there are never any.
2616 : : else
2617 : : result =
2618 : 0 : MOABI->get_entities_by_type_and_tag( handle, type, (Tag*)tag_handles, (const void* const*)tag_vals,
2619 [ # # ]: 0 : num_tags_vals, out_entities, Interface::INTERSECT, recursive );
2620 : : }
2621 [ # # ]: 0 : else if( entity_type != iBase_ALL_TYPES )
2622 : : {
2623 : : // need to loop over all types of this dimension
2624 [ # # ]: 0 : DimensionPair dimpair = CN::getDimPair( entity_type );
2625 [ # # ][ # # ]: 0 : for( EntityType tp = dimpair.first; tp <= dimpair.second; tp++ )
2626 : : {
2627 [ # # ]: 0 : Range tmp_range;
2628 : : ErrorCode tmp_result =
2629 : 0 : MOABI->get_entities_by_type_and_tag( handle, type, (Tag*)tag_handles, (const void* const*)tag_vals,
2630 [ # # ]: 0 : num_tags_vals, tmp_range, Interface::INTERSECT, recursive );
2631 [ # # ]: 0 : if( MB_SUCCESS != tmp_result )
2632 : 0 : result = tmp_result;
2633 : : else
2634 [ # # ]: 0 : out_entities.merge( tmp_range );
2635 : 0 : }
2636 : : }
2637 : : else
2638 : 0 : result = MOABI->get_entities_by_type_and_tag( handle, type, (Tag*)tag_handles, (const void* const*)tag_vals,
2639 [ # # ]: 0 : num_tags_vals, out_entities, Interface::INTERSECT, recursive );
2640 : :
2641 [ # # ][ # # ]: 0 : CHKERR( result, "iMesh_GetEntities:ERROR getting entities." );
2642 : :
2643 [ # # ][ # # ]: 0 : ALLOC_CHECK_ARRAY_NOFAIL( entity_handles, out_entities.size() );
[ # # ][ # # ]
2644 : :
2645 [ # # ]: 0 : Range::iterator iter = out_entities.begin();
2646 [ # # ]: 0 : Range::iterator end_iter = out_entities.end();
2647 : 0 : int k = 0;
2648 : :
2649 : : // filter out entity sets here
2650 [ # # ][ # # ]: 0 : if( iBase_ALL_TYPES == entity_type && iMesh_ALL_TOPOLOGIES == entity_topology )
2651 : : {
2652 [ # # ][ # # ]: 0 : for( ; iter != end_iter && MOABI->type_from_handle( *iter ) != MBENTITYSET; ++iter )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
2653 [ # # ]: 0 : ( *entity_handles )[k++] = (iBase_EntityHandle)*iter;
2654 : : }
2655 : : else
2656 : : {
2657 [ # # ][ # # ]: 0 : for( ; iter != end_iter; ++iter )
[ # # ]
2658 [ # # ]: 0 : ( *entity_handles )[k++] = (iBase_EntityHandle)*iter;
2659 : : }
2660 : :
2661 : : // now it's safe to set the size; set it to k, not out_entities.size(), to
2662 : : // account for sets which might have been removed
2663 : 0 : *entity_handles_size = k;
2664 : :
2665 [ # # ]: 0 : RETURN( iBase_SUCCESS );
2666 : : }
2667 : :
2668 : 4 : void iMesh_getEntSetsByTagsRec( iMesh_Instance instance,
2669 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2670 : : /*in*/ const iBase_TagHandle* tag_handles,
2671 : : /*in*/ const char* const* tag_vals,
2672 : : /*in*/ const int num_tags_vals,
2673 : : /*in*/ const int recursive,
2674 : : /*out*/ iBase_EntitySetHandle** set_handles,
2675 : : /*out*/ int* set_handles_allocated,
2676 : : /*out*/ int* set_handles_size,
2677 : : /*out*/ int* err )
2678 : : {
2679 [ + - ]: 4 : Range out_entities;
2680 : :
2681 : 4 : EntityHandle handle = ENTITY_HANDLE( entity_set_handle );
2682 : : ErrorCode result;
2683 : :
2684 : 4 : result = MOABI->get_entities_by_type_and_tag( handle, MBENTITYSET, (Tag*)tag_handles, (const void* const*)tag_vals,
2685 [ + - ][ - + ]: 4 : num_tags_vals, out_entities, Interface::INTERSECT, recursive );CHKERR( result, "ERROR getting entities." );
[ # # ]
2686 : :
2687 [ + - ][ + - ]: 8 : ALLOC_CHECK_ARRAY_NOFAIL( set_handles, out_entities.size() );
[ - + ][ + - ]
2688 : :
2689 [ + - ][ + - ]: 4 : std::copy( out_entities.begin(), out_entities.end(), ( (EntityHandle*)*set_handles ) );
[ + - ]
2690 : :
2691 [ + - ]: 8 : RETURN( iBase_SUCCESS );
2692 : : }
2693 : :
2694 : 0 : void iMesh_MBCNType( /*in*/ const int imesh_entity_topology,
2695 : : /*out*/ int* mbcn_type )
2696 : : {
2697 [ # # ][ # # ]: 0 : if( iMesh_POINT > imesh_entity_topology || iMesh_ALL_TOPOLOGIES <= imesh_entity_topology )
2698 : 0 : *mbcn_type = -1;
2699 : : else
2700 : 0 : *mbcn_type = mb_topology_table[imesh_entity_topology];
2701 : 0 : }
2702 : :
2703 : 5 : void iMesh_tagIterate( iMesh_Instance instance,
2704 : : /*in*/ const iBase_TagHandle tag_handle, iBase_EntityArrIterator entArr_iterator,
2705 : : /**< [in] Iterator being queried */
2706 : : void* data,
2707 : : /**< [out] Pointer to pointer that will be set to tag data memory
2708 : : \ref trio) */
2709 : : int* count,
2710 : : /**< [out] Number of contiguous entities in this subrange */
2711 : : int* err
2712 : : /**< [out] Returned Error status (see iBase_ErrorType) */
2713 : : )
2714 : : {
2715 [ - + ]: 5 : MBRangeIter* ri = dynamic_cast< MBRangeIter* >( entArr_iterator );
2716 [ - + ][ # # ]: 5 : if( !ri ) CHKERR( MB_FAILURE, "Wrong type of iterator, need a range-based iterator for iMesh_tagIterate." );
2717 : :
2718 : 5 : ErrorCode result = MOABI->tag_iterate( TAG_HANDLE( tag_handle ), ri->position(), ri->end(), *count,
2719 [ - + ]: 5 : *static_cast< void** >( data ) );CHKERR( result, "Problem getting tag iterator." );
2720 : :
2721 : 5 : RETURN( iBase_SUCCESS );
2722 : : }
2723 : :
2724 : 0 : void iMesh_connectIterate( iMesh_Instance instance, iBase_EntityArrIterator entArr_iterator,
2725 : : /**< [in] Iterator being queried */
2726 : : iBase_EntityHandle** connect,
2727 : : /**< [out] Pointer to pointer that will be set to connectivity data memory */
2728 : : int* verts_per_entity,
2729 : : /**< [out] Pointer to integer set to number of vertices per entity */
2730 : : int* count,
2731 : : /**< [out] Number of contiguous entities in this subrange */
2732 : : int* err
2733 : : /**< [out] Returned Error status (see iBase_ErrorType) */
2734 : : )
2735 : : {
2736 [ # # ]: 0 : MBRangeIter* ri = dynamic_cast< MBRangeIter* >( entArr_iterator );
2737 [ # # ][ # # ]: 0 : if( !ri ) CHKERR( MB_FAILURE, "Wrong type of iterator, need a range-based iterator for iMesh_connectIterate." );
2738 : :
2739 : : ErrorCode result =
2740 : 0 : MOABI->connect_iterate( ri->position(), ri->end(), reinterpret_cast< EntityHandle*& >( *connect ),
2741 [ # # ]: 0 : *verts_per_entity, *count );CHKERR( result, "Problem getting connect iterator." );
2742 : :
2743 : 0 : RETURN( iBase_SUCCESS );
2744 : : }
2745 : :
2746 : 0 : void iMesh_coordsIterate( iMesh_Instance instance, iBase_EntityArrIterator entArr_iterator,
2747 : : /**< [in] Iterator being queried */
2748 : : double** xcoords_ptr,
2749 : : /**< [out] Pointer to pointer that will be set to x coordinate data memory */
2750 : : double** ycoords_ptr,
2751 : : /**< [out] Pointer to pointer that will be set to y coordinate data memory */
2752 : : double** zcoords_ptr,
2753 : : /**< [out] Pointer to pointer that will be set to z coordinate data memory */
2754 : : int* count,
2755 : : /**< [out] Number of contiguous entities in this subrange */
2756 : : int* err
2757 : : /**< [out] Returned Error status (see iBase_ErrorType) */
2758 : : )
2759 : : {
2760 [ # # ]: 0 : MBRangeIter* ri = dynamic_cast< MBRangeIter* >( entArr_iterator );
2761 [ # # ][ # # ]: 0 : if( !ri ) CHKERR( MB_FAILURE, "Wrong type of iterator, need a range-based iterator for iMesh_coordsIterate." );
2762 : :
2763 : : ErrorCode result =
2764 [ # # ]: 0 : MOABI->coords_iterate( ri->position(), ri->end(), *xcoords_ptr, *ycoords_ptr, *zcoords_ptr, *count );CHKERR( result, "Problem getting coords iterator." );
2765 : :
2766 : 0 : RETURN( iBase_SUCCESS );
2767 : : }
2768 : :
2769 : 2 : void iMesh_stepEntIter( iMesh_Instance instance,
2770 : : /**< [in] iMesh instance handle */
2771 : : iBase_EntityIterator ent_iterator,
2772 : : /**< [in] Iterator being queried */
2773 : : int step_length,
2774 : : /**< [in] Number of entities to step the iterator */
2775 : : int* at_end,
2776 : : /**< [out] Non-zero if iterator is at the end of the iteration */
2777 : : int* err
2778 : : /**< [out] Returned Error status (see iBase_ErrorType) */
2779 : : )
2780 : : {
2781 : : iMesh_stepEntArrIter( instance, reinterpret_cast< iBase_EntityArrIterator >( ent_iterator ), step_length, at_end,
2782 : 2 : err );
2783 : 2 : }
2784 : :
2785 : 6 : void iMesh_stepEntArrIter( iMesh_Instance instance,
2786 : : /**< [in] iMesh instance handle */
2787 : : iBase_EntityArrIterator entArr_iterator,
2788 : : /**< [in] Iterator being queried */
2789 : : int step_length,
2790 : : /**< [in] Number of entities to step the iterator */
2791 : : int* at_end,
2792 : : /**< [out] Non-zero if iterator is at the end of the iteration */
2793 : : int* err
2794 : : /**< [out] Returned Error status (see iBase_ErrorType) */
2795 : : )
2796 : : {
2797 : : bool tmp;
2798 [ + - ][ - + ]: 6 : ErrorCode result = entArr_iterator->step( step_length, tmp );CHKERR( result, "Problem stepping iterator." );
[ # # ]
2799 : 6 : *at_end = tmp;
2800 [ + - ]: 6 : RETURN( iBase_SUCCESS );
2801 : : }
2802 : :
2803 : : /**
2804 : : * Method: initEntArrIter[]
2805 : : */
2806 : 96 : void iMesh_initEntArrIterRec( iMesh_Instance instance,
2807 : : /*in*/ const iBase_EntitySetHandle entity_set_handle,
2808 : : /*in*/ const int requested_entity_type,
2809 : : /*in*/ const int requested_entity_topology,
2810 : : /*in*/ const int requested_array_size,
2811 : : /*in*/ const int resilient,
2812 : : /*in*/ const int recursive,
2813 : : /*out*/ iBase_EntityArrIterator* entArr_iterator, int* err )
2814 : : {
2815 [ + - ][ - + ]: 96 : CHKENUM( requested_entity_type, iBase_EntityType, iBase_INVALID_ENTITY_TYPE );
[ # # ]
2816 [ + - ][ - + ]: 96 : CHKENUM( requested_entity_topology, iMesh_EntityTopology, iBase_INVALID_ENTITY_TOPOLOGY );
[ # # ]
2817 [ - + ][ # # ]: 96 : if( resilient ) ERROR( iBase_NOT_SUPPORTED, "reslient iterators not supported" );
2818 : :
2819 : 96 : EntityType req_type = mb_topology_table[requested_entity_topology];
2820 : :
2821 [ + + ]: 96 : if( requested_entity_topology != iMesh_ALL_TOPOLOGIES )
2822 : : {
2823 [ + + ]: 68 : if( requested_entity_type != iBase_ALL_TYPES )
2824 : : {
2825 [ + - ][ + - ]: 2 : if( requested_entity_topology != iMesh_SEPTAHEDRON && requested_entity_type != CN::Dimension( req_type ) )
[ - + ][ - + ]
2826 [ # # ]: 0 : ERROR( iBase_BAD_TYPE_AND_TOPO, "type and topology are inconsistant" );
2827 : :
2828 : : // Special-case handling for septahedra since we don't support them
2829 [ - + ][ # # ]: 2 : else if( requested_entity_topology == iMesh_SEPTAHEDRON && requested_entity_type != iBase_REGION )
2830 [ # # ]: 0 : ERROR( iBase_BAD_TYPE_AND_TOPO, "type and topology are inconsistant" );
2831 : : }
2832 : : }
2833 : :
2834 : : ErrorCode result;
2835 : : unsigned flags;
2836 [ + - ][ - + ]: 96 : result = MOABI->get_meshset_options( ENTITY_HANDLE( entity_set_handle ), flags );CHKERR( result, "Invalid entity set handle" );
[ # # ]
2837 : :
2838 [ + + ]: 96 : if( flags & MESHSET_ORDERED )
2839 : : *entArr_iterator =
2840 : : new MBListIter( (iBase_EntityType)requested_entity_type, (iMesh_EntityTopology)requested_entity_topology,
2841 [ + - ][ + - ]: 30 : ENTITY_HANDLE( entity_set_handle ), requested_array_size, recursive );
2842 : : else
2843 : : *entArr_iterator =
2844 : : new MBRangeIter( (iBase_EntityType)requested_entity_type, (iMesh_EntityTopology)requested_entity_topology,
2845 [ + - ][ + - ]: 66 : ENTITY_HANDLE( entity_set_handle ), requested_array_size, recursive );
2846 [ + - ]: 96 : result = ( *entArr_iterator )->reset( MOABI );
2847 [ - + ][ # # ]: 96 : if( MB_SUCCESS != result ) delete *entArr_iterator;CHKERR( result, "iMesh_initEntArrIter: ERROR getting entities of proper type or topology." );
[ - + ][ # # ]
2848 [ + - ]: 96 : RETURN( iBase_SUCCESS );
2849 : : }
2850 : :
2851 : 35 : void iMesh_createTagWithOptions( iMesh_Instance instance,
2852 : : /*in*/ const char* tag_name,
2853 : : /*in*/ const char* tmp_tag_options,
2854 : : /*in*/ const int tag_size,
2855 : : /*in*/ const int tag_type,
2856 : : /*out*/ iBase_TagHandle* tag_handle,
2857 : : /*out*/ int* err,
2858 : : /*in*/ const int tag_name_len,
2859 : : /*in*/ const int tag_options_len )
2860 : : {
2861 [ - + ][ # # ]: 35 : if( tag_size < 0 ) ERROR( iBase_INVALID_ARGUMENT, "iMesh_createTag: invalid tag size" );
2862 [ + - ][ - + ]: 35 : CHKENUM( tag_type, iBase_TagValueType, iBase_INVALID_ARGUMENT );
[ # # ]
2863 : :
2864 [ + - ]: 35 : std::string tmp_tagname( tag_name, tag_name_len );
2865 [ + - ]: 35 : eatwhitespace( tmp_tagname );
2866 : :
2867 : 35 : moab::TagType storage = MB_TAG_SPARSE;
2868 : : ErrorCode result;
2869 : :
2870 : : // declared here 'cuz might have to hold destination of a default value ptr
2871 [ + - ]: 70 : std::string storage_type;
2872 : 35 : const void* def_val = NULL;
2873 [ + - ]: 70 : std::vector< int > def_int;
2874 [ + - ]: 70 : std::vector< double > def_dbl;
2875 [ + - ]: 70 : std::vector< moab::EntityHandle > def_handles;
2876 : : int dum_int;
2877 : : double dum_dbl;
2878 : :
2879 [ + + ]: 35 : if( 0 != tag_options_len )
2880 : : {
2881 [ + - ]: 3 : std::string tag_options = filter_options( tmp_tag_options, tmp_tag_options + tag_options_len );
2882 [ + - ][ + - ]: 6 : FileOptions opts( tag_options.c_str() );
2883 : 3 : const char* option_vals[] = { "SPARSE", "DENSE", "BIT", "MESH" };
2884 : : const moab::TagType opt_types[] = { moab::MB_TAG_SPARSE, moab::MB_TAG_DENSE, moab::MB_TAG_BIT,
2885 : 3 : moab::MB_TAG_MESH };
2886 : 3 : int opt_num = -1;
2887 [ + - ]: 3 : result = opts.match_option( "TAG_STORAGE_TYPE", option_vals, opt_num );
2888 [ - + ]: 3 : if( MB_FAILURE == result )
2889 [ # # ]: 0 : ERROR( result, "iMesh_createTagWithOptions: option string not recognized." );
2890 [ + - ]: 3 : else if( MB_SUCCESS == result )
2891 : : {
2892 [ + - ][ - + ]: 3 : assert( opt_num >= 0 && opt_num <= 3 );
2893 : 3 : storage = opt_types[opt_num];
2894 : : }
2895 : :
2896 : : // now look for default value option; reuse storage_type
2897 : 3 : storage_type.clear();
2898 [ + - ]: 3 : result = opts.get_option( "TAG_DEFAULT_VALUE", storage_type );
2899 [ + + ]: 3 : if( MB_SUCCESS == result )
2900 : : {
2901 : : // ok, need to parse the string into a proper default value
2902 [ - + - - : 2 : switch( tag_type )
- ]
2903 : : {
2904 : : case iBase_INTEGER:
2905 [ # # ]: 0 : result = opts.get_int_option( "TAG_DEFAULT_VALUE", dum_int );
2906 [ # # ]: 0 : def_int.resize( tag_size );
2907 [ # # ]: 0 : std::fill( def_int.begin(), def_int.end(), dum_int );
2908 [ # # ]: 0 : def_val = &def_int[0];
2909 : 0 : break;
2910 : : case iBase_DOUBLE:
2911 [ + - ]: 2 : result = opts.get_real_option( "TAG_DEFAULT_VALUE", dum_dbl );
2912 [ + - ]: 2 : def_dbl.resize( tag_size );
2913 [ + - ]: 2 : std::fill( def_dbl.begin(), def_dbl.end(), dum_dbl );
2914 [ + - ]: 2 : def_val = &def_dbl[0];
2915 : 2 : break;
2916 : : case iBase_ENTITY_HANDLE:
2917 : : // for default handle, will have to use int
2918 [ # # ]: 0 : result = opts.get_int_option( "TAG_DEFAULT_VALUE", dum_int );
2919 [ # # ]: 0 : if( 0 > dum_int )
2920 [ # # ]: 0 : ERROR( result, "iMesh_createTagWithOptions: for default handle-type tag, "
2921 : : "must use non-negative int on input." );
2922 [ # # ]: 0 : def_handles.resize( tag_size );
2923 [ # # ]: 0 : std::fill( def_handles.begin(), def_handles.end(), (moab::EntityHandle)dum_int );
2924 [ # # ]: 0 : def_val = &def_handles[0];
2925 : 0 : break;
2926 : : case iBase_BYTES:
2927 [ # # ]: 0 : if( (int)storage_type.length() < tag_size )
2928 [ # # ]: 0 : ERROR( result, "iMesh_createTagWithOptions: default value for byte-type "
2929 : : "tag must be large enough to store tag value." );
2930 : 0 : def_val = storage_type.c_str();
2931 [ + - ]: 3 : break;
2932 : : }
2933 : 3 : }
2934 : : }
2935 : :
2936 : : moab::Tag new_tag;
2937 : 35 : result = MOABI->tag_get_handle( tmp_tagname.c_str(), tag_size, mb_data_type_table[tag_type], new_tag,
2938 [ + - ]: 35 : storage | MB_TAG_EXCL, def_val );
2939 : :
2940 [ + + ]: 35 : if( MB_SUCCESS != result )
2941 : : {
2942 [ + - ]: 3 : std::string msg( "iMesh_createTag: " );
2943 [ + - ]: 3 : if( MB_ALREADY_ALLOCATED == result )
2944 : : {
2945 [ + - ]: 3 : msg += "Tag already exists with name: \"";
2946 : 3 : *tag_handle = (iBase_TagHandle)new_tag;
2947 : : }
2948 : : else
2949 [ # # ]: 0 : msg += "Failed to create tag with name: \"";
2950 [ + - ]: 3 : msg += tag_name;
2951 [ + - ]: 3 : msg += "\".";
2952 [ + - ]: 3 : ERROR( result, msg.c_str() );
2953 : : }
2954 : :
2955 [ + + ]: 32 : if( tag_type == iBase_ENTITY_HANDLE )
2956 [ + - ]: 9 : MBIMESHI->note_ent_handle_tag( new_tag );
2957 [ - + ]: 23 : else if( tag_type == iBase_ENTITY_SET_HANDLE )
2958 [ # # ]: 0 : MBIMESHI->note_set_handle_tag( new_tag );
2959 : :
2960 : 32 : *tag_handle = (iBase_TagHandle)new_tag;
2961 : :
2962 [ + - ]: 67 : RETURN( iBase_SUCCESS );
2963 : :
2964 : : /* old implementation:
2965 : : Tag new_tag;
2966 : : int this_size = tag_size;
2967 : :
2968 : : ErrorCode result = MOABI->tag_get_handle(tmp_tagname.c_str(),
2969 : : this_size,
2970 : : mb_data_type_table[tag_type],
2971 : : new_tag,
2972 : : MB_TAG_SPARSE|MB_TAG_EXCL);
2973 : :
2974 : : if (MB_SUCCESS != result) {
2975 : : std::string msg("iMesh_createTag: ");
2976 : : if (MB_ALREADY_ALLOCATED == result) {
2977 : : msg += "Tag already exists with name: \"";
2978 : : *tag_handle = (iBase_TagHandle) new_tag;
2979 : : }
2980 : : else
2981 : : msg += "Failed to create tag with name: \"";
2982 : : msg += tag_name;
2983 : : msg += "\".";
2984 : : ERROR(result,msg.c_str());
2985 : : }
2986 : :
2987 : : if (tag_type == iBase_ENTITY_HANDLE)
2988 : : MBIMESHI->note_ent_handle_tag( new_tag );
2989 : : else if (tag_type == iBase_ENTITY_SET_HANDLE)
2990 : : MBIMESHI->note_set_handle_tag( new_tag );
2991 : :
2992 : : *tag_handle = (iBase_TagHandle) new_tag;
2993 : : */
2994 : : }
2995 : :
2996 : : #ifdef __cplusplus
2997 : : } // extern "C"
2998 : : #endif
2999 : :
3000 : 0 : ErrorCode create_int_ents( MBiMesh* mbimesh, Range& from_ents, const EntityHandle* in_set )
3001 : : {
3002 : : // MBiMesh* mbimesh = dynamic_cast<MBiMesh*>(instance);
3003 [ # # ]: 0 : assert( mbimesh );
3004 [ # # ][ # # ]: 0 : assert( mbimesh->AdjTable[10] || mbimesh->AdjTable[5] );
3005 [ # # ]: 0 : Range int_ents;
3006 : : ErrorCode result;
3007 : 0 : Interface* instance = mbimesh->mbImpl;
3008 [ # # ]: 0 : if( mbimesh->AdjTable[10] )
3009 : : {
3010 [ # # ]: 0 : result = instance->get_adjacencies( from_ents, 2, true, int_ents, Interface::UNION );
3011 [ # # ]: 0 : if( MB_SUCCESS != result ) return result;
3012 [ # # ]: 0 : unsigned int old_size = from_ents.size();
3013 [ # # ]: 0 : from_ents.merge( int_ents );
3014 [ # # ][ # # ]: 0 : if( old_size != from_ents.size() && in_set )
[ # # ][ # # ]
3015 : : {
3016 [ # # ]: 0 : result = instance->add_entities( *in_set, int_ents );
3017 [ # # ]: 0 : if( MB_SUCCESS != result ) return result;
3018 : : }
3019 : : }
3020 : :
3021 [ # # ]: 0 : if( mbimesh->AdjTable[5] )
3022 : : {
3023 [ # # ]: 0 : int_ents.clear();
3024 [ # # ]: 0 : result = instance->get_adjacencies( from_ents, 1, true, int_ents, Interface::UNION );
3025 [ # # ]: 0 : if( MB_SUCCESS != result ) return result;
3026 [ # # ]: 0 : unsigned int old_size = from_ents.size();
3027 [ # # ]: 0 : from_ents.merge( int_ents );
3028 [ # # ][ # # ]: 0 : if( old_size != from_ents.size() && in_set )
[ # # ][ # # ]
3029 : : {
3030 [ # # ]: 0 : result = instance->add_entities( *in_set, int_ents );
3031 [ # # ]: 0 : if( MB_SUCCESS != result ) return result;
3032 : : }
3033 : : }
3034 : :
3035 : 0 : return MB_SUCCESS;
3036 : : }
3037 : :
3038 : 131 : void eatwhitespace( std::string& this_string )
3039 : : {
3040 : 131 : std::string::size_type p = this_string.find_last_not_of( " " );
3041 [ + - ]: 131 : if( p != this_string.npos ) this_string.resize( p + 1 );
3042 : 131 : }
3043 : :
3044 : 2 : void iMesh_createStructuredMesh( iMesh_Instance instance,
3045 : : /*in*/ int* local_dims,
3046 : : /*in*/ int* global_dims,
3047 : : /*in*/ double* i_vals,
3048 : : /*in*/ double* j_vals,
3049 : : /*in*/ double* k_vals,
3050 : : /*in*/ int resolve_shared,
3051 : : /*in*/ int ghost_dim,
3052 : : /*in*/ int bridge_dim,
3053 : : /*in*/ int num_layers,
3054 : : /*in*/ int addl_ents,
3055 : : /*in*/ int vert_gids,
3056 : : /*in*/ int elem_gids,
3057 : : /*inout*/ iBase_EntitySetHandle* set_handle,
3058 : : /*out*/ int* err )
3059 : : {
3060 : 2 : ScdInterface* scdi = NULL;
3061 [ + - ][ - + ]: 2 : ErrorCode rval = MOABI->query_interface( scdi );CHKERR( rval, "Couldn't get structured mesh interface." );
[ # # ]
3062 : :
3063 [ + - ]: 2 : Range tmp_range;
3064 : : ScdBox* scd_box;
3065 : : rval =
3066 : 4 : scdi->construct_box( HomCoord( local_dims[0], local_dims[1], ( -1 != local_dims[2] ? local_dims[2] : 0 ), 1 ),
3067 : 6 : HomCoord( local_dims[3], local_dims[4], ( -1 != local_dims[5] ? local_dims[5] : 0 ), 1 ),
3068 [ - + ][ + - ]: 2 : NULL, 0, scd_box, NULL, NULL, ( vert_gids ? true : false ) );CHKERR( rval, "Trouble creating scd vertex sequence." );
[ - + ][ + - ]
[ + - ][ - + ]
[ # # ]
3069 : :
3070 : : // set the global box parameters
3071 [ + - ]: 2 : if( global_dims )
3072 : : {
3073 [ + + ]: 14 : for( int i = 0; i < 6; i++ )
3074 [ + - ]: 12 : scd_box->par_data().gDims[i] = global_dims[i];
3075 : : }
3076 : :
3077 [ + - ][ + - ]: 2 : tmp_range.insert( scd_box->start_vertex(), scd_box->start_vertex() + scd_box->num_vertices() - 1 );
[ + - ][ + - ]
3078 [ + - ][ + - ]: 2 : tmp_range.insert( scd_box->start_element(), scd_box->start_element() + scd_box->num_elements() - 1 );
[ + - ][ + - ]
3079 [ + - ][ + - ]: 2 : tmp_range.insert( scd_box->box_set() );
3080 : :
3081 [ + - ]: 2 : if( set_handle )
3082 : : {
3083 [ + - ]: 2 : if( !( *set_handle ) )
3084 : : {
3085 : : // return the new ScdBox's set
3086 [ + - ]: 2 : *set_handle = reinterpret_cast< iBase_EntitySetHandle >( scd_box->box_set() );
3087 : : }
3088 : : else
3089 : : {
3090 : : // add the new ScdBox's set to the given file set
3091 [ # # ]: 0 : EntityHandle s = scd_box->box_set();
3092 [ # # ][ # # ]: 2 : rval = MOABI->add_entities( ENTITY_HANDLE( *set_handle ), &s, 1 );CHKERR( rval, "Couldn't add box set to file set." );
[ # # ]
3093 : : }
3094 : : }
3095 : :
3096 : : // get a ptr to global id memory
3097 : : void* data;
3098 : : int count;
3099 [ + - ][ + - ]: 2 : Range::const_iterator topv, bote, tope;
[ + - ]
3100 : :
3101 : 2 : Tag gid_tag = 0;
3102 : 2 : int *v_gid_data = NULL, *e_gid_data = NULL;
3103 [ - + ][ # # ]: 2 : if( vert_gids || elem_gids ) { gid_tag = MOABI->globalId_tag(); }
[ + - ]
3104 : :
3105 [ + - ]: 2 : if( vert_gids )
3106 : : {
3107 : : topv = tmp_range.upper_bound( tmp_range.begin(), tmp_range.end(),
3108 [ + - ][ + - ]: 2 : scd_box->start_vertex() + scd_box->num_vertices() );
[ + - ][ + - ]
[ + - ]
3109 : :
3110 [ + - ][ + - ]: 2 : rval = MOABI->tag_iterate( gid_tag, tmp_range.begin(), topv, count, data );CHKERR( rval, "Failed to get tag iterator." );
[ - + ][ # # ]
3111 [ + - ][ - + ]: 2 : assert( count == scd_box->num_vertices() );
3112 : 2 : v_gid_data = (int*)data;
3113 : : }
3114 : :
3115 [ + - ]: 2 : if( elem_gids )
3116 : : {
3117 [ + - ][ + - ]: 2 : bote = tmp_range.lower_bound( tmp_range.begin(), tmp_range.end(), scd_box->start_element() );
[ + - ][ + - ]
3118 [ + - ][ + - ]: 2 : tope = tmp_range.upper_bound( tmp_range.begin(), tmp_range.end(), *bote + scd_box->num_elements() );
[ + - ][ + - ]
[ + - ]
3119 : :
3120 [ + - ][ - + ]: 2 : rval = MOABI->tag_iterate( gid_tag, bote, tope, count, data );CHKERR( rval, "Failed to get tag iterator." );
[ # # ]
3121 [ + - ][ - + ]: 2 : assert( count == scd_box->num_elements() );
3122 : 2 : e_gid_data = (int*)data;
3123 : : }
3124 : :
3125 [ + - ][ + - ]: 2 : if( i_vals || j_vals || k_vals || v_gid_data || e_gid_data )
[ + - ][ - + ]
[ # # ]
3126 : : {
3127 : :
3128 : : // set the vertex coordinates
3129 : : double *xc, *yc, *zc;
3130 [ + - ][ - + ]: 2 : rval = scd_box->get_coordinate_arrays( xc, yc, zc );CHKERR( rval, "Couldn't get vertex coordinate arrays." );
[ # # ]
3131 : :
3132 : : int i, j, k, il, jl, kl;
3133 : 2 : int dil = local_dims[3] - local_dims[0] + 1;
3134 : 2 : int djl = local_dims[4] - local_dims[1] + 1;
3135 [ + - ]: 2 : int di = ( global_dims ? global_dims[3] - global_dims[0] + 1 : dil );
3136 [ + - ]: 2 : int dj = ( global_dims ? global_dims[4] - global_dims[1] + 1 : djl );
3137 [ + + ]: 4 : for( kl = local_dims[2]; kl <= local_dims[5]; kl++ )
3138 : : {
3139 : 2 : k = kl - local_dims[2];
3140 [ + + ]: 132 : for( jl = local_dims[1]; jl <= local_dims[4]; jl++ )
3141 : : {
3142 : 130 : j = jl - local_dims[1];
3143 [ + + ]: 8580 : for( il = local_dims[0]; il <= local_dims[3]; il++ )
3144 : : {
3145 : 8450 : i = il - local_dims[0];
3146 : 8450 : unsigned int pos = i + j * dil + k * dil * djl;
3147 [ - + ]: 8450 : xc[pos] = ( i_vals ? i_vals[i] : -1.0 );
3148 [ - + ]: 8450 : yc[pos] = ( j_vals ? j_vals[j] : -1.0 );
3149 [ - + ][ # # ]: 8450 : zc[pos] = ( -1 == local_dims[2] ? 0.0 : ( k_vals ? k_vals[k] : -1.0 ) );
3150 [ + - ]: 8450 : if( v_gid_data )
3151 : : {
3152 [ - + ]: 8450 : *v_gid_data = ( -1 != kl ? kl * di * dj : 0 ) + jl * di + il + 1;
3153 : 8450 : v_gid_data++;
3154 : : }
3155 [ + - ][ - + ]: 8450 : if( e_gid_data && kl < local_dims[5] && jl < local_dims[4] && il < local_dims[3] )
[ # # ][ # # ]
3156 : : {
3157 [ # # ]: 0 : *e_gid_data = ( -1 != kl ? kl * ( di - 1 ) * ( dj - 1 ) : 0 ) + jl * ( di - 1 ) + il + 1;
3158 : 0 : e_gid_data++;
3159 : : }
3160 : : }
3161 : : }
3162 : : }
3163 : : }
3164 : :
3165 : : #ifdef MOAB_HAVE_MPI
3166 : : // do parallel stuff, if requested
3167 [ + - ]: 2 : if( resolve_shared )
3168 : : {
3169 [ + - ]: 2 : ParallelComm* pcomm = ParallelComm::get_pcomm( MOABI, 0 );
3170 [ - + ]: 2 : if( pcomm )
3171 : : {
3172 : :
3173 : : rval =
3174 [ # # ][ # # ]: 0 : pcomm->resolve_shared_ents( 0, MOABI->dimension_from_handle( scd_box->start_element() ), 0, &gid_tag );CHKERR( rval, "Trouble resolving shared vertices." );
[ # # ][ # # ]
[ # # ]
3175 : :
3176 [ # # ]: 0 : if( -1 != ghost_dim )
3177 : : {
3178 [ # # ][ # # ]: 2 : rval = pcomm->exchange_ghost_cells( ghost_dim, bridge_dim, num_layers, addl_ents, true );CHKERR( rval, "Trouble exchanging ghosts." );
[ # # ]
3179 : : }
3180 : : }
3181 : : }
3182 : : #else
3183 : : // empty statement to remove compiler warning
3184 : : if( resolve_shared || ghost_dim || bridge_dim || num_layers || addl_ents ) {}
3185 : : #endif
3186 : :
3187 [ + - ]: 2 : RETURN( iBase_SUCCESS );
3188 : : }
3189 : :
3190 : 130 : void iMesh_freeMemory( iMesh_Instance /*instance*/,
3191 : : /**< [in] iMesh instance handle */
3192 : : void** ptrToMem )
3193 : : {
3194 : 130 : free( *ptrToMem );
3195 : 130 : *ptrToMem = 0;
3196 : 130 : return;
3197 [ + - ][ + - ]: 60 : }
|