[MOAB-dev] r2871 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri May 1 16:38:16 CDT 2009


Author: kraftche
Date: 2009-05-01 16:38:16 -0500 (Fri, 01 May 2009)
New Revision: 2871

Modified:
   MOAB/trunk/MBCore.cpp
   MOAB/trunk/MBCore.hpp
   MOAB/trunk/MBInterface.hpp
   MOAB/trunk/MeshSetSequence.cpp
   MOAB/trunk/MeshSetSequence.hpp
   MOAB/trunk/SequenceManager.hpp
   MOAB/trunk/TypeSequenceManager.hpp
Log:
add get_entities_by_type and get_entities_by_dimension that pass back an std::vector<MBEntityHandle>

Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/MBCore.cpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -1243,6 +1243,35 @@
   return result;
 }
 
+MBErrorCode MBCore::get_entities_by_dimension(const MBEntityHandle meshset,
+                                                const int dimension, 
+                                                std::vector<MBEntityHandle> &entities,
+                                                const bool recursive) const
+{
+  MBErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_dimension( sequence_manager(), meshset, dimension, entities, recursive );
+  }
+  else if (dimension > 3) {
+    sequence_manager()->get_entities( MBENTITYSET, entities );
+    result = MB_SUCCESS;
+  } 
+  else {
+    for (MBEntityType this_type = MBCN::TypeDimensionMap[dimension].first;
+         this_type <= MBCN::TypeDimensionMap[dimension].second;
+         this_type++) {
+      sequence_manager()->get_entities( this_type, entities );
+    }
+  }
+
+  return result;
+}
+
 MBErrorCode MBCore::get_entities_by_type( const MBEntityHandle meshset,
                                           const MBEntityType type, 
                                           MBRange &entities,
@@ -1265,6 +1294,28 @@
   return result;
 }
 
+MBErrorCode MBCore::get_entities_by_type( const MBEntityHandle meshset,
+                                          const MBEntityType type, 
+                                          std::vector<MBEntityHandle> &entities,
+                                          const bool recursive) const
+{
+  MBErrorCode result = MB_SUCCESS;
+  if (meshset) {
+    const EntitySequence* seq;
+    result = sequence_manager()->find( meshset, seq );
+    if (MB_SUCCESS != result)
+      return result;
+    const MeshSetSequence* mseq = reinterpret_cast<const MeshSetSequence*>(seq);
+    result = mseq->get_type( sequence_manager(), meshset, type, entities, recursive );
+  }  
+  else {
+    sequence_manager()->get_entities( type, entities );
+    result = MB_SUCCESS;
+  }
+
+  return result;
+}
+
 MBErrorCode MBCore::get_entities_by_type_and_tag(const MBEntityHandle meshset,
                                                    const MBEntityType type,
                                                    const MBTag *tags,

Modified: MOAB/trunk/MBCore.hpp
===================================================================
--- MOAB/trunk/MBCore.hpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/MBCore.hpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -331,11 +331,16 @@
           MBRange entities;
           get_entities_by_dimension( dimension, entities ); //get 2D MBEntityHandles in the database
           \endcode */
-    virtual MBErrorCode get_entities_by_dimension(const MBEntityHandle meshset,
+    virtual MBErrorCode get_entities_by_dimension( const MBEntityHandle meshset,
                                                    const int dimension, 
                                                    MBRange &entities,
                                                    const bool recursive = false) const;
 
+    virtual MBErrorCode get_entities_by_dimension( const MBEntityHandle meshset,
+                                                   const int dimension, 
+                                                   std::vector<MBEntityHandle> &entities,
+                                                   const bool recursive = false) const;
+
       //! Retrieves all entities in the data base of given type.  
       /** \param type MBEntityType of entities desired (ie, MeshHex, MeshEdge, MeshTri, etc )
           \param entities Range in which entities of MBEntityType <em>type</em> are returned.
@@ -345,11 +350,16 @@
           MBRange entities;
           get_entities_by_dimension( type, entities ); //get MeshTet type MBEntityHandles in the database
           \endcode */
-    virtual MBErrorCode get_entities_by_type(const MBEntityHandle meshset,
+    virtual MBErrorCode get_entities_by_type( const MBEntityHandle meshset,
                                               const MBEntityType type, 
                                               MBRange &entities,
                                               const bool recursive = false) const;
 
+    virtual MBErrorCode get_entities_by_type( const MBEntityHandle meshset,
+                                              const MBEntityType type, 
+                                              std::vector<MBEntityHandle> &entities,
+                                              const bool recursive = false) const;
+
     virtual MBErrorCode get_entities_by_type_and_tag(const MBEntityHandle meshset,
                                                       const MBEntityType type,
                                                       const MBTag *tag_handles,

Modified: MOAB/trunk/MBInterface.hpp
===================================================================
--- MOAB/trunk/MBInterface.hpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/MBInterface.hpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -609,6 +609,11 @@
                                                 MBRange &entities,
                                                 const bool recursive = false)  const = 0;
 
+  virtual MBErrorCode get_entities_by_dimension(const MBEntityHandle meshset,
+                                                const int dimension, 
+                                                std::vector<MBEntityHandle> &entities,
+                                                const bool recursive = false)  const = 0;
+
     //! Retrieve all entities of a given type in the database or meshset.
     /** Appends entities to list passed in.
         \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).
@@ -630,6 +635,11 @@
                                            MBRange &entities,
                                            const bool recursive = false) const = 0;
 
+  virtual MBErrorCode get_entities_by_type(const MBEntityHandle meshset,
+                                           const MBEntityType type, 
+                                           std::vector<MBEntityHandle> &entities,
+                                           const bool recursive = false) const = 0;
+
     //! Retrieve entities in the database or meshset which have any or all of the tag(s) and (optionally)
     //! value(s) specified.
     /** \param meshset Meshset whose entities are being queried (zero if query is for entire mesh).

Modified: MOAB/trunk/MeshSetSequence.cpp
===================================================================
--- MOAB/trunk/MeshSetSequence.cpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/MeshSetSequence.cpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -172,6 +172,25 @@
 MBErrorCode MeshSetSequence::get_dimension( const SequenceManager* seqman,
                                             MBEntityHandle handle,
                                             int dimension,
+                                            std::vector<MBEntityHandle>& entities,
+                                            bool recursive ) const
+{
+  if (!recursive) {
+    get_set(handle)->get_entities_by_dimension( dimension, entities );
+    return MB_SUCCESS;
+  }
+  else {
+    std::vector<const MBMeshSet*> 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_dimension( const SequenceManager* seqman,
+                                            MBEntityHandle handle,
+                                            int dimension,
                                             MBRange& entities,
                                             bool recursive ) const
 {
@@ -191,6 +210,28 @@
 MBErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
                                        MBEntityHandle handle,
                                        MBEntityType type,
+                                       std::vector<MBEntityHandle>& 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, 0, &entities );
+  }
+  else {
+    std::vector<const MBMeshSet*> 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;
+  }
+}
+
+MBErrorCode MeshSetSequence::get_type( const SequenceManager* seqman,
+                                       MBEntityHandle handle,
+                                       MBEntityType type,
                                        MBRange& entities,
                                        bool recursive ) const
 {
@@ -266,7 +307,8 @@
 MBErrorCode MeshSetSequence::recursive_get_sets( MBEntityHandle start_set,
                               const SequenceManager* seq_sets,
                               std::vector<const MBMeshSet*>* sets,
-                              MBRange* set_handles )
+                              MBRange* set_handles,
+                              std::vector<MBEntityHandle>* set_vector )
 {
   std::set<MBEntityHandle> visited;
   std::vector<MBEntityHandle> stack;
@@ -305,6 +347,12 @@
     for (it = visited.begin(); it != visited.end(); ++it)
       hint = set_handles->insert( hint, *it, *it );
   }
+  
+  if (set_vector) {
+    if (remove_start_set)
+      visited.erase( start_set );
+    std::copy( visited.begin(), visited.end(), std::back_inserter(*set_vector) );
+  }
     
   return MB_SUCCESS;
 }

Modified: MOAB/trunk/MeshSetSequence.hpp
===================================================================
--- MOAB/trunk/MeshSetSequence.hpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/MeshSetSequence.hpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -74,7 +74,9 @@
   
   MBErrorCode get_entities( MBEntityHandle set, std::vector<MBEntityHandle>& entities ) const;
   MBErrorCode get_entities(  SequenceManager const* seqman, MBEntityHandle set,                    MBRange& entities, bool recursive ) const;
+  MBErrorCode get_dimension( SequenceManager const* seqman, MBEntityHandle set, int dim,           std::vector<MBEntityHandle>& entities, bool recursive ) const;
   MBErrorCode get_dimension( SequenceManager const* seqman, MBEntityHandle set, int dim,           MBRange& entities, bool recursive ) const;
+  MBErrorCode get_type(      SequenceManager const* seqman, MBEntityHandle set, MBEntityType type, std::vector<MBEntityHandle>& entities, bool recursive ) const;
   MBErrorCode get_type(      SequenceManager const* seqman, MBEntityHandle set, MBEntityType type, MBRange& entities, bool recursive ) const;
   
   MBErrorCode num_entities(  SequenceManager const* seqman, MBEntityHandle set,                    int& count, bool recursive ) const;
@@ -102,7 +104,8 @@
   static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
                             SequenceManager const* set_sequences,
                             std::vector<const MBMeshSet*>* sets_out = 0,
-                            MBRange* set_handles_out = 0 );
+                            MBRange* set_handles_out = 0,
+                            std::vector<MBEntityHandle>* set_handle_vect_out = 0 );
   static MBErrorCode recursive_get_sets( MBEntityHandle start_set,
                             SequenceManager* set_sequences,
                             std::vector<MBMeshSet*>& sets_out );

Modified: MOAB/trunk/SequenceManager.hpp
===================================================================
--- MOAB/trunk/SequenceManager.hpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/SequenceManager.hpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -37,6 +37,10 @@
    void get_entities( MBEntityType type, MBRange& entities_out ) const
       { typeData[type].get_entities( entities_out ); }
     
+      /** Get all entities of a given MBEntityType */
+   void get_entities( MBEntityType type, std::vector<MBEntityHandle>& entities_out ) const
+      { typeData[type].get_entities( entities_out ); }
+    
       /** Count entities of a given MBEntityType */
     MBEntityID get_number_entities( MBEntityType type ) const
       { return typeData[type].get_number_entities(); }

Modified: MOAB/trunk/TypeSequenceManager.hpp
===================================================================
--- MOAB/trunk/TypeSequenceManager.hpp	2009-05-01 21:24:27 UTC (rev 2870)
+++ MOAB/trunk/TypeSequenceManager.hpp	2009-05-01 21:38:16 UTC (rev 2871)
@@ -5,6 +5,7 @@
 #include "MBRange.hpp"
 
 #include <set>
+#include <vector>
 class TagServer;
 
 /**\brief Maintain data structures organizing EntitySequence instances
@@ -181,6 +182,9 @@
     /**\brief Get handles for all entities in all sequences. */
   inline void get_entities( MBRange& entities_out ) const;
   
+    /**\brief Get handles for all entities in all sequences. */
+  inline void get_entities( std::vector<MBEntityHandle>& entities_out ) const;
+  
     /**\brief Get number of entities represented by all sequences. */
   inline MBEntityID get_number_entities() const;
   
@@ -422,6 +426,13 @@
     in = entities_out.insert( in, (*i)->start_handle(), (*i)->end_handle() );
 }
 
+inline void TypeSequenceManager::get_entities( std::vector<MBEntityHandle>& entities_out ) const
+{
+  for (const_iterator i = begin(); i != end(); ++i)
+    for (MBEntityHandle j = (*i)->start_handle(); j <= (*i)->end_handle(); ++j)
+      entities_out.push_back( j );
+}
+
 inline MBEntityID TypeSequenceManager::get_number_entities() const
 {
   MBEntityID count = 0;



More information about the moab-dev mailing list