ErrorCode WriteDamsel::write_entities(RangeSeqIntersectIter &rsi) { // write the entities; these entities will be in the same sequence and will be contiguous, guaranteed EntityHandle start_ent = rsi.get_start_handle(), end_ent = rsi.get_end_handle(); // create a damsel container for these entity handles damsel_container ent_cont; ent_cont = DMSLcontainer_create_sequence(dU.dmslModel, start_ent, (int)(end_ent-start_ent+1), 1); std::cerr << "MOAB: created model container: ent_cont = " << ent_cont <<std::endl; if (DAMSEL_CONTAINER_INVALID == ent_cont) CHK_MB_ERR(MB_FAILURE, "Bad sequence returned by Damsel."); damsel_err_t err = DMSLmodel_map_handles_inventing_file_handles(ent_cont); CHK_DMSL_ERR(err, "Failed to map handles."); // get # verts per entity and entity type EntityType etype = mbImpl->type_from_handle(start_ent); assert(MBMAXTYPE != etype); int num_connect = rsi.get_sequence()->values_per_entity(); assert(0 < num_connect); // get the connectivity storage location and pass to damsel Range ent_range(start_ent, end_ent); int count; EntityHandle *connect; int verts_per_ent; ErrorCode rval = mbImpl->connect_iterate(ent_range.begin(), ent_range.end(), connect, verts_per_ent, count); CHK_MB_ERR_2(rval, "Failed to get connect iterator for entities starting with handle %lu.", rsi.get_start_handle()); if (count != (int)ent_range.size()) CHK_MB_ERR_2(MB_FAILURE, "Entity subrange not in the same sequence for entities starting with handle %lu.", rsi.get_start_handle()); // define the entities to damsel err = DMSLentity_define_fast(ent_cont, DamselUtil::mtod_entity_type[etype], num_connect, (damsel_handle*)connect); CHK_DMSL_ERR_2(err, "DMSLentity_define failed for entities starting with handle %lu.", rsi.get_start_handle()); // write dense tags rval = map_dense_tags(rsi, ent_cont); CHK_MB_ERR(rval, NULL); err = DMSLcontainer_release(ent_cont); CHK_DMSL_ERR(err, "Problem releasing entity handle container."); return MB_SUCCESS; }
ErrorCode WriteDamsel::write_sets(RangeSeqIntersectIter &rsi) { // write the sets ErrorCode rval = MB_SUCCESS; std::vector<EntityHandle> ents; damsel_container mcont; damsel_err_t err; unsigned int i, num_sets = rsi.get_end_handle() - rsi.get_start_handle() + 1; std::vector<unsigned int> set_flags(num_sets, 0); EntityHandle seth; for (seth = rsi.get_start_handle(), i = 0; seth <= rsi.get_end_handle(); seth++, i++) { // get all the entities in the set ents.clear(); rval = mbImpl->get_entities_by_handle(seth, ents); CHK_MB_ERR_2(rval, "get_entities_by_handle failed for set %lu.", seth); if (!ents.empty()) { mcont = DMSLcontainer_create_vector(dU.dmslModel, (damsel_handle*)&ents[0], ents.size()); } else { mcont = DMSLcontainer_create_vector(dU.dmslModel, (damsel_handle*)NULL, 0); } std::cerr << "MOAB: created model container: sets_cont = " << mcont <<std::endl; // get the set type (range or set) unsigned int opts; rval = mbImpl->get_meshset_options(seth, opts); CHK_MB_ERR_2(rval, "Failed to get options for meshset %lu.", seth); damsel_collection_type coll_type = (opts&MESHSET_SET ? DAMSEL_HANDLE_COLLECTION_TYPE_SET : DAMSEL_HANDLE_COLLECTION_TYPE_VECTOR); // parents/children... // set flags if (opts & MESHSET_TRACK_OWNER) set_flags[i] |= MESHSET_TRACK_OWNER; else set_flags[i] &= !MESHSET_TRACK_OWNER; // create the collection DMSLcoll_create(dU.dmslModel, (damsel_handle_ptr) &seth, mcont, coll_type); // release the container err = DMSLcontainer_release(mcont); CHK_DMSL_ERR(err, "Problem releasing set entity handle container."); } // set the COLL_FLAGS tag, using assign (direct) // make a container of set handles... mcont = DMSLcontainer_create_sequence(dU.dmslModel, rsi.get_start_handle(), num_sets, 1); std::cerr << "MOAB: created model container: sets_cont = " << mcont <<std::endl; // assign the tags on them err = DMSLmodel_map_tag(&set_flags[0], mcont, (damsel_handle_ptr)&(dU.collFlagsTag.mTagh)); CHK_DMSL_ERR(err, "Failed to assign COLL_FLAGS tag for sets."); err = DMSLmodel_map_handles_inventing_file_handles(mcont); CHK_DMSL_ERR(err, "Failed to map set handles."); // map other dense tags rval = map_dense_tags(rsi, mcont); CHK_MB_ERR(rval, "Failed to map dense tags for sets."); return rval; }
ErrorCode WriteDamsel::write_vertices(RangeSeqIntersectIter &rsi) { // write the vertices; these vertices will be in the same sequence and will be contiguous, guaranteed EntityHandle start_vert = rsi.get_start_handle(), end_vert = rsi.get_end_handle(); // create a damsel container for these vertex handles damsel_container vertex_cont = DMSLcontainer_create_sequence(dU.dmslModel, start_vert, (int)(end_vert-start_vert+1), 1); std::cerr << "MOAB: created model container: vertex_cont = " << vertex_cont <<std::endl; if (DAMSEL_CONTAINER_INVALID == vertex_cont) CHK_MB_ERR_2(MB_FAILURE, "Failed to create vertex sequence for vertices starting with handle %lu.", rsi.get_start_handle()); damsel_err_t err = DMSLmodel_map_handles_inventing_file_handles(vertex_cont); CHK_DMSL_ERR(err, "Failed to map handles."); // define the entities to damsel err = DMSLentity_define(vertex_cont, DAMSEL_ENTITY_TYPE_VERTEX, 1, vertex_cont); CHK_DMSL_ERR_2(err, "Failure in DMSLentity_define for vertices starting with handle %lu.", rsi.get_start_handle()); // get the vertex coordinates storage locations and pass to damsel Range vert_range(start_vert, end_vert); double *xcoords = NULL, *ycoords = NULL, *zcoords = NULL; int count; ErrorCode rval = mbImpl->coords_iterate(vert_range.begin(), vert_range.end(), xcoords, ycoords, zcoords, count); CHK_MB_ERR_2(rval, "Failed to get coordinate iterator for vertices starting with handle %lu.", rsi.get_start_handle()); if (count != (int)vert_range.size()) { CHK_MB_ERR_2(MB_FAILURE, "Vertex subrange not in the same sequence for vertices starting with handle %lu.", rsi.get_start_handle()); } if (xcoords && !ycoords && !zcoords) { // interleaved // map the data to damsel err = DMSLmodel_map_tag(xcoords, vertex_cont, (damsel_handle_ptr)&dU.xcoordsTag.mTagh); CHK_DMSL_ERR_2(err, "Failed to assign vertex coordinates tag for vertices starting with handle %lu.", rsi.get_start_handle()); } else { // map the data to damsel err = DMSLmodel_map_tag(xcoords, vertex_cont, (damsel_handle_ptr)&dU.xcoordsTag.mTagh); CHK_DMSL_ERR_2(err, "Failed to assign vertex x coordinates tag for vertices starting with handle %lu.", rsi.get_start_handle()); err = DMSLmodel_map_tag(ycoords, vertex_cont, (damsel_handle_ptr)&dU.ycoordsTag.mTagh); CHK_DMSL_ERR_2(err, "Failed to assign vertex y coordinates tag for vertices starting with handle %lu.", rsi.get_start_handle()); err = DMSLmodel_map_tag(zcoords, vertex_cont, (damsel_handle_ptr)&dU.zcoordsTag.mTagh); CHK_DMSL_ERR_2(err, "Failed to assign vertex z coordinates tag for vertices starting with handle %lu.", rsi.get_start_handle()); } // write/map dense tags rval = map_dense_tags(rsi, vertex_cont); CHK_MB_ERR(rval, NULL); err = DMSLcontainer_release(vertex_cont); CHK_DMSL_ERR(err, "Problem releasing vertex handle container."); return MB_SUCCESS; }