cgma
CubitPointData.cpp
Go to the documentation of this file.
00001 #include "CubitPointData.hpp"
00002 #include "CubitFacet.hpp"
00003 #include "CubitFacetEdge.hpp"
00004 #include "ToolData.hpp"
00005 #include "CubitFacetData.hpp"
00006 #include "CubitFacetEdgeData.hpp"
00007 #include "CastTo.hpp"
00008 
00009 static int point_counter = 0;
00010 
00011 //===========================================================================
00012 // Function Name: CubitPointData
00013 //
00014 // Member Type:  PUBLIC
00015 // Description:  constructor
00016 // Author: 
00017 // Date:
00018 //===========================================================================
00019 CubitPointData::CubitPointData( double x_val, double y_val, double z_val )
00020   : coords( x_val, y_val, z_val )
00021 {
00022   attachedFacets = NULL;
00023   point_counter++;
00024   entityId = point_counter;
00025 }
00026 
00027 //===========================================================================
00028 // Function Name: CubitPointData
00029 //
00030 // Member Type:  PUBLIC
00031 // Description:  constructor
00032 // Author: 
00033 // Date:
00034 //===========================================================================
00035 CubitPointData::CubitPointData(double x_val, double y_val, double z_val,int *)
00036   : coords(x_val, y_val, z_val)
00037 {
00038   attachedFacets = NULL;
00039   point_counter++;
00040   entityId = point_counter;
00041 }
00042 
00043 //===========================================================================
00044 // Function Name: CubitPointData
00045 //
00046 // Member Type:  PUBLIC
00047 // Description:  constructor
00048 // Author: 
00049 // Date:
00050 //===========================================================================
00051 CubitPointData::CubitPointData( const CubitVector &new_point )
00052   : coords( new_point )
00053 {
00054   attachedFacets = NULL;
00055   point_counter++;
00056   entityId = point_counter;
00057 }
00058 
00059 //===========================================================================
00060 // Function Name: ~CubitPoint
00061 //
00062 // Member Type:  PUBLIC
00063 // Description:  destructor
00064 // Author: 
00065 // Date:
00066 //===========================================================================
00067 CubitPointData::~CubitPointData()
00068 {
00069   delete attachedFacets;
00070 }
00071 
00072 //===========================================================================
00073 // Function Name: coordinates
00074 //
00075 // Member Type:  PUBLIC
00076 // Description:  return coordinates of point in form of array
00077 // Author: 
00078 // Date:
00079 //===========================================================================
00080 void CubitPointData::coordinates(double point_array[3])
00081 {
00082   point_array[0] = coords.x();
00083   point_array[1] = coords.y();
00084   point_array[2] = coords.z();
00085 }
00086 
00087 //===========================================================================
00088 // Function Name: add_facet
00089 //
00090 // Member Type:  PUBLIC
00091 // Description:  add a facet to the point's adjacency list
00092 // Author: 
00093 // Date:
00094 //===========================================================================
00095 void CubitPointData::add_facet( CubitFacet *facet )
00096 {
00097   if ( attachedFacets == NULL )
00098     attachedFacets = new DLIList<CubitFacet*>(8);
00099   attachedFacets->append(facet);
00100   return;
00101 }
00102 
00103 //===========================================================================
00104 // Function Name: remove_facet
00105 //
00106 // Member Type:  PUBLIC
00107 // Description:  remove a facet to the point's adjacency list
00108 // Author: 
00109 // Date:
00110 //===========================================================================
00111 void CubitPointData::remove_facet( CubitFacet *facet )
00112 {
00113   if ( attachedFacets == NULL )
00114     return;
00115   attachedFacets->remove(facet);
00116   return;
00117 }
00118 
00119 //===========================================================================
00120 // Function Name: edges
00121 //
00122 // Member Type:  PUBLIC
00123 // Description:  return the list of facet-edges attached to this point
00124 // Author: sjowen
00125 // Date:  4/28/01
00126 //===========================================================================
00127 void CubitPointData::edges( DLIList<CubitFacetEdge *> &edge_list )
00128 {
00129   int ii, jj, kk;
00130   CubitFacet *facet_ptr;
00131   CubitFacetEdge *edge_ptr, *check_edge_ptr;
00132   
00133   if(attachedFacets == NULL)
00134     return;
00135 
00136   for (ii=0; ii<attachedFacets->size(); ii++)
00137   {
00138     facet_ptr = attachedFacets->get_and_step();
00139     for (jj=0; jj<3; jj++)
00140     {
00141       edge_ptr = facet_ptr->edge( jj );
00142       if (edge_ptr)
00143       {
00144         if (edge_ptr->point(0) == this ||
00145           edge_ptr->point(1) == this)
00146         {
00147           int found = 0;
00148           for (kk=0; kk<edge_list.size() && !found; kk++)
00149           {
00150             check_edge_ptr = edge_list.get_and_step();
00151             if (check_edge_ptr == edge_ptr)
00152               found = 1;
00153           }
00154           if (!found)
00155           {
00156             edge_list.append( edge_ptr );
00157           }
00158         }
00159       }
00160     }
00161   }
00162   
00163   return;
00164 }
00165 
00166 
00167 //===========================================================================
00168 // Function Name: num_adj_facets
00169 //
00170 // Member Type:  PUBLIC
00171 // Description:  return the number of facets attached to the point
00172 // Author: 
00173 // Date:
00174 //===========================================================================
00175 int CubitPointData::num_adj_facets()
00176 { 
00177   if (attachedFacets == NULL)
00178     return 0;
00179   else
00180     return attachedFacets->size(); 
00181 }
00182 
00183 //===========================================================================
00184 // Function Name: merge_points
00185 //
00186 // Member Type:  PUBLIC
00187 // Description:  merge this point with another
00188 // Note:         currently ignores edges - call before defining the edges
00189 // Author: sjowen
00190 // Date: 9/18/01
00191 //===========================================================================
00192 CubitStatus CubitPointData::merge_points( CubitPoint *other_point,
00193                                           CubitBoolean keep_point /* = CUBIT_FALSE*/)
00194 {
00195   if( other_point == this )
00196     return CUBIT_SUCCESS;
00197   
00198   DLIList<CubitFacet *>facet_list;
00199   other_point->facets( facet_list );
00200   CubitFacet *adj_facet;
00201   CubitFacetData *afd;
00202   int ii;
00203   for (ii=0; ii<facet_list.size(); ii++)
00204   {
00205     adj_facet = facet_list.get_and_step();
00206     other_point->remove_facet( adj_facet );
00207     afd = CAST_TO(adj_facet, CubitFacetData);
00208     if (afd->point(0) == other_point)
00209       afd->set_point( this, 0 );
00210     else if(afd->point(1) == other_point)
00211       afd->set_point( this, 1 );
00212     else if(afd->point(2) == other_point)
00213       afd->set_point( this, 2 );
00214     else
00215     {
00216       assert(0);
00217       return CUBIT_FAILURE;
00218     }
00219 
00220     this->add_facet( adj_facet );
00221   
00222       // added by J.Kraftcheck - 2/14/03 - update edges also!!!
00223     CubitFacetEdgeData* afed;
00224     for ( int j = 0; j < 3; j++ ) {
00225       if( adj_facet->edge(j) ) {
00226         afed = dynamic_cast<CubitFacetEdgeData*>(adj_facet->edge(j));
00227         if ( afed->point(0) == other_point ) 
00228           afed->set_point(this, 0);
00229         else if( afed->point(1) == other_point )
00230           afed->set_point(this, 1);
00231       }
00232     } 
00233   }
00234   
00235   if (!keep_point)
00236     delete other_point;
00237   return CUBIT_SUCCESS;
00238 }
00239 
00240 CubitStatus CubitPointData::collapse_edge( CubitPointData *dead_point )
00241 {
00242   int i, j;
00243   
00244     // Get the list of facets that will be destroyed
00245   DLIList<CubitFacet*> dead_facets, edge_facets;
00246   shared_facets( dead_point, dead_facets );
00247 
00248     // Get edges to update
00249   DLIList<CubitFacetEdge*> adj_edge_list;
00250   dead_point->edges(adj_edge_list);
00251   
00252     // Get edge to collapse
00253   CubitFacetEdge* collapse = 0;
00254   for ( i = adj_edge_list.size(); i-- && !collapse; )
00255     if (adj_edge_list.step_and_get()->other_point(dead_point) == this)
00256       collapse = adj_edge_list.extract();
00257 
00258     // For each dead facet...
00259   CubitFacetData *dead_facet, *edge_facet;
00260   CubitFacetEdgeData *keep_edge, *dead_edge;
00261   for ( i = dead_facets.size(); i--; )
00262   {
00263       // Get dead facet and relevant indices
00264     dead_facet = dynamic_cast<CubitFacetData*>(dead_facets.get_and_step());
00265     assert(!!dead_facet);
00266     int dead_pt_index = dead_facet->point_index(dead_point);
00267     int this_pt_index = dead_facet->point_index(this);
00268     int other_pt_index = 3 - dead_pt_index - this_pt_index;
00269     
00270       // The get the other point (facet should have 
00271       // this point, the dead point, and one other).
00272     CubitPoint* other_pt = dead_facet->point(other_pt_index);
00273     
00274       // Get the edges to merge
00275     dead_edge = dynamic_cast<CubitFacetEdgeData*>(dead_facet->edge(this_pt_index));
00276     keep_edge = dynamic_cast<CubitFacetEdgeData*>(dead_facet->edge(dead_pt_index));
00277     edge_facets.clean_out();
00278 
00279     //propagate all the tds from dead edge to keep edge
00280     DLIList<ToolData*> tds;
00281     dead_edge->get_all_TDs(&tds);
00282     for (int i=0; i<tds.size(); i++)
00283     {
00284       ToolData* new_td = tds.get_and_step()->propogate(keep_edge);
00285       if (new_td)
00286         keep_edge->add_TD(new_td);
00287     }
00288     
00289       // Get the list of adjacent facets to be updated
00290     dead_point->shared_facets(other_pt, edge_facets);
00291     
00292       // Determine relative sense of edges
00293     int dead_edge_pt = dead_edge->point(0) == other_pt ? 0 : 1;
00294     int rel_edge_sense = keep_edge->point(dead_edge_pt) == other_pt ? 1 : -1;
00295     
00296       // Update edge in each adjacent facet (merge keep_edge with dead_edge)
00297     for ( j = edge_facets.size(); j--; )
00298     {
00299       edge_facet = dynamic_cast<CubitFacetData*>(edge_facets.get_and_step());
00300       if ( edge_facet == dead_facet )
00301         continue;
00302       
00303       int dead_index = edge_facet->point_index(dead_point);
00304       int edge_index = (dead_index+1) % 3;
00305       if ( edge_facet->point(edge_index) == other_pt )
00306         edge_index = (dead_index+2) % 3;
00307       
00308       if ( dead_edge )
00309       {
00310         assert(edge_facet->edge(edge_index) == dead_edge);
00311         dead_edge->remove_facet(edge_facet);
00312         edge_facet->edge( 0, edge_index );
00313       }
00314       if ( keep_edge )
00315       {
00316         assert(edge_facet->edge(edge_index) == 0);
00317         keep_edge->add_facet(edge_facet);
00318         edge_facet->edge( keep_edge, edge_index );
00319         int use = rel_edge_sense * edge_facet->edge_use(edge_index);
00320         edge_facet->edge_use( use, edge_index );
00321       }
00322     }
00323     
00324       // delete dead entities
00325     
00326     delete dead_facet;
00327     
00328     if (dead_edge)
00329     {
00330       assert(dead_edge->num_adj_facets() == 0);
00331       
00332       adj_edge_list.move_to(dead_edge);
00333       assert(adj_edge_list.get() == dead_edge);
00334       adj_edge_list.extract();
00335       
00336       delete dead_edge;
00337     }
00338   }
00339   
00340   while (adj_edge_list.size())
00341   {
00342     keep_edge = dynamic_cast<CubitFacetEdgeData*>(adj_edge_list.pop());
00343     assert(!!keep_edge);
00344     if (keep_edge->point(0) == dead_point)
00345       keep_edge->set_point(this, 0);
00346     else if(keep_edge->point(1) == dead_point)
00347       keep_edge->set_point(this, 1);
00348     else
00349       assert(0);
00350   }
00351   
00352   DLIList<CubitFacet*> adj_facet_list(dead_point->num_adj_facets());
00353   dead_point->facets(adj_facet_list);
00354   while (adj_facet_list.size())
00355   {
00356     CubitFacetData* facet = dynamic_cast<CubitFacetData*>(adj_facet_list.pop());
00357     assert(!!facet);
00358     
00359     int index = facet->point_index(dead_point);
00360     assert((unsigned)index < (unsigned)3 && facet->point(index) == dead_point);
00361     
00362     dead_point->remove_facet(facet);
00363     this->add_facet(facet);
00364     facet->set_point( this, index );
00365   }
00366   
00367   
00368     // delete dead entities
00369   if ( collapse )
00370   {
00371     assert( collapse->num_adj_facets() == 0 );
00372     delete collapse;
00373   }
00374 
00375   assert( dead_point->num_adj_facets() == 0 );
00376   delete dead_point;
00377   
00378   return CUBIT_SUCCESS;
00379 }
00380   
00381 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines