cgma
SurfaceOverlapFacet.cpp
Go to the documentation of this file.
00001 //- Class: SurfaceOverlapFacet
00002 //- Description: Facet definition class for efficient processing
00003 //-              for SurfaceOverlapTool.  
00004 //- Owner: Steve Storm
00005 //- Created: January 26, 2003
00006 
00007 #include "SurfaceOverlapFacet.hpp"
00008 #include "GfxPreview.hpp"
00009 
00010 AnalyticGeometryTool* SurfaceOverlapFacet::agt = AnalyticGeometryTool::instance();
00011 
00012 // Constructor
00013 SurfaceOverlapFacet::SurfaceOverlapFacet( GPoint p[3] )
00014 {
00015   t.b.x = p[0].x;
00016   t.b.y = p[0].y;
00017   t.b.z = p[0].z;
00018 
00019   t.e0.x = p[1].x - p[0].x;
00020   t.e0.y = p[1].y - p[0].y;
00021   t.e0.z = p[1].z - p[0].z;
00022 
00023   t.e1.x = p[2].x - p[0].x;
00024   t.e1.y = p[2].y - p[0].y;
00025   t.e1.z = p[2].z - p[0].z;
00026 
00027   CubitVector min;
00028    
00029   min.set( CUBIT_MIN_3( p[0].x, p[1].x, p[2].x ),
00030     CUBIT_MIN_3( p[0].y, p[1].y, p[2].y ),
00031     CUBIT_MIN_3( p[0].z, p[1].z, p[2].z ) );
00032   
00033   CubitVector max;
00034   
00035   max.set( CUBIT_MAX_3( p[0].x, p[1].x, p[2].x ),
00036     CUBIT_MAX_3( p[0].y, p[1].y, p[2].y ),
00037     CUBIT_MAX_3( p[0].z, p[1].z, p[2].z ) );
00038 
00039   boundingBox.reset( min, max );
00040 }
00041 
00042 // Destructor
00043 SurfaceOverlapFacet::~SurfaceOverlapFacet()
00044 {
00045 }
00046 
00047 double SurfaceOverlapFacet::distance( SurfaceOverlapFacet &other_facet )
00048 {
00049   double s, t2, u, v;
00050   return agt->MinTriangleTriangle( t, other_facet.t, s, t2, u, v );
00051 }
00052 
00053 double SurfaceOverlapFacet::perimeter()
00054 {
00055   CubitVector pt0( t.b.x, t.b.y, t.b.z );
00056   CubitVector pt1( t.b.x + t.e0.x,
00057                    t.b.y + t.e0.y,
00058                    t.b.z + t.e0.z );
00059   CubitVector pt2( t.b.x + t.e1.x,
00060                    t.b.y + t.e1.y,
00061                    t.b.z + t.e1.z ); 
00062 
00063   double total_dist = pt0.distance_between(pt1);
00064   total_dist += pt1.distance_between( pt2 );
00065   total_dist += pt2.distance_between( pt0 );
00066 
00067   return total_dist;
00068 }
00069 
00070 bool SurfaceOverlapFacet::facet_points_within_tol( SurfaceOverlapFacet *other_face, double tolerance )
00071 {
00072   CubitVector tmp_pt( t.b.x, t.b.y, t.b.z );
00073   if( this->distance_from_position( tmp_pt ) > tolerance )
00074     return false;
00075 
00076   tmp_pt.set( t.b.x + t.e0.x,
00077               t.b.y + t.e0.y,
00078               t.b.z + t.e0.z );
00079 
00080   if( this->distance_from_position( tmp_pt ) > tolerance )
00081     return false;
00082 
00083   tmp_pt.set( t.b.x + t.e1.x,
00084               t.b.y + t.e1.y,
00085               t.b.z + t.e1.z );
00086 
00087   if( this->distance_from_position( tmp_pt ) > tolerance )
00088     return false;
00089 
00090   return true;
00091 }
00092 
00093 double SurfaceOverlapFacet::distance_from_position( CubitVector &position )
00094 {
00095   double s,t;  
00096   Point3 tmp_point;
00097   tmp_point.x = position.x();
00098   tmp_point.y = position.y();
00099   tmp_point.z = position.z();
00100   return agt->MinPointTriangle( tmp_point, this->t, s, t );
00101 } 
00102 
00103 CubitBoolean
00104 SurfaceOverlapFacet::facing( SurfaceOverlapFacet &other_facet )
00105 {
00106     double norm1[3];
00107     agt->Normal( t, norm1 );
00108     double norm2[3];
00109     agt->Normal( other_facet.t, norm2 );
00110 
00111     // move to the origin
00112     double o1[3];
00113     o1[0] = other_facet.t.b.x-t.b.x;
00114     o1[1] = other_facet.t.b.y-t.b.y;
00115     o1[2] = other_facet.t.b.z-t.b.z;
00116 
00117     double dot_p = agt->dot_vec(norm1,o1);
00118     return (CubitBoolean)(dot_p >= 0.0);
00119 }
00120 
00121 double
00122 SurfaceOverlapFacet::angle( SurfaceOverlapFacet &other_facet )
00123 {
00124   return agt->Angle( t, other_facet.t ) * RADtoDEG;
00125 }
00126 
00127 double
00128 SurfaceOverlapFacet::projected_overlap( SurfaceOverlapFacet &other_facet, CubitBoolean draw_overlap )
00129 {
00130   double tmp_double = agt->ProjectedOverlap( t, other_facet.t, draw_overlap );
00131 
00132   if( tmp_double > 0.00 ) 
00133   {
00134     CubitVector edge0(t.e0.x, t.e0.y, t.e0.z);  
00135     CubitVector edge1(t.e1.x, t.e1.y, t.e1.z);  
00136     CubitVector normal = edge0 * edge1;
00137     double area_facet1 = normal.length() / 2;
00138 
00139     edge0.set(other_facet.t.e0.x, other_facet.t.e0.y, other_facet.t.e0.z);  
00140     edge1.set(other_facet.t.e1.x, other_facet.t.e1.y, other_facet.t.e1.z);  
00141     normal = edge0 * edge1;
00142     double area_facet2 = normal.length() / 2;
00143     
00144     //don't report overlapping area between facets unless it is greater 
00145     //than one hundredth of the area of the smaller facet
00146     if( area_facet1 < area_facet2 )
00147     {
00148       if( tmp_double < (area_facet1*0.01))
00149         tmp_double = 0.0;
00150     }
00151     else if( tmp_double < (area_facet2*0.01 ))
00152       tmp_double = 0.0;
00153   }
00154   return tmp_double;
00155 }
00156 
00157 
00158 void SurfaceOverlapFacet::draw( int color ) 
00159 {
00160   CubitVector point1 = CubitVector( t.b.x, t.b.y, t.b.z );    
00161   CubitVector point2 = CubitVector( t.e0.x + t.b.x, 
00162                                     t.e0.y + t.b.y, 
00163                                     t.e0.z + t.b.z );    
00164   CubitVector point3 = CubitVector( t.e1.x + t.b.x, 
00165                                     t.e1.y + t.b.y, 
00166                                     t.e1.z + t.b.z );    
00167 
00168   GfxPreview::draw_line( point1, point2, color );
00169   GfxPreview::draw_line( point2, point3, color );
00170   GfxPreview::draw_line( point1, point3, color );
00171   
00172   return;
00173 }
00174 
00175 CubitVector SurfaceOverlapFacet::centroid()
00176 {
00177 
00178   CubitVector point1 = CubitVector( t.b.x, t.b.y, t.b.z );    
00179   CubitVector point2 = CubitVector( t.e0.x + t.b.x, 
00180                                     t.e0.y + t.b.y, 
00181                                     t.e0.z + t.b.z );    
00182   CubitVector point3 = CubitVector( t.e1.x + t.b.x, 
00183                                     t.e1.y + t.b.y, 
00184                                     t.e1.z + t.b.z );    
00185 
00186   point1 += point2;
00187   point1 += point3;
00188   point1 /= 3;
00189   
00190   return point1;
00191 }
00192 
00193 CubitVector SurfaceOverlapFacet::smallest_edge_midpoint()
00194 {
00195   CubitVector point1 = CubitVector( t.b.x, t.b.y, t.b.z );    
00196   CubitVector point2 = CubitVector( t.e0.x + t.b.x, 
00197                                     t.e0.y + t.b.y, 
00198                                     t.e0.z + t.b.z );    
00199   CubitVector point3 = CubitVector( t.e1.x + t.b.x, 
00200                                     t.e1.y + t.b.y, 
00201                                     t.e1.z + t.b.z );    
00202   
00203   double len_12 = point1.distance_between( point2 );
00204   double len_23 = point2.distance_between( point3 );
00205   double len_13 = point1.distance_between( point3 );
00206 
00207   if( (len_12 < len_23) && (len_12 < len_13) )
00208   {
00209     point1 += point2;
00210     point1 /= 2;
00211     return point1;
00212   }
00213   else if( len_23 < len_13 )
00214   {
00215     point2 += point3;
00216     point2 /= 2;
00217     return point2;
00218   }
00219   else
00220   {
00221     point1 += point3;
00222     point1 /= 2;
00223     return point1;
00224   }
00225 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines