cgma
TDSurfaceOverlap.cpp
Go to the documentation of this file.
00001 // TDSurfaceOverlap.cpp
00002 
00003 #include "TDSurfaceOverlap.hpp"
00004 #include "GMem.hpp"
00005 #include "RefFace.hpp"
00006 #include "SurfaceOverlapFacet.hpp"
00007 
00008 TDSurfaceOverlap::TDSurfaceOverlap( RefFace *ref_face_ptr,
00009                                     unsigned short ang_facet_tol, double abs_facet_tol,
00010                                     double gap_max )
00011 {
00012   refFacePtr = ref_face_ptr;
00013   aTree = NULL;
00014   marked = 0;
00015   bodiesRetrieved = 0;
00016   angFacetTol = ang_facet_tol;
00017   absFacetTol = abs_facet_tol;
00018   gapMax = gap_max;
00019 }
00020 
00021 TDSurfaceOverlap::~TDSurfaceOverlap()
00022 {
00023   while( facetList.size() ) delete facetList.pop();
00024   if( aTree )
00025     delete aTree;
00026 }
00027 
00028 DLIList<SurfaceOverlapFacet*> *
00029 TDSurfaceOverlap::get_facet_list()
00030 {
00031   if( facetList.size() )
00032     return &facetList;
00033 
00034   GMem *gmem_ptr = new GMem;
00035   CubitStatus stat = refFacePtr->get_graphics( *gmem_ptr, angFacetTol, absFacetTol );
00036 
00037   if( !stat )
00038   {
00039     delete gmem_ptr;
00040     return NULL;
00041   }
00042 
00043   GPoint* plist = gmem_ptr->point_list();
00044   int* facet_list = gmem_ptr->facet_list();
00045 
00046   int i;
00047    
00048   GPoint p[3];
00049   for (i = 0; i < gmem_ptr->fListCount; )
00050   {
00051     int sides = facet_list[i++];
00052     if (sides != 3)
00053     {
00054       PRINT_WARNING("Skipping n-sided polygone in triangle list"
00055                     " in TDSurfaceOverlap.\n");
00056       i += sides;
00057     }
00058     else
00059     {
00060       p[0] = plist[facet_list[i++]];
00061       p[1] = plist[facet_list[i++]];
00062       p[2] = plist[facet_list[i++]];
00063    
00064       SurfaceOverlapFacet *facet = new SurfaceOverlapFacet( p );
00065       facetList.append( facet );
00066     }
00067   }
00068 
00069   delete gmem_ptr;
00070 
00071   return &facetList;
00072 }
00073 
00074 AbstractTree<SurfaceOverlapFacet*> *
00075 TDSurfaceOverlap::get_facet_rtree()
00076 {
00077   if( !aTree && !get_facet_list() )
00078     return NULL;
00079 
00080   if( !aTree )
00081   {
00082     aTree = new RTree<SurfaceOverlapFacet*>( gapMax );
00083 
00084     int i;
00085     for( i=facetList.size(); i--; )
00086     {
00087       SurfaceOverlapFacet *facet_ptr = facetList.get_and_step();
00088       aTree->add( facet_ptr );
00089     }
00090   }
00091 
00092   return aTree;
00093 }
00094 
00095 DLIList<Body*> *
00096 TDSurfaceOverlap::get_body_list()
00097 {
00098   if( bodiesRetrieved )
00099     return &bodyList;
00100 
00101   refFacePtr->bodies( bodyList );
00102   bodiesRetrieved = 1;
00103   return &bodyList;
00104 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines