cgma
TDOctreeRefEdge.cpp
Go to the documentation of this file.
00001 //- Class:       TDOctreeRefEdge
00002 //- Description: Tool data for storing additional information needed for generating line source entities.
00003 //- Owner:       W. R. Quadors
00004 //- Checked by:
00005 //- Version:
00006 #include "TDOctreeRefEdge.hpp" 
00007 #include "CubitDefines.h" 
00008 #include "ToolData.hpp"
00009 #include "MemoryManager.hpp" 
00010 #include "DLIList.hpp"
00011 #include "CastTo.hpp"
00012 #include "RefEdge.hpp"
00013 #include "GMem.hpp"
00014 
00015 
00016 
00017 // Constructor  
00018 TDOctreeRefEdge::TDOctreeRefEdge(){
00019   resultPointData = new GMem;
00020   visit = CUBIT_FALSE;
00021 }
00022 
00023 
00024 // Distructor
00025 TDOctreeRefEdge::~TDOctreeRefEdge(){
00026   clean_gpoint_list();
00027     //PRINT_INFO("Inside ~TDOctreeRefEdge\n");
00028 }
00029 
00030 void TDOctreeRefEdge::clean_gpoint_list(){
00031   delete resultPointData;  
00032 }
00033 
00034 //-------------------------------------------------------------------------
00035 // Purpose       : To create TDOctreeRefEdge to MRefFace
00036 //
00037 // Special Notes :
00038 //
00039 // Creator       : W R Quadros
00040 //
00041 // Creation Date : 07/03
00042 //------------------------------------------------------------------------- 
00043 CubitStatus TDOctreeRefEdge::add_td(  RefEdge *mref_edge )
00044 {
00045   ToolData *td;
00046   td = mref_edge->get_TD(&TDOctreeRefEdge::is_td_skl_mref_edge);
00047   if ( td == NULL )
00048   {
00049     TDOctreeRefEdge *td_gm = new TDOctreeRefEdge;
00050     mref_edge->add_TD( td_gm);
00051     td_gm->set_mref_edge( mref_edge );
00052   }
00053   else
00054   {
00055     TDOctreeRefEdge *td_gm = CAST_TO(td, TDOctreeRefEdge);
00056     td_gm->set_mref_edge( mref_edge );
00057   }
00058   return CUBIT_SUCCESS;
00059 }
00060 
00061 //-------------------------------------------------------------------------
00062 // Purpose       : get the TDOctreeRefEdge for a RefEdge
00063 //
00064 // Special Notes :
00065 //
00066 // Creator       : W R Quadros
00067 //
00068 // Creation Date : 07/03
00069 //------------------------------------------------------------------------- 
00070 TDOctreeRefEdge* TDOctreeRefEdge::get_td( RefEdge *mref_edge )
00071 {
00072   ToolData *td;
00073   td = mref_edge->get_TD(&TDOctreeRefEdge::is_td_skl_mref_edge);
00074   if ( td != NULL )
00075   {
00076     TDOctreeRefEdge *td_gm = CAST_TO(td, TDOctreeRefEdge);
00077     return td_gm;
00078   }
00079   return (TDOctreeRefEdge*) NULL;
00080 }
00081  
00082 // curve decimating function
00083 // takes in points to decimate based on an angle_tolerance in degrees
00084 // and puts results into the result point data
00085 void TDOctreeRefEdge::decimate_curve_points_for_source_entity(GMem& point_data, double angle_tolerance, GMem& result_point_data)
00086 {
00087     // pointListCount instead of point_data.point_list_size()  (they are different)
00088   int num_pre_points = point_data.pointListCount;
00089 
00090     // only decimate if we have more than 2 points
00091   if(num_pre_points <= 2)
00092   {
00093     result_point_data = point_data;
00094     return;
00095   }
00096 
00097     // get threshold value
00098   const double threshold = cos( DEGREES_TO_RADIANS(angle_tolerance) );
00099 
00100     // mark array for what to keep and throw
00101   char* mark_array = new char[num_pre_points];
00102     // zero means keep the point, non-zero means remove the point
00103   memset(mark_array, 0, num_pre_points);
00104 
00105   int num_points_to_keep = 2;   // initialize to keep start and end points
00106 
00107   int i;
00108   GPoint* point_data_array = point_data.point_list();
00109     // initialize first point
00110   GPoint* pre_point = &(point_data_array[0]);
00111     // traverse all but start and end points
00112   for(i=1; i<(num_pre_points-1); i++)
00113   {
00114 
00115       // create two vectors
00116       // one from i-1 to i and another from i to i+1
00117     GPoint* point = &(point_data_array[i]);
00118     GPoint* next_point = &(point_data_array[i+1]);
00119 
00120     CubitVector v1(CubitVector(pre_point->x, pre_point->y, pre_point->z), 
00121                    CubitVector(point->x, point->y, point->z));
00122     v1.normalize();
00123 
00124     CubitVector v2(CubitVector(point->x, point->y, point->z),
00125                    CubitVector(next_point->x, next_point->y, next_point->z));
00126     v2.normalize();
00127 
00128       // compute whether to keep the point
00129     double dot_product = v1 % v2;
00130 
00131     bool keep = dot_product > threshold ? false : true;
00132 
00133       // if keep
00134     if(keep)
00135     {
00136       num_points_to_keep++;
00137       pre_point = point;
00138     }
00139       // if not keep
00140     else
00141     {
00142       mark_array[i] = 1;
00143     }
00144   }
00145 
00146     // make a new GPoint array
00147   GPoint* new_point_list = new GPoint[num_points_to_keep];
00148   int new_point_list_count = 0;
00149     // copy points to keep into the new array
00150   for(i=0; i<num_pre_points; i++)
00151   {
00152     if(mark_array[i] == 0)
00153     {
00154       new_point_list[new_point_list_count] = point_data_array[i];
00155       new_point_list_count++;
00156     }
00157   }
00158 
00159   delete [] mark_array;
00160 
00161   assert(new_point_list_count == num_points_to_keep);
00162     //printf("reduced points from %i to %i\n", num_pre_points, num_points_to_keep);
00163 
00164     // put data into the result gmem
00165   result_point_data.replace_point_list(new_point_list, new_point_list_count, new_point_list_count);
00166   result_point_data.points_consolidated(CUBIT_TRUE);
00167 }
00168 
00169 CubitBoolean TDOctreeRefEdge::generate_gpoint_list( double decimation_ang )
00170 {
00171     // get facets from cgm
00172   GMem point_data;
00173   refEdge->get_graphics( point_data );
00174     // decimate the facets to the resolution we want
00175 
00176   TDOctreeRefEdge::decimate_curve_points_for_source_entity( point_data, decimation_ang, *resultPointData);
00177 
00178   return CUBIT_TRUE;
00179 }
00180 
00181 
00182 
00183 //====================================================================== 
00184 // Description: return curvature at a point on the edge 
00185 // Author: sjowen 
00186 // Modified: W R Quadros
00187 // Date: 01/2005 
00188 //====================================================================== 
00189 CubitBoolean TDOctreeRefEdge::find_curve_curvature_using_three_points(CubitVector point_a, CubitVector point_b, CubitVector point_c, CubitVector &curvature ){
00190 
00191 
00192   CubitVector vec_ba, vec_bc;
00193 
00194   vec_ba = point_a - point_b; 
00195   vec_bc = point_c - point_b; 
00196   
00197     // Squares of lengths of the edges incident to `a'.
00198   double ba_length = vec_ba.length_squared();
00199   double bc_length = vec_bc.length_squared();
00200   
00201     // Cross product of these edges.
00202     // (Take your chances with floating-point roundoff.)
00203   CubitVector cross = vec_ba * vec_bc;
00204   
00205     // Calculate the denominator of the formulae.
00206   double denominator = 0.5 / (cross % cross);
00207   assert(denominator != 0.0);
00208   
00209     // Calculate offset (from `a') of circumcenter.
00210   CubitVector circle_center  = (ba_length * vec_bc - bc_length * vec_ba) * cross;
00211   circle_center *= denominator;
00212 
00213     //store radius
00214   double radius = circle_center.length();
00215   circle_center.normalize();
00216   circle_center /= radius;
00217   
00218   curvature = circle_center; 
00219   return CUBIT_TRUE; 
00220 } 
00221 
00222   // EOF
00223 
00224 
00225 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines