[MOAB-dev] r3682 - in MOAB/trunk/src: . moab
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Fri Mar 19 19:00:21 CDT 2010
Author: kraftche
Date: 2010-03-19 19:00:20 -0500 (Fri, 19 Mar 2010)
New Revision: 3682
Modified:
MOAB/trunk/src/BitTagServer.cpp
MOAB/trunk/src/Core.cpp
MOAB/trunk/src/MeshSet.hpp
MOAB/trunk/src/MeshSetSequence.cpp
MOAB/trunk/src/SequenceManager.cpp
MOAB/trunk/src/SequenceManager.hpp
MOAB/trunk/src/SparseTagCollection.cpp
MOAB/trunk/src/moab/Core.hpp
MOAB/trunk/src/moab/Interface.hpp
Log:
Make Interface::get_entities_by_type{and_tag} and
Interface::get_number_entities_by_type{and_tag} return
results for all types if type is MBMAXTYPE
A) I'm tired of writing a loop over every type every time I
want to get all entities with a tag
B) Writing a simple loop isn't necessarily the same thing
depending on the value of the 'condition' argument
Modified: MOAB/trunk/src/BitTagServer.cpp
===================================================================
--- MOAB/trunk/src/BitTagServer.cpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/BitTagServer.cpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -271,6 +271,9 @@
ErrorCode BitTag::get_entities( EntityType type, Range& entities ) const
{
+ if (MBMAXTYPE == type)
+ return get_entities(entities);
+
const int per_page = ents_per_page();
Range::iterator hint = entities.begin();
for (size_t i = 0; i < pageList[type].size(); ++i) {
@@ -294,12 +297,12 @@
EntityID count;
size_t page;
int offset, per_page = ents_per_page();
- Range::const_iterator j, i = range.lower_bound( in_type );
+ Range::const_iterator j, i = in_type == MBMAXTYPE ? range.begin() : range.lower_bound( in_type );
EntityHandle h;
while (i != range.end()) {
h = *i;
unpack( h, type, page, offset );
- if (type != in_type)
+ if (in_type != MBMAXTYPE && type != in_type)
break;
i = i.end_of_block();
@@ -324,6 +327,16 @@
Range& entities,
unsigned char bits ) const
{
+ if (MBMAXTYPE == type) {
+ ErrorCode rval;
+ for (--type; type >= MBVERTEX; --type) {
+ rval = get_entities_with_bits( type, entities, bits );
+ if (MB_SUCCESS != rval)
+ return rval;
+ }
+ return MB_SUCCESS;
+ }
+
const int per_page = ents_per_page();
for (size_t i = 0; i < pageList[type].size(); ++i) {
if (pageList[type][i]) {
@@ -342,6 +355,16 @@
Range& entities,
unsigned char bits ) const
{
+ if (MBMAXTYPE == in_type) {
+ ErrorCode rval;
+ for (--in_type; in_type >= MBVERTEX; --in_type) {
+ rval = get_entities_with_bits( range, in_type, entities, bits );
+ if (MB_SUCCESS != rval)
+ return rval;
+ }
+ return MB_SUCCESS;
+ }
+
EntityType type;
EntityID count;
size_t page;
@@ -377,8 +400,20 @@
ErrorCode BitTag::get_number_entities( EntityType type,
int& num_entities ) const
{
+ num_entities = 0;
+ if (MBMAXTYPE == type) {
+ int tmp;
+ ErrorCode rval;
+ for (--type; type >= MBVERTEX; --type) {
+ rval = get_number_entities( type, tmp );
+ if (MB_SUCCESS != rval)
+ return rval;
+ num_entities += tmp;
+ }
+ return MB_SUCCESS;
+ }
+
const int per_page = ents_per_page();
- num_entities = 0;
if (pageList[type].empty())
return MB_SUCCESS;
if (pageList[type][0])
Modified: MOAB/trunk/src/Core.cpp
===================================================================
--- MOAB/trunk/src/Core.cpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/Core.cpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -1666,11 +1666,12 @@
const void* const* values,
const int num_tags,
int &num_entities,
+ int condition,
const bool recursive) const
{
Range dum_ents;
ErrorCode result = get_entities_by_type_and_tag(meshset, type, tag_handles, values, num_tags,
- dum_ents, recursive);
+ dum_ents, condition, recursive);
num_entities = dum_ents.size();
return result;
}
Modified: MOAB/trunk/src/MeshSet.hpp
===================================================================
--- MOAB/trunk/src/MeshSet.hpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/MeshSet.hpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -467,7 +467,10 @@
{
size_t count;
const EntityHandle* ptr = get_contents( count );
- if (vector_based()) {
+ if (MBMAXTYPE == type) {
+ return get_entities( entity_list );
+ }
+ else if (vector_based()) {
std::remove_copy_if( ptr, ptr+count,
std::back_inserter( entity_list ),
not_type_test(type) );
@@ -500,7 +503,10 @@
{
size_t count;
const EntityHandle* ptr = get_contents( count );
- if (vector_based()) {
+ if (MBMAXTYPE == type) {
+ return get_entities( entity_list );
+ }
+ else if (vector_based()) {
std::remove_copy_if( ptr, ptr+count,
range_inserter( entity_list ),
not_type_test(type) );
@@ -534,7 +540,10 @@
unsigned int result;
size_t count;
const EntityHandle* ptr = get_contents( count );
- if (vector_based()) {
+ if (MBMAXTYPE == type) {
+ return num_entities( );
+ }
+ else if (vector_based()) {
#ifndef __SUNPRO_CC
result = std::count_if( ptr, ptr+count, type_test(type) );
#else
Modified: MOAB/trunk/src/MeshSetSequence.cpp
===================================================================
--- MOAB/trunk/src/MeshSetSequence.cpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/MeshSetSequence.cpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -222,6 +222,13 @@
else if (type == MBENTITYSET) {
return recursive_get_sets( handle, seqman, 0, 0, &entities );
}
+ else if (type == MBMAXTYPE) {
+ Range tmp;
+ ErrorCode rval = get_entities( seqman, handle, tmp, recursive );
+ if (MB_SUCCESS == rval)
+ entities.insert( entities.end(), tmp.begin(), tmp.end() );
+ return rval;
+ }
else {
std::vector<const MeshSet*> list;
ErrorCode rval = recursive_get_sets( handle, seqman, &list );
@@ -244,6 +251,13 @@
else if (type == MBENTITYSET) {
return recursive_get_sets( handle, seqman, 0, &entities );
}
+ else if (type == MBMAXTYPE) {
+ std::vector<const MeshSet*> list;
+ ErrorCode rval = recursive_get_sets( handle, seqman, &list );
+ for (std::vector<const MeshSet*>::iterator i = list.begin(); i != list.end(); ++i)
+ (*i)->get_non_set_entities( entities );
+ return rval;
+ }
else {
std::vector<const MeshSet*> list;
ErrorCode rval = recursive_get_sets( handle, seqman, &list );
Modified: MOAB/trunk/src/SequenceManager.cpp
===================================================================
--- MOAB/trunk/src/SequenceManager.cpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/SequenceManager.cpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -117,6 +117,28 @@
new (typeData+t) TypeSequenceManager();
}
+void SequenceManager::get_entities( Range& entities_out ) const
+{
+ for (EntityType t = MBENTITYSET; t >= MBVERTEX; --t)
+ typeData[t].get_entities( entities_out );
+}
+
+void SequenceManager::get_entities( std::vector<EntityHandle>& entities_out ) const
+{
+ for (EntityType t = MBVERTEX; t != MBMAXTYPE; ++t)
+ typeData[t].get_entities( entities_out );
+}
+
+EntityID SequenceManager::get_number_entities( ) const
+{
+ EntityID sum = 0;
+ for (EntityType t = MBVERTEX; t != MBMAXTYPE; ++t)
+ sum += typeData[t].get_number_entities();
+ return sum;
+}
+
+
+
ErrorCode SequenceManager::check_valid_entities( const Range& entities ) const
{
ErrorCode rval;
@@ -1431,6 +1453,16 @@
if (tag_id >= tagSizes.size() || !tagSizes[tag_id])
return MB_TAG_NOT_FOUND;
+ if (type == MBMAXTYPE) {
+ ErrorCode rval;
+ for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
+ rval = get_tagged_entities( tag_id, t, entities_out );
+ if (MB_SUCCESS != rval)
+ return rval;
+ }
+ return MB_SUCCESS;
+ }
+
Range::iterator insert = entities_out.begin();
const TypeSequenceManager& map = entity_map( type );
if (tagSizes[tag_id] == MB_VARIABLE_LENGTH) {
@@ -1464,6 +1496,19 @@
return MB_TAG_NOT_FOUND;
count = 0;
+
+ if (type == MBMAXTYPE) {
+ ErrorCode rval;
+ for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
+ int tmp = 0;
+ rval = count_tagged_entities( tag_id, t, tmp );
+ if (MB_SUCCESS != rval)
+ return rval;
+ count += tmp;
+ }
+ return MB_SUCCESS;
+ }
+
const TypeSequenceManager& map = entity_map( type );
if (tagSizes[tag_id] == MB_VARIABLE_LENGTH) {
@@ -1498,6 +1543,16 @@
if (id >= tagSizes.size() || !tagSizes[id])
return MB_TAG_NOT_FOUND;
+ if (type == MBMAXTYPE) {
+ ErrorCode rval;
+ for (EntityType t = MBVERTEX; t < MBMAXTYPE; ++t) {
+ rval = get_entities_with_tag_value( id, tag_info, t, entities_out, value, size );
+ if (MB_SUCCESS != rval)
+ return rval;
+ }
+ return MB_SUCCESS;
+ }
+
Range::iterator insert = entities_out.begin();
const TypeSequenceManager& map = entity_map( type );
for (TypeSequenceManager::const_iterator i = map.begin(); i != map.end(); ++i) {
@@ -1525,9 +1580,10 @@
return MB_TAG_NOT_FOUND;
Range::iterator insert = entities_out.begin();
- Range::const_pair_iterator p = range.lower_bound(type);
+ Range::const_pair_iterator p = type == MBMAXTYPE ? range.begin() : range.lower_bound(type);
for (Range::const_pair_iterator p = range.const_pair_begin();
- p != range.const_pair_end() && TYPE_FROM_HANDLE(p->first) == type;
+ p != range.const_pair_end() &&
+ (MBMAXTYPE == type || TYPE_FROM_HANDLE(p->first) == type);
++p) {
EntityHandle start = p->first;
Modified: MOAB/trunk/src/SequenceManager.hpp
===================================================================
--- MOAB/trunk/src/SequenceManager.hpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/SequenceManager.hpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -35,17 +35,36 @@
return typeData[TYPE_FROM_HANDLE(handle)].find( handle, sequence_out );
}
- /** Get all entities of a given EntityType */
- void get_entities( EntityType type, Range& entities_out ) const
- { typeData[type].get_entities( entities_out ); }
+ /** Get all entities of a given EntityType, return all entities
+ * if type == MBMAXTYPE */
+ void get_entities( EntityType type, Range& entities_out ) const
+ {
+ if (type == MBMAXTYPE)
+ get_entities( entities_out );
+ else
+ typeData[type].get_entities( entities_out );
+ }
+
+ void get_entities( Range& entities_out ) const;
- /** Get all entities of a given EntityType */
- void get_entities( EntityType type, std::vector<EntityHandle>& entities_out ) const
- { typeData[type].get_entities( entities_out ); }
+ /** Get all entities of a given EntityType, return all entities
+ * if type == MBMAXTYPE */
+ void get_entities( EntityType type, std::vector<EntityHandle>& entities_out ) const
+ {
+ if (type == MBMAXTYPE)
+ get_entities( entities_out );
+ else
+ typeData[type].get_entities( entities_out );
+ }
+ void get_entities( std::vector<EntityHandle>& entities_out ) const;
+
/** Count entities of a given EntityType */
EntityID get_number_entities( EntityType type ) const
- { return typeData[type].get_number_entities(); }
+ { return type == MBMAXTYPE ? get_number_entities() : typeData[type].get_number_entities(); }
+
+ /** Count entities of a given EntityType */
+ EntityID get_number_entities( ) const;
/** Get most recently accessed sequence for a given type */
const EntitySequence* get_last_accessed_sequence( EntityType type ) const
Modified: MOAB/trunk/src/SparseTagCollection.cpp
===================================================================
--- MOAB/trunk/src/SparseTagCollection.cpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/SparseTagCollection.cpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -183,7 +183,7 @@
myMapType::iterator iter;
for(iter = mData.begin(); iter != mData.end(); ++iter)
{
- if(TYPE_FROM_HANDLE(iter->first) == type)
+ if(MBMAXTYPE == type || TYPE_FROM_HANDLE(iter->first) == type)
num_entities++;
}
return MB_SUCCESS;
@@ -195,7 +195,7 @@
myMapType::iterator iter;
for(iter = mData.begin(); iter != mData.end(); ++iter)
{
- if(TYPE_FROM_HANDLE(iter->first) == type)
+ if(MBMAXTYPE == type || TYPE_FROM_HANDLE(iter->first) == type)
entities.insert(iter->first);
}
return MB_SUCCESS;
@@ -210,6 +210,18 @@
const void* tag_value,
int value_size)
{
+ if (MBMAXTYPE == type) {
+ ErrorCode rval;
+ while (type--) {
+ rval = get_entities_with_tag_value( tag_info, type, entities, tag_value, value_size );
+ if (MB_SUCCESS != rval)
+ return rval;
+ }
+ return MB_SUCCESS;
+ }
+
+
+
myMapType::iterator iter, end;
#ifdef HAVE_UNORDERED_MAP
iter = mData.begin();
Modified: MOAB/trunk/src/moab/Core.hpp
===================================================================
--- MOAB/trunk/src/moab/Core.hpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/moab/Core.hpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -444,6 +444,7 @@
const void* const* values,
const int num_tags,
int &num_entities,
+ const int condition = Interface::INTERSECT,
const bool recursive = false) const;
//! Retrieves all entities in the data base
Modified: MOAB/trunk/src/moab/Interface.hpp
===================================================================
--- MOAB/trunk/src/moab/Interface.hpp 2010-03-19 23:56:57 UTC (rev 3681)
+++ MOAB/trunk/src/moab/Interface.hpp 2010-03-20 00:00:20 UTC (rev 3682)
@@ -772,6 +772,7 @@
const void* const* values,
const int num_tags,
int &num_entities,
+ const int condition = Interface::INTERSECT,
const bool recursive = false) const = 0;
//! Returns number of entities in the data base or meshset
More information about the moab-dev
mailing list