moab
Entity Set Operators

Functions

void iMesh_subtract (iMesh_Instance instance, const iBase_EntitySetHandle entity_set_1, const iBase_EntitySetHandle entity_set_2, iBase_EntitySetHandle *result_entity_set, int *err)
 Subtract contents of one entity set from another.
void iMesh_intersect (iMesh_Instance instance, const iBase_EntitySetHandle entity_set_1, const iBase_EntitySetHandle entity_set_2, iBase_EntitySetHandle *result_entity_set, int *err)
 Intersect contents of one entity set with another.
void iMesh_unite (iMesh_Instance instance, const iBase_EntitySetHandle entity_set_1, const iBase_EntitySetHandle entity_set_2, iBase_EntitySetHandle *result_entity_set, int *err)
 Unite contents of one entity set with another.

Function Documentation

void iMesh_intersect ( iMesh_Instance  instance,
const iBase_EntitySetHandle  entity_set_1,
const iBase_EntitySetHandle  entity_set_2,
iBase_EntitySetHandle result_entity_set,
int *  err 
)

Intersect contents of one entity set with another.

Intersect contents of one entity set with another

Parameters:
[in]instanceiMesh instance handle
[in]entity_set_1Entity set being intersected with another
[in]entity_set_2Entity set being intersected with another
[out]result_entity_setPointer to entity set returned from function
[out]errReturned Error status (see iBase_ErrorType)

Definition at line 2437 of file iMesh_MOAB.cpp.

  {
    EntityHandle temp_set;
    EntityHandle set1 = ENTITY_HANDLE(entity_set_1),
      set2 = ENTITY_HANDLE(entity_set_2);

    int isList1, isList2;
    iMesh_isList(instance, entity_set_1, &isList1, err);
    if (*err != iBase_SUCCESS) return;
    iMesh_isList(instance, entity_set_2, &isList2, err);
    if (*err != iBase_SUCCESS) return;

    ErrorCode result;
    if (isList1 && isList2)
      result = MOABI->create_meshset(MESHSET_ORDERED, temp_set);
    else
      result = MOABI->create_meshset(MESHSET_SET, temp_set);

    if (MB_SUCCESS != result)
      ERROR(result, "iMesh_intersect: couldn't create result set.");

    if (!entity_set_1 && !entity_set_2) {
        // intersecting the root set with itself, so get everything...
      Range entities;
      result = MOABI->get_entities_by_handle(0, entities);
      if (MB_SUCCESS == result)
        result = MOABI->add_entities(temp_set, entities);
        // ...but not the newly-created set!
      if (MB_SUCCESS == result)
        result = MOABI->remove_entities(temp_set, &temp_set, 1);
    }
    else if (!entity_set_1) {
      result = MOABI->unite_meshset(temp_set, set2);
    }
    else if (!entity_set_2) {
      result = MOABI->unite_meshset(temp_set, set1);
    }
    else {
      if (isList1 && isList2) {
          // ITAPS has very specific rules about the behavior of intersection on
          // list-type sets. Since MOAB doesn't (and likely will never) work
          // exactly this way, we implement our own algorithm here.

#ifdef HAVE_UNORDERED_MAP
        typedef UNORDERED_MAP_NS::unordered_map<EntityHandle, size_t> lookup_t;
#else
        typedef std::map<EntityHandle, size_t> lookup_t;
#endif

          // First, build a lookup table for the second set.
        lookup_t lookup;
        {
          std::vector<EntityHandle> contents2;
          result = MOABI->get_entities_by_handle(set2, contents2);
          CHKERR(result,"iMesh_intersect: ERROR intersect failed.");

          for (std::vector<EntityHandle>::iterator i = contents2.begin();
               i != contents2.end(); ++i) {
#ifdef HAVE_UNORDERED_MAP
            lookup_t::iterator j = lookup.find(*i);
#else
            lookup_t::iterator j = lookup.lower_bound(*i);
#endif
            if (j != lookup.end() && j->first == *i)
              ++j->second;
            else
              lookup.insert(j, lookup_t::value_type(*i, 1));
          }
        }

          // Then, iterate over the contents of the first set and check for
          // their existence in the second set.
        std::vector<EntityHandle> contents1;
        result = MOABI->get_entities_by_handle(set1, contents1);
        CHKERR(result,"iMesh_intersect: ERROR intersect failed.");

        std::vector<EntityHandle>::iterator w = contents1.begin();
        for (std::vector<EntityHandle>::iterator i = contents1.begin();
             i != contents1.end(); ++i) {
          lookup_t::iterator j = lookup.find(*i);
          if (j != lookup.end() && j->second) {
            --j->second;
            *w = *i;
            ++w;
          }
        }

        result = MOABI->add_entities(temp_set, &contents1[0],
                                     w - contents1.begin());
      }
      else {
        result = MOABI->unite_meshset(temp_set, set1);
        if (MB_SUCCESS == result)
          result = MOABI->intersect_meshset(temp_set, set2);
      }
    }

    CHKERR(result,"iMesh_intersect: ERROR intersect failed.");
    *result_entity_set = (iBase_EntitySetHandle)temp_set;

    RETURN(iBase_SUCCESS);
  }
void iMesh_subtract ( iMesh_Instance  instance,
const iBase_EntitySetHandle  entity_set_1,
const iBase_EntitySetHandle  entity_set_2,
iBase_EntitySetHandle result_entity_set,
int *  err 
)

Subtract contents of one entity set from another.

Subtract contents of one entity set from another

Parameters:
[in]instanceiMesh instance handle
[in]entity_set_1Entity set from which other set is being subtracted
[in]entity_set_2Entity set being subtracted from other set
[out]result_entity_setPointer to entity set returned from function
[out]errReturned Error status (see iBase_ErrorType)

Definition at line 2388 of file iMesh_MOAB.cpp.

  {
    EntityHandle temp_set;
    EntityHandle set1 = ENTITY_HANDLE(entity_set_1),
      set2 = ENTITY_HANDLE(entity_set_2);

    int isList1, isList2;
    iMesh_isList(instance, entity_set_1, &isList1, err);
    if (*err != iBase_SUCCESS) return;
    iMesh_isList(instance, entity_set_2, &isList2, err);
    if (*err != iBase_SUCCESS) return;

    ErrorCode result;
    if (isList1 && isList2)
      result = MOABI->create_meshset(MESHSET_ORDERED, temp_set);
    else
      result = MOABI->create_meshset(MESHSET_SET, temp_set);

    if (MB_SUCCESS != result)
      ERROR(result, "iMesh_subtract: couldn't create result set.");

      // if the second set is the root set, the result is always the empty set
    if (entity_set_2) {
      if (!entity_set_1) {
          // subtracting from the root set, so get everything first...
        Range entities;
        result = MOABI->get_entities_by_handle(0,entities);
        if (MB_SUCCESS == result)
          result = MOABI->add_entities(temp_set, entities);
          // ...but not the newly-created set!
        if (MB_SUCCESS == result)
          result = MOABI->remove_entities(temp_set, &temp_set, 1);
      }
      else
        result = MOABI->unite_meshset(temp_set, set1);

      if (MB_SUCCESS == result)
        result = MOABI->subtract_meshset(temp_set, set2);
    }

    CHKERR(result, "iMesh_subtract: ERROR subtract failed.");
    *result_entity_set = (iBase_EntitySetHandle)temp_set;

    RETURN(iBase_SUCCESS);
  }
void iMesh_unite ( iMesh_Instance  instance,
const iBase_EntitySetHandle  entity_set_1,
const iBase_EntitySetHandle  entity_set_2,
iBase_EntitySetHandle result_entity_set,
int *  err 
)

Unite contents of one entity set with another.

Parameters:
[in]instanceiMesh instance handle
[in]entity_set_1Entity set being united with another
[in]entity_set_2Entity set being united with another
[out]result_entity_setPointer to entity set returned from function
[out]errReturned Error status (see iBase_ErrorType)

Definition at line 2543 of file iMesh_MOAB.cpp.

  {
    EntityHandle temp_set;
    EntityHandle set1 = ENTITY_HANDLE(entity_set_1),
      set2 = ENTITY_HANDLE(entity_set_2);

    int isList1, isList2;
    iMesh_isList(instance, entity_set_1, &isList1, err);
    if (*err != iBase_SUCCESS) return;
    iMesh_isList(instance, entity_set_2, &isList2, err);
    if (*err != iBase_SUCCESS) return;

    ErrorCode result;
    if (isList1 && isList2)
      result = MOABI->create_meshset(MESHSET_ORDERED, temp_set);
    else
      result = MOABI->create_meshset(MESHSET_SET, temp_set);

    if (MB_SUCCESS != result)
      ERROR(result, "iMesh_unite: couldn't create result set.");


    if (entity_set_1 && entity_set_2) {
      result = MOABI->unite_meshset(temp_set, set1);
      if (MB_SUCCESS == result)
        result = MOABI->unite_meshset(temp_set, set2);
    }
    else {
        // uniting with the root set, so get everything...
      Range entities;
      result = MOABI->get_entities_by_handle(0, entities);
      if (MB_SUCCESS == result)
        result = MOABI->add_entities(temp_set, entities);
        // ...but not the newly-created set!
      if (MB_SUCCESS == result)
        result = MOABI->remove_entities(temp_set, &temp_set, 1);
    }

    CHKERR(result,"iMesh_unite: ERROR unite failed.");

    *result_entity_set = (iBase_EntitySetHandle)temp_set;

    RETURN(iBase_SUCCESS);
  }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines