cgma
offset_curves.cpp
Go to the documentation of this file.
00001 
00010 #undef NDEBUG
00011 #include <cassert>
00012 
00013 #include "GeometryModifyEngine.hpp"
00014 #include "GeometryModifyTool.hpp"
00015 #include "GeometryQueryTool.hpp"
00016 #include "CubitMessage.hpp"
00017 #include "Body.hpp"
00018 #include "RefVolume.hpp"
00019 #include "RefFace.hpp"
00020 #include "RefEdge.hpp"
00021 #include "RefVertex.hpp"
00022 #include "InitCGMA.hpp"
00023 #include "OCCBody.hpp"
00024 #include "OCCSurface.hpp"
00025 #include "OCCCurve.hpp"
00026 #include "OCCDrawTool.hpp"
00027 #include "CubitCompat.hpp"
00028 
00029 #ifndef SRCDIR
00030 # define SRCDIR .
00031 #endif
00032 
00033 #define STRINGIFY_(X) #X
00034 #define STRINGIFY(X) STRINGIFY_(X)
00035 #define SRCPATH STRINGIFY(SRCDIR) "/"
00036 
00037 // forward declare some functions used and defined later
00038 CubitStatus read_geometry(int, const char **, bool local = false);
00039 CubitStatus make_Point();
00040 // macro for printing a separator line
00041 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00042 
00043 
00044 // main program - initialize, then send to proper function
00045 int main (int argc, char **argv)
00046 {
00047   CubitStatus status = InitCGMA::initialize_cgma("OCC");
00048   if (CUBIT_SUCCESS != status) return 1;
00049 
00050   //Do make point.
00051   status = make_Point();
00052   if (status == CUBIT_FAILURE) 
00053      PRINT_INFO("Operation Failed");
00054 
00055   int ret_val = ( CubitMessage::instance()->error_count() );
00056   if ( ret_val > 5 )
00057   {
00058     PRINT_ERROR("Errors found during Mergechk session.\n");
00059   }
00060   return ret_val-5;
00061   
00062 }
00063 
00068 CubitStatus read_geometry(int num_files, const char **argv, bool local) 
00069 {
00070   CubitStatus status = CUBIT_SUCCESS;
00071   GeometryQueryTool *gti = GeometryQueryTool::instance();
00072   assert(gti);
00073   int i;
00074   
00075   PRINT_SEPARATOR;
00076 
00077   for (i = 0; i < num_files; i++) {
00078     std::string filename( local ? "./" : SRCPATH );
00079     filename += argv[i];
00080     status = CubitCompat_import_solid_model(filename.c_str(), "OCC");
00081     if (status != CUBIT_SUCCESS) {
00082       PRINT_ERROR("Problems reading geometry file %s.\n", filename.c_str());
00083     }
00084   }
00085   PRINT_SEPARATOR;
00086 
00087   return CUBIT_SUCCESS;
00088 }
00089 
00090 CubitStatus make_Point()
00091 {
00092   GeometryQueryTool *gti = GeometryQueryTool::instance();
00093   GeometryModifyTool *gmti = GeometryModifyTool::instance();
00094 
00095   CubitVector vector1(10,10,10);
00096   CubitVector vector2(-10,-10,10);
00097   CubitVector vector3(10, -10, 10);
00098 
00099   gmti->make_RefVertex(vector1,5);
00100   gmti->make_RefVertex(vector2,5);
00101   gmti->make_RefVertex(vector3,5);
00102   DLIList<RefEntity*>  free_entities;
00103   gti->get_free_ref_entities(free_entities);
00104 
00105   DLIList<RefEntity*> ref_entity_list;
00106   const CubitString cubit_version="10.2";
00107   int num_ents_exported=0;
00108   const char *filename = "curves.brep";
00109   const char *filetype = "OCC";
00110  
00111   RefVertex* vertex1 = CAST_TO(free_entities.step_and_get(),RefVertex);
00112   RefVertex* vertex2 = CAST_TO(free_entities.step_and_get(),RefVertex);
00113   RefVertex* vertex3 = CAST_TO(free_entities.step_and_get(),RefVertex); 
00114  
00115   //make all kinds of curves.
00116   CubitVector center_pnt(0,0,10);
00117   DLIList<CubitVector*> list;
00118   CubitVector center_pnt1(5,8,10);
00119   CubitVector center_pnt2(1,2,10);
00120   CubitVector center_pnt3(-2,-3.5,10);
00121   list.append(&vector1);
00122   list.append(&center_pnt1);
00123   list.append(&center_pnt2);
00124   list.append(&center_pnt);
00125   list.append(&center_pnt3);
00126   list.append(&vector2);
00127   RefEdge* new_edge_1 = gmti->make_RefEdge(SPLINE_CURVE_TYPE, vertex1,
00128                                           vertex2, list);
00129   double d = new_edge_1->measure();
00130   assert(fabs(d - 29.55)<0.01);
00131 
00132   //Added test for offset curve.
00133   DLIList<RefEdge*> offset_edges;
00134   offset_edges.append(new_edge_1);
00135   CubitVector v12(3,1,0);
00136   DLIList<RefEdge*> output_edge_list;
00137   CubitStatus rsl = gmti->offset_curves(offset_edges, output_edge_list, 1,  v12);
00138   assert(rsl == CUBIT_FAILURE);
00139  
00140   //straight line
00141   RefEdge* new_edge_2 = gmti->make_RefEdge(STRAIGHT_CURVE_TYPE, vertex1,
00142                                         vertex2, &center_pnt);
00143   d = new_edge_2->measure();
00144   assert(fabs(d - 28.284) <0.001);
00145 
00146   //Added test for offset curve.
00147   CubitVector v_null(0,0,0);
00148   offset_edges.clean_out();
00149   offset_edges.append(new_edge_2);
00150   CubitVector offset_v(1,-1,0);
00151   rsl = gmti->offset_curves(offset_edges, output_edge_list, 1,  offset_v);
00152   DLIList<RefEdge*> ref_edges;
00153   gti->ref_edges(ref_edges);
00154   ref_edges.last();
00155   RefEdge* offset_edge = ref_edges.get();
00156   d = offset_edge->measure(); 
00157   assert(fabs(d - 28.284) <0.001);
00158 
00159   RefVertex* start_v = offset_edge->start_vertex();
00160   CubitVector loc = start_v->coordinates();
00161   CubitVector closest_p(10.70710, 9.292893, 10);
00162   assert(fabs(loc.distance_between(closest_p)) < 0.0001);
00163 
00164   rsl = gmti->offset_curves(offset_edges, output_edge_list, 1,  offset_v);
00165   ref_edges.clean_out();
00166   gti->ref_edges(ref_edges);
00167   ref_edges.last();
00168   offset_edge = ref_edges.get();
00169   d = offset_edge->measure();
00170   assert(fabs(d - 28.284) <0.001);
00171 
00172   start_v = offset_edge->start_vertex();
00173   loc = start_v->coordinates();
00174   assert(fabs(loc.distance_between(closest_p)) < 0.0001);
00175 
00176   rsl = gmti->offset_curves(offset_edges, output_edge_list, 1, v_null);
00177   assert(rsl == CUBIT_FAILURE);
00178 
00179   //arc curve
00180   RefEdge* new_edge_3 = gmti->make_RefEdge(ARC_CURVE_TYPE, vertex1,
00181                                         vertex3, &center_pnt);
00182   d = new_edge_3->measure();
00183   assert(fabs(d - 31.4159) < 0.0001);
00184 
00185   CubitVector p_center(20, 0, 10);
00186   RefEdge* new_edge_31 = gmti->make_RefEdge(ARC_CURVE_TYPE, vertex3,
00187                                         vertex1, &p_center);
00188   d = new_edge_31->measure();
00189   assert(fabs(d - 31.4159) < 0.0001);
00190 
00191   offset_edges.clean_out();
00192   offset_edges.append(new_edge_31);
00193   rsl = gmti->offset_curves(offset_edges, output_edge_list, -1,  v12);
00194   ref_edges.clean_out();
00195   gti->ref_edges(ref_edges); 
00196   ref_edges.last();
00197   offset_edge = ref_edges.get();
00198   d = offset_edge->measure();
00199   assert(fabs(d-28.2743) < 0.0001);
00200   CubitVector curve_center;
00201   curve_center = offset_edge->center_point();
00202   CubitVector center_p(19, 0, 10);
00203   assert(fabs(curve_center.distance_between(center_p)) < 0.0001);
00204 
00205   offset_edges.clean_out();
00206   offset_edges.append(new_edge_3);
00207   rsl = gmti->offset_curves(offset_edges, output_edge_list, 1,  v12);
00208   ref_edges.clean_out();
00209   gti->ref_edges(ref_edges);
00210   ref_edges.last();
00211   offset_edge = ref_edges.get();
00212   d = offset_edge->measure();
00213   assert(fabs(d-34.5575) < 0.0001);
00214   curve_center = offset_edge->center_point();
00215   CubitVector center_p2(-1, 0, 10);
00216   assert(fabs(curve_center.distance_between(center_p2)) < 0.0001);
00217 
00218   offset_edges.clean_out();
00219   offset_edges.append(new_edge_31);
00220   offset_edges.append(new_edge_3);
00221   rsl = gmti->offset_curves(offset_edges, output_edge_list, 1,  v12);
00222   ref_edges.clean_out();
00223   gti->ref_edges(ref_edges);
00224   ref_edges.last();
00225   offset_edge = ref_edges.get();
00226   d = offset_edge->measure();
00227   assert(fabs(d-34.5575) < 0.0001);
00228 
00229   ref_edges.back();
00230   offset_edge = ref_edges.get();
00231   d = offset_edge->measure();
00232   assert(fabs(d-34.5575) < 0.0001);
00233   
00234   //ellipse curve
00235   RefEdge* new_edge_4 = gmti->make_RefEdge(ELLIPSE_CURVE_TYPE, vertex1,
00236                                         vertex3, &center_pnt);
00237   d = new_edge_4->measure();
00238   assert(fabs(d - 22.21) < 0.01); 
00239 
00240   offset_edges.clean_out();
00241   offset_edges.append(new_edge_4);
00242   rsl = gmti->offset_curves(offset_edges, output_edge_list, 1.0, v_null);
00243   assert(rsl == CUBIT_FAILURE);
00244 
00245   //PARABOLA_CURVE_TYPE
00246   RefEdge* new_edge_6 = gmti->make_RefEdge(PARABOLA_CURVE_TYPE, vertex1,
00247                                         vertex3, &center_pnt);
00248   d = new_edge_6->measure();
00249   assert(fabs(d-29.56546) < 0.0001);
00250 
00251   offset_edges.clean_out();
00252   offset_edges.append(new_edge_6);
00253   rsl = gmti->offset_curves(offset_edges, output_edge_list, 2.0, v_null );
00254   assert(rsl == CUBIT_FAILURE);
00255 
00256   //HYPERBOLA_CURVE_TYPE
00257   RefEdge* new_edge_7 = gmti->make_RefEdge(HYPERBOLA_CURVE_TYPE, vertex1,
00258                                         vertex3, &center_pnt);
00259   d = new_edge_7->measure();
00260   assert(fabs(d-21.6815) < 0.0001);
00261 
00262   offset_edges.clean_out();
00263   offset_edges.append(new_edge_7);
00264   rsl = gmti->offset_curves(offset_edges, output_edge_list, -2.0, v_null);
00265   assert(rsl == CUBIT_FAILURE);
00266 
00267   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00268                                  num_ents_exported, cubit_version);
00269 
00270   remove(filename);
00271 
00272   free_entities.clean_out();
00273   gti->get_free_ref_entities(free_entities);
00274 
00275   //delete all free vertices and edges
00276   for (int j = free_entities.size(); j--;)
00277   {
00278      gti->delete_RefEntity( free_entities.get_and_step());
00279   }
00280 
00281   return rsl;
00282 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines