cgma
CubitFacetData.cpp
Go to the documentation of this file.
00001 #include "CubitFacet.hpp" 
00002 #include "CubitPoint.hpp" 
00003 #include "CubitPointData.hpp" 
00004 #include "CubitVector.hpp" 
00005 #include "GeometryDefines.h"  
00006 #include "CubitPlane.hpp" 
00007 #include "CubitFacetEdge.hpp" 
00008 #include "CubitFacetData.hpp"
00009 #include "CubitFacetEdgeData.hpp" 
00010 #include "CastTo.hpp" 
00011 #include "ToolData.hpp" 
00012 #include "GfxDebug.hpp"
00013 #include "TDFacetBoundaryPoint.hpp"
00014 #include "CubitMessage.hpp"
00015 
00016 #ifndef CUBIT_MAX 
00017 #define CUBIT_MAX(a,b) (((a) > (b)) ? (a) : (b)) 
00018 #endif 
00019 #ifndef CUBIT_MIN 
00020 #define CUBIT_MIN(a,b) (((a) < (b)) ? (a) : (b)) 
00021 #endif 
00022 #define min3(a,b,c) CUBIT_MIN((CUBIT_MIN((a),(b))),(c)) 
00023 #define max3(a,b,c) CUBIT_MAX((CUBIT_MAX((a),(b))),(c)) 
00024 static int counter_id = 0; 
00025  
00026 //=========================================================================== 
00027 //Function Name: CubitFacetData 
00028 // 
00029 //Member Type:  PUBLIC 
00030 //Description:  constructor 
00031 //=========================================================================== 
00032 CubitFacetData::CubitFacetData( CubitPoint *p1, CubitPoint *p2, 
00033                                 CubitPoint *p3 ) 
00034 { 
00035   assert( p1 && p2 && p3 ); 
00036   assert( p1 != p2 && p1 != p3 && p2 != p3 ); 
00037   pointArray[0] = p1; 
00038   pointArray[1] = p2; 
00039   pointArray[2] = p3; 
00040   p1->add_facet(this); 
00041   p2->add_facet(this); 
00042   p3->add_facet(this); 
00043  
00044   edgeArray[0] = NULL; 
00045   edgeArray[1] = NULL; 
00046   edgeArray[2] = NULL; 
00047   edgeUse[0] = edgeUse[1] = edgeUse[2] = 0; 
00048   patchCtrlPts = NULL; 
00049  
00050   
00051   counter_id++; 
00052   entityId = counter_id; 
00053 
00054   plane(); 
00055  
00056   define_bounding_box();
00057  
00058 } 
00059 
00060 //=========================================================================== 
00061 //Function Name: CubitFacetData 
00062 // 
00063 //Member Type:  PUBLIC 
00064 //Description:  constructor 
00065 //=========================================================================== 
00066 CubitFacetData::CubitFacetData( CubitFacetEdge *e1, CubitFacetEdge *e2, 
00067                                 CubitFacetEdge *e3 ) 
00068 { 
00069   assert( e1 && e2 && e3 ); 
00070   assert( e1 != e2 && e1 != e3 && e2 != e3 ); 
00071 
00072   edgeArray[0] = e1; 
00073   edgeArray[1] = e2; 
00074   edgeArray[2] = e3; 
00075 
00076   define_point(e2, e3, 0);
00077   define_point(e3, e1, 1);
00078   define_point(e1, e2, 2);
00079   e1->add_facet(this);
00080   e2->add_facet(this);
00081   e3->add_facet(this);
00082 
00083   patchCtrlPts = NULL; 
00084 
00085   plane(); 
00086   counter_id++; 
00087   entityId = counter_id; 
00088  
00089   define_bounding_box();
00090  
00091 } 
00092 
00093 //=========================================================================== 
00094 //Function Name: CubitFacetData 
00095 // 
00096 //Member Type:  PUBLIC 
00097 //Description:  constructor 
00098 //=========================================================================== 
00099 CubitFacetData::CubitFacetData( CubitPoint *p1, CubitPoint *p2,
00100                                 CubitPoint *p3, int *tool_data)
00101 {
00102   assert( p1 && p2 && p3 );
00103   assert( p1 != p2 && p1 != p3 && p2 != p3 );
00104   pointArray[0] = p1;
00105   pointArray[1] = p2;
00106   pointArray[2] = p3;
00107 
00108   edgeArray[0] = NULL; 
00109   edgeArray[1] = NULL; 
00110   edgeArray[2] = NULL; 
00111 
00112   p1->add_facet(this);
00113   p2->add_facet(this);
00114   p3->add_facet(this);
00115 
00116   edgeArray[0] = 0;
00117   edgeArray[1] = 0;
00118   edgeArray[2] = 0;
00119   allocate_edge(p2,p3,0);
00120   allocate_edge(p3,p1,1);
00121   allocate_edge(p1,p2,2);
00122 
00123   patchCtrlPts = NULL;
00124 
00125   plane();
00126   counter_id++;
00127   entityId = counter_id;
00128   // update toolID
00129   if(tool_data)
00130     set_tool_id(*tool_data);
00131 
00132   define_bounding_box();
00133 } 
00134  
00135 //=========================================================================== 
00136 //Function Name: ~CubitFacetData 
00137 // 
00138 //Member Type:  PUBLIC 
00139 //Description:  destructor 
00140 //=========================================================================== 
00141 CubitFacetData::~CubitFacetData() 
00142 {
00143   destruct_facet_internals();
00144 }
00145 
00146 void CubitFacetData::destruct_facet_internals()
00147 {
00148   int ii = 3; 
00149   for (ii = 2; ii>=0; ii--){
00150     //remove this triangle-point association at the points. 
00151     CubitPoint *current_point = point(ii);
00152     if (current_point)
00153       current_point->remove_facet(this);     
00154 
00155     pointArray[ii] = NULL;
00156     
00157      //remove edge-point association at the edges
00158      
00159      CubitFacetEdge *current_edge = edgeArray[ii];
00160      
00161      if (current_edge) {
00162        CubitStatus status = current_edge->remove_facet(this);
00163        if (CUBIT_SUCCESS != status) {
00164          PRINT_ERROR("Failed to remove facet at current edge.\n");
00165          return;
00166        }
00167      }
00168      edgeArray[ii] = NULL;
00169   }
00170 }
00171 
00172 
00173 //=========================================================================== 
00174 //Function Name: closest_point 
00175 // 
00176 //Member Type:  PUBLIC 
00177 //Description:  return the closest point on plane defined by the facet 
00178 //=========================================================================== 
00179 CubitStatus CubitFacetData::closest_point(const CubitVector &point,  
00180                                           CubitVector &closest_point ) 
00181 { 
00182   if( cachedPlane ) 
00183   { 
00184     closest_point = cachedPlane->project( point ); 
00185     return CUBIT_SUCCESS; 
00186   } 
00187    
00188   CubitVector normal_vec = normal(); 
00189   CubitVector P0 = pointArray[0]->coordinates(); 
00190   CubitVector point_to_P0 = point - P0; 
00191   CubitVector P0_to_projection; 
00192   //Store the normal squared the the dot product of the normal and vector to the point. 
00193   double normal_length_sq = normal_vec.length_squared(); 
00194   //If the normal is zero, get out! 
00195   if ( normal_length_sq < CUBIT_RESABS ) 
00196      return CUBIT_FAILURE; 
00197   double point_to_P0_dot_norm = point_to_P0%normal_vec; 
00198   //Use P0_to_projection as a temporary to store half the equation. 
00199   P0_to_projection = (point_to_P0_dot_norm/normal_length_sq)*normal_vec; 
00200   P0_to_projection = point_to_P0 - P0_to_projection; 
00201   //Now we have the vector from P0, to the closest point.  Add the vector  
00202   //to P0, and you have the location! 
00203   closest_point = P0 + P0_to_projection; 
00204   return CUBIT_SUCCESS; 
00205 } 
00206  
00207 //------------------------------------------------------------------------- 
00208 // Purpose       : Local modification functions. 
00209 // 
00210 // Special Notes :  
00211 // 
00212 // Creator       : Jason Kraftcheck 
00213 // 
00214 // Creation Date : 03/25/00 
00215 //------------------------------------------------------------------------- 
00216 CubitPoint* CubitFacetData::split_edge( int edge_index,
00217                                         const CubitVector& position )
00218 {
00219   CubitPoint* pt1 = point((edge_index+1)%2);
00220   CubitPoint* pt2 = point((edge_index+2)%2);
00221   return split_edge( pt1, pt2, position );
00222 }
00223 
00224 CubitPoint* CubitFacetData::split_edge( CubitPoint* edge1_pt,  
00225                                         CubitPoint* edge2_pt, 
00226                                         const CubitVector& position ) 
00227 { 
00228   CubitPointData* new_pt = new CubitPointData(position);
00229   
00230     // split edge, if there is one
00231   
00232   CubitFacetEdge* edge = edge1_pt->shared_edge( edge2_pt );
00233   CubitFacetEdgeData* new_edge = 0;
00234   if ( edge ) {
00235     CubitFacetEdgeData* edge_d = dynamic_cast<CubitFacetEdgeData*>(edge);
00236     assert(!!edge_d);
00237     
00238       // make sure new edge has same orientation as old edge
00239     new_edge = dynamic_cast<CubitFacetEdgeData*>(new_pt->shared_edge(edge2_pt));
00240     if ( edge->point(0) == edge1_pt ) {
00241       edge_d->set_point(new_pt, 1);
00242       if ( !new_edge )
00243       {
00244         new_edge = new CubitFacetEdgeData( new_pt, edge2_pt );
00245         DLIList<ToolData*> tds;
00246         edge->get_all_TDs(&tds);
00247         for (int i=0; i<tds.size(); i++)
00248         {
00249           ToolData* new_td = tds.get_and_step()->propogate(new_edge);
00250           if (new_td)
00251             new_edge->add_TD(new_td);
00252         }
00253       }
00254       else if( new_edge->point(0) != new_pt )
00255         new_edge->flip();
00256     } else {
00257       edge_d->set_point(new_pt, 0);
00258       if ( !new_edge )
00259       {
00260         new_edge = new CubitFacetEdgeData( edge2_pt, new_pt );
00261         DLIList<ToolData*> tds;
00262         edge->get_all_TDs(&tds);
00263         for (int i=0; i<tds.size(); i++)
00264         {
00265           ToolData* new_td = tds.get_and_step()->propogate(new_edge);
00266           if (new_td)
00267             new_edge->add_TD(new_td);
00268         }
00269       }
00270       else if( new_edge->point(1) != new_pt )
00271         new_edge->flip();
00272     }
00273   }
00274   
00275     // split triangles
00276   
00277   DLIList<CubitFacet*> facets;
00278   edge1_pt->shared_facets( edge2_pt, facets );
00279   
00280   facets.reset();
00281   for ( int i = facets.size(); i--; ) {
00282 
00283     CubitFacet* facet = facets.get_and_step();
00284     CubitFacetData* facet_d = dynamic_cast<CubitFacetData*>(facet);
00285     assert(!!facet_d);
00286    
00287  
00288       // fix up existing facet
00289     
00290     int pt2_index = facet->point_index( edge2_pt );
00291     bool edge_reversed = ( edge1_pt == facet->point( (pt2_index+1) % 3 ) );
00292     int edge_index = (pt2_index + 1 + edge_reversed) % 3;
00293     
00294     edge2_pt->remove_facet( facet );
00295     facet_d->set_point( new_pt, pt2_index );
00296     new_pt->add_facet( facet );
00297     facet->update_plane();
00298     
00299 
00300       // make new facet
00301       
00302     CubitPoint* other_pt = facet->point( edge_index );
00303     CubitFacetData* new_facet;
00304     if ( edge_reversed )
00305       new_facet = new CubitFacetData( other_pt, edge2_pt, new_pt );
00306     else
00307       new_facet = new CubitFacetData( other_pt, new_pt, edge2_pt );
00308 
00309     DLIList<ToolData*> td_list;
00310     facet->get_all_TDs(&td_list);
00311     for (int i=0; i< td_list.size(); i++)
00312     {
00313       ToolData* new_td = td_list.get_and_step()->propogate(new_facet);
00314       if (new_td)
00315       {
00316         new_facet->add_TD(new_td);
00317       }
00318     }
00319    
00320     if ( new_edge ) {
00321       assert(!new_facet->edge(0));
00322       new_facet->edge( new_edge, 0 );
00323       new_edge->add_facet( new_facet );
00324       int sense = new_facet->point( 1 ) == new_edge->point(0) ? 1 : -1;
00325       new_facet->edge_use( sense, 0 );
00326     }
00327 
00328     
00329       // move other edge, if there is one
00330 
00331     int pt1_index =  (pt2_index + 2 - edge_reversed) % 3;
00332     CubitFacetEdge* other_edge = facet->edge(pt1_index);
00333     if ( other_edge ) {
00334       other_edge->remove_facet(facet);
00335       facet->edge( 0, pt1_index );
00336       int e_index = 1 + edge_reversed;
00337       assert(!new_facet->edge(e_index));
00338       new_facet->edge( other_edge, e_index );
00339       other_edge->add_facet(new_facet);
00340       int sense = new_facet->point( (e_index+1)%3 ) == other_edge->point(0) ? 1 : -1;
00341       new_facet->edge_use( sense, e_index );
00342     }
00343 
00344     // what about a new edge for each of the adj_facets and its tool data
00345 
00346   }
00347        
00348   return new_pt; 
00349 } 
00350  
00351 //------------------------------------------------------------------------- 
00352 // Purpose       : insert a point into the facet 
00353 // 
00354 // Special Notes : create two new facets and return them 
00355 // 
00356 // Creator       :  
00357 // 
00358 // Creation Date :  
00359 //------------------------------------------------------------------------- 
00360 CubitPoint* CubitFacetData::insert_point( const CubitVector& position, 
00361                                           CubitFacet*& new_tri1_out, 
00362                                           CubitFacet*& new_tri2_out )   
00363 { 
00364   CubitPointData* new_point = new CubitPointData( position ); 
00365   CubitFacetData *new_tri1, *new_tri2;
00366   new_tri1 = new CubitFacetData( point(1), point(2), new_point ); 
00367   new_tri2 = new CubitFacetData( point(2), point(0), new_point ); 
00368    
00369   point(2)->remove_facet( this ); 
00370   set_point( new_point, 2 );
00371   new_point->add_facet( this );
00372   
00373   if ( edge(0) ) {
00374     new_tri1->edge( edge(0), 2 );
00375     new_tri1->edge_use( edge_use(0), 2 );
00376     edge(0)->remove_facet(this);
00377     edge(0)->add_facet(new_tri1);
00378     edge( 0, 0 );
00379   }
00380   
00381   if ( edge(1) ) {
00382     new_tri2->edge( edge(1), 2 );
00383     new_tri2->edge_use( edge_use(1), 2 );
00384     edge(1)->remove_facet(this);
00385     edge(1)->add_facet(new_tri2);
00386     edge( 0, 1 );
00387   }
00388  
00389   update_plane();
00390   
00391   new_tri1_out = new_tri1;
00392   new_tri2_out = new_tri2;
00393   return new_point; 
00394 } 
00395  
00396  
00397 //------------------------------------------------------------------------- 
00398 // Purpose       : reorient the facet 
00399 // 
00400 // Special Notes :  This function should only be used if it is acceptable  
00401 //                  to change the underlying data representation of the  
00402 //                  facets  (for example the Sierra facet representation  
00403 //                  cannot change and will not permit changing of the 
00404 //                  node orders on a facet)  
00405 // 
00406 //                  Also note that if this function is used, the isBackwards 
00407 //                  flag on the facet should be set appropriately. 
00408 // 
00409 // Creator       : Steve Owen 
00410 // 
00411 // Creation Date : 06/28/00 
00412 //------------------------------------------------------------------------- 
00413 void CubitFacetData::flip() 
00414 { 
00415   CubitVector* ctrl_points=control_points( );
00416   
00417   CubitPoint *pt_tmp = pointArray[1]; 
00418   pointArray[1] = pointArray[2]; 
00419   pointArray[2] = pt_tmp; 
00420  
00421   CubitFacetEdge *ed_tmp = edgeArray[1]; 
00422   edgeArray[1] = edgeArray[2]; 
00423   edgeArray[2] = ed_tmp;
00424 
00425     //make sure the edgeUses are matched with the correct edge...
00426   int ed_use_tmp = edgeUse[1];
00427   edgeUse[1]=edgeUse[2];
00428   edgeUse[2]=ed_use_tmp;
00429   
00430     //now flip the edge uses...
00431   int ii;
00432   for (ii=0; ii<3; ii++) 
00433   { 
00434     if (edgeUse[ii] == -1) {
00435       edgeUse[ii] = 1; 
00436     }
00437     else if(edgeUse[ii] == 1) {
00438       edgeUse[ii] = -1; 
00439     }
00440   }
00441   if(ctrl_points){
00442     CubitVector tmp_point;
00443     tmp_point = ctrl_points[0];
00444     ctrl_points[0]=ctrl_points[1];
00445     ctrl_points[1]=tmp_point;
00446     tmp_point = ctrl_points[2];
00447     ctrl_points[2]=ctrl_points[5];
00448     ctrl_points[5]=tmp_point;
00449     tmp_point = ctrl_points[3];
00450     ctrl_points[3]=ctrl_points[4];
00451     ctrl_points[4]=tmp_point;
00452   }
00453   update_plane();
00454     //update the normals on the points (including boundary points)
00455   for (ii=0; ii<3; ii++) 
00456   {
00457     pointArray[ii]->compute_avg_normal();
00458     TDFacetBoundaryPoint* tdfbp =
00459       TDFacetBoundaryPoint::get_facet_boundary_point(pointArray[ii]);
00460     if(tdfbp){
00461       if(!tdfbp->reset_normals()){
00462         PRINT_ERROR("Could not reset all the normals for a point.\n");
00463       }
00464     }
00465   }
00466   
00467 } 
00468  
00469 //===========================================================================
00470 //Function Name: allocate_edge
00471 //
00472 //Member Type:  PRIVATE
00473 //Description:  associate facetedge with this facet
00474 //Special Notes: 1. Assume edge(p1,p2) is in Counter-clockwise direction wrt to//                  this facet)
00475 //               2. Helper function to Constructor
00476 //===========================================================================
00477 void CubitFacetData::allocate_edge(CubitPoint *p1, CubitPoint *p2, int edge_index){
00478   
00479   assert(edge_index >= 0 && edge_index < 3);
00480   assert(p1 != NULL && p2 != NULL);
00481 
00482   CubitFacetEdge* shared_edge = p1->get_edge(p2);
00483   
00484   if(shared_edge == NULL){
00485     //- if edge don't exist, create it
00486     edgeArray[edge_index] = (CubitFacetEdge *) new CubitFacetEdgeData(p1,p2);
00487     edgeUse[edge_index] = 1;
00488   } else {
00489     edgeArray[edge_index] = shared_edge;
00490     shared_edge->add_facet(this);
00491     if(shared_edge->point(0) == p1)
00492       edgeUse[edge_index]= 1;
00493     else
00494       edgeUse[edge_index] = -1;
00495     
00496   }
00497   
00498 }
00499 
00500 
00501 //===========================================================================
00502 //Function Name: define_point
00503 //
00504 //Member Type:  PRIVATE
00505 //Description:  define the point based on its adjacent edges.  define the 
00506 //              edge uses too.
00507 //Special Notes: 1. Assume edge(e1,e2) is in Counter-clockwise direction wrt 
00508 //                  this facet
00509 //               2. Helper function to Constructor
00510 //===========================================================================
00511 void CubitFacetData::define_point(CubitFacetEdge *e1, 
00512                                   CubitFacetEdge *e2, 
00513                                   int point_index)
00514 {
00515   
00516   assert(point_index >= 0 && point_index < 3);
00517   assert(e1 != NULL && e2 != NULL);
00518 
00519   CubitPoint *pA, *pB, *pC, *pD;
00520   pA = e1->point(0);
00521   pB = e1->point(1);
00522   pC = e2->point(0);
00523   pD = e2->point(1);
00524   if(pC == pB || pC == pA)
00525   {
00526     pointArray[point_index] = pC;
00527     pC->add_facet(this);
00528     edgeUse[(point_index+2)%3] = 1;
00529   }
00530   else if(pD == pB || pD == pA)
00531   {
00532     pointArray[point_index] = pD;
00533     pD->add_facet(this);
00534     edgeUse[(point_index+2)%3] = -1;
00535   }
00536   else
00537   {
00538     assert(0);  // the edges are not adjacent;
00539   }
00540   
00541 }
00542 
00543 //===========================================================================
00544 //Function Name: define_bounding_box
00545 //
00546 //Member Type:  PRIVATE
00547 //Description:  compute and store the bounding box
00548 //               Helper function to Constructor
00549 //===========================================================================
00550 void CubitFacetData::define_bounding_box()
00551 {
00552   CubitVector bbox_min, bbox_max; 
00553   CubitPoint *p1 = pointArray[0];
00554   CubitPoint *p2 = pointArray[1];
00555   CubitPoint *p3 = pointArray[2];
00556   bbox_min.x(min3(p1->x(),p2->x(),p3->x())); 
00557   bbox_min.y(min3(p1->y(),p2->y(),p3->y())); 
00558   bbox_min.z(min3(p1->z(),p2->z(),p3->z())); 
00559   bbox_max.x(max3(p1->x(),p2->x(),p3->x())); 
00560   bbox_max.y(max3(p1->y(),p2->y(),p3->y())); 
00561   bbox_max.z(max3(p1->z(),p2->z(),p3->z())); 
00562   bBox.reset(bbox_min,bbox_max);
00563 }
00564 
00565 CubitStatus CubitFacetData::flip_edge( CubitFacetEdge *edge )
00566 {
00567   int i;
00568   for(i=0; i<3; i++)
00569   {
00570     if (edgeArray[i] == edge)
00571       return flip_edge(i);
00572   }
00573   return CUBIT_FAILURE;
00574 }
00575 
00576 CubitStatus CubitFacetData::flip_edge( int this_edge_index ) 
00577 {
00578     // get point indices on this facet
00579   int this_pt1_index = (this_edge_index+1)%3;
00580   int this_pt2_index = (this_edge_index+2)%3;
00581   
00582     // get edge points
00583   CubitPoint* point1 = point(this_pt1_index);
00584   CubitPoint* point2 = point(this_pt2_index);
00585 
00586     // can only be one adjacent facet at edge
00587   DLIList<CubitFacet*> pt_facets;
00588   point1->shared_facets(point2, pt_facets);
00589   if ( pt_facets.size() != 2 || !pt_facets.move_to(this) )
00590     return CUBIT_FAILURE;
00591   
00592     // get other facet
00593   CubitFacetData* other_facet = NULL;
00594   if( pt_facets.get() == this )
00595   {
00596     other_facet = dynamic_cast<CubitFacetData*>(pt_facets.next());
00597   }
00598   else
00599     if( pt_facets.next() == this )
00600     {
00601       other_facet = dynamic_cast<CubitFacetData*>( pt_facets.get() );
00602     }
00603     else
00604     {
00605       assert(0);
00606       return CUBIT_FAILURE;
00607     }
00608 
00609   assert(other_facet);
00610   
00611     // get indices on other facet
00612   int other_pt1_index = other_facet->point_index(point1);
00613   int other_pt2_index = (other_pt1_index+1)%3;
00614   int other_edge_index = (other_pt1_index+2)%3;
00615   if ( other_facet->point(other_pt2_index) != point2 ) {
00616     other_pt2_index = other_edge_index;
00617     other_edge_index = (other_pt1_index+1)%3;
00618   }
00619   assert( other_facet->point(other_pt2_index) == point2 );
00620   
00621     // check facet orientation
00622   int this_flip_use = this->edge_use(this_edge_index);
00623   int other_flip_use = other_facet->edge_use(other_edge_index);
00624   if ( this_flip_use == other_flip_use )
00625   {
00626     // Facets don't have consistant normals!!
00627     assert(0);
00628     return CUBIT_FAILURE;
00629   }
00630   
00631     // get the opposite points on facets
00632   CubitPoint* this_other_pt = this->point(this_edge_index);
00633   CubitPoint* other_other_pt = other_facet->point(other_edge_index);
00634   if(this_other_pt == other_other_pt){
00635     PRINT_WARNING("Unable to perform flip.\n");
00636     return CUBIT_FAILURE;
00637   }
00638   
00639   
00640     // get the edge that is to be moved from this to the other facet
00641   CubitFacetEdge* this_trade_edge = this->edge(this_pt2_index);
00642     // get the edge thatis to be moved from the other facet to this
00643   CubitFacetEdge* other_trade_edge = other_facet->edge(other_pt1_index);
00644   if(this_trade_edge == other_trade_edge){
00645     PRINT_WARNING("Unable to perform flip (2).\n");
00646     return CUBIT_FAILURE;
00647   }
00648   int this_trade_use = this->edge_use(this_pt2_index);
00649   if ( this_trade_edge )
00650   {
00651     this_trade_edge->remove_facet(this);
00652     this_trade_edge->add_facet(other_facet);
00653   }
00654   
00655   int other_trade_use = other_facet->edge_use(other_pt1_index);
00656   if ( other_trade_edge )
00657   {
00658     other_trade_edge->remove_facet(other_facet);
00659     other_trade_edge->add_facet(this);
00660   }
00661   
00662     // get the edge to flip and change its points
00663   CubitFacetEdgeData* flip_edge 
00664     = dynamic_cast<CubitFacetEdgeData*>(edge(this_edge_index));
00665   if ( flip_edge )
00666   {
00667       // orient edge such that the edge uses stay the same
00668     int dir = (flip_edge->point(0) == point1);
00669     flip_edge->set_point( this_other_pt, 1-dir );
00670     flip_edge->set_point( other_other_pt, dir );
00671   }
00672   
00673 
00674     // change this facet
00675   this->edge( other_trade_edge, this_edge_index );
00676   this->edge_use( other_trade_use, this_edge_index );
00677   this->edge( flip_edge, this_pt2_index );
00678   this->edge_use( this_flip_use, this_pt2_index );
00679   point1->remove_facet(this);
00680   other_other_pt->add_facet(this);
00681   this->set_point( other_other_pt, this_pt1_index );
00682   
00683   
00684     // change the other facet
00685   other_facet->edge( this_trade_edge, other_edge_index );
00686   other_facet->edge_use( this_trade_use, other_edge_index );
00687   other_facet->edge( flip_edge, other_pt1_index );
00688   other_facet->edge_use( other_flip_use, other_pt1_index );
00689   point2->remove_facet(other_facet);
00690   this_other_pt->add_facet(other_facet);
00691   other_facet->set_point( this_other_pt, other_pt2_index );
00692   
00693   // make sure everything is correct
00694 #ifndef NDEBUG
00695   for ( int i = 0; i < 3; i++ )
00696   {
00697     if ( this->edge(i) )
00698     {
00699       int start_index, end_index;
00700       if ( this->edge_use(i) == 1 )
00701       {
00702         start_index = (i+1)%3;
00703         end_index = (i+2)%3;
00704       }
00705       else
00706       {
00707         assert(this->edge_use(i) == -1);
00708         start_index = (i+2)%3;
00709         end_index = (i+1)%3;
00710       }
00711       assert ( this->edge(i)->point(0) == this->point(start_index) );
00712       assert ( this->edge(i)->point(1) == this->point(end_index) );
00713     }
00714     
00715     if ( other_facet->edge(i) )
00716     {
00717       int start_index, end_index;
00718       if ( other_facet->edge_use(i) == 1 )
00719       {
00720         start_index = (i+1)%3;
00721         end_index = (i+2)%3;
00722       }
00723       else
00724       {
00725         assert(other_facet->edge_use(i) == -1);
00726         start_index = (i+2)%3;
00727         end_index = (i+1)%3;
00728       }
00729       assert ( other_facet->edge(i)->point(0) == other_facet->point(start_index) );
00730       assert ( other_facet->edge(i)->point(1) == other_facet->point(end_index) );
00731     }
00732   }
00733 #endif
00734   
00735   return CUBIT_SUCCESS;
00736 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines