LCOV - code coverage report
Current view: top level - geom/virtual - PartitionLumpImprint.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 1 765 0.1 %
Date: 2020-06-30 00:58:45 Functions: 2 26 7.7 %
Branches: 2 2250 0.1 %

           Branch data     Line data    Source code
       1                 :            : //-------------------------------------------------------------------------
       2                 :            : // Filename      : PartitionLumpImprint.cpp
       3                 :            : //
       4                 :            : // Purpose       : Imprint a lump with a polyline-loop
       5                 :            : //
       6                 :            : // Special Notes : 
       7                 :            : //
       8                 :            : // Creator       : Jason Kraftcheck
       9                 :            : //
      10                 :            : // Creation Date : 02/05/03
      11                 :            : //-------------------------------------------------------------------------
      12                 :            : 
      13                 :            : #include "PartitionLumpImprint.hpp"
      14                 :            : 
      15                 :            : #include "PartitionLump.hpp"
      16                 :            : #include "PartitionSurface.hpp"
      17                 :            : #include "PartitionLoop.hpp"
      18                 :            : #include "PartitionCoEdge.hpp"
      19                 :            : #include "PartitionCurve.hpp"
      20                 :            : #include "PartitionPoint.hpp"
      21                 :            : 
      22                 :            : #include "CubitVector.hpp"
      23                 :            : #include "PartitionEngine.hpp"
      24                 :            : #include "SegmentedCurve.hpp"
      25                 :            : #include "PartPTCurve.hpp"
      26                 :            : #include "PartSurfFacetTool.hpp"
      27                 :            : 
      28                 :            : #include "CubitFacetData.hpp"
      29                 :            : #include "CubitFacetEdgeData.hpp"
      30                 :            : #include "CubitPointData.hpp"
      31                 :            : 
      32                 :            : const double DIST_TOL = 1000.0 * GEOMETRY_RESABS;
      33                 :            : const double DIST_TOL_SQR = DIST_TOL*DIST_TOL;
      34                 :            : 
      35                 :            : const int PART_LUMP_DEBUG = 88;
      36                 :            : #define PART_LUMP_PRINT(...) PRINT_DEBUG(PART_LUMP_DEBUG, __VA_ARGS__)
      37                 :            : #include "GfxDebug.hpp"
      38                 :            : 
      39                 :            : //-------------------------------------------------------------------------
      40                 :            : // Purpose       : Constructor - initialize some stuff
      41                 :            : //
      42                 :            : // Special Notes : 
      43                 :            : //
      44                 :            : // Creator       : Jason Kraftcheck
      45                 :            : //
      46                 :            : // Creation Date : 02/05/03
      47                 :            : //-------------------------------------------------------------------------
      48                 :          0 : PartitionLumpImprint::PartitionLumpImprint( PartitionLump* set_lump )
      49 [ #  # ][ #  # ]:          0 :   : lump(set_lump)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      50                 :            : {
      51         [ #  # ]:          0 :   lump->get_all_children( entityList );
      52         [ #  # ]:          0 :   entityList.reset();
      53                 :            :   
      54 [ #  # ][ #  # ]:          0 :   for( int i = 0; i < entityList.size(); i++ )
      55 [ #  # ][ #  # ]:          0 :     rTree.add(entityList.get_and_step());
      56 [ #  # ][ #  # ]:          0 :   entityList.append(lump);
      57                 :            :   
      58                 :          0 :   newSurface = 0;
      59                 :          0 : }
      60                 :            : 
      61                 :            : //-------------------------------------------------------------------------
      62                 :            : // Purpose       : Add an entity to internal structures
      63                 :            : //
      64                 :            : // Special Notes : 
      65                 :            : //
      66                 :            : // Creator       : Jason Kraftcheck
      67                 :            : //
      68                 :            : // Creation Date : 02/05/03
      69                 :            : //-------------------------------------------------------------------------
      70                 :          0 : bool PartitionLumpImprint::add( PartitionEntity* entity )
      71                 :            : {
      72         [ #  # ]:          0 :   if( !entityList.append_unique(entity) )
      73                 :          0 :     return false;
      74                 :            :     
      75                 :          0 :   rTree.add(entity);
      76                 :          0 :   return true;
      77                 :            : }
      78                 :            : 
      79                 :            : 
      80                 :            : //-------------------------------------------------------------------------
      81                 :            : // Purpose       : Set up for imprint
      82                 :            : //
      83                 :            : // Special Notes : 
      84                 :            : //
      85                 :            : // Creator       : Jason Kraftcheck
      86                 :            : //
      87                 :            : // Creation Date : 02/05/03
      88                 :            : //-------------------------------------------------------------------------
      89                 :          0 : void PartitionLumpImprint::init( DLIList<CubitFacet*>* facets )
      90                 :            : {
      91                 :          0 :   int i, j, junk = 0;
      92 [ #  # ][ #  # ]:          0 :   PART_LUMP_PRINT("Beginning imprint\n");
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      93                 :            :   
      94         [ #  # ]:          0 :   boundaryEdges.clean_out();
      95         [ #  # ]:          0 :   newEntities.clean_out();
      96         [ #  # ]:          0 :   assert(newSurface == 0);
      97                 :            : 
      98         [ #  # ]:          0 :   if ( facets )
      99                 :            :   {
     100                 :            :       // clear all marks
     101 [ #  # ][ #  # ]:          0 :     for ( i = facets->size(); i--; )
     102                 :            :     {
     103         [ #  # ]:          0 :       CubitFacet* facet = facets->get_and_step();
     104 [ #  # ][ #  # ]:          0 :       facet->point(0)->marked(0);
     105 [ #  # ][ #  # ]:          0 :       facet->point(1)->marked(0);
     106 [ #  # ][ #  # ]:          0 :       facet->point(2)->marked(0);
     107                 :            :     }
     108                 :            : 
     109                 :            :       // copy facets 
     110         [ #  # ]:          0 :     DLIList<CubitPointData*> new_facet_pts;
     111 [ #  # ][ #  # ]:          0 :     for ( i = facets->size(); i--; )
     112                 :            :     {
     113         [ #  # ]:          0 :       CubitFacet* facet = facets->get_and_step();
     114                 :            :       CubitPointData *pts[3];
     115         [ #  # ]:          0 :       for ( j = 0; j < 3; j++ )
     116                 :            :       {
     117         [ #  # ]:          0 :         CubitPoint* pt = facet->point(j);
     118 [ #  # ][ #  # ]:          0 :         if ( !pt->marked() )
     119                 :            :         {
     120 [ #  # ][ #  # ]:          0 :           pts[j] = new CubitPointData(pt->coordinates());
                 [ #  # ]
     121         [ #  # ]:          0 :           new_facet_pts.append(pts[j]);
     122 [ #  # ][ #  # ]:          0 :           pt->marked(new_facet_pts.size());
     123                 :            :         }
     124                 :            :         else
     125                 :            :         {
     126         [ #  # ]:          0 :           new_facet_pts.reset();
     127 [ #  # ][ #  # ]:          0 :           pts[j] = new_facet_pts.next(pt->marked()-1);
     128                 :            :         }
     129                 :            :       }
     130 [ #  # ][ #  # ]:          0 :       facetList.append( new CubitFacetData(pts[0], pts[1], pts[2], &junk ) );
                 [ #  # ]
     131                 :            :     }
     132                 :            : 
     133                 :            :       // clear marks on input facets
     134 [ #  # ][ #  # ]:          0 :     for ( i = facets->size(); i--; )
     135                 :            :     {
     136         [ #  # ]:          0 :       CubitFacet* facet = facets->get_and_step();
     137 [ #  # ][ #  # ]:          0 :       facet->point(0)->marked(0);
     138 [ #  # ][ #  # ]:          0 :       facet->point(1)->marked(0);
     139 [ #  # ][ #  # ]:          0 :       facet->point(2)->marked(0);
     140         [ #  # ]:          0 :     }
     141                 :            :   }
     142                 :            : 
     143                 :            :     // mark boundary edges with a 1, others with a 0
     144 [ #  # ][ #  # ]:          0 :   for ( i = facetList.size(); i--; )
     145                 :            :   {
     146         [ #  # ]:          0 :     CubitFacetData* facet = facetList.get_and_step();
     147         [ #  # ]:          0 :     for ( j = 0; j < 3; j++ )
     148 [ #  # ][ #  # ]:          0 :       facet->edge(j)->marked( facet->edge(j)->marked() + 1 );
         [ #  # ][ #  # ]
     149                 :            :   }
     150                 :            :   
     151 [ #  # ][ #  # ]:          0 :   for ( i = facetList.size(); i--; )
     152                 :            :   {
     153         [ #  # ]:          0 :     CubitFacetData* facet = facetList.get_and_step();
     154         [ #  # ]:          0 :     for ( j = 0; j < 3; j++ )
     155                 :            :     {
     156 [ #  # ][ #  # ]:          0 :       if ( facet->edge(j)->marked() == 1 )
                 [ #  # ]
     157 [ #  # ][ #  # ]:          0 :         boundaryEdges.append( facet->edge(j) );
     158 [ #  # ][ #  # ]:          0 :       facet->edge(j)->marked(0);
     159                 :            :     }
     160                 :            :   }
     161                 :            :   
     162 [ #  # ][ #  # ]:          0 :   for ( i = boundaryEdges.size(); i--; )
     163 [ #  # ][ #  # ]:          0 :     boundaryEdges.get_and_step()->marked(1);
     164                 :          0 : }
     165                 :            : 
     166                 :          0 : void PartitionLumpImprint::begin_loop( DLIList<CubitPoint*>& points )
     167                 :            : {
     168         [ #  # ]:          0 :   loopPoints = points;
     169                 :            :   
     170                 :            :     // associate each point with a geometric entity using rtree
     171         [ #  # ]:          0 :   DLIList<PartitionEntity*> closest_list;
     172 [ #  # ][ #  # ]:          0 :   CubitBox box;
     173         [ #  # ]:          0 :   loopPoints.reset();
     174 [ #  # ][ #  # ]:          0 :   for( int i = 0; i < loopPoints.size(); i++ )
     175                 :            :   {
     176         [ #  # ]:          0 :     CubitPoint* pt = loopPoints.next(i);
     177         [ #  # ]:          0 :     closest_list.clean_out();
     178         [ #  # ]:          0 :     CubitVector v = pt->coordinates();
     179         [ #  # ]:          0 :     box.reset( CubitVector( v.x() - DIST_TOL,
     180         [ #  # ]:          0 :                             v.y() - DIST_TOL,
     181         [ #  # ]:          0 :                             v.z() - DIST_TOL ),
     182         [ #  # ]:          0 :                CubitVector( v.x() + DIST_TOL,
     183         [ #  # ]:          0 :                             v.y() + DIST_TOL,
     184 [ #  # ][ #  # ]:          0 :                             v.z() + DIST_TOL ) );
         [ #  # ][ #  # ]
     185                 :            :                             
     186         [ #  # ]:          0 :     rTree.find( box, closest_list );
     187         [ #  # ]:          0 :     PartitionEntity* closest = find_closest( v, closest_list );
     188         [ #  # ]:          0 :     if ( closest ) {
     189         [ #  # ]:          0 :       set_point_owner(pt, closest);
     190                 :            :     } else {
     191 [ #  # ][ #  # ]:          0 :       set_point_owner(pt, lump);
     192                 :            :     }
     193         [ #  # ]:          0 :   }
     194                 :          0 : }
     195                 :            :     
     196                 :            : //-------------------------------------------------------------------------
     197                 :            : // Purpose       : Find closest entity in passed list to position
     198                 :            : //
     199                 :            : // Special Notes : 
     200                 :            : //
     201                 :            : // Creator       : Jason Kraftcheck
     202                 :            : //
     203                 :            : // Creation Date : 02/26/03
     204                 :            : //-------------------------------------------------------------------------
     205                 :          0 : PartitionEntity* PartitionLumpImprint::find_closest(
     206                 :            :   const CubitVector& pt, 
     207                 :            :   DLIList<PartitionEntity*>& closest_list,
     208                 :            :   bool use_tolerance )
     209                 :            : { 
     210                 :            :   PartitionPoint* ppoint;
     211                 :            :   PartitionCurve* pcurve;
     212                 :            :   PartitionSurface* psurf;
     213         [ #  # ]:          0 :   closest_list.reset();
     214         [ #  # ]:          0 :   double closest_dist_sqr = use_tolerance ? DIST_TOL_SQR : CUBIT_DBL_MAX;
     215                 :          0 :   PartitionEntity* closest = 0;
     216                 :          0 :   int closest_dim = 3;
     217         [ #  # ]:          0 :   CubitVector c;
     218                 :            : 
     219 [ #  # ][ #  # ]:          0 :   for( int i = closest_list.size(); i--; )
     220                 :            :   {
     221         [ #  # ]:          0 :     PartitionEntity* entity = closest_list.get_and_step();
     222                 :          0 :     int dim = 3;
     223 [ #  # ][ #  # ]:          0 :     if( (ppoint = dynamic_cast<PartitionPoint*>(entity)) )
     224                 :            :     {
     225 [ #  # ][ #  # ]:          0 :       c = ppoint->coordinates();
     226                 :          0 :       dim = 0;
     227                 :            :     }
     228 [ #  # ][ #  # ]:          0 :     else if( (pcurve = dynamic_cast<PartitionCurve*>(entity)) )
     229                 :            :     {
     230         [ #  # ]:          0 :       pcurve->closest_point_trimmed( pt, c );
     231                 :          0 :       dim = 1;
     232                 :            :     }
     233 [ #  # ][ #  # ]:          0 :     else if( (psurf = dynamic_cast<PartitionSurface*>(entity)) )
     234                 :            :     {
     235 [ #  # ][ #  # ]:          0 :       psurf->closest_point_trimmed( pt, c );
     236                 :          0 :       dim = 2;
     237                 :            :     }
     238                 :            :     else
     239                 :          0 :       assert(0);
     240                 :            : 
     241                 :            : 
     242                 :            :       // want the entity of smallest dimension within
     243                 :            :       // tolerance of point.
     244 [ #  # ][ #  # ]:          0 :     double dist_sqr = (pt - c).length_squared();
     245         [ #  # ]:          0 :     if ( use_tolerance ) 
     246                 :            :     {
     247 [ #  # ][ #  # ]:          0 :       if( (dim == closest_dim && dist_sqr <  closest_dist_sqr) || 
                 [ #  # ]
     248         [ #  # ]:          0 :           (dim <  closest_dim && dist_sqr <= DIST_TOL_SQR ) )
     249                 :            :       {
     250                 :          0 :         closest_dist_sqr = dist_sqr;
     251                 :          0 :         closest = entity;
     252                 :          0 :         closest_dim = dim;
     253                 :            :       }
     254                 :            :     } 
     255                 :            :     else 
     256                 :            :     {
     257                 :          0 :       double diff = closest_dist_sqr - dist_sqr;
     258 [ #  # ][ #  # ]:          0 :       if ( (dim  > closest_dim && diff >  DIST_TOL_SQR) ||
                 [ #  # ]
     259 [ #  # ][ #  # ]:          0 :            (dim == closest_dim && diff >  0.0         ) ||
     260         [ #  # ]:          0 :            (dim  < closest_dim && diff > -DIST_TOL_SQR) )
     261                 :            :       {
     262                 :          0 :         closest_dist_sqr = dist_sqr;
     263                 :          0 :         closest = entity;
     264                 :          0 :         closest_dim = dim;
     265                 :            :       }
     266                 :            :     }
     267                 :            :   }
     268                 :            : 
     269                 :          0 :   return closest;
     270                 :            : }
     271                 :            :   
     272                 :            : //-------------------------------------------------------------------------
     273                 :            : // Purpose       : Clean up after imprint
     274                 :            : //
     275                 :            : // Special Notes : 
     276                 :            : //
     277                 :            : // Creator       : Jason Kraftcheck
     278                 :            : //
     279                 :            : // Creation Date : 02/05/03
     280                 :            : //-------------------------------------------------------------------------
     281                 :          0 : void PartitionLumpImprint::clean_up_loop()
     282                 :            : {
     283         [ #  # ]:          0 :   for( int i = entityList.size(); i--; )
     284                 :          0 :     entityList.get_and_step()->mark = 0;
     285                 :          0 :   entityList.reset();
     286                 :          0 :   loopPoints.clean_out();
     287                 :          0 :   pointAssoc.clear();
     288                 :          0 : }
     289                 :            : 
     290                 :            : //-------------------------------------------------------------------------
     291                 :            : // Purpose       : get the owner of a point in the loop of imprint points
     292                 :            : //
     293                 :            : // Special Notes : 
     294                 :            : //
     295                 :            : // Creator       : Jason Kraftcheck
     296                 :            : //
     297                 :            : // Creation Date : 02/05/03
     298                 :            : //-------------------------------------------------------------------------
     299                 :          0 : PartitionEntity* PartitionLumpImprint::point_owner( CubitPoint* pt ) 
     300                 :            : {
     301                 :          0 :   return pointAssoc[pt];
     302                 :            : }
     303                 :            : 
     304                 :            : //-------------------------------------------------------------------------
     305                 :            : // Purpose       : Set point owner
     306                 :            : //
     307                 :            : // Special Notes : 
     308                 :            : //
     309                 :            : // Creator       : Jason Kraftcheck
     310                 :            : //
     311                 :            : // Creation Date : 02/07/03
     312                 :            : //-------------------------------------------------------------------------
     313                 :          0 : void PartitionLumpImprint::set_point_owner( CubitPoint* pt, 
     314                 :            :                                             PartitionEntity* owner )
     315                 :            : {
     316         [ #  # ]:          0 :   CubitVector closest;
     317                 :          0 :   PartitionPoint* ppt = 0;
     318                 :          0 :   PartitionCurve* pcv = 0;
     319                 :          0 :   PartitionSurface* psf = 0;
     320 [ #  # ][ #  # ]:          0 :   if( 0 != (ppt = dynamic_cast<PartitionPoint*>(owner)) ) {
     321 [ #  # ][ #  # ]:          0 :     pt->set( ppt->coordinates() );
     322 [ #  # ][ #  # ]:          0 :   } else if( 0 != (pcv = dynamic_cast<PartitionCurve*>(owner)) ) {
     323 [ #  # ][ #  # ]:          0 :     pcv->closest_point( pt->coordinates(), closest );
     324         [ #  # ]:          0 :     pt->set( closest );
     325 [ #  # ][ #  # ]:          0 :   } else if( 0 != (psf = dynamic_cast<PartitionSurface*>(owner)) ) {
     326 [ #  # ][ #  # ]:          0 :     psf->closest_point( pt->coordinates(), &closest );
     327         [ #  # ]:          0 :     pt->set( closest );
     328                 :            :   }
     329                 :            : 
     330 [ #  # ][ #  # ]:          0 :   if( DEBUG_FLAG(PART_LUMP_DEBUG) )
                 [ #  # ]
     331                 :            :   {
     332                 :          0 :     const char* type = 0;
     333                 :          0 :     int color = 0;
     334         [ #  # ]:          0 :     if( ppt ) {
     335                 :          0 :       type = "Point";   color = CUBIT_BLUE_INDEX;
     336         [ #  # ]:          0 :     } else if( pcv ) {
     337                 :          0 :       type = "Curve";   color = CUBIT_CYAN_INDEX;
     338         [ #  # ]:          0 :     } else if( psf ) {
     339                 :          0 :       type = "Surface"; color = CUBIT_YELLOW_INDEX;
     340                 :            :     } else {
     341                 :          0 :       type = "Lump";    color = CUBIT_RED_INDEX;
     342                 :            :     }
     343                 :            :     
     344                 :          0 :     int index = -1;
     345 [ #  # ][ #  # ]:          0 :     if ( loopPoints.move_to(pt) )
     346         [ #  # ]:          0 :       index = loopPoints.get_index();
     347         [ #  # ]:          0 :     loopPoints.reset();
     348                 :            : 
     349         [ #  # ]:          0 :     TopologyBridge* tb = dynamic_cast<TopologyBridge*>(owner);
     350 [ #  # ][ #  # ]:          0 :     RefEntity* re = dynamic_cast<RefEntity*>(tb->topology_entity());
     351 [ #  # ][ #  # ]:          0 :     PART_LUMP_PRINT("%d. (%f,%f,%f) -> %s %p (%d)\n", index,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     352                 :            :                       pt->coordinates().x(), pt->coordinates().y(), pt->coordinates().z(), 
     353         [ #  # ]:          0 :                       type, (void*)owner, re?re->id():0 );
     354 [ #  # ][ #  # ]:          0 :     GfxDebug::draw_point( pt->coordinates(), color );
     355         [ #  # ]:          0 :     GfxDebug::flush();
     356                 :            :   }
     357                 :            : 
     358         [ #  # ]:          0 :   pointAssoc[pt] = owner;
     359                 :          0 : }
     360                 :            : 
     361                 :            : //-------------------------------------------------------------------------
     362                 :            : // Purpose       : Get points owned by passed entity
     363                 :            : //
     364                 :            : // Special Notes : 
     365                 :            : //
     366                 :            : // Creator       : Jason Kraftcheck
     367                 :            : //
     368                 :            : // Creation Date : 03/03/03
     369                 :            : //-------------------------------------------------------------------------
     370                 :          0 : void PartitionLumpImprint::get_owned_points( PartitionEntity* owner,
     371                 :            :                                              DLIList<CubitPoint*>& results )
     372                 :            : {
     373         [ #  # ]:          0 :   std::map<CubitPoint*,PartitionEntity*>::iterator itor = pointAssoc.begin();
     374 [ #  # ][ #  # ]:          0 :   for ( ; itor != pointAssoc.end(); ++itor )
         [ #  # ][ #  # ]
     375 [ #  # ][ #  # ]:          0 :     if( itor->second == owner )
     376 [ #  # ][ #  # ]:          0 :       results.append(itor->first);
     377                 :          0 : }
     378                 :            : 
     379                 :            : 
     380                 :            : //-------------------------------------------------------------------------
     381                 :            : // Purpose       : Entry point for imprinting
     382                 :            : //
     383                 :            : // Special Notes : 
     384                 :            : //
     385                 :            : // Creator       : Jason Kraftcheck
     386                 :            : //
     387                 :            : // Creation Date : 04/14/03
     388                 :            : //-------------------------------------------------------------------------
     389                 :          0 : PartitionSurface* PartitionLumpImprint::imprint( DLIList<CubitFacet*>& facets,
     390                 :            :                                                  DLIList<PartitionEntity*>& new_list )
     391                 :            : {
     392         [ #  # ]:          0 :   init(&facets);
     393         [ #  # ]:          0 :   DLIList<CubitVector> empty_list;
     394 [ #  # ][ #  # ]:          0 :   return imprint( empty_list, new_list );
     395                 :            : }
     396                 :            : 
     397                 :          0 : PartitionSurface* PartitionLumpImprint::imprint( DLIList<CubitFacetData*>& facets,
     398                 :            :                                                  DLIList<CubitVector>& vertices,
     399                 :            :                                                  DLIList<PartitionEntity*>& new_list )
     400                 :            : {
     401                 :          0 :   facetList = facets;
     402                 :          0 :   init(0);
     403                 :          0 :   return imprint( vertices, new_list );
     404                 :            : }
     405                 :            : 
     406                 :          0 : PartitionSurface* PartitionLumpImprint::imprint( DLIList<CubitVector>& vertices,
     407                 :            :                                                  DLIList<PartitionEntity*>& new_list )
     408                 :            : {
     409                 :            :   int i, j;
     410                 :            :   
     411 [ #  # ][ #  # ]:          0 :   newSurface = new PartitionSurface( lump );
     412                 :            :   
     413                 :            :   
     414                 :            :     // Make vertices where requested.
     415 [ #  # ][ #  # ]:          0 :   DLIList<CubitPoint*> vtx_points, all_points;
                 [ #  # ]
     416         [ #  # ]:          0 :   for ( j = 0; j < 3; j++ )
     417 [ #  # ][ #  # ]:          0 :     for ( i = facetList.size(); i--; )
     418 [ #  # ][ #  # ]:          0 :       facetList.get_and_step()->point(j)->marked(1);
                 [ #  # ]
     419                 :            :   
     420         [ #  # ]:          0 :   for ( j = 0; j < 3; j++ ) {
     421 [ #  # ][ #  # ]:          0 :     for ( i = facetList.size(); i--; ) {
     422 [ #  # ][ #  # ]:          0 :       if ( facetList.step_and_get()->point(j)->marked() ) {
         [ #  # ][ #  # ]
     423 [ #  # ][ #  # ]:          0 :         facetList.get()->point(j)->marked(0);
                 [ #  # ]
     424 [ #  # ][ #  # ]:          0 :         all_points.append( facetList.get()->point(j) );
                 [ #  # ]
     425                 :            :       }
     426                 :            :     }
     427                 :            :   }
     428                 :            :   
     429 [ #  # ][ #  # ]:          0 :   for ( i = vertices.size(); i--; )
     430                 :            :   {
     431                 :          0 :     double closest_sqr = CUBIT_DBL_MAX;
     432                 :          0 :     CubitPoint* closest_pt = 0;
     433 [ #  # ][ #  # ]:          0 :     CubitVector vect = vertices.get_and_step();
     434 [ #  # ][ #  # ]:          0 :     for ( j = all_points.size(); j--; )
     435                 :            :     {
     436         [ #  # ]:          0 :       CubitPoint* pt = all_points.step_and_get();
     437 [ #  # ][ #  # ]:          0 :       double dist_sqr = (pt->coordinates() - vect).length_squared();
                 [ #  # ]
     438         [ #  # ]:          0 :       if ( dist_sqr < closest_sqr ) 
     439                 :            :       {
     440                 :          0 :         closest_sqr = dist_sqr;
     441                 :          0 :         closest_pt = pt;
     442                 :            :       }
     443                 :            :     }
     444         [ #  # ]:          0 :     vtx_points.append( closest_pt );
     445                 :            :   }
     446                 :            :   
     447                 :            :   
     448                 :            : 
     449                 :            :     // For each closed chain of boundary edges
     450 [ #  # ][ #  # ]:          0 :   DLIList<CubitFacetEdge*> pt_edges;
     451 [ #  # ][ #  # ]:          0 :   DLIList<CubitPoint*> chain, chain_verts;
         [ #  # ][ #  # ]
     452         [ #  # ]:          0 :   int unused = boundaryEdges.size();
     453         [ #  # ]:          0 :   while( unused )
     454                 :            :   {
     455                 :            :       // find first edge
     456 [ #  # ][ #  # ]:          0 :     for ( i = boundaryEdges.size(); i--; )
     457 [ #  # ][ #  # ]:          0 :       if ( boundaryEdges.step_and_get()->marked() )
                 [ #  # ]
     458                 :          0 :         break;
     459                 :            :     
     460 [ #  # ][ #  # ]:          0 :     if ( !boundaryEdges.get()->marked() )
                 [ #  # ]
     461                 :          0 :       break;
     462                 :            :     
     463         [ #  # ]:          0 :     chain.clean_out();
     464         [ #  # ]:          0 :     chain_verts.clean_out();
     465         [ #  # ]:          0 :     CubitFacetEdge* edge = boundaryEdges.get();
     466         [ #  # ]:          0 :     edge->marked(0);
     467                 :          0 :     unused--;
     468         [ #  # ]:          0 :     CubitPoint* first_pt = edge->point(0);
     469         [ #  # ]:          0 :     CubitPoint* point = edge->point(1);
     470                 :            :     
     471         [ #  # ]:          0 :     CubitFacet* facet = edge->adj_facet(0);
     472         [ #  # ]:          0 :     int edge_index = facet->edge_index(edge);
     473 [ #  # ][ #  # ]:          0 :     if ( facet->edge_use(edge_index) == -1 )
     474         [ #  # ]:          0 :       std::swap(first_pt, point);
     475                 :            :     
     476         [ #  # ]:          0 :     while( point != first_pt )
     477                 :            :     {
     478         [ #  # ]:          0 :       chain.append( point );
     479 [ #  # ][ #  # ]:          0 :       if ( vtx_points.is_in_list(point) )
     480         [ #  # ]:          0 :         chain_verts.append(point);
     481                 :            :         
     482         [ #  # ]:          0 :       pt_edges.clean_out();
     483         [ #  # ]:          0 :       point->edges(pt_edges);
     484 [ #  # ][ #  # ]:          0 :       for ( j = pt_edges.size(); j--; )
     485 [ #  # ][ #  # ]:          0 :         if ( pt_edges.step_and_get()->marked() )
                 [ #  # ]
     486                 :          0 :           break;
     487                 :            :       
     488 [ #  # ][ #  # ]:          0 :       if ( !pt_edges.get()->marked() )
                 [ #  # ]
     489                 :          0 :         break;
     490                 :            :     
     491         [ #  # ]:          0 :       edge = pt_edges.get();
     492         [ #  # ]:          0 :       edge->marked(0);
     493                 :          0 :       unused--;
     494         [ #  # ]:          0 :       point = edge->other_point(point);
     495                 :            :     }
     496                 :            :     
     497         [ #  # ]:          0 :     if ( point != first_pt )
     498                 :          0 :       break;
     499                 :            :     
     500         [ #  # ]:          0 :     chain.append( first_pt );
     501 [ #  # ][ #  # ]:          0 :     if ( vtx_points.is_in_list(first_pt) )
     502         [ #  # ]:          0 :       chain_verts.append(first_pt);
     503                 :            :       
     504                 :            :       // remove edges from boundaryList that will be 
     505                 :            :       // destroyed by merging with other facet edges.
     506 [ #  # ][ #  # ]:          0 :     for ( i = boundaryEdges.size(); i--; )
     507 [ #  # ][ #  # ]:          0 :       if( boundaryEdges.step_and_get()->marked() == 0 )
                 [ #  # ]
     508         [ #  # ]:          0 :         boundaryEdges.change_to(0);
     509         [ #  # ]:          0 :     boundaryEdges.remove_all_with_value(0);
     510                 :            :     
     511                 :            :     
     512         [ #  # ]:          0 :     PartitionLoop* new_loop = imprint( chain, chain_verts );
     513         [ #  # ]:          0 :     if (!new_loop)
     514                 :            :     {
     515                 :          0 :       unused = 1;
     516                 :          0 :       break;
     517                 :            :     }
     518                 :            :     
     519         [ #  # ]:          0 :     newSurface->add(new_loop);
     520                 :            :   }
     521                 :            :   
     522         [ #  # ]:          0 :   if ( !unused )
     523                 :            :   {
     524         [ #  # ]:          0 :     new_list = newEntities;
     525                 :          0 :     PartitionSurface* result = newSurface;
     526         [ #  # ]:          0 :     result->set_facet_data( facetList );
     527                 :          0 :     newSurface = 0;
     528                 :          0 :     return result;
     529                 :            :   }
     530                 :            :   
     531         [ #  # ]:          0 :   abort_imprint();
     532         [ #  # ]:          0 :   return 0;
     533                 :            : }
     534                 :            :   
     535                 :            : 
     536                 :            : //-------------------------------------------------------------------------
     537                 :            : // Purpose       : Imprint one loop onto the volume
     538                 :            : //
     539                 :            : // Special Notes : 
     540                 :            : //
     541                 :            : // Creator       : Jason Kraftcheck
     542                 :            : //
     543                 :            : // Creation Date : 02/05/03
     544                 :            : //-------------------------------------------------------------------------
     545                 :          0 : PartitionLoop* PartitionLumpImprint::imprint( DLIList<CubitPoint*>& loop ,
     546                 :            :                                               DLIList<CubitPoint*>& vtx_points)
     547                 :            : {
     548         [ #  # ]:          0 :   begin_loop( loop );
     549         [ #  # ]:          0 :   DLIList<PartitionCoEdge*> results;
     550                 :            :   
     551 [ #  # ][ #  # ]:          0 :   if( ! make_vertices( vtx_points ) )
     552                 :            :   {
     553 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("PartitionLumpImprint::make_vertices() failed.\n");
         [ #  # ][ #  # ]
     554                 :          0 :     return 0;
     555                 :            :   }
     556                 :            :   
     557 [ #  # ][ #  # ]:          0 :   if( ! do_imprint() )
     558                 :            :   {
     559 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("PartitionLumpImprint::do_imprint() failed.\n");
         [ #  # ][ #  # ]
     560                 :          0 :     return 0;
     561                 :            :   }
     562                 :            :   
     563 [ #  # ][ #  # ]:          0 :   if( ! make_volume_curves() )
     564                 :            :   {
     565 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("PartitionLumpImprint::make_volume_curves() failed.\n");
         [ #  # ][ #  # ]
     566                 :          0 :     return 0;
     567                 :            :    }
     568                 :            :  
     569 [ #  # ][ #  # ]:          0 :   if( ! get_curves(results) )
     570                 :            :   {
     571 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("PartitionLumpImprint::get_curves() failed.\n");
         [ #  # ][ #  # ]
     572                 :          0 :     return 0;
     573                 :            :   }
     574                 :            : 
     575                 :            : //for ( int i = 0; i < results.size(); i++ )
     576                 :            : //  results.get_and_step()->draw_facets(CUBIT_RED_INDEX);
     577                 :            : 
     578                 :            :   
     579 [ #  # ][ #  # ]:          0 :   PartitionLoop* new_loop = new PartitionLoop;
     580         [ #  # ]:          0 :   results.reverse();
     581                 :          0 :   PartitionCoEdge* prev = 0;
     582 [ #  # ][ #  # ]:          0 :   while ( results.size() )
     583                 :            :   {
     584         [ #  # ]:          0 :     PartitionCoEdge* coe = results.pop();
     585         [ #  # ]:          0 :     new_loop->insert_after( coe, prev );
     586                 :          0 :     prev = coe;
     587                 :            :   }
     588                 :            :   
     589         [ #  # ]:          0 :   clean_up_loop();
     590                 :            :   
     591         [ #  # ]:          0 :   return new_loop;
     592                 :            : }
     593                 :            : 
     594                 :            : //-------------------------------------------------------------------------
     595                 :            : // Purpose       : Create vertices where asked to do so
     596                 :            : //
     597                 :            : // Special Notes : 
     598                 :            : //
     599                 :            : // Creator       : Jason Kraftcheck
     600                 :            : //
     601                 :            : // Creation Date : 02/05/03
     602                 :            : //-------------------------------------------------------------------------
     603                 :          0 : CubitStatus PartitionLumpImprint::make_vertices( DLIList<CubitPoint*>& vtx_points )
     604                 :            : {
     605         [ #  # ]:          0 :   for( int i = 0; i < vtx_points.size(); i++ )
     606                 :            :   {
     607                 :          0 :     CubitPoint* pt = vtx_points.get_and_step();
     608                 :          0 :     PartitionEntity* entity = point_owner(pt);
     609         [ #  # ]:          0 :     if( !entity )
     610                 :          0 :       continue;
     611                 :            :     
     612                 :            :     
     613 [ #  # ][ #  # ]:          0 :     if( dynamic_cast<TBPoint*>(entity) ) {
                 [ #  # ]
     614                 :            :      ; // already a point
     615                 :            :     }
     616 [ #  # ][ #  # ]:          0 :     else if( dynamic_cast<Curve*>(entity) ) {
                 [ #  # ]
     617         [ #  # ]:          0 :       if( !partitionCurve( pt ) )
     618                 :          0 :         return CUBIT_FAILURE;
     619                 :            :     }
     620 [ #  # ][ #  # ]:          0 :     else if( dynamic_cast<Surface*>(entity) ) {
                 [ #  # ]
     621         [ #  # ]:          0 :       if( !makePointCurve( pt ) )
     622                 :          0 :         return CUBIT_FAILURE;
     623                 :            :     }
     624         [ #  # ]:          0 :     else if( !makeFreePoint( pt ) ) {
     625                 :          0 :       return CUBIT_FAILURE;
     626                 :            :     }
     627                 :            :   }
     628                 :          0 :   return CUBIT_SUCCESS;
     629                 :            : }
     630                 :            : 
     631                 :            : //-------------------------------------------------------------------------
     632                 :            : // Purpose       : Try to clean up failed imprint
     633                 :            : //
     634                 :            : // Special Notes : Always returns CUBIT_FAILURE
     635                 :            : //
     636                 :            : // Creator       : Jason Kraftcheck
     637                 :            : //
     638                 :            : // Creation Date : 02/05/03
     639                 :            : //-------------------------------------------------------------------------
     640                 :          0 : CubitStatus PartitionLumpImprint::abort_imprint()
     641                 :            : {
     642 [ #  # ][ #  # ]:          0 :   PRINT_ERROR("Loop-Volume imprint failed in PartitionLumpImprint\n"
                 [ #  # ]
     643         [ #  # ]:          0 :               "\tAttempting to restore state.\n");
     644                 :            :   
     645         [ #  # ]:          0 :   clean_up_loop();
     646                 :            : 
     647         [ #  # ]:          0 :   DLIList<PartitionCurve*> curves;
     648 [ #  # ][ #  # ]:          0 :   DLIList<PartitionPoint*> points;
     649 [ #  # ][ #  # ]:          0 :   CAST_LIST( newEntities, curves, PartitionCurve );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     650 [ #  # ][ #  # ]:          0 :   CAST_LIST( newEntities, points, PartitionPoint );  
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     651                 :            :   
     652 [ #  # ][ #  # ]:          0 :   while( curves.size() )
     653                 :            :   {
     654         [ #  # ]:          0 :     PartitionCurve* curve = curves.pop();
     655                 :            : 
     656                 :            :     // if num curves for the startpoint/endpoint equals one, this point will
     657                 :            :     // get cleaned up when the curve is deleted or removed
     658                 :            :     // so remove the point from the list of points to clean up
     659 [ #  # ][ #  # ]:          0 :     if (1 == curve->start_point()->num_curves())
                 [ #  # ]
     660 [ #  # ][ #  # ]:          0 :       points.remove(curve->start_point());
     661 [ #  # ][ #  # ]:          0 :     if (1 == curve->end_point()->num_curves())
                 [ #  # ]
     662 [ #  # ][ #  # ]:          0 :       points.remove(curve->end_point());
     663                 :            : 
     664 [ #  # ][ #  # ]:          0 :     if( &(curve->sub_entity_set()) == &(lump->sub_entity_set()) )
                 [ #  # ]
     665 [ #  # ][ #  # ]:          0 :       delete curve;
     666                 :            :     else
     667 [ #  # ][ #  # ]:          0 :       PartitionEngine::instance().remove_curve(curve);
     668                 :            :   }
     669                 :            : 
     670                 :            : 
     671 [ #  # ][ #  # ]:          0 :   while( points.size() )
     672                 :            :   {
     673         [ #  # ]:          0 :     PartitionPoint* point = points.pop();
     674 [ #  # ][ #  # ]:          0 :     if( point->next_curve() == 0 )
     675 [ #  # ][ #  # ]:          0 :       delete point;
     676 [ #  # ][ #  # ]:          0 :     else if( dynamic_cast<PartPTCurve*>(point->next_curve()) )
         [ #  # ][ #  # ]
     677 [ #  # ][ #  # ]:          0 :       PartitionEngine::instance().remove_point_curve(point);
     678 [ #  # ][ #  # ]:          0 :     else if( dynamic_cast<Curve*>(point->partitioned_entity()) )
         [ #  # ][ #  # ]
     679 [ #  # ][ #  # ]:          0 :       PartitionEngine::instance().remove_point(point);
     680                 :            :   }
     681                 :            :   
     682 [ #  # ][ #  # ]:          0 :   while( facetList.size() )
     683 [ #  # ][ #  # ]:          0 :     PartitionEngine::delete_facet( facetList.pop() );
     684                 :            :   
     685         [ #  # ]:          0 :   return CUBIT_FAILURE;
     686                 :            : }
     687                 :            : 
     688                 :            : //-------------------------------------------------------------------------
     689                 :            : // Purpose       : Partition a curve and update local data
     690                 :            : //
     691                 :            : // Special Notes : 
     692                 :            : //
     693                 :            : // Creator       : Jason Kraftcheck
     694                 :            : //
     695                 :            : // Creation Date : 02/05/03
     696                 :            : //-------------------------------------------------------------------------
     697                 :          0 : CubitStatus PartitionLumpImprint::partitionCurve( CubitPoint* pt )
     698                 :            : {
     699                 :            :     // get entities
     700         [ #  # ]:          0 :   PartitionEntity* ent = point_owner(pt);
     701         [ #  # ]:          0 :   PartitionCurve* curve = dynamic_cast<PartitionCurve*>(ent);
     702         [ #  # ]:          0 :   assert(!!curve);
     703                 :            :   
     704 [ #  # ][ #  # ]:          0 :   PART_LUMP_PRINT("Splitting curve %p (%d) at (%f,%f,%f)\n",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     705                 :            :     (void*)curve, dynamic_cast<RefEntity*>(curve->topology_entity()) ?
     706                 :            :            dynamic_cast<RefEntity*>(curve->topology_entity())->id() : 0,
     707         [ #  # ]:          0 :     pt->coordinates().x(), pt->coordinates().y(), pt->coordinates().z() );
     708                 :            :   
     709                 :            :     // get list of associated points that will need to be moved
     710                 :            :     // to the new partition of the curve after the split.
     711 [ #  # ][ #  # ]:          0 :   double u_end = curve->u_from_position( pt->coordinates() );
     712         [ #  # ]:          0 :   DLIList<CubitPoint*> points_to_move;
     713 [ #  # ][ #  # ]:          0 :   get_owned_points( curve, points_to_move );
     714                 :            :   
     715                 :            :   CubitPoint* curve_pt;
     716 [ #  # ][ #  # ]:          0 :   for( int i = points_to_move.size(); i--; )
     717                 :            :   {
     718         [ #  # ]:          0 :     curve_pt = points_to_move.step_and_get();
     719 [ #  # ][ #  # ]:          0 :     double u = curve->u_from_position( curve_pt->coordinates() );
     720 [ #  # ][ #  # ]:          0 :     if( u < u_end || curve_pt == pt )
     721         [ #  # ]:          0 :       points_to_move.change_to(0);
     722                 :            :   }
     723         [ #  # ]:          0 :   points_to_move.remove_all_with_value(0);
     724                 :            :   
     725                 :            :     // partition curve
     726 [ #  # ][ #  # ]:          0 :   PartitionPoint* new_pt = new PartitionPoint( pt->coordinates(), curve );
         [ #  # ][ #  # ]
     727                 :            :   PartitionCurve* new_curve = 
     728 [ #  # ][ #  # ]:          0 :     PartitionEngine::instance().insert_point( curve, new_pt );
     729                 :            :   
     730                 :            :     // partition failed
     731         [ #  # ]:          0 :   if( !new_curve )
     732                 :            :   {
     733 [ #  # ][ #  # ]:          0 :     delete new_pt;
     734                 :          0 :     return CUBIT_FAILURE;
     735                 :            :   }
     736                 :            :   
     737                 :            :     // update internal lists
     738 [ #  # ][ #  # ]:          0 :   add(new_pt);
     739 [ #  # ][ #  # ]:          0 :   add(new_curve);
     740 [ #  # ][ #  # ]:          0 :   newEntities.append(new_pt);
     741 [ #  # ][ #  # ]:          0 :   pt->set( new_pt->coordinates() );
     742 [ #  # ][ #  # ]:          0 :   set_point_owner( pt, new_pt );
     743                 :            :   
     744                 :            :     // update point associativity
     745 [ #  # ][ #  # ]:          0 :   while( points_to_move.size() )
     746 [ #  # ][ #  # ]:          0 :     set_point_owner( points_to_move.pop(), new_curve );
                 [ #  # ]
     747                 :            :   
     748         [ #  # ]:          0 :   return CUBIT_SUCCESS;
     749                 :            : }
     750                 :            : 
     751                 :            : 
     752                 :            : //-------------------------------------------------------------------------
     753                 :            : // Purpose       : Partition a surface and update internal data structures
     754                 :            : //
     755                 :            : // Special Notes : 
     756                 :            : //
     757                 :            : // Creator       : Jason Kraftcheck
     758                 :            : //
     759                 :            : // Creation Date : 02/05/03
     760                 :            : //-------------------------------------------------------------------------
     761                 :          0 : CubitStatus PartitionLumpImprint::partitionSurface( int first_point_id,
     762                 :            :                                                     int last_point_id,
     763                 :            :                                                     PartitionSurface* surface )
     764                 :            : {
     765 [ #  # ][ #  # ]:          0 :   PartitionEntity* start_owner = point_owner(point(first_point_id));
     766 [ #  # ][ #  # ]:          0 :   PartitionEntity* end_owner = point_owner(point(last_point_id));
     767         [ #  # ]:          0 :   PartitionPoint* start_point = dynamic_cast<PartitionPoint*>(start_owner);
     768         [ #  # ]:          0 :   PartitionPoint* end_point = dynamic_cast<PartitionPoint*>(end_owner);
     769 [ #  # ][ #  # ]:          0 :   if ( (start_owner != lump && !start_point) ||
         [ #  # ][ #  # ]
     770 [ #  # ][ #  # ]:          0 :        (end_owner != lump && !end_point) ) {
     771 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Facet boundary too coarse to resolve imprint.\n");
         [ #  # ][ #  # ]
     772                 :          0 :     return CUBIT_FAILURE;
     773                 :            :   } 
     774                 :            : 
     775         [ #  # ]:          0 :   int i, next_point_id = (first_point_id + 1) % num_points();
     776         [ #  # ]:          0 :   if( !surface )
     777                 :            :   {
     778         [ #  # ]:          0 :     assert(next_point_id != last_point_id);
     779 [ #  # ][ #  # ]:          0 :     surface = dynamic_cast<PartitionSurface*>(point_owner(point(next_point_id)));
                 [ #  # ]
     780         [ #  # ]:          0 :     assert(!!surface);
     781                 :            :   }
     782                 :            :   
     783                 :            :   if ( PART_LUMP_DEBUG ) {
     784 [ #  # ][ #  # ]:          0 :     RefEntity* re = dynamic_cast<RefEntity*>(surface->topology_entity());
     785 [ #  # ][ #  # ]:          0 :     PART_LUMP_PRINT("Inserting curve into surface %p (%d)\n",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     786         [ #  # ]:          0 :       (void*)surface, re ? re->id() : 0 );
     787                 :            :   }
     788                 :            :   
     789         [ #  # ]:          0 :   DLIList<CubitPoint*> segments;
     790         [ #  # ]:          0 :   first_point_id %= num_points();
     791         [ #  # ]:          0 :   int last_id = last_point_id % num_points();
     792                 :            :   
     793                 :            :   int start, stop;
     794         [ #  # ]:          0 :   if ( start_point )
     795                 :          0 :     start = first_point_id;
     796                 :            :   else
     797                 :          0 :     start = next_point_id;
     798         [ #  # ]:          0 :   if ( end_point )
     799         [ #  # ]:          0 :     stop = (last_id + 1) % num_points();
     800                 :            :   else
     801                 :          0 :     stop = last_id;
     802                 :            :   
     803         [ #  # ]:          0 :   if( start == last_id )
     804                 :            :   {
     805                 :          0 :     i = start;
     806         [ #  # ]:          0 :     do {
     807 [ #  # ][ #  # ]:          0 :       segments.append(point(i));
     808         [ #  # ]:          0 :       i = (i+1) % num_points();
     809                 :            :     } while( i != start );
     810 [ #  # ][ #  # ]:          0 :     segments.append(point(start));
     811                 :            :   }
     812                 :            :   else
     813                 :            :   {
     814 [ #  # ][ #  # ]:          0 :     for ( i = start; i != stop; i = (i + 1) % num_points() )
     815 [ #  # ][ #  # ]:          0 :       segments.append(point(i));
     816                 :            :   }
     817                 :            :   
     818 [ #  # ][ #  # ]:          0 :   assert(surface&&start_owner&&end_owner && start_owner!=surface && end_owner!=surface );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     819                 :            : 
     820 [ #  # ][ #  # ]:          0 :   DLIList<CubitVector*> segment_points;
     821         [ #  # ]:          0 :   segments.reset();
     822 [ #  # ][ #  # ]:          0 :   for ( i = segments.size(); i--; )
     823 [ #  # ][ #  # ]:          0 :     segment_points.append( new CubitVector( segments.get_and_step()->coordinates() ) );
         [ #  # ][ #  # ]
     824                 :            :   
     825 [ #  # ][ #  # ]:          0 :   DLIList<PartitionSurface*> input_list(1), new_surfs;
         [ #  # ][ #  # ]
     826 [ #  # ][ #  # ]:          0 :   DLIList<PartitionCurve*> new_curves;
     827         [ #  # ]:          0 :   input_list.append(surface);
     828         [ #  # ]:          0 :   CubitStatus result = PartitionEngine::instance().
     829         [ #  # ]:          0 :     insert_curve( input_list, segment_points, new_surfs, new_curves );
     830 [ #  # ][ #  # ]:          0 :   while( segment_points.size() )
     831         [ #  # ]:          0 :     delete segment_points.pop();
     832                 :            :     
     833         [ #  # ]:          0 :   if ( !result )
     834                 :            :   {
     835 [ #  # ][ #  # ]:          0 :     PRINT_ERROR("Surface partitioning failed in PartitionLumpImprint\n");
         [ #  # ][ #  # ]
     836                 :          0 :     return CUBIT_FAILURE;
     837                 :            :   }
     838                 :            :   
     839                 :            :     // Add all new geometry to 'entities'.  Append everything except
     840                 :            :     // the surfaces to curves_and_points.
     841 [ #  # ][ #  # ]:          0 :   DLIList<PartitionEntity*> entities;
     842 [ #  # ][ #  # ]:          0 :   DLIList<PartitionPoint*> new_points;
     843                 :            :     
     844                 :            :     // Do Surfaces
     845 [ #  # ][ #  # ]:          0 :   if( new_surfs.move_to( surface ) )
     846         [ #  # ]:          0 :     new_surfs.extract();
     847         [ #  # ]:          0 :   new_surfs.reset();
     848 [ #  # ][ #  # ]:          0 :   for ( i = new_surfs.size(); i--; )
     849 [ #  # ][ #  # ]:          0 :     entities.append(new_surfs.get_and_step());
                 [ #  # ]
     850                 :            :     
     851                 :            :     // Get new points
     852 [ #  # ][ #  # ]:          0 :   for ( i = new_curves.size(); i--; )
     853                 :            :   {
     854 [ #  # ][ #  # ]:          0 :     new_curves.get()->start_point()->mark = 1;
     855 [ #  # ][ #  # ]:          0 :     new_curves.get()->end_point()->mark = 1;
     856         [ #  # ]:          0 :     new_curves.step();
     857                 :            :   }
     858         [ #  # ]:          0 :   if ( start_point )
     859                 :          0 :     start_point->mark = 0;
     860         [ #  # ]:          0 :   if ( end_point )
     861                 :          0 :     end_point->mark = 0;
     862 [ #  # ][ #  # ]:          0 :   for ( i = new_curves.size(); i--; )
     863                 :            :   {
     864 [ #  # ][ #  # ]:          0 :     if ( new_curves.get()->start_point()->mark )
                 [ #  # ]
     865                 :            :     {
     866 [ #  # ][ #  # ]:          0 :       PartitionPoint* pt = new_curves.get()->start_point();
     867                 :          0 :       pt->mark = 0;
     868         [ #  # ]:          0 :       new_points.append( pt );
     869 [ #  # ][ #  # ]:          0 :       entities.append( pt );
     870                 :            :     }
     871 [ #  # ][ #  # ]:          0 :     if ( new_curves.get()->end_point()->mark )
                 [ #  # ]
     872                 :            :     {
     873 [ #  # ][ #  # ]:          0 :       PartitionPoint* pt = new_curves.get()->end_point();
     874                 :          0 :       pt->mark = 0;
     875         [ #  # ]:          0 :       new_points.append( pt );
     876 [ #  # ][ #  # ]:          0 :       entities.append( pt );
     877                 :            :     }
     878 [ #  # ][ #  # ]:          0 :     entities.append( new_curves.get() );
                 [ #  # ]
     879         [ #  # ]:          0 :     new_curves.step();
     880                 :            :   }
     881                 :            : 
     882                 :            :     // If first and/or last segment points were already
     883                 :            :     // associated with a vertex, don't search for a new
     884                 :            :     // entity to associate them with.
     885         [ #  # ]:          0 :   if( start_point ) {
     886         [ #  # ]:          0 :     segments.reset();
     887         [ #  # ]:          0 :     segments.remove();
     888                 :            :   }
     889         [ #  # ]:          0 :   if( end_point ) {
     890         [ #  # ]:          0 :     segments.pop();
     891                 :            :   }
     892                 :            : 
     893                 :            :   // Associate split segments with points
     894 [ #  # ][ #  # ]:          0 :   for ( i = new_points.size(); i--; )
     895                 :            :   {
     896 [ #  # ][ #  # ]:          0 :     if (segments.size() == 0)
     897                 :          0 :         break;
     898                 :            : 
     899         [ #  # ]:          0 :     PartitionPoint* vert = new_points.get_and_step();
     900                 :          0 :     CubitPoint* pt = 0;
     901         [ #  # ]:          0 :     segments.reset();
     902                 :          0 :     int closest_index = -1;
     903                 :          0 :     double closest_sqr = CUBIT_DBL_MAX;
     904 [ #  # ][ #  # ]:          0 :     for ( int j = 0; j < segments.size(); j++ )
     905                 :            :     {
     906         [ #  # ]:          0 :       pt = segments.get_and_step();
     907 [ #  # ][ #  # ]:          0 :       double dist_sqr = (pt->coordinates() - vert->coordinates()).length_squared();
         [ #  # ][ #  # ]
     908         [ #  # ]:          0 :       if ( dist_sqr < closest_sqr ) {
     909                 :          0 :         closest_sqr = dist_sqr;
     910                 :          0 :         closest_index = j;
     911                 :            :       }
     912                 :            :     }
     913         [ #  # ]:          0 :     assert(closest_index >= 0);
     914         [ #  # ]:          0 :     segments.reset();
     915         [ #  # ]:          0 :     segments.step(closest_index);
     916         [ #  # ]:          0 :     pt = segments.extract();
     917 [ #  # ][ #  # ]:          0 :     assert(point_owner(pt) == surface);
                 [ #  # ]
     918 [ #  # ][ #  # ]:          0 :     pt->set( vert->coordinates() );
     919 [ #  # ][ #  # ]:          0 :     set_point_owner( pt, vert );
     920                 :            :   }
     921                 :            : 
     922                 :            :   // Associate remaining segment points with curves
     923                 :            :   PartitionEntity* entity;
     924 [ #  # ][ #  # ]:          0 :   while( segments.size() )
     925                 :            :   {
     926         [ #  # ]:          0 :     CubitPoint* pt = segments.pop();
     927                 :          0 :     PartitionCurve* closest = 0;
     928                 :          0 :     double closest_sqr = CUBIT_DBL_MAX;
     929         [ #  # ]:          0 :     CubitVector pos;
     930 [ #  # ][ #  # ]:          0 :     for ( i = new_curves.size(); i--; )
     931                 :            :     {
     932         [ #  # ]:          0 :       PartitionCurve* curve = new_curves.get_and_step();
     933 [ #  # ][ #  # ]:          0 :       curve->closest_point_trimmed( pt->coordinates(), pos );
     934 [ #  # ][ #  # ]:          0 :       double dist_sqr = (pos - pt->coordinates()).length_squared();
                 [ #  # ]
     935         [ #  # ]:          0 :       if ( dist_sqr < closest_sqr )
     936                 :            :       {
     937                 :          0 :         closest_sqr = dist_sqr;
     938                 :          0 :         closest = curve;
     939                 :            :       }
     940                 :            :     }
     941         [ #  # ]:          0 :     assert(closest != NULL);
     942 [ #  # ][ #  # ]:          0 :     closest->closest_point( pt->coordinates(), pos );
     943         [ #  # ]:          0 :     pt->set(pos);
     944 [ #  # ][ #  # ]:          0 :     set_point_owner(pt, closest);
     945                 :            :   }
     946                 :            : 
     947                 :            :   
     948                 :            :     // append everything to newEntites and call add for each
     949         [ #  # ]:          0 :   newEntities += entities;
     950         [ #  # ]:          0 :   entities.reset();
     951 [ #  # ][ #  # ]:          0 :   for ( i = entities.size(); i--; )
     952 [ #  # ][ #  # ]:          0 :     add( entities.get_and_step() );
     953                 :            :     
     954                 :            :     // now add the orignal surface to entities  -- entities
     955                 :            :     // becomes the list of entities that other polyline points
     956                 :            :     // on the surface must lie on after the split
     957 [ #  # ][ #  # ]:          0 :   entities.append(surface);
     958                 :            :     
     959                 :            :     // Associate any other points on the surface that 
     960                 :            :     // haven't been used yet with the appropriate 
     961                 :            :     // sub-region of the surface partitions.
     962 [ #  # ][ #  # ]:          0 :   DLIList<CubitPoint*> surf_points;
     963 [ #  # ][ #  # ]:          0 :   get_owned_points( surface, surf_points );
     964 [ #  # ][ #  # ]:          0 :   for ( i = surf_points.size(); i--; )
     965                 :            :   {
     966         [ #  # ]:          0 :     CubitPoint* pt = surf_points.get_and_step();
     967 [ #  # ][ #  # ]:          0 :     entity = find_closest( pt->coordinates(), entities, false );
     968         [ #  # ]:          0 :     assert(!!entity);
     969         [ #  # ]:          0 :     set_point_owner(pt, entity);
     970                 :            :   }
     971                 :            :   
     972         [ #  # ]:          0 :   return CUBIT_SUCCESS;
     973                 :            : }
     974                 :            : 
     975                 :            : //-------------------------------------------------------------------------
     976                 :            : // Purpose       : Create a point-curve on a surface
     977                 :            : //
     978                 :            : // Special Notes : 
     979                 :            : //
     980                 :            : // Creator       : Jason Kraftcheck
     981                 :            : //
     982                 :            : // Creation Date : 02/05/03
     983                 :            : //-------------------------------------------------------------------------
     984                 :          0 : CubitStatus PartitionLumpImprint::makePointCurve( CubitPoint* pt )
     985                 :            : {
     986                 :          0 :   PartitionEntity* ent = point_owner(pt);
     987         [ #  # ]:          0 :   PartitionSurface* surf = dynamic_cast<PartitionSurface*>(ent);
     988                 :            :   CubitPointData* cpd = 
     989 [ #  # ][ #  # ]:          0 :     PartitionEngine::instance().project_to_surface(surf, pt->coordinates());
     990                 :            :   
     991 [ #  # ][ #  # ]:          0 :   PART_LUMP_PRINT("Creating vertex on surface %p (%d) at (%f,%f,%f)\n",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     992                 :            :     (void*)surf, dynamic_cast<RefEntity*>(surf->topology_entity()) ?
     993                 :            :           dynamic_cast<RefEntity*>(surf->topology_entity())->id() : 0,
     994         [ #  # ]:          0 :     pt->coordinates().x(), pt->coordinates().y(), pt->coordinates().z() );
     995                 :            :     
     996                 :          0 :   PartitionPoint* new_point = 0;
     997         [ #  # ]:          0 :   if( cpd )
     998                 :          0 :     new_point = PartitionEngine::instance().insert_point_curve( surf, cpd );
     999                 :            :   
    1000         [ #  # ]:          0 :   if ( !new_point )
    1001                 :            :   {
    1002 [ #  # ][ #  # ]:          0 :    PRINT_ERROR("PartitionLumpImprint: point-curve creation failed.\n");
    1003                 :          0 :    return CUBIT_FAILURE;
    1004                 :            :   }
    1005                 :            :   
    1006         [ #  # ]:          0 :   add(new_point);
    1007 [ #  # ][ #  # ]:          0 :   newEntities.append(new_point);
    1008         [ #  # ]:          0 :   pt->set(new_point->coordinates());
    1009         [ #  # ]:          0 :   set_point_owner( pt, new_point );
    1010                 :          0 :   return CUBIT_SUCCESS;
    1011                 :            : }
    1012                 :            : 
    1013                 :            : //-------------------------------------------------------------------------
    1014                 :            : // Purpose       : Create a free point in the volume
    1015                 :            : //
    1016                 :            : // Special Notes : 
    1017                 :            : //
    1018                 :            : // Creator       : Jason Kraftcheck
    1019                 :            : //
    1020                 :            : // Creation Date : 02/05/03
    1021                 :            : //-------------------------------------------------------------------------
    1022                 :          0 : CubitStatus PartitionLumpImprint::makeFreePoint( CubitPoint* pt )
    1023                 :            : {
    1024                 :            :   
    1025 [ #  # ][ #  # ]:          0 :   PART_LUMP_PRINT("Creating free vertex at (%f,%f,%f)\n",
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1026         [ #  # ]:          0 :     pt->coordinates().x(), pt->coordinates().y(), pt->coordinates().z() );
    1027                 :            : 
    1028 [ #  # ][ #  # ]:          0 :   assert( point_owner(pt) == lump );
    1029 [ #  # ][ #  # ]:          0 :   PartitionPoint* new_pt = new PartitionPoint( pt->coordinates(), lump );
                 [ #  # ]
    1030         [ #  # ]:          0 :   add(new_pt);
    1031 [ #  # ][ #  # ]:          0 :   newEntities.append(new_pt);
    1032         [ #  # ]:          0 :   set_point_owner( pt, new_pt );
    1033                 :          0 :   return CUBIT_SUCCESS;
    1034                 :            : }
    1035                 :            : 
    1036                 :            : //-------------------------------------------------------------------------
    1037                 :            : // Purpose       : Create a free curve in the volume
    1038                 :            : //
    1039                 :            : // Special Notes : End points must already exist
    1040                 :            : //
    1041                 :            : // Creator       : Jason Kraftcheck
    1042                 :            : //
    1043                 :            : // Creation Date : 02/05/03
    1044                 :            : //-------------------------------------------------------------------------
    1045                 :          0 : CubitStatus PartitionLumpImprint::makeFreeCurve( int start_id, int end_id )
    1046                 :            : {
    1047                 :            :   PartitionPoint* start_pt 
    1048 [ #  # ][ #  # ]:          0 :     = dynamic_cast<PartitionPoint*>(point_owner(point(start_id)));
                 [ #  # ]
    1049                 :            :   PartitionPoint* end_pt 
    1050 [ #  # ][ #  # ]:          0 :     = dynamic_cast<PartitionPoint*>(point_owner(point(end_id)));
                 [ #  # ]
    1051 [ #  # ][ #  # ]:          0 :   if( !start_pt || !end_pt )
    1052                 :          0 :     return CUBIT_FAILURE;
    1053                 :            :   
    1054 [ #  # ][ #  # ]:          0 :   PART_LUMP_PRINT("Creating free curve from point %p (%d) (%f,%f,%f)"
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1055                 :            :                   "  to point %p (%d) (%f,%f,%f)\n",
    1056                 :            :     (void*)start_pt, dynamic_cast<RefEntity*>(start_pt->topology_entity()) ?
    1057                 :            :               dynamic_cast<RefEntity*>(start_pt->topology_entity())->id() : 0,
    1058                 :            :     start_pt->coordinates().x(), start_pt->coordinates().y(), start_pt->coordinates().z(),
    1059                 :            :     (void*)end_pt, dynamic_cast<RefEntity*>(end_pt->topology_entity()) ?
    1060                 :            :             dynamic_cast<RefEntity*>(end_pt->topology_entity())->id() : 0,
    1061         [ #  # ]:          0 :     end_pt->coordinates().x(), end_pt->coordinates().y(), end_pt->coordinates().z());
    1062                 :            :     
    1063                 :          0 :   bool all_pts = false;
    1064         [ #  # ]:          0 :   if( start_id == end_id )
    1065                 :            :   {
    1066         [ #  # ]:          0 :     end_id = (end_id+1)%num_points();
    1067                 :          0 :     all_pts = true;
    1068                 :            :   }
    1069                 :            :   
    1070                 :            :   int i;
    1071         [ #  # ]:          0 :   DLIList<CubitPoint*> points;
    1072 [ #  # ][ #  # ]:          0 :   points.append( point(start_id) );
    1073         [ #  # ]:          0 :   end_id %= num_points();
    1074 [ #  # ][ #  # ]:          0 :   for( i = (start_id + 1) % num_points(); i != end_id; i = (i+1)%num_points() )
                 [ #  # ]
    1075                 :            :   {
    1076 [ #  # ][ #  # ]:          0 :     if( point_owner(point(i)) != lump )
         [ #  # ][ #  # ]
    1077                 :          0 :       return CUBIT_FAILURE;
    1078 [ #  # ][ #  # ]:          0 :     points.append( point(i) );
    1079                 :            :   }
    1080 [ #  # ][ #  # ]:          0 :   points.append( point(all_pts ? start_id : end_id) );
                 [ #  # ]
    1081                 :            :   
    1082 [ #  # ][ #  # ]:          0 :   DLIList<CubitVector*> curve_segments;
    1083         [ #  # ]:          0 :   points.reset();
    1084 [ #  # ][ #  # ]:          0 :   for( i = points.size(); i--; )
    1085 [ #  # ][ #  # ]:          0 :     curve_segments.append( new CubitVector(points.get_and_step()->coordinates()));
         [ #  # ][ #  # ]
    1086 [ #  # ][ #  # ]:          0 :   SegmentedCurve* curve = new SegmentedCurve( lump, curve_segments );
    1087 [ #  # ][ #  # ]:          0 :   while( curve_segments.size() )
    1088         [ #  # ]:          0 :     delete curve_segments.pop();
    1089         [ #  # ]:          0 :   curve->start_point(start_pt);
    1090         [ #  # ]:          0 :   curve->end_point(end_pt);
    1091 [ #  # ][ #  # ]:          0 :   add(curve);
    1092 [ #  # ][ #  # ]:          0 :   newEntities.append(curve);
    1093 [ #  # ][ #  # ]:          0 :   for( i = (start_id + 1) % num_points(); i != end_id; i = (i+1)%num_points() )
                 [ #  # ]
    1094 [ #  # ][ #  # ]:          0 :     set_point_owner( point(i), curve );
                 [ #  # ]
    1095                 :            : 
    1096         [ #  # ]:          0 :   return CUBIT_SUCCESS;
    1097                 :            : }
    1098                 :            : 
    1099                 :            : //-------------------------------------------------------------------------
    1100                 :            : // Purpose       : Partition curves and surfaces on imprint loop
    1101                 :            : //
    1102                 :            : // Special Notes : 
    1103                 :            : //
    1104                 :            : // Creator       : Jason Kraftcheck
    1105                 :            : //
    1106                 :            : // Creation Date : 02/06/03
    1107                 :            : //-------------------------------------------------------------------------
    1108                 :          0 : CubitStatus PartitionLumpImprint::do_imprint() 
    1109                 :            : {
    1110                 :            :     // partition curves
    1111                 :            :   int i;
    1112         [ #  # ]:          0 :   for( i = 0; i <= num_points(); i++ )
    1113                 :            :   {
    1114                 :            :       // If the point owner isn't a curve, skip it.
    1115                 :          0 :     PartitionEntity* curr = point_owner(point(i));
    1116         [ #  # ]:          0 :     PartitionCurve* curve = dynamic_cast<PartitionCurve*>(curr);
    1117         [ #  # ]:          0 :     if( !curve )
    1118                 :          0 :       continue;
    1119                 :            :       
    1120                 :            :       // Split the curve at any point at which the polyline 
    1121                 :            :       // leaves the curve (except the end points, of course)
    1122                 :          0 :     PartitionEntity* prev = point_owner(point(i-1));
    1123                 :          0 :     PartitionEntity* next = point_owner(point(i+1));
    1124 [ #  # ][ #  # ]:          0 :     if( (prev != curr && 
    1125 [ #  # ][ #  # ]:          0 :          prev != curve->start_point() && 
    1126 [ #  # ][ #  # ]:          0 :          prev != curve->end_point()) ||
                 [ #  # ]
    1127         [ #  # ]:          0 :         (next != curr &&
    1128 [ #  # ][ #  # ]:          0 :          next != curve->start_point() &&
    1129         [ #  # ]:          0 :          next != curve->end_point()) )
    1130                 :            :     {
    1131         [ #  # ]:          0 :       if( !partitionCurve( point(i) ) )
    1132                 :          0 :         return CUBIT_FAILURE;
    1133                 :            :     }
    1134                 :            :   }            
    1135                 :            :       
    1136                 :            :     // partition surfaces
    1137                 :            :   
    1138                 :            :     // find position to start at
    1139         [ #  # ]:          0 :   for( i = 0; i < num_points(); i++ )
    1140   [ #  #  #  # ]:          0 :     if( point_owner(point(i)) != point_owner(point(i+1)) ||
                 [ #  # ]
    1141         [ #  # ]:          0 :         !dynamic_cast<PartitionSurface*>(point_owner(point(i))) )
    1142                 :          0 :       break;
    1143                 :            :   
    1144                 :            :     // loop through all points
    1145                 :          0 :   int index = i + 1;
    1146         [ #  # ]:          0 :   for( i = 0; i <= num_points(); )
    1147                 :            :   {
    1148                 :            :       // loop until we are at a point on a surface
    1149                 :          0 :     PartitionSurface* surf = 0;
    1150 [ #  # ][ #  # ]:          0 :     while( i <= num_points() &&
                 [ #  # ]
    1151         [ #  # ]:          0 :          !(surf = dynamic_cast<PartitionSurface*>(point_owner(point(index)))) )
    1152                 :            :     {
    1153                 :          0 :       i++;
    1154                 :          0 :       index++;
    1155                 :            :     }
    1156                 :            :     
    1157         [ #  # ]:          0 :     if( i > num_points() )
    1158                 :          0 :       break;
    1159                 :            :     
    1160                 :            :       // need the previous point too
    1161                 :          0 :     int prev_index = index - 1;
    1162                 :            :     
    1163                 :            :       // find remaining points on surface
    1164                 :          0 :     index++;
    1165                 :          0 :     i++;
    1166 [ #  # ][ #  # ]:          0 :     while( i <= num_points() && (point_owner(point(index)) == surf) )
         [ #  # ][ #  # ]
    1167                 :            :     {
    1168                 :          0 :       index++;
    1169                 :          0 :       i++;
    1170                 :            :     }
    1171                 :            :     
    1172                 :            :       // loop stoped past last point on surface
    1173                 :            :       // store it and back up one.
    1174                 :          0 :     int next_index = index;
    1175                 :          0 :     index--;
    1176                 :          0 :     i--;
    1177                 :            :     
    1178                 :            :       // partition the surface
    1179         [ #  # ]:          0 :     if( ! partitionSurface( prev_index, next_index ) )
    1180                 :          0 :       return CUBIT_FAILURE;
    1181                 :            :   }
    1182                 :            :   
    1183                 :            :     // check for additional surface partitions where
    1184                 :            :     // the polyline has points on the boundary but
    1185                 :            :     // not the interior of the surface
    1186         [ #  # ]:          0 :   for( i = 0; i <= num_points(); i++ )
    1187                 :            :   {
    1188 [ #  # ][ #  # ]:          0 :     PartitionPoint* pt1 = dynamic_cast<PartitionPoint*>(point_owner(point(i)));
                 [ #  # ]
    1189 [ #  # ][ #  # ]:          0 :     PartitionPoint* pt2 = dynamic_cast<PartitionPoint*>(point_owner(point(i+1)));
                 [ #  # ]
    1190 [ #  # ][ #  # ]:          0 :     if( !pt1 || !pt2 || pt1->common_curve(pt2) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1191                 :          0 :       continue;
    1192                 :            : 
    1193 [ #  # ][ #  # ]:          0 :     CubitVector close, midpt = (pt1->coordinates() + pt2->coordinates()) / 2;
         [ #  # ][ #  # ]
                 [ #  # ]
    1194                 :          0 :     PartitionSurface* surf = 0;
    1195                 :          0 :     PartitionCurve* curve = 0;
    1196                 :          0 :     double closest_dist = DIST_TOL_SQR;
    1197 [ #  # ][ #  # ]:          0 :     while( (curve = pt1->next_curve(curve)) )
    1198                 :            :     {
    1199                 :          0 :       PartitionCoEdge* coedge = 0;
    1200 [ #  # ][ #  # ]:          0 :       while( (coedge = curve->next_coedge(coedge)) )
    1201                 :            :       {
    1202 [ #  # ][ #  # ]:          0 :         PartitionSurface* surface = coedge->get_loop()->get_surface();
    1203         [ #  # ]:          0 :         if( surface == surf )
    1204                 :          0 :           continue;
    1205                 :            :           
    1206                 :          0 :         bool surf_contains_pt2 = false;
    1207                 :          0 :         PartitionCurve* curve2 = 0;
    1208 [ #  # ][ #  # ]:          0 :         while( (curve2 = pt2->next_curve(curve2)) && !surf_contains_pt2 )
         [ #  # ][ #  # ]
    1209                 :            :         {
    1210                 :          0 :           PartitionCoEdge* coedge2 = 0;
    1211 [ #  # ][ #  # ]:          0 :           while( (coedge2 = curve2->next_coedge(coedge2)) )
    1212                 :            :           {
    1213 [ #  # ][ #  # ]:          0 :             if( coedge2->get_loop()->get_surface() == surface )
                 [ #  # ]
    1214                 :            :             {
    1215                 :          0 :               surf_contains_pt2 = true;
    1216                 :          0 :               break;
    1217                 :            :             }
    1218                 :            :           }
    1219                 :            :         }
    1220         [ #  # ]:          0 :         if( ! surf_contains_pt2 )
    1221                 :          0 :           continue;
    1222                 :            :           
    1223         [ #  # ]:          0 :         surface->closest_point( midpt, &close );
    1224 [ #  # ][ #  # ]:          0 :         double dist_sqr = (close - midpt).length_squared();
    1225 [ #  # ][ #  # ]:          0 :         if( dist_sqr <= DIST_TOL_SQR &&
    1226         [ #  # ]:          0 :             (!surf || dist_sqr < closest_dist) )
    1227                 :          0 :           surf = surface;
    1228                 :          0 :           closest_dist = dist_sqr;
    1229                 :            :       }
    1230                 :            :     }
    1231                 :            :       
    1232                 :          0 :     int end = i + 1;
    1233 [ #  # ][ #  # ]:          0 :     if( surf && !partitionSurface(i, end, surf) )
         [ #  # ][ #  # ]
    1234                 :          0 :       return CUBIT_FAILURE;
    1235                 :          0 :     i = end - 1;
    1236                 :            :   }
    1237                 :            : 
    1238                 :          0 :   return CUBIT_SUCCESS;
    1239                 :            : }
    1240                 :            : 
    1241                 :            : //-------------------------------------------------------------------------
    1242                 :            : // Purpose       : Construct free curves in lump interior to complete
    1243                 :            : //                 the imprint loop
    1244                 :            : //
    1245                 :            : // Special Notes : 
    1246                 :            : //
    1247                 :            : // Creator       : Jason Kraftcheck
    1248                 :            : //
    1249                 :            : // Creation Date : 02/06/03
    1250                 :            : //-------------------------------------------------------------------------
    1251                 :          0 : CubitStatus PartitionLumpImprint::make_volume_curves()
    1252                 :            : {
    1253                 :            :     // start at any point not owned by the volume
    1254                 :            :   int i;
    1255 [ #  # ][ #  # ]:          0 :   for( i = 0; i <= num_points() && point_owner(point(i)) == lump; i++ );
         [ #  # ][ #  # ]
    1256                 :            :    
    1257                 :            :     // if everything is owned by the volume, make one vertex
    1258 [ #  # ][ #  # ]:          0 :   if( point_owner(point(i)) == lump && !makeFreePoint(point(i)) )
         [ #  # ][ #  # ]
    1259                 :          0 :     return CUBIT_FAILURE;
    1260                 :            :   
    1261                 :            :     // create free curves from points in volume interior
    1262                 :          0 :   int index = i % num_points();
    1263         [ #  # ]:          0 :   for( i = 0; i <= num_points(); )
    1264                 :            :   {
    1265                 :            :       // advance until a point in the volume interior
    1266 [ #  # ][ #  # ]:          0 :     while( i <= num_points() && point_owner(point(index)) != lump )
         [ #  # ][ #  # ]
    1267                 :            :     {
    1268                 :          0 :       i++;
    1269                 :          0 :       index = (index + 1) % num_points();
    1270                 :            :     }
    1271                 :            :     
    1272         [ #  # ]:          0 :     if( i > num_points() )
    1273                 :          0 :       break;
    1274                 :            :     
    1275                 :            :       // vertex to begin curve is at previous index
    1276                 :          0 :     int prev_index = (index + num_points() - 1) % num_points();
    1277                 :            :     
    1278                 :            :       // advance util we find a point not in the volume interior
    1279                 :            :       // (actually until a vertex possibly in the volume interior)
    1280 [ #  # ][ #  # ]:          0 :     while( i <= num_points() && point_owner(point(index)) == lump )
         [ #  # ][ #  # ]
    1281                 :            :     {
    1282                 :          0 :       i++;
    1283                 :          0 :       index = (index + 1) % num_points();
    1284                 :            :     }
    1285                 :            :     
    1286                 :            :       // construct the curve
    1287         [ #  # ]:          0 :     if( !makeFreeCurve( prev_index, index ) )
    1288                 :          0 :       return CUBIT_FAILURE;
    1289                 :            :   }
    1290                 :            :   
    1291                 :            :     // create free curves where two points in are on vertices
    1292                 :            :     // but there does not already exist a curve connecting the
    1293                 :            :     // points
    1294         [ #  # ]:          0 :   for( i = 0; i <= num_points(); i++ )
    1295                 :            :   {
    1296         [ #  # ]:          0 :     PartitionPoint* pt1 = dynamic_cast<PartitionPoint*>(point_owner(point(i)));
    1297         [ #  # ]:          0 :     PartitionPoint* pt2 = dynamic_cast<PartitionPoint*>(point_owner(point(i+1)));
    1298 [ #  # ][ #  # ]:          0 :     if( pt1 && pt2 && !pt1->common_curve(pt2) && !makeFreeCurve(i,i+1) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1299                 :          0 :       return CUBIT_FAILURE;
    1300                 :            :   }
    1301                 :            :   
    1302                 :          0 :   return CUBIT_SUCCESS;
    1303                 :            : }
    1304                 :            : 
    1305                 :            : //-------------------------------------------------------------------------
    1306                 :            : // Purpose       : Get the curves in the imprint loop
    1307                 :            : //
    1308                 :            : // Special Notes : 
    1309                 :            : //
    1310                 :            : // Creator       : Jason Kraftcheck
    1311                 :            : //
    1312                 :            : // Creation Date : 02/06/03
    1313                 :            : //-------------------------------------------------------------------------
    1314                 :          0 : CubitStatus PartitionLumpImprint::get_curves( DLIList<PartitionCoEdge*>& list )
    1315                 :            : {
    1316         [ #  # ]:          0 :   list.clean_out();
    1317 [ #  # ][ #  # ]:          0 :   DLIList<CubitFacetEdgeData*> facet_edges, curve_edges;
                 [ #  # ]
    1318                 :          0 :   CubitStatus result = CUBIT_SUCCESS;
    1319                 :            :   
    1320                 :            :     // search for a vertex to begin at
    1321                 :            :   int i;
    1322                 :          0 :   PartitionPoint* pt = 0;
    1323 [ #  # ][ #  # ]:          0 :   for( i = 0; i < num_points(); i++ )
    1324 [ #  # ][ #  # ]:          0 :     if( (pt = dynamic_cast<PartitionPoint*>(point_owner(point(i)))) )
         [ #  # ][ #  # ]
    1325                 :          0 :       break;
    1326         [ #  # ]:          0 :   if( !pt )
    1327                 :          0 :     return CUBIT_FAILURE;
    1328         [ #  # ]:          0 :   CubitPoint* prev_facet_pt = point(i);
    1329                 :            :   
    1330                 :          0 :   int index = i + 1;
    1331                 :          0 :   PartitionCurve* curve = 0;
    1332 [ #  # ][ #  # ]:          0 :   for( i = 0; result && i < num_points(); i++, index++ )
         [ #  # ][ #  # ]
    1333                 :            :   {
    1334         [ #  # ]:          0 :     CubitPoint* facet_pt = point(index);
    1335                 :            :     CubitFacetEdgeData* edge = 
    1336 [ #  # ][ #  # ]:          0 :       dynamic_cast<CubitFacetEdgeData*>(prev_facet_pt->shared_edge( facet_pt ));
    1337         [ #  # ]:          0 :     if ( !edge ) {
    1338                 :          0 :       result = CUBIT_FAILURE;
    1339                 :          0 :       break;
    1340                 :            :     }
    1341         [ #  # ]:          0 :     facet_edges.append(edge);
    1342                 :          0 :     prev_facet_pt = facet_pt;
    1343                 :            :     
    1344                 :            :     PartitionPoint* pt2;
    1345                 :            :     PartitionCurve* curve2;
    1346 [ #  # ][ #  # ]:          0 :     if( (pt2 = dynamic_cast<PartitionPoint*>(point_owner(point(index)))) )
         [ #  # ][ #  # ]
    1347                 :            :     {
    1348         [ #  # ]:          0 :       if( curve )
    1349                 :            :       {
    1350 [ #  # ][ #  # ]:          0 :         if( curve->other_point(pt) != pt2 )
    1351                 :          0 :           result = CUBIT_FAILURE;
    1352                 :            :       }
    1353                 :            :       else
    1354                 :            :       {
    1355                 :            :           //find common curves
    1356                 :          0 :         curve = 0;
    1357                 :          0 :         PartitionCurve* tmp_curve = 0;
    1358 [ #  # ][ #  # ]:          0 :         while( (tmp_curve = pt->next_curve(tmp_curve) ) != NULL )
    1359                 :            :         {
    1360 [ #  # ][ #  # ]:          0 :           if ( tmp_curve->other_point(pt) != pt2 )
    1361                 :          0 :             continue;
    1362                 :            :           
    1363         [ #  # ]:          0 :           if( !curve )
    1364                 :            :           {
    1365                 :          0 :             curve = tmp_curve;
    1366                 :          0 :             continue;
    1367                 :            :           }
    1368                 :            :           
    1369 [ #  # ][ #  # ]:          0 :           CubitVector mid = 0.5 * (pt->coordinates() + pt2->coordinates());
         [ #  # ][ #  # ]
    1370 [ #  # ][ #  # ]:          0 :           CubitVector cpt, tpt;
    1371         [ #  # ]:          0 :           curve->closest_point( mid, cpt );
    1372         [ #  # ]:          0 :           tmp_curve->closest_point( mid, tpt );
    1373         [ #  # ]:          0 :           cpt -= mid;
    1374         [ #  # ]:          0 :           tpt -= mid;
    1375 [ #  # ][ #  # ]:          0 :           if ( cpt.length_squared() > tpt.length_squared() )
                 [ #  # ]
    1376                 :          0 :             curve = tmp_curve;
    1377                 :            :         }
    1378                 :            : 
    1379         [ #  # ]:          0 :         if( !curve )
    1380                 :          0 :           result = CUBIT_FAILURE;
    1381                 :            :       }
    1382                 :            :       
    1383         [ #  # ]:          0 :       if ( !result )
    1384                 :          0 :         break;
    1385                 :            : 
    1386                 :            :       CubitSense sense;
    1387 [ #  # ][ #  # ]:          0 :       if ( curve->start_point() != curve->end_point() ) {
                 [ #  # ]
    1388         [ #  # ]:          0 :         sense = curve->start_point() == pt ? CUBIT_FORWARD : CUBIT_REVERSED;
    1389                 :            :       } else {
    1390 [ #  # ][ #  # ]:          0 :         CubitVector junk, tangent;
    1391         [ #  # ]:          0 :         facet_edges.last();
    1392 [ #  # ][ #  # ]:          0 :         CubitVector es = facet_edges.get()->point(0)->coordinates();
                 [ #  # ]
    1393 [ #  # ][ #  # ]:          0 :         CubitVector ee = facet_edges.get()->point(1)->coordinates();
                 [ #  # ]
    1394 [ #  # ][ #  # ]:          0 :         curve->closest_point( 0.5*(es+ee), junk, &tangent );
                 [ #  # ]
    1395 [ #  # ][ #  # ]:          0 :         sense = (ee-es)%tangent < 0.0 ? CUBIT_REVERSED : CUBIT_FORWARD;
                 [ #  # ]
    1396                 :            :       }
    1397                 :            : 
    1398 [ #  # ][ #  # ]:          0 :       PartitionCoEdge* new_coedge = new PartitionCoEdge( newSurface, sense );
    1399         [ #  # ]:          0 :       curve->add(new_coedge);
    1400         [ #  # ]:          0 :       list.append(new_coedge);
    1401                 :          0 :       curve = 0;
    1402                 :          0 :       pt = pt2;
    1403         [ #  # ]:          0 :       facet_edges.append(0);
    1404                 :            :     }
    1405                 :            :     else 
    1406                 :            :     {
    1407 [ #  # ][ #  # ]:          0 :       curve2 = dynamic_cast<PartitionCurve*>(point_owner(point(index)));
                 [ #  # ]
    1408                 :            :       
    1409 [ #  # ][ #  # ]:          0 :       if( !curve2 || (curve && curve != curve2) )
                 [ #  # ]
    1410                 :          0 :         result = CUBIT_FAILURE;
    1411                 :            :       else
    1412                 :          0 :         curve = curve2;
    1413                 :            :     }
    1414                 :            :   }
    1415                 :            :   
    1416         [ #  # ]:          0 :   if ( result )
    1417                 :            :   {
    1418                 :            :       // seam facet edges
    1419         [ #  # ]:          0 :     facet_edges.reset();
    1420         [ #  # ]:          0 :     list.reset();
    1421         [ #  # ]:          0 :     int used = facet_edges.size();
    1422 [ #  # ][ #  # ]:          0 :     for ( i = list.size(); i--; )
    1423                 :            :     {
    1424 [ #  # ][ #  # ]:          0 :       PartitionCurve* curve = list.get_and_step()->get_curve();
    1425         [ #  # ]:          0 :       curve_edges.clean_out();
    1426                 :            :       CubitFacetEdgeData* edge;
    1427 [ #  # ][ #  # ]:          0 :       while ( used-- && (edge = facet_edges.get_and_step()) )
         [ #  # ][ #  # ]
    1428         [ #  # ]:          0 :         curve_edges.append(edge);
    1429                 :            :   
    1430 [ #  # ][ #  # ]:          0 :       assert(curve_edges.size());
    1431 [ #  # ][ #  # ]:          0 :       if ( !seam_curve( curve_edges, curve, facetList ) )
    1432                 :            :       {
    1433                 :          0 :         result = CUBIT_FAILURE;
    1434                 :          0 :         break;
    1435                 :            :       }
    1436                 :            :     }
    1437                 :            :   }
    1438                 :            :   
    1439         [ #  # ]:          0 :   if (result)
    1440                 :          0 :     return CUBIT_SUCCESS;
    1441                 :            :   
    1442 [ #  # ][ #  # ]:          0 :   while ( list.size() )
    1443                 :            :   {
    1444         [ #  # ]:          0 :     PartitionCoEdge* coedge = list.pop();
    1445 [ #  # ][ #  # ]:          0 :     coedge->get_curve()->remove(coedge);
    1446 [ #  # ][ #  # ]:          0 :     delete coedge;
    1447                 :            :   }
    1448         [ #  # ]:          0 :   return CUBIT_FAILURE;
    1449                 :            : }
    1450                 :            : 
    1451                 :          0 : CubitStatus PartitionLumpImprint::seam_curve ( DLIList<CubitFacetEdgeData*>& edges,
    1452                 :            :                                                PartitionCurve* curve,
    1453                 :            :                                                DLIList<CubitFacetData*>& facets )
    1454                 :            : {
    1455                 :            :   // Get start and end facet points for chain of edges
    1456                 :            :   CubitPoint *start_point_t, *end_point_t;
    1457 [ #  # ][ #  # ]:          0 :   if (edges.size() == 1)
    1458                 :            :   {
    1459 [ #  # ][ #  # ]:          0 :     start_point_t = edges.get()->point(0);
    1460 [ #  # ][ #  # ]:          0 :     end_point_t = edges.get()->point(1);
    1461                 :            :   }
    1462                 :            :   else
    1463                 :            :   {
    1464         [ #  # ]:          0 :     edges.last();
    1465 [ #  # ][ #  # ]:          0 :     end_point_t = edges.get()->shared_point( edges.prev() );
                 [ #  # ]
    1466 [ #  # ][ #  # ]:          0 :     end_point_t = edges.get()->other_point( end_point_t );
    1467         [ #  # ]:          0 :     edges.reset();
    1468 [ #  # ][ #  # ]:          0 :     start_point_t = edges.get()->shared_point( edges.next() );
                 [ #  # ]
    1469 [ #  # ][ #  # ]:          0 :     start_point_t = edges.get()->other_point( start_point_t );
    1470                 :            :   }
    1471                 :            :   
    1472         [ #  # ]:          0 :   CubitPointData* start_point = dynamic_cast<CubitPointData*>(start_point_t);
    1473         [ #  # ]:          0 :   CubitPointData*   end_point = dynamic_cast<CubitPointData*>(  end_point_t);
    1474 [ #  # ][ #  # ]:          0 :   assert(start_point && end_point);
    1475                 :            :   
    1476                 :            :   // If list if edges is backwards on curve, reverse it
    1477 [ #  # ][ #  # ]:          0 :   if (curve->start_point() == curve->end_point())
                 [ #  # ]
    1478                 :            :   {
    1479         [ #  # ]:          0 :     assert( start_point == end_point );
    1480         [ #  # ]:          0 :     edges.reset();
    1481         [ #  # ]:          0 :     CubitVector s = start_point->coordinates();
    1482 [ #  # ][ #  # ]:          0 :     CubitVector e = edges.get()->other_point(start_point)->coordinates();
                 [ #  # ]
    1483 [ #  # ][ #  # ]:          0 :     CubitVector j, t;
    1484 [ #  # ][ #  # ]:          0 :     curve->closest_point ( 0.5 * (s + e), j, &t );
                 [ #  # ]
    1485 [ #  # ][ #  # ]:          0 :     if ( (e - s) % t < 0.0 )
                 [ #  # ]
    1486         [ #  # ]:          0 :       edges.reverse();
    1487                 :            :   }
    1488                 :            :   else
    1489                 :            :   {
    1490 [ #  # ][ #  # ]:          0 :     if (curve->start_point()->facet_point() == end_point ||
         [ #  # ][ #  # ]
                 [ #  # ]
    1491 [ #  # ][ #  # ]:          0 :         curve->end_point()->facet_point() == start_point)
    1492                 :            :     {
    1493         [ #  # ]:          0 :       std::swap(start_point, end_point);
    1494         [ #  # ]:          0 :       edges.reverse();
    1495                 :            :     }
    1496 [ #  # ][ #  # ]:          0 :     else if (curve->start_point()->facet_point() != start_point &&
         [ #  # ][ #  # ]
                 [ #  # ]
    1497 [ #  # ][ #  # ]:          0 :              curve->end_point()->facet_point() != end_point)
    1498                 :            :     {
    1499 [ #  # ][ #  # ]:          0 :       double fwd = (curve->start_point()->coordinates() - start_point->coordinates()).length()
         [ #  # ][ #  # ]
                 [ #  # ]
    1500 [ #  # ][ #  # ]:          0 :                  + (curve->end_point()->coordinates() - end_point->coordinates()).length();
         [ #  # ][ #  # ]
                 [ #  # ]
    1501 [ #  # ][ #  # ]:          0 :       double rev = (curve->end_point()->coordinates() - start_point->coordinates()).length()
         [ #  # ][ #  # ]
                 [ #  # ]
    1502 [ #  # ][ #  # ]:          0 :                  + (curve->start_point()->coordinates() - end_point->coordinates()).length();
         [ #  # ][ #  # ]
                 [ #  # ]
    1503         [ #  # ]:          0 :       if (fwd > rev)
    1504                 :            :       {
    1505         [ #  # ]:          0 :         std::swap(start_point, end_point);
    1506         [ #  # ]:          0 :         edges.reverse();
    1507                 :            :       }
    1508                 :            :     }
    1509                 :            :   }
    1510                 :            :   
    1511                 :            :   // Merge facet points at start and end vertices
    1512 [ #  # ][ #  # ]:          0 :   if (curve->start_point()->facet_point() != start_point)
                 [ #  # ]
    1513                 :            :   {
    1514 [ #  # ][ #  # ]:          0 :     if (curve->start_point()->facet_point())
                 [ #  # ]
    1515 [ #  # ][ #  # ]:          0 :       curve->start_point()->facet_point()->merge_points(start_point);
                 [ #  # ]
    1516                 :            :     else
    1517 [ #  # ][ #  # ]:          0 :       curve->start_point()->facet_point(start_point);
    1518                 :            :   }
    1519 [ #  # ][ #  # ]:          0 :   if (curve->start_point() != curve->end_point() &&
         [ #  # ][ #  # ]
                 [ #  # ]
    1520 [ #  # ][ #  # ]:          0 :       curve->end_point()->facet_point() != end_point)
    1521                 :            :   {
    1522 [ #  # ][ #  # ]:          0 :     if (curve->end_point()->facet_point())
                 [ #  # ]
    1523 [ #  # ][ #  # ]:          0 :       curve->end_point()->facet_point()->merge_points(end_point);
                 [ #  # ]
    1524                 :            :     else
    1525 [ #  # ][ #  # ]:          0 :       curve->end_point()->facet_point(end_point);
    1526                 :            :   }
    1527                 :            :   
    1528                 :            :   // Now seam interior points/edges
    1529         [ #  # ]:          0 :   return PartSurfFacetTool::seam_curve( edges, curve, facets );
    1530 [ +  - ][ +  - ]:       6364 : }

Generated by: LCOV version 1.11