[MOAB-dev] r2885 - in MOAB/trunk: . tools/iMesh

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri May 15 11:40:02 CDT 2009


Author: kraftche
Date: 2009-05-15 11:40:02 -0500 (Fri, 15 May 2009)
New Revision: 2885

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
   MOAB/trunk/MBInterface.hpp
   MOAB/trunk/MeshSetSequence.cpp
   MOAB/trunk/MeshSetSequence.hpp
   MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
Log:
o Add MBInterface::get_contained_meshsets and MBInterface::num_contained_meshset
  analogous to get_parent_meshsets, num_parent_meshsets.
  
o Use get_contained_meshsets for complete implementation of iMesh_getEntSets

o Use num_contained_meshsets for complete implementation of iMesh_getNumEntSets



Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2009-05-15 16:39:48 UTC (rev 2884)
+++ MOAB/trunk/MBCore.cpp	2009-05-15 16:40:02 UTC (rev 2885)
@@ -2578,6 +2578,39 @@
   return MB_SUCCESS;
 }
 
+MBErrorCode MBCore::get_contained_meshsets( const MBEntityHandle meshset,
+                                            std::vector<MBEntityHandle> &children,
+                                            const int num_hops) const
+{
+  if (0 == meshset) {
+    return get_entities_by_type( meshset, MBENTITYSET, children );
+  }
+
+  const EntitySequence *seq;
+  MBErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+
+  return mseq->get_contained_sets( sequence_manager(), meshset, children, num_hops );
+}
+
+MBErrorCode MBCore::get_contained_meshsets( const MBEntityHandle meshset,
+                                            MBRange &children,
+                                            const int num_hops) const
+{
+  if (0 == meshset) {
+    return get_entities_by_type( meshset, MBENTITYSET, children );
+  }
+
+  std::vector<MBEntityHandle> child_vec;
+  MBErrorCode result = get_contained_meshsets(meshset, child_vec, num_hops);
+  if (MB_SUCCESS != result) return result;
+  std::sort( child_vec.begin(), child_vec.end() );
+  std::copy(child_vec.rbegin(), child_vec.rend(), mb_range_inserter(children));
+  return MB_SUCCESS;
+}
+
 MBErrorCode MBCore::num_parent_meshsets(const MBEntityHandle meshset, int* number,
                                         const int num_hops) const
 {
@@ -2612,7 +2645,23 @@
   return mseq->num_children( sequence_manager(), meshset, *number, num_hops );
 }
 
+MBErrorCode MBCore::num_contained_meshsets(const MBEntityHandle meshset, int* number,
+                                       const int num_hops) const
+{
+  if (0 == meshset) {
+    return get_number_entities_by_type( 0, MBENTITYSET, *number );
+  }
+  
+  const EntitySequence *seq;
+  MBErrorCode rval = sequence_manager()->find( meshset, seq );
+  if (MB_SUCCESS != rval)
+    return MB_ENTITY_NOT_FOUND;
+  const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
 
+  return mseq->num_contained_sets( sequence_manager(), meshset, *number, num_hops );
+}
+
+
 MBErrorCode MBCore::add_parent_meshset( MBEntityHandle meshset, 
                                         const MBEntityHandle parent_meshset)
 {

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2009-05-15 16:39:48 UTC (rev 2884)
+++ MOAB/trunk/MBCore.hpp	2009-05-15 16:40:02 UTC (rev 2885)
@@ -900,6 +900,16 @@
                                          MBRange &children, 
                                           const int num_hops = 1) const;
 
+  //! get contained meshsets
+  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
+                                             std::vector<MBEntityHandle> &contained, 
+                                             const int num_hops = 1) const;
+
+  //! get contained meshsets
+  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
+                                             MBRange &contained, 
+                                             const int num_hops = 1) const;
+
   //! gets number of parent meshsets
   virtual MBErrorCode num_parent_meshsets(const MBEntityHandle meshset,  
                                           int *number,
@@ -910,6 +920,11 @@
                                          int *number, 
                                          const int num_hops = 1) const;
 
+  //! gets number of contained meshsets
+  virtual MBErrorCode num_contained_meshsets(const MBEntityHandle meshset, 
+                                             int *number, 
+                                             const int num_hops = 1) const;
+
   //! add a parent meshset
   virtual MBErrorCode add_parent_meshset(MBEntityHandle meshset, 
                                           const MBEntityHandle parent_meshset);

Modified: MOAB/trunk/MBInterface.hpp
===================================================================
--- MOAB/trunk/MBInterface.hpp	2009-05-15 16:39:48 UTC (rev 2884)
+++ MOAB/trunk/MBInterface.hpp	2009-05-15 16:40:02 UTC (rev 2885)
@@ -1458,6 +1458,36 @@
                                          MBRange &children, 
                                          const int num_hops = 1) const = 0;
 
+    /**\brief Get mesh sets contained in a mesh set
+     *
+     * If <em>num_hops</em> is 1, only immediate contents are returned. 
+     * Otherwise a recursive query of all contained sets is performed, 
+     * returning every visted set.  The value of num_hops limites the
+     * depth of the search, with zero indicating no depth limit. 
+     *
+     *\param meshset The mesh set whose contents are being queried
+     *\param contained The result list.
+     *\param num_hops Number of generations to traverse (0 = all)
+     */
+  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
+                                         std::vector<MBEntityHandle> &contained, 
+                                         const int num_hops = 1) const = 0;
+
+    /**\brief Get mesh sets contained in a mesh set
+     *
+     * If <em>num_hops</em> is 1, only immediate contents are returned. 
+     * Otherwise a recursive query of all contained sets is performed, 
+     * returning every visted set.  The value of num_hops limites the
+     * depth of the search, with zero indicating no depth limit. 
+     *
+     *\param meshset The mesh set whose contents are being queried
+     *\param contained The result list.
+     *\param num_hops Number of generations to traverse (0 = all)
+     */
+  virtual MBErrorCode get_contained_meshsets(const MBEntityHandle meshset, 
+                                             MBRange &contained, 
+                                             const int num_hops = 1) const = 0;
+
     //! Get the number of parent mesh sets of a mesh set
     /** Identical to get_parent_meshsets, only number is returned instead of actual parents.
         \param meshset The mesh set whose parents are being queried
@@ -1476,6 +1506,18 @@
                                          int *number,
                                          const int num_hops = 1) const = 0;
 
+    /**\brief Get the number of mesh sets contained in a mesh set
+     *
+     * Return the number of sets that would be returned by get_contained_meshsets
+     *
+     *\param meshset  The initial set to begin the query from.
+     *\param number   (Output) The result count.
+     *\param num_hops Search depth (0 => unbounded).
+     */
+  virtual MBErrorCode num_contained_meshsets(const MBEntityHandle meshset, 
+                                             int *number,
+                                             const int num_hops = 1) const = 0;
+
     //! Add a parent mesh set to a mesh set
     /** Make <em>parent_meshset</em> a new parent of <em>child_meshset</em>.  This function does 
         <em>not</em> add a corresponding child link to <em>parent_meshset</em>.

Modified: MOAB/trunk/MeshSetSequence.cpp
===================================================================
--- MOAB/trunk/MeshSetSequence.cpp	2009-05-15 16:39:48 UTC (rev 2884)
+++ MOAB/trunk/MeshSetSequence.cpp	2009-05-15 16:40:02 UTC (rev 2885)
@@ -391,12 +391,14 @@
 MBErrorCode MeshSetSequence::get_parent_child_meshsets( MBEntityHandle meshset,
                                     const SequenceManager* seq_sets,
                                     std::vector<MBEntityHandle>& results,
-                                    int num_hops, bool parents ) const
+                                    int num_hops, SearchType link_type ) const
 {
   MBErrorCode result = MB_SUCCESS;
   std::vector<MBEntityHandle>::iterator i;
-  const MBEntityHandle* array;
-  int k, count;
+  const MBEntityHandle *array, *end;
+  MBEntityHandle s, e;
+  int count;
+  size_t n;
   
     // Skip any meshsets already in input vector (yes, don't
     // get their children either even if num_hops would indicate
@@ -422,12 +424,50 @@
         return rval;
       const MBMeshSet *ms_ptr = reinterpret_cast<const MeshSetSequence*>(seq)->get_set( *i );
       
-        // querying for parents or children?
-      array = parents ? ms_ptr->get_parents(count) : ms_ptr->get_children(count);
+      
+      switch (link_type) {
+      case CONTAINED:
+        array = ms_ptr->get_contents(n);
+        end = array + n;
+        if (ms_ptr->vector_based()) {
+          for (; array != end; ++array) 
+            if (MBENTITYSET == TYPE_FROM_HANDLE(*array) &&
+                visited.insert(*array).second) 
+              lists[1-index].push_back(*array);
+        }
+        else {
+          assert(n%2 == 0);
+          array = std::lower_bound( array, array+n, FIRST_HANDLE(MBENTITYSET) );
+            // only part of first block is of type
+          if ((end - array)%2) {
+            ++array;
+            s = FIRST_HANDLE(MBENTITYSET);
+            e = *array;
+            for (; s <= e; ++s) 
+              if (visited.insert(s).second)
+                lists[1-index].push_back(s);
+          }
+          while (array < end) {
+            s = *array++;
+            e = *array++;
+            for (; s <= e; ++s) 
+              if (visited.insert(s).second)
+                lists[1-index].push_back(s);
+          }
+        }
+        continue;
+      case PARENTS:
+        array = ms_ptr->get_parents(count);
+        break;
+      case CHILDREN:
+        array = ms_ptr->get_children(count);
+        break;
+      }
+      
         // copy any parents/children we haven't visited yet into list
-      for (k = 0; k < count; ++k) 
-        if (visited.insert(array[k]).second) 
-          lists[1-index].push_back(array[k]);
+      for (end = array+count; array != end; ++array) 
+        if (visited.insert(*array).second) 
+          lists[1-index].push_back(*array);
     }
     
       // iterate
@@ -463,9 +503,9 @@
   }
   
   if (num_hops > 0)
-    return get_parent_child_meshsets( handle, seqman, parents, num_hops, true );
+    return get_parent_child_meshsets( handle, seqman, parents, num_hops, PARENTS );
   else
-    return get_parent_child_meshsets( handle, seqman, parents, -1, true );
+    return get_parent_child_meshsets( handle, seqman, parents, -1, PARENTS );
 }
 
 MBErrorCode MeshSetSequence::get_children( const SequenceManager* seqman,
@@ -487,11 +527,26 @@
   }
 
   if (num_hops > 0) 
-    return get_parent_child_meshsets( handle, seqman, children, num_hops, false );
+    return get_parent_child_meshsets( handle, seqman, children, num_hops, CHILDREN );
   else 
-    return get_parent_child_meshsets( handle, seqman, children, -1, false );
+    return get_parent_child_meshsets( handle, seqman, children, -1, CHILDREN );
 }
 
+MBErrorCode MeshSetSequence::get_contained_sets( const SequenceManager* seqman,
+                                           MBEntityHandle handle,
+                                           std::vector<MBEntityHandle>& contained,
+                                           int num_hops ) const
+{
+  if (num_hops == 1 && contained.empty()) {
+    return get_set(handle)->get_entities_by_type( MBENTITYSET, contained );
+  }
+
+  if (num_hops > 0) 
+    return get_parent_child_meshsets( handle, seqman, contained, num_hops, CONTAINED );
+  else 
+    return get_parent_child_meshsets( handle, seqman, contained, -1, CONTAINED );
+}
+
 MBErrorCode MeshSetSequence::num_parents( const SequenceManager* seqman,
                                           MBEntityHandle handle,
                                           int& number,
@@ -524,3 +579,19 @@
   number = children.size();
   return result;
 }
+
+MBErrorCode MeshSetSequence::num_contained_sets( const SequenceManager* seqman,
+                                           MBEntityHandle handle,
+                                           int& number,
+                                           int num_hops ) const
+{
+  if (num_hops == 1) {
+    number = get_set( handle )->num_entities_by_type(MBENTITYSET);
+    return MB_SUCCESS;
+  }
+  
+  std::vector<MBEntityHandle> contained;
+  MBErrorCode result = get_contained_sets( seqman, handle, contained, num_hops );
+  number = contained.size();
+  return result;
+}

Modified: MOAB/trunk/MeshSetSequence.hpp
===================================================================
--- MOAB/trunk/MeshSetSequence.hpp	2009-05-15 16:39:48 UTC (rev 2884)
+++ MOAB/trunk/MeshSetSequence.hpp	2009-05-15 16:40:02 UTC (rev 2885)
@@ -83,13 +83,17 @@
   MBErrorCode num_dimension( SequenceManager const* seqman, MBEntityHandle set, int dim,           int& count, bool recursive ) const;
   MBErrorCode num_type(      SequenceManager const* seqman, MBEntityHandle set, MBEntityType type, int& count, bool recursive ) const;
 
-  MBErrorCode get_parents ( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& parents,  int num_hops ) const;
-  MBErrorCode get_children( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& children, int num_hops ) const;
-  MBErrorCode num_parents ( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
-  MBErrorCode num_children( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
+  MBErrorCode get_parents       ( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& parents,  int num_hops ) const;
+  MBErrorCode get_children      ( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& children, int num_hops ) const;
+  MBErrorCode get_contained_sets( SequenceManager const* seqman, MBEntityHandle of, std::vector<MBEntityHandle>& contents, int num_hops ) const;
+  MBErrorCode num_parents       ( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
+  MBErrorCode num_children      ( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
+  MBErrorCode num_contained_sets( SequenceManager const* seqman, MBEntityHandle of, int& number, int num_hops ) const;
   
 private:
 
+  enum SearchType { PARENTS, CHILDREN, CONTAINED };
+
   MeshSetSequence( MeshSetSequence& split_from, MBEntityHandle split_at )
     : EntitySequence( split_from, split_at )
     {}
@@ -99,7 +103,7 @@
   MBErrorCode get_parent_child_meshsets( MBEntityHandle meshset,
                                     SequenceManager const* set_sequences,
                                     std::vector<MBEntityHandle>& results,
-                                    int num_hops, bool parents ) const;
+                                    int num_hops, SearchType link_type ) const;
                                     
   static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
                             SequenceManager const* set_sequences,

Modified: MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp
===================================================================
--- MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp	2009-05-15 16:39:48 UTC (rev 2884)
+++ MOAB/trunk/tools/iMesh/iMesh_MOAB.cpp	2009-05-15 16:40:02 UTC (rev 2885)
@@ -1023,25 +1023,17 @@
                            /*in*/ const int num_hops,
                            int *num_sets, int *err) 
   {
-    if (num_hops > 1) {
-      iMesh_processError(iBase_NOT_SUPPORTED, 
-                         "iMesh_getNumEntSets: not currently implemented for num_hops > 1.");
-      *num_sets = 0;
-      RETURN(iBase_NOT_SUPPORTED);
-    }
-    
-    MBErrorCode result = MBI->get_number_entities_by_type
-      (ENTITY_HANDLE(entity_set_handle), MBENTITYSET, 
-       *num_sets, (num_hops == -1 ? true : false));
-
-    if (result != MB_SUCCESS) {
+    MBErrorCode rval = MBI->num_contained_meshsets( ENTITY_HANDLE(entity_set_handle),
+                                                    num_sets,
+                                                    std::max(0,num_hops) );
+    if (rval != MB_SUCCESS) {
       std::string msg("iMesh_entitysetGetNumberEntitySets:ERROR getting number of entitysets "
                       "in EntitySet, with error type: ");
-      msg += MBI->get_error_string(result);
-      iMesh_processError(iBase_ERROR_MAP[result], msg.c_str());
+      msg += MBI->get_error_string(rval);
+      iMesh_processError(iBase_ERROR_MAP[rval], msg.c_str());
     }
 
-    RETURN(iBase_ERROR_MAP[result]);
+    RETURN(iBase_ERROR_MAP[rval]);
   } 
 
   void iMesh_getEntSets(iMesh_Instance instance,
@@ -1051,29 +1043,18 @@
                         /*inout*/ int* contained_entset_handles_allocated,
                         /*inout*/ int* contained_entset_handles_size, int *err) 
   {
-    if (num_hops > 1) {
-      iMesh_processError(iBase_NOT_SUPPORTED, "iMesh_getEntSets: not currently implemented for num_hops > 1.");
-      RETURN(iBase_NOT_SUPPORTED);
+    std::vector<MBEntityHandle> sets;
+    MBErrorCode rval = MBI->get_contained_meshsets( ENTITY_HANDLE(entity_set_handle),
+                                                    sets, 
+                                                    std::max( num_hops, 0 ) );
+    if (MB_SUCCESS != rval) {
+      iMesh_processError(iBase_ERROR_MAP[rval], "iMesh_entitysetGetEntitySets: problem getting entities by type.");
+      RETURN(iBase_ERROR_MAP[rval]);
     }
-    
-    MBRange sets;
-    MBErrorCode result = MBI->get_entities_by_type
-      (ENTITY_HANDLE(entity_set_handle), MBENTITYSET, sets, (num_hops == -1 ? true : false));
-    if (MB_SUCCESS != result) {
-      iMesh_processError(iBase_ERROR_MAP[result], "iMesh_entitysetGetEntitySets: problem getting entities by type.");
-      RETURN(iBase_ERROR_MAP[result]);
-    }
-
     CHECK_SIZE(*contained_entset_handles, *contained_entset_handles_allocated,
                (int)sets.size(), iBase_EntitySetHandle, iBase_MEMORY_ALLOCATION_FAILED);
 
-    MBRange::iterator iter = sets.begin();
-    MBRange::iterator end_iter = sets.end();
-    int k = 0;
-
-    for (; iter != end_iter; iter++)
-      (*contained_entset_handles)[k++] = (iBase_EntitySetHandle)*iter;
-
+    std::copy( sets.begin(), sets.end(), (MBEntityHandle*)*contained_entset_handles );
     *contained_entset_handles_size = sets.size();
     RETURN(iBase_SUCCESS);
   }



More information about the moab-dev mailing list