[MOAB-dev] r2866 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri May 1 09:43:32 CDT 2009


Author: kraftche
Date: 2009-05-01 09:43:32 -0500 (Fri, 01 May 2009)
New Revision: 2866

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MeshSetSequence.cpp
   MOAB/trunk/MeshSetSequence.hpp
Log:
recursive query of entity sets

Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2009-04-30 21:05:58 UTC (rev 2865)
+++ MOAB/trunk/MBCore.cpp	2009-05-01 14:43:32 UTC (rev 2866)
@@ -1243,14 +1243,11 @@
   return result;
 }
 
-MBErrorCode MBCore::get_entities_by_type(const MBEntityHandle meshset,
-                                           const MBEntityType type, 
-                                           MBRange &entities,
-                                           const bool recursive) const
+MBErrorCode MBCore::get_entities_by_type( const MBEntityHandle meshset,
+                                          const MBEntityType type, 
+                                          MBRange &entities,
+                                          const bool recursive) const
 {
-  if (recursive && type == MBENTITYSET)  // will never return anything
-    return MB_TYPE_OUT_OF_RANGE;
-  
   MBErrorCode result = MB_SUCCESS;
   if (meshset) {
     const EntitySequence* seq;

Modified: MOAB/trunk/MeshSetSequence.cpp
===================================================================
--- MOAB/trunk/MeshSetSequence.cpp	2009-04-30 21:05:58 UTC (rev 2865)
+++ MOAB/trunk/MeshSetSequence.cpp	2009-05-01 14:43:32 UTC (rev 2866)
@@ -155,7 +155,7 @@
   }
   else {
     std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, list );
+    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
     for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_non_set_entities( entities );
     return rval;
@@ -181,26 +181,29 @@
   }
   else {
     std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, list );
+    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
     for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_dimension( dimension, entities );
     return rval;
   }
 }
 
-MBErrorCode MeshSetSequence::get_type(      const SequenceManager* seqman,
-                                            MBEntityHandle handle,
-                                            MBEntityType type,
-                                            MBRange& entities,
-                                            bool recursive ) const
+MBErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
+                                       MBEntityHandle handle,
+                                       MBEntityType type,
+                                       MBRange& entities,
+                                       bool recursive ) const
 {
   if (!recursive) {
     get_set(handle)->get_entities_by_type( type, entities );
     return MB_SUCCESS;
   }
+  else if (type == MBENTITYSET) {
+    return recursive_get_sets( handle, seqman, 0, &entities );
+  }
   else {
     std::vector<const MBMeshSet*> list;
-    MBErrorCode rval = recursive_get_sets( handle, seqman, list );
+    MBErrorCode rval = recursive_get_sets( handle, seqman, &list );
     for (std::vector<const MBMeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
       (*i)->get_entities_by_type( type, entities );
     return rval;
@@ -262,17 +265,22 @@
 
 MBErrorCode MeshSetSequence::recursive_get_sets( MBEntityHandle start_set,
                               const SequenceManager* seq_sets,
-                              std::vector<const MBMeshSet*>& sets )
+                              std::vector<const MBMeshSet*>* sets,
+                              MBRange* set_handles )
 {
   std::set<MBEntityHandle> visited;
   std::vector<MBEntityHandle> stack;
   stack.push_back( start_set );
+  bool remove_start_set = true;
   while (!stack.empty()) {
     MBEntityHandle handle = stack.back();
     stack.pop_back();
     
-    if (!visited.insert(handle).second)
+    if (!visited.insert(handle).second) {
+      if (handle == start_set)
+        remove_start_set = false;
       continue;
+    }
     
     const EntitySequence* seq;
     MBErrorCode rval = seq_sets->find( handle, seq );
@@ -281,12 +289,22 @@
     
     const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
     const MBMeshSet *ms_ptr = mseq->get_set( handle );
-    sets.push_back( ms_ptr );
+    if (sets)
+      sets->push_back( ms_ptr );
     
     MBRange tmp_range;
     ms_ptr->get_entities_by_type( MBENTITYSET, tmp_range );
     std::copy( tmp_range.begin(), tmp_range.end(), std::back_inserter( stack ) );
   }
+  
+  if (set_handles) {
+    if (remove_start_set)
+      visited.erase( start_set );
+    MBRange::iterator hint = set_handles->begin();
+    std::set<MBEntityHandle>::iterator it;
+    for (it = visited.begin(); it != visited.end(); ++it)
+      hint = set_handles->insert( hint, *it, *it );
+  }
     
   return MB_SUCCESS;
 }

Modified: MOAB/trunk/MeshSetSequence.hpp
===================================================================
--- MOAB/trunk/MeshSetSequence.hpp	2009-04-30 21:05:58 UTC (rev 2865)
+++ MOAB/trunk/MeshSetSequence.hpp	2009-05-01 14:43:32 UTC (rev 2866)
@@ -101,7 +101,8 @@
                                     
   static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
                             SequenceManager const* set_sequences,
-                            std::vector<const MBMeshSet*>& sets_out );
+                            std::vector<const MBMeshSet*>* sets_out = 0,
+                            MBRange* set_handles_out = 0 );
   static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
                             SequenceManager* set_sequences,
                             std::vector<MBMeshSet*>& sets_out );



More information about the moab-dev mailing list