LCOV - code coverage report
Current view: top level - src - MergeMesh.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 196 207 94.7 %
Date: 2020-12-16 07:07:30 Functions: 11 12 91.7 %
Branches: 273 536 50.9 %

           Branch data     Line data    Source code
       1                 :            : #include "moab/MergeMesh.hpp"
       2                 :            : 
       3                 :            : #include "moab/Skinner.hpp"
       4                 :            : #include "moab/AdaptiveKDTree.hpp"
       5                 :            : #include "moab/Range.hpp"
       6                 :            : #include "moab/CartVect.hpp"
       7                 :            : 
       8                 :            : #include "Internals.hpp"
       9                 :            : #include <vector>
      10                 :            : #include <algorithm>
      11                 :            : #include <string>
      12                 :            : #include <vector>
      13                 :            : #include <cassert>
      14                 :            : #include <iostream>
      15                 :            : #include <iomanip>
      16                 :            : 
      17                 :            : #include <stdlib.h>
      18                 :            : 
      19                 :            : namespace moab
      20                 :            : {
      21                 :            : 
      22                 :          4 : MergeMesh::MergeMesh( Interface* impl, bool printErrorIn )
      23         [ +  - ]:          4 :     : mbImpl( impl ), mbMergeTag( 0 ), mergeTol( 0.001 ), mergeTolSq( 0.000001 ), printError( printErrorIn )
      24                 :            : {
      25                 :          4 : }
      26                 :            : 
      27                 :          8 : MergeMesh::~MergeMesh()
      28                 :            : {
      29         [ +  - ]:          4 :     if( mbMergeTag ) mbImpl->tag_delete( mbMergeTag );
      30                 :          4 :     mbMergeTag = NULL;
      31         [ -  + ]:          4 : }
      32                 :            : 
      33                 :          0 : ErrorCode MergeMesh::merge_entities( EntityHandle* elems, int elems_size, const double merge_tol, const int do_merge,
      34                 :            :                                      const int update_sets, Tag merge_tag, bool do_higher_dim )
      35                 :            : {
      36                 :          0 :     mergeTol   = merge_tol;
      37                 :          0 :     mergeTolSq = merge_tol * merge_tol;
      38         [ #  # ]:          0 :     Range tmp_elems;
      39         [ #  # ]:          0 :     tmp_elems.insert( elems, elems + elems_size );
      40         [ #  # ]:          0 :     ErrorCode result = merge_entities( tmp_elems, merge_tol, do_merge, update_sets, (Tag)merge_tag, do_higher_dim );
      41                 :            : 
      42                 :          0 :     return result;
      43                 :            : }
      44                 :            : 
      45                 :            : /*  This function appears to be not necessary after MOAB conversion
      46                 :            : 
      47                 :            :  void MergeMesh::perform_merge(iBase_TagHandle merge_tag)
      48                 :            :  {
      49                 :            :  // put into a range
      50                 :            :  ErrorCode result = perform_merge((Tag) merge_tag);
      51                 :            :  if (result != MB_SUCCESS)
      52                 :            :  throw MKException(iBase_FAILURE, "");
      53                 :            :  }*/
      54                 :            : 
      55                 :          2 : ErrorCode MergeMesh::merge_entities( Range& elems, const double merge_tol, const int do_merge, const int, Tag merge_tag,
      56                 :            :                                      bool merge_higher_dim )
      57                 :            : {
      58                 :            :     // If merge_higher_dim is true, do_merge must also be true
      59 [ +  - ][ -  + ]:          2 :     if( merge_higher_dim && !do_merge ) { return MB_FAILURE; }
      60                 :            : 
      61                 :          2 :     mergeTol   = merge_tol;
      62                 :          2 :     mergeTolSq = merge_tol * merge_tol;
      63                 :            : 
      64                 :            :     // get the skin of the entities
      65         [ +  - ]:          2 :     Skinner skinner( mbImpl );
      66         [ +  - ]:          4 :     Range skin_range;
      67         [ +  - ]:          2 :     ErrorCode result = skinner.find_skin( 0, elems, 0, skin_range, false, false );
      68         [ -  + ]:          2 :     if( MB_SUCCESS != result ) return result;
      69                 :            : 
      70                 :            :     // create a tag to mark merged-to entity; reuse tree_root
      71                 :          2 :     EntityHandle tree_root = 0;
      72         [ +  - ]:          2 :     if( 0 == merge_tag )
      73                 :            :     {
      74                 :            :         result = mbImpl->tag_get_handle( "__merge_tag", 1, MB_TYPE_HANDLE, mbMergeTag, MB_TAG_DENSE | MB_TAG_EXCL,
      75         [ +  - ]:          2 :                                          &tree_root );
      76         [ -  + ]:          2 :         if( MB_SUCCESS != result ) return result;
      77                 :            :     }
      78                 :            :     else
      79                 :          0 :         mbMergeTag = merge_tag;
      80                 :            : 
      81                 :            :     // build a kd tree with the vertices
      82         [ +  - ]:          4 :     AdaptiveKDTree kd( mbImpl );
      83         [ +  - ]:          2 :     result = kd.build_tree( skin_range, &tree_root );
      84         [ -  + ]:          2 :     if( MB_SUCCESS != result ) return result;
      85                 :            : 
      86                 :            :     // find matching vertices, mark them
      87         [ +  - ]:          2 :     result = find_merged_to( tree_root, kd, mbMergeTag );
      88         [ -  + ]:          2 :     if( MB_SUCCESS != result ) return result;
      89                 :            : 
      90                 :            :     // merge them if requested
      91         [ +  - ]:          2 :     if( do_merge )
      92                 :            :     {
      93         [ +  - ]:          2 :         result = perform_merge( mbMergeTag );
      94         [ -  + ]:          2 :         if( MB_SUCCESS != result ) return result;
      95                 :            :     }
      96                 :            : 
      97 [ +  - ][ +  - ]:          2 :     if( merge_higher_dim && deadEnts.size() != 0 )
                 [ +  - ]
      98                 :            :     {
      99         [ +  - ]:          2 :         result = merge_higher_dimensions( elems );
     100         [ -  + ]:          2 :         if( MB_SUCCESS != result ) return result;
     101                 :            :     }
     102                 :            : 
     103                 :          4 :     return MB_SUCCESS;
     104                 :            : }
     105                 :            : 
     106                 :          1 : ErrorCode MergeMesh::merge_all( EntityHandle meshset, const double merge_tol )
     107                 :            : {
     108                 :            :     ErrorCode rval;
     109         [ +  - ]:          1 :     if( 0 == mbMergeTag )
     110                 :            :     {
     111                 :          1 :         EntityHandle def_val = 0;
     112                 :            :         rval = mbImpl->tag_get_handle( "__merge_tag", 1, MB_TYPE_HANDLE, mbMergeTag, MB_TAG_DENSE | MB_TAG_EXCL,
     113 [ +  - ][ -  + ]:          1 :                                        &def_val );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     114                 :            :     }
     115                 :            :     // get all entities;
     116                 :            :     // get all vertices connected
     117                 :            :     // build a kdtree
     118                 :            :     // find merged to
     119                 :          1 :     mergeTol   = merge_tol;
     120                 :          1 :     mergeTolSq = merge_tol * merge_tol;
     121                 :            : 
     122                 :            :     // get all vertices
     123         [ +  - ]:          1 :     Range entities;
     124 [ +  - ][ -  + ]:          1 :     rval = mbImpl->get_entities_by_handle( meshset, entities, /*recursive*/ true );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     125         [ +  - ]:          2 :     Range sets = entities.subset_by_type( MBENTITYSET );
     126 [ +  - ][ +  - ]:          1 :     entities   = subtract( entities, sets );
     127         [ +  - ]:          2 :     Range verts;
     128 [ +  - ][ -  + ]:          1 :     rval = mbImpl->get_connectivity( entities, verts );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     129                 :            : 
     130                 :            :     // build a kd tree with the vertices
     131         [ +  - ]:          2 :     AdaptiveKDTree kd( mbImpl );
     132                 :            :     EntityHandle tree_root;
     133 [ +  - ][ -  + ]:          1 :     rval = kd.build_tree( verts, &tree_root );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     134                 :            :     // find matching vertices, mark them
     135 [ +  - ][ -  + ]:          1 :     rval = find_merged_to( tree_root, kd, mbMergeTag );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     136                 :            : 
     137 [ +  - ][ -  + ]:          1 :     rval = perform_merge( mbMergeTag );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     138                 :            : 
     139         [ +  - ]:          1 :     if( deadEnts.size() != 0 )
     140                 :            :     {
     141 [ +  - ][ -  + ]:          1 :         rval = merge_higher_dimensions( entities );MB_CHK_ERR( rval );
         [ #  # ][ #  # ]
     142                 :            :     }
     143                 :          2 :     return MB_SUCCESS;
     144                 :            : }
     145                 :          4 : ErrorCode MergeMesh::perform_merge( Tag merge_tag )
     146                 :            : {
     147                 :            :     // we start with an empty range of vertices that are "merged to"
     148                 :            :     // they are used (eventually) for higher dim entities
     149                 :          4 :     mergedToVertices.clear();
     150                 :            :     ErrorCode result;
     151         [ -  + ]:          4 :     if( deadEnts.size() == 0 )
     152                 :            :     {
     153 [ #  # ][ #  # ]:          0 :         if( printError ) std::cout << "\nWarning: Geometries don't have a common face; Nothing to merge" << std::endl;
                 [ #  # ]
     154                 :          0 :         return MB_SUCCESS;  // nothing to merge carry on with the program
     155                 :            :     }
     156 [ +  - ][ +  - ]:          4 :     if( mbImpl->type_from_handle( *deadEnts.begin() ) != MBVERTEX ) return MB_FAILURE;
                 [ -  + ]
     157         [ +  - ]:          4 :     std::vector< EntityHandle > merge_tag_val( deadEnts.size() );
     158         [ +  - ]:          8 :     Range deadEntsRange;
     159 [ +  - ][ +  - ]:          4 :     std::copy( deadEnts.rbegin(), deadEnts.rend(), range_inserter( deadEntsRange ) );
     160 [ +  - ][ +  - ]:          4 :     result = mbImpl->tag_get_data( merge_tag, deadEntsRange, &merge_tag_val[0] );
     161         [ -  + ]:          4 :     if( MB_SUCCESS != result ) return result;
     162                 :            : 
     163         [ +  - ]:          4 :     std::set<EntityHandle>::iterator rit;
     164                 :            :     unsigned int i;
     165 [ +  - ][ +  - ]:        400 :     for( rit = deadEnts.begin(), i = 0; rit != deadEnts.end(); ++rit, i++ )
                 [ +  + ]
     166                 :            :     {
     167 [ +  - ][ -  + ]:        396 :         assert( merge_tag_val[i] );
     168 [ +  - ][ +  - ]:        396 :         if( MBVERTEX == TYPE_FROM_HANDLE( merge_tag_val[i] ) ) mergedToVertices.insert( merge_tag_val[i] );
         [ +  - ][ +  - ]
                 [ +  - ]
     169 [ +  - ][ +  - ]:        396 :         result = mbImpl->merge_entities( merge_tag_val[i], *rit, false, false );
                 [ +  - ]
     170         [ -  + ]:        396 :         if( MB_SUCCESS != result ) { return result; }
     171                 :            :     }
     172         [ +  - ]:          4 :     result = mbImpl->delete_entities( deadEntsRange );
     173                 :          8 :     return result;
     174                 :            : }
     175                 :            : // merge vertices according to an input tag
     176                 :            : // merge them if the tags are equal
     177                 :            : struct handle_id
     178                 :            : {
     179                 :            :     EntityHandle eh;
     180                 :            :     int val;
     181                 :            : };
     182                 :            : 
     183                 :            : // handle structure comparison function for qsort
     184                 :            : // if the id is the same , compare the handle.
     185                 :       2493 : int compare_handle_id( const void* a, const void* b )
     186                 :            : {
     187                 :            : 
     188                 :       2493 :     handle_id* ia = (handle_id*)a;
     189                 :       2493 :     handle_id* ib = (handle_id*)b;
     190 [ +  + ][ +  - ]:       2493 :     if( ia->val == ib->val ) { return ( ia->eh < ib->eh ) ? -1 : 1; }
     191                 :            :     else
     192                 :            :     {
     193                 :       2393 :         return ( ia->val - ib->val );
     194                 :            :     }
     195                 :            : }
     196                 :            : 
     197                 :          1 : ErrorCode MergeMesh::merge_using_integer_tag( Range& verts, Tag user_tag, Tag merge_tag )
     198                 :            : {
     199                 :            :     ErrorCode rval;
     200                 :            :     DataType tag_type;
     201         [ +  - ]:          1 :     rval = mbImpl->tag_get_data_type( user_tag, tag_type );
     202 [ +  - ][ -  + ]:          1 :     if( rval != MB_SUCCESS || tag_type != MB_TYPE_INTEGER ) return MB_FAILURE;
     203                 :            : 
     204 [ +  - ][ +  - ]:          1 :     std::vector< int > vals( verts.size() );
     205 [ +  - ][ +  - ]:          1 :     rval = mbImpl->tag_get_data( user_tag, verts, &vals[0] );
     206         [ -  + ]:          1 :     if( rval != MB_SUCCESS ) return rval;
     207                 :            : 
     208         [ +  - ]:          1 :     if( 0 == merge_tag )
     209                 :            :     {
     210                 :          1 :         EntityHandle def_val = 0;
     211                 :            :         rval = mbImpl->tag_get_handle( "__merge_tag", 1, MB_TYPE_HANDLE, mbMergeTag, MB_TAG_DENSE | MB_TAG_EXCL,
     212         [ +  - ]:          1 :                                        &def_val );
     213         [ -  + ]:          1 :         if( MB_SUCCESS != rval ) return rval;
     214                 :            :     }
     215                 :            :     else
     216                 :          0 :         mbMergeTag = merge_tag;
     217                 :            : 
     218 [ +  - ][ +  - ]:          2 :     std::vector< handle_id > handles( verts.size() );
     219                 :          1 :     int i = 0;
     220 [ +  - ][ +  - ]:        501 :     for( Range::iterator vit = verts.begin(); vit != verts.end(); ++vit )
         [ +  - ][ +  - ]
                 [ +  + ]
     221                 :            :     {
     222 [ +  - ][ +  - ]:        500 :         handles[i].eh  = *vit;
     223 [ +  - ][ +  - ]:        500 :         handles[i].val = vals[i];
     224                 :        500 :         i++;
     225                 :            :     }
     226                 :            :     // std::sort(handles.begin(), handles.end(), compare_handle_id);
     227 [ +  - ][ +  - ]:          1 :     qsort( &handles[0], handles.size(), sizeof( handle_id ), compare_handle_id );
     228                 :          1 :     i = 0;
     229 [ +  - ][ +  + ]:        405 :     while( i < (int)verts.size() - 1 )
     230                 :            :     {
     231         [ +  - ]:        404 :         handle_id first = handles[i];
     232                 :        404 :         int j           = i + 1;
     233 [ +  - ][ +  + ]:        499 :         while( handles[j].val == first.val && j < (int)verts.size() )
         [ +  - ][ +  - ]
                 [ +  + ]
     234                 :            :         {
     235 [ +  - ][ +  - ]:         95 :             rval = mbImpl->tag_set_data( mbMergeTag, &( handles[j].eh ), 1, &( first.eh ) );
     236         [ -  + ]:         95 :             if( rval != MB_SUCCESS ) return rval;
     237 [ +  - ][ +  - ]:         95 :             deadEnts.insert( handles[j].eh );
     238                 :         95 :             j++;
     239                 :            :         }
     240                 :        404 :         i = j;
     241                 :            :     }
     242                 :            : 
     243         [ +  - ]:          1 :     rval = perform_merge( mbMergeTag );
     244                 :            : 
     245                 :          2 :     return rval;
     246                 :            : }
     247                 :          3 : ErrorCode MergeMesh::find_merged_to( EntityHandle& tree_root, AdaptiveKDTree& tree, Tag merge_tag )
     248                 :            : {
     249         [ +  - ]:          3 :     AdaptiveKDTreeIter iter;
     250                 :            : 
     251                 :            :     // evaluate vertices in this leaf
     252 [ +  - ][ +  - ]:          6 :     Range leaf_range, leaf_range2;
     253         [ +  - ]:          6 :     std::vector< EntityHandle > sorted_leaves;
     254         [ +  - ]:          6 :     std::vector< double > coords;
     255 [ +  - ][ +  - ]:          6 :     std::vector< EntityHandle > merge_tag_val, leaves_out;
     256                 :            : 
     257         [ +  - ]:          3 :     ErrorCode result = tree.get_tree_iterator( tree_root, iter );
     258         [ -  + ]:          3 :     if( MB_SUCCESS != result ) return result;
     259         [ +  + ]:        390 :     while( result == MB_SUCCESS )
     260                 :            :     {
     261 [ +  - ][ +  - ]:        387 :         sorted_leaves.push_back( iter.handle() );
     262         [ +  - ]:        387 :         result = iter.step();
     263                 :            :     }
     264         [ -  + ]:          3 :     if( result != MB_ENTITY_NOT_FOUND ) return result;
     265         [ +  - ]:          3 :     std::sort( sorted_leaves.begin(), sorted_leaves.end() );
     266                 :            : 
     267                 :          3 :     std::vector< EntityHandle >::iterator it;
     268 [ +  - ][ +  - ]:        390 :     for( it = sorted_leaves.begin(); it != sorted_leaves.end(); ++it )
                 [ +  + ]
     269                 :            :     {
     270                 :            : 
     271         [ +  - ]:        387 :         leaf_range.clear();
     272 [ +  - ][ +  - ]:        387 :         result = mbImpl->get_entities_by_handle( *it, leaf_range );
     273         [ -  + ]:        387 :         if( MB_SUCCESS != result ) return result;
     274 [ +  - ][ +  - ]:        387 :         coords.resize( 3 * leaf_range.size() );
     275 [ +  - ][ +  - ]:        387 :         merge_tag_val.resize( leaf_range.size() );
     276 [ +  - ][ +  - ]:        387 :         result = mbImpl->get_coords( leaf_range, &coords[0] );
     277         [ -  + ]:        387 :         if( MB_SUCCESS != result ) return result;
     278 [ +  - ][ +  - ]:        387 :         result = mbImpl->tag_get_data( merge_tag, leaf_range, &merge_tag_val[0] );
     279         [ -  + ]:        387 :         if( MB_SUCCESS != result ) return result;
     280         [ +  - ]:        387 :         Range::iterator rit;
     281                 :            :         unsigned int i;
     282                 :        387 :         bool inleaf_merged, outleaf_merged = false;
     283         [ +  - ]:        387 :         unsigned int lr_size = leaf_range.size();
     284                 :            : 
     285 [ +  - ][ +  - ]:       4235 :         for( i = 0, rit = leaf_range.begin(); i != lr_size; ++rit, i++ )
                 [ +  + ]
     286                 :            :         {
     287 [ +  - ][ +  + ]:       3848 :             if( 0 != merge_tag_val[i] ) continue;
     288 [ +  - ][ +  - ]:       2230 :             CartVect from( &coords[3 * i] );
     289                 :       2230 :             inleaf_merged = false;
     290                 :            : 
     291                 :            :             // check close-by leaves too
     292                 :       2230 :             leaves_out.clear();
     293                 :            :             result =
     294 [ +  - ][ +  - ]:       2230 :                 tree.distance_search( from.array(), mergeTol, leaves_out, mergeTol, 1.0e-6, NULL, NULL, &tree_root );
     295         [ +  - ]:       2230 :             leaf_range2.clear();
     296 [ +  - ][ +  - ]:      12708 :             for( std::vector< EntityHandle >::iterator vit = leaves_out.begin(); vit != leaves_out.end(); ++vit )
                 [ +  + ]
     297                 :            :             {
     298 [ +  - ][ +  - ]:      10478 :                 if( *vit > *it )
                 [ +  + ]
     299                 :            :                 {  // if we haven't visited this leaf yet in the outer loop
     300 [ +  - ][ +  - ]:       4124 :                     result = mbImpl->get_entities_by_handle( *vit, leaf_range2, Interface::UNION );
     301         [ -  + ]:       4124 :                     if( MB_SUCCESS != result ) return result;
     302                 :            :                 }
     303                 :            :             }
     304 [ +  - ][ +  + ]:       2230 :             if( !leaf_range2.empty() )
     305                 :            :             {
     306 [ +  - ][ +  - ]:       1667 :                 coords.resize( 3 * ( lr_size + leaf_range2.size() ) );
     307 [ +  - ][ +  - ]:       1667 :                 merge_tag_val.resize( lr_size + leaf_range2.size() );
     308 [ +  - ][ +  - ]:       1667 :                 result = mbImpl->get_coords( leaf_range2, &coords[3 * lr_size] );
     309         [ -  + ]:       1667 :                 if( MB_SUCCESS != result ) return result;
     310 [ +  - ][ +  - ]:       1667 :                 result = mbImpl->tag_get_data( merge_tag, leaf_range2, &merge_tag_val[lr_size] );
     311         [ -  + ]:       1667 :                 if( MB_SUCCESS != result ) return result;
     312                 :       1667 :                 outleaf_merged = false;
     313                 :            :             }
     314                 :            : 
     315                 :            :             // check other verts in this leaf
     316         [ +  + ]:      46864 :             for( unsigned int j = i + 1; j < merge_tag_val.size(); j++ )
     317                 :            :             {
     318 [ +  + ][ +  - ]:      44634 :                 EntityHandle to_ent = j >= lr_size ? leaf_range2[j - lr_size] : leaf_range[j];
                 [ +  - ]
     319                 :            : 
     320 [ +  - ][ +  + ]:      44634 :                 if( *rit == to_ent ) continue;
     321                 :            : 
     322 [ +  - ][ +  - ]:      42967 :                 if( ( from - CartVect( &coords[3 * j] ) ).length_squared() < mergeTolSq )
         [ +  - ][ +  - ]
                 [ +  + ]
     323                 :            :                 {
     324 [ +  - ][ +  - ]:       2935 :                     merge_tag_val[j] = *rit;
     325         [ +  + ]:       2935 :                     if( j < lr_size ) { inleaf_merged = true; }
     326                 :            :                     else
     327                 :            :                     {
     328                 :       1317 :                         outleaf_merged = true;
     329                 :            :                     }
     330         [ +  - ]:      42967 :                     deadEnts.insert( to_ent );
     331                 :            :                 }
     332                 :            :             }
     333         [ +  + ]:       2230 :             if( outleaf_merged )
     334                 :            :             {
     335 [ +  - ][ +  - ]:        973 :                 result = mbImpl->tag_set_data( merge_tag, leaf_range2, &merge_tag_val[leaf_range.size()] );
                 [ +  - ]
     336         [ -  + ]:        973 :                 if( MB_SUCCESS != result ) return result;
     337                 :        973 :                 outleaf_merged = false;
     338                 :            :             }
     339         [ +  + ]:       2230 :             if( inleaf_merged )
     340                 :            :             {
     341 [ +  - ][ +  - ]:       1206 :                 result = mbImpl->tag_set_data( merge_tag, leaf_range, &merge_tag_val[0] );
     342         [ -  + ]:       2230 :                 if( MB_SUCCESS != result ) return result;
     343                 :            :             }
     344                 :            :         }
     345                 :            :     }
     346                 :          6 :     return MB_SUCCESS;
     347                 :            : }
     348                 :            : 
     349                 :            : // Determine which higher dimensional entities should be merged
     350                 :          3 : ErrorCode MergeMesh::merge_higher_dimensions( Range& elems )
     351                 :            : {
     352                 :            :     // apply a different strategy
     353                 :            :     // look at the vertices that were merged to, earlier, and find all entities adjacent to them
     354                 :            :     // elems (input) are used just for initial connectivity
     355                 :            :     ErrorCode result;
     356         [ +  - ]:          3 :     Range verts;
     357         [ +  - ]:          3 :     result = mbImpl->get_connectivity( elems, verts );
     358         [ -  + ]:          3 :     if( MB_SUCCESS != result ) return result;
     359                 :            : 
     360                 :            :     // all higher dim entities that will be merged will be connected to the vertices that were
     361                 :            :     // merged earlier; we will look at these vertices only
     362         [ +  - ]:          6 :     Range mergedToVertsRange;
     363 [ +  - ][ +  - ]:          3 :     std::copy( mergedToVertices.rbegin(), mergedToVertices.rend(), range_inserter( mergedToVertsRange ) );
     364         [ +  - ]:          6 :     Range vertsOfInterest = intersect( mergedToVertsRange, verts );
     365                 :            :     // Go through each dimension
     366 [ +  - ][ +  - ]:          6 :     Range possibleEntsToMerge, conn, matches, moreDeadEnts;
         [ +  - ][ +  - ]
     367                 :            : 
     368         [ +  + ]:          9 :     for( int dim = 1; dim < 3; dim++ )
     369                 :            :     {
     370         [ +  - ]:          6 :         moreDeadEnts.clear();
     371         [ +  - ]:          6 :         possibleEntsToMerge.clear();
     372         [ +  - ]:          6 :         result = mbImpl->get_adjacencies( vertsOfInterest, dim, false, possibleEntsToMerge, Interface::UNION );
     373         [ -  + ]:          6 :         if( MB_SUCCESS != result ) return result;
     374                 :            :         // Go through each possible entity and see if it shares vertices with another entity of same
     375                 :            :         // dimension
     376 [ +  - ][ +  - ]:         20 :         for( Range::iterator pit = possibleEntsToMerge.begin(); pit != possibleEntsToMerge.end(); ++pit )
         [ +  - ][ +  - ]
                 [ +  + ]
     377                 :            :         {
     378         [ +  - ]:         14 :             EntityHandle eh = *pit;  // possible entity to be matched
     379         [ +  - ]:         14 :             conn.clear();
     380                 :            :             // Get the vertices connected to it in a range
     381                 :            : 
     382         [ +  - ]:         14 :             result = mbImpl->get_connectivity( &eh, 1, conn );
     383         [ -  + ]:         14 :             if( MB_SUCCESS != result ) return result;
     384         [ +  - ]:         14 :             matches.clear();
     385                 :            :             // now retrieve all entities connected to all conn vertices
     386         [ +  - ]:         14 :             result = mbImpl->get_adjacencies( conn, dim, false, matches, Interface::INTERSECT );
     387         [ -  + ]:         14 :             if( MB_SUCCESS != result ) return result;
     388 [ +  - ][ +  + ]:         14 :             if( matches.size() > 1 )
     389                 :            :             {
     390 [ +  - ][ +  - ]:         50 :                 for( Range::iterator matchIt = matches.begin(); matchIt != matches.end(); ++matchIt )
         [ +  - ][ +  - ]
                 [ +  + ]
     391                 :            :                 {
     392         [ +  - ]:         40 :                     EntityHandle to_remove = *matchIt;
     393         [ +  + ]:         40 :                     if( to_remove != eh )
     394                 :            :                     {
     395         [ +  - ]:         30 :                         moreDeadEnts.insert( to_remove );
     396         [ +  - ]:         30 :                         result = mbImpl->merge_entities( eh, to_remove, false, false );
     397         [ -  + ]:         30 :                         if( result != MB_SUCCESS ) return result;
     398         [ +  - ]:         30 :                         possibleEntsToMerge.erase( to_remove );
     399                 :            :                     }
     400                 :            :                 }
     401                 :            :             }
     402                 :            :         }
     403                 :            :         // Delete the entities of dimension dim
     404         [ +  - ]:          6 :         result = mbImpl->delete_entities( moreDeadEnts );
     405         [ -  + ]:          6 :         if( result != MB_SUCCESS ) return result;
     406                 :            :     }
     407                 :          6 :     return MB_SUCCESS;
     408                 :            : #if 0
     409                 :            :   Range skinEnts, adj, matches, moreDeadEnts;
     410                 :            :   ErrorCode result;
     411                 :            :   Skinner skinner(mbImpl);
     412                 :            :   //Go through each dimension
     413                 :            :   for (int dim = 1; dim < 3; dim++)
     414                 :            :   {
     415                 :            :     skinEnts.clear();
     416                 :            :     moreDeadEnts.clear();
     417                 :            :     result = skinner.find_skin(0, elems, dim, skinEnts, false, false);
     418                 :            :     //Go through each skin entity and see if it shares adjacancies with another entity
     419                 :            :     for (Range::iterator skinIt = skinEnts.begin();
     420                 :            :         skinIt != skinEnts.end(); ++skinIt)
     421                 :            :     {
     422                 :            :       adj.clear();
     423                 :            :       //Get the adjacencies 1 dimension lower
     424                 :            :       result = mbImpl->get_adjacencies(&(*skinIt), 1, dim - 1, false, adj);
     425                 :            :       if (result != MB_SUCCESS)
     426                 :            :         return result;
     427                 :            :       //See what other entities share these adjacencies
     428                 :            :       matches.clear();
     429                 :            :       result = mbImpl->get_adjacencies(adj, dim, false, matches,
     430                 :            :           Interface::INTERSECT);
     431                 :            :       if (result != MB_SUCCESS)
     432                 :            :         return result;
     433                 :            :       //If there is more than one entity, then we have some to merge and erase
     434                 :            :       if (matches.size() > 1)
     435                 :            :       {
     436                 :            :         for (Range::iterator matchIt = matches.begin();
     437                 :            :             matchIt != matches.end(); ++matchIt)
     438                 :            :         {
     439                 :            :           if (*matchIt != *skinIt)
     440                 :            :           {
     441                 :            :             moreDeadEnts.insert(*matchIt);
     442                 :            :             result = mbImpl->merge_entities(*skinIt, *matchIt, false, false);
     443                 :            :             if (result != MB_SUCCESS)
     444                 :            :               return result;
     445                 :            :             skinEnts.erase(*matchIt);
     446                 :            :           }
     447                 :            :         }
     448                 :            :       }
     449                 :            :     }
     450                 :            :     //Delete the entities
     451                 :            :     result = mbImpl->delete_entities(moreDeadEnts);
     452                 :            :     if (result != MB_SUCCESS)
     453                 :            :       return result;
     454                 :            :   }
     455                 :            :   return MB_SUCCESS;
     456                 :            : #endif
     457                 :            : }
     458                 :            : 
     459 [ +  - ][ +  - ]:        228 : }  // End namespace moab

Generated by: LCOV version 1.11