cgma
CubitQuadFacetData.cpp
Go to the documentation of this file.
00001 //
00002 // File: CubitQuadFacetData.cpp
00003 //
00004 // Owner: sjowen
00005 //
00006 
00007 #include "CubitQuadFacetData.hpp"
00008 #include "CubitPoint.hpp"
00009 #include "CubitFacetEdge.hpp"
00010 #include "CubitFacetEdgeData.hpp"
00011 #include "CubitFacet.hpp"
00012 #include "CubitFacetData.hpp"
00013 
00014 //===========================================================================
00015 //  Function: CubitQuadFacetData
00016 //  Purpose:  constructor
00017 //  Notes:    defines a quad facet given two existing triangle facets.
00018 //            The points on the facet are also passed in so the quad
00019 //            can be oriented with respect to its triangles
00020 //  Date:     4/11/01
00021 //  Author:   sjowen
00022 //===========================================================================
00023 CubitQuadFacetData::CubitQuadFacetData(
00024   CubitFacet *tri_facets[2],
00025   CubitPoint *points[4] )
00026 {
00027   myTriangleFacets[0] = tri_facets[0];
00028   myTriangleFacets[1] = tri_facets[1];
00029 
00030   CubitBoolean found = CUBIT_FALSE;
00031   CubitPoint *pt;
00032   int ii, jj, kk;
00033 
00034   for (jj=0; jj<2; jj++)
00035   {
00036     for (kk=0; kk<3; kk++)
00037     {
00038       pt = myTriangleFacets[jj]->point(kk);
00039       found = CUBIT_FALSE;
00040       for (ii=0; ii<4 && !found; ii++)
00041       {
00042         if (points[ii] == pt)
00043         {
00044           triToQuadIndex[jj][kk] = ii;
00045           found = CUBIT_TRUE;
00046         }
00047       }
00048 
00049       // If assertion occurs, the that points passed to the constructor do 
00050       // not match the points on the triangle facets
00051 
00052       assert(found == CUBIT_TRUE);
00053     }
00054   }
00055 }
00056 
00057 //===========================================================================
00058 //  Function: CubitQuadFacetData
00059 //  Purpose:  constructor
00060 //  Notes:    defines a quad facet given its ordered point array.
00061 //            Two triangle facets are created
00062 //  Date:     4/11/01
00063 //  Author:   sjowen
00064 //===========================================================================
00065 CubitQuadFacetData::CubitQuadFacetData(
00066   CubitPoint *point0, CubitPoint *point1, 
00067   CubitPoint *point2, CubitPoint *point3 )
00068 {
00069   
00070   // The orientation of the triangles in the quad is arbitrary.
00071   // We may want to split based on some other criteria (ie. angles)
00072 
00073   myTriangleFacets[0] = new CubitFacetData( point0, point1, point2 );
00074   myTriangleFacets[1] = new CubitFacetData( point2, point3, point0 );
00075 
00076   triToQuadIndex[0][0] = 0;
00077   triToQuadIndex[0][1] = 1;
00078   triToQuadIndex[0][2] = 2;
00079   triToQuadIndex[1][0] = 2;
00080   triToQuadIndex[1][1] = 3;
00081   triToQuadIndex[1][2] = 0;
00082 }
00083 
00084 //===========================================================================
00085 //  Function: CubitQuadFacetData
00086 //  Purpose:  constructor
00087 //  Notes:    defines a quad facet given its ordered edge array.
00088 //            Two triangle facets are created
00089 //  Date:     4/11/01
00090 //  Author:   sjowen
00091 //===========================================================================
00092 CubitQuadFacetData::CubitQuadFacetData(
00093   CubitFacetEdge *e0, CubitFacetEdge *e1,
00094   CubitFacetEdge *e2, CubitFacetEdge *e3 )
00095 {
00096   // create the diagonal edge
00097 
00098   CubitPoint *p0 = e3->shared_point(e0);
00099   CubitPoint *p2 = e1->shared_point(e2);
00100   assert(p0 != NULL && p2 != NULL);
00101 
00102   CubitFacetEdge *e4 = (CubitFacetEdge *) new CubitFacetEdgeData( p0, p2 );
00103 
00104   // create the triangles
00105 
00106   myTriangleFacets[0] = new CubitFacetData( e1, e4, e0 );
00107   myTriangleFacets[1] = new CubitFacetData( e3, e4, e2 );
00108 
00109   triToQuadIndex[0][0] = 0;
00110   triToQuadIndex[0][1] = 1;
00111   triToQuadIndex[0][2] = 2;
00112   triToQuadIndex[1][0] = 2;
00113   triToQuadIndex[1][1] = 3;
00114   triToQuadIndex[1][2] = 0;
00115 }
00116 
00117 //===========================================================================
00118 //  Function: CubitQuadFacetData
00119 //  Purpose:  constructor
00120 //  Notes:    defines a quad facet given its ordered point array.
00121 //            Two triangle facets are created
00122 //  Date:     4/11/01
00123 //  Author:   sjowen
00124 //===========================================================================
00125 CubitQuadFacetData::CubitQuadFacetData(
00126   CubitPoint *points[4] )
00127 {
00128   
00129   // The orientation of the triangles in the quad is arbitrary.
00130   // We may want to split based on some other criteria (ie. angles)
00131 
00132   myTriangleFacets[0] = new CubitFacetData( points[0], points[1], points[2] );
00133   myTriangleFacets[1] = new CubitFacetData( points[2], points[3], points[0] );
00134 
00135   triToQuadIndex[0][0] = 0;
00136   triToQuadIndex[0][1] = 1;
00137   triToQuadIndex[0][2] = 2;
00138   triToQuadIndex[1][0] = 2;
00139   triToQuadIndex[1][1] = 3;
00140   triToQuadIndex[1][2] = 0;
00141 }
00142 
00143 //===========================================================================
00144 //  Function: ~CubitQuadFacetData
00145 //  Purpose:  destructor
00146 //  Date:     4/11/01
00147 //  Author:   sjowen
00148 //===========================================================================
00149 CubitQuadFacetData::~CubitQuadFacetData()
00150 {
00151   if (myTriangleFacets[0] == NULL && myTriangleFacets[1] == NULL)
00152     return;
00153 
00154   assert(myTriangleFacets[0] && myTriangleFacets[1]);
00155 
00156   // determine the dialogonal edge
00157   CubitPoint *p0 = this->point(0);
00158   CubitPoint *p2 = this->point(2);
00159   CubitFacetEdge *dedge = NULL;
00160   if (p0 != NULL && p2 != NULL)
00161   {
00162     dedge = p0->shared_edge(p2);
00163   }
00164 
00165   // delete both triangles
00166   delete myTriangleFacets[0];
00167   delete myTriangleFacets[1];
00168 
00169   // delete the dialgonal edge
00170   if (dedge != NULL)
00171   { 
00172     delete dedge;
00173   }
00174 }
00175 
00176 //===========================================================================
00177 //  Function: ~CubitQuadFacetData
00178 //  Purpose:  destructor
00179 //  Date:     4/11/01
00180 //  Author:   sjowen
00181 //===========================================================================
00182 void CubitQuadFacetData::remove_tri_facets(  )
00183 {
00184   myTriangleFacets[0] = NULL;
00185   myTriangleFacets[1] = NULL;
00186 }
00187 
00188 //===========================================================================
00189 //  Function: points
00190 //  Purpose:  get the points from the facet
00191 //  Date:     4/11/01
00192 //  Author:   sjowen
00193 //===========================================================================
00194 void CubitQuadFacetData::points(
00195   CubitPoint *thepoints[4] )
00196 {
00197 
00198   thepoints[triToQuadIndex[0][0]] = myTriangleFacets[0]->point(0);
00199   thepoints[triToQuadIndex[0][1]] = myTriangleFacets[0]->point(1);
00200   thepoints[triToQuadIndex[0][2]] = myTriangleFacets[0]->point(2);
00201   thepoints[triToQuadIndex[1][0]] = myTriangleFacets[1]->point(0);
00202   thepoints[triToQuadIndex[1][1]] = myTriangleFacets[1]->point(1);
00203   thepoints[triToQuadIndex[1][2]] = myTriangleFacets[1]->point(2);
00204 }
00205 
00206 //===========================================================================
00207 //  Function: point
00208 //  Purpose:  get the point from the facet
00209 //  Date:     11/28/2002
00210 //  Author:   sjowen
00211 //===========================================================================
00212 CubitPoint *CubitQuadFacetData::point( int index )
00213 {
00214   int ii, jj;
00215   for (ii=0; ii<2; ii++)
00216   {
00217     for (jj=0; jj<3; jj++)
00218     {
00219       if (triToQuadIndex[ii][jj] == index)
00220       {
00221         return myTriangleFacets[ii]->point(jj);
00222       }
00223     }
00224   }
00225   assert(0);  // index is probably out of range
00226   return NULL;
00227 }
00228 
00229 //===========================================================================
00230 //  Function: edge
00231 //  Purpose:  get the edge from the facet
00232 //  Date:     11/28/2002
00233 //  Author:   sjowen
00234 //===========================================================================
00235 CubitFacetEdge *CubitQuadFacetData::edge( int index )
00236 {
00237   int ii, jj;
00238   CubitPoint *p0 = NULL;
00239   CubitPoint *p1 = NULL;
00240   int index1 = (index + 1) % 4;
00241   for (ii=0; ii<2; ii++)
00242   {
00243     for (jj=0; jj<3; jj++)
00244     {
00245       if (triToQuadIndex[ii][jj] == index)
00246       {
00247         p0 = myTriangleFacets[ii]->point(jj);
00248       }
00249       else if ( triToQuadIndex[ii][jj] == index1 )
00250       {
00251         p1 = myTriangleFacets[ii]->point(jj);
00252       }
00253     }
00254   }
00255   assert(p0 != NULL && p1 != NULL);  // index is probably out of range
00256   
00257   return p0->shared_edge( p1 );
00258 }
00259 
00260 
00261 //===========================================================================
00262 //  Function: get_tri_facet
00263 //  Purpose:  return the underlying triangle of which the point_ptr is a vertex
00264 //  Date:     11/28/2002
00265 //  Author:   sjowen
00266 //===========================================================================
00267 CubitFacet *CubitQuadFacetData::get_tri_facet_at_point( CubitPoint *point_ptr )
00268 {
00269   int ii, jj;
00270   for (ii=0; ii<2; ii++)
00271   {
00272     for (jj=0; jj<3; jj++)
00273     { 
00274       if (myTriangleFacets[ii]->point(jj) == point_ptr)
00275       {
00276         return myTriangleFacets[ii]; 
00277       }
00278     }
00279   }
00280   assert(0);  // point isn't on facet
00281   return NULL;
00282 }
00283 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines