[MOAB-dev] r3304 - MOAB/trunk
kraftche at cae.wisc.edu
kraftche at cae.wisc.edu
Fri Nov 6 22:34:51 CST 2009
Author: kraftche
Date: 2009-11-06 22:34:51 -0600 (Fri, 06 Nov 2009)
New Revision: 3304
Modified:
MOAB/trunk/MBCore.cpp
Log:
Move special case for 1 input entity in vector-vector get_adjaciences to
common intersect implementation:
o moves conditional statement outside of loop, reducing skinning time
a little bit (6.86s vs 7.01s).
o avoids doing swap on input vector, which might avoid additional memory
allocations for many vector-vector calls in a loop
o all versions of get_adjacencies with op==intersect benefit from the
optimization, rather than just the vector-vector one.
Modified: MOAB/trunk/MBCore.cpp
===================================================================
--- MOAB/trunk/MBCore.cpp 2009-11-07 02:44:41 UTC (rev 3303)
+++ MOAB/trunk/MBCore.cpp 2009-11-07 04:34:51 UTC (rev 3304)
@@ -1120,6 +1120,28 @@
std::vector<MBEntityHandle> temp_vec;
std::vector<MBEntityHandle>::iterator adj_it, w_it;
MBErrorCode result = MB_SUCCESS;
+
+ if (begin == end) {
+ adj_entities.clear(); // intersection
+ return MB_SUCCESS;
+ }
+
+ // First iteration is a special case if input list is empty.
+ // Rather than returning nothing (intersecting with empty
+ // input list), we begin with the adjacencies for the first entity.
+ if (adj_entities.empty()) {
+ MBEntityType type = TYPE_FROM_HANDLE(*begin);
+ if (to_dimension == MBCN::Dimension(type))
+ adj_entities.push_back(*begin);
+ else if(to_dimension == 0 && type != MBPOLYHEDRON)
+ result = mb->get_connectivity(&(*begin), 1, adj_entities);
+ else
+ result = mb->a_entity_factory()->get_adjacencies(*begin, to_dimension,
+ create_if_missing, adj_entities);
+ if (MB_SUCCESS != result)
+ return result;
+ ++begin;
+ }
for (ITER from_it = begin; from_it != end; from_it++)
{
@@ -1138,12 +1160,6 @@
if (MB_SUCCESS != result)
return result;
- // If first iteration and input is empty, begin with first set of adjacencies
- if (from_it == begin && adj_entities.empty()) {
- adj_entities.swap( temp_vec );
- continue;
- }
-
// otherwise intersect with the current set of results
w_it = adj_it = adj_entities.begin();
if (temp_vec.size()*adj_entities.size() < SORT_THRESHOLD) {
@@ -1202,24 +1218,14 @@
std::vector<MBEntityHandle> &adj_entities,
const int operation_type )
{
- MBErrorCode result;
- if (num_entities == 1 && adj_entities.empty()) {
- if(to_dimension == 0 && TYPE_FROM_HANDLE(from_entities[0]) != MBPOLYHEDRON)
- result = get_connectivity(&from_entities[0], 1, adj_entities);
- else
- result = aEntityFactory->get_adjacencies(from_entities[0], to_dimension,
- create_if_missing, adj_entities);
-
- //adj_entities.erase( std::remove( adj_entities.begin(), adj_entities.end(), 0 ), adj_entities.end() );
- return result;
- }
- else if (operation_type == MBInterface::INTERSECT)
+ if (operation_type == MBInterface::INTERSECT)
return get_adjacencies_intersection( this, from_entities, from_entities+num_entities,
to_dimension, create_if_missing, adj_entities );
else if (operation_type != MBInterface::UNION)
return MB_FAILURE;
// do union
+ MBErrorCode result;
std::vector<MBEntityHandle> tmp_storage;
const MBEntityHandle* conn;
int len;
More information about the moab-dev
mailing list