cgma
makept.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 > 2 )
00057   {
00058     PRINT_ERROR("Errors found during Mergechk session.\n");
00059   }
00060   return ret_val-2;
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   //test for creating prisms
00096   Body* prism1 = gmti->prism(10, 7, 5, 2); 
00097   Body* prism2 = gmti->prism(10, 7, 5, 5);
00098   Body* prism3 = gmti->prism(10, 8, 5, 2);
00099   Body* prism4 = gmti->prism(10, 8, 5, 5);
00100   CubitStatus rsl = CUBIT_SUCCESS;
00101   DLIList<RefEntity*> ref_entity_list;
00102   int num_ents_exported=0;
00103   const CubitString cubit_version="10.2";
00104   const char * filename = "prism.occ";
00105   const char * filetype = "OCC";
00106 
00107   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00108                                  num_ents_exported, cubit_version);
00109 
00110   remove(filename);
00111 
00112   CubitBox box1 = prism1->bounding_box();  
00113   CubitVector min(-5.0, -1.949, -5.0);
00114   CubitVector max(4.504, 1.949, 5.0);
00115   CubitBox test_box(min, max);
00116   assert(box1 >= test_box);
00117   test_box *= 1.02;
00118   assert( box1 <= test_box );
00119   
00120   box1 = prism2->bounding_box();
00121   min.set(-5.0, -4.874, -5.0);
00122   max.set(4.504, 4.874, 5.0);
00123   test_box.reset(min, max);
00124   assert(box1 >= test_box);
00125   test_box *= 1.02;
00126   assert( box1 <= test_box );
00127 
00128   box1 = prism3->bounding_box();
00129   min.set(-4.619, -1.847, -5.0);
00130   max.set(4.619, 1.847, 5.0);
00131   test_box.reset(min, max);
00132   assert(box1 >= test_box);
00133   test_box *= 1.02;
00134   assert( box1 <= test_box );
00135 
00136   box1 = prism4->bounding_box();
00137   min.set(-4.619, -4.619, -5.0);
00138   max.set(4.619, 4.619, 5.0);
00139   test_box.reset(min, max);
00140   assert(box1 >= test_box);
00141   test_box *= 1.02;
00142   assert( box1 <= test_box );
00143 
00144   DLIList<Body*> bodies;
00145   gti->bodies(bodies);
00146   gti->delete_Body(bodies);
00147 
00148   //test for creating pyramids
00149   Body* pyramid1 = gmti->pyramid(10, 7, 5, 2, 2);
00150   Body* pyramid2 = gmti->pyramid(10, 7, 5, 5, 2);
00151   Body* pyramid3 = gmti->pyramid(10, 8, 5, 2, 2);
00152   Body* pyramid4 = gmti->pyramid(10, 8, 5, 5, 2);
00153   Body* pyramid5 = gmti->pyramid(10, 4, 5, 2, 0);
00154   Body* pyramid6 = gmti->pyramid(10, 4, 5, 5, 0);
00155   ref_entity_list.clean_out();
00156   num_ents_exported=0;
00157   filename = "pyramid.occ";
00158 
00159   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00160                                  num_ents_exported, cubit_version);
00161 
00162   remove(filename);
00163   box1 = pyramid1->bounding_box();
00164   min.set(-5.0, -1.949, -5.0);
00165   max.set(4.504, 1.949, 5.0);
00166   test_box.reset(min, max);
00167   assert(box1 >= test_box); 
00168   test_box *= 1.02;
00169   assert( box1 <= test_box );
00170 
00171   box1 = pyramid2->bounding_box();
00172   min.set(-5.0, -4.874, -5.0);
00173   max.set(4.504, 4.874, 5.0);
00174   test_box.reset(min, max);
00175   assert(box1 >= test_box);
00176   test_box *= 1.02;
00177   assert( box1 <= test_box );
00178 
00179   box1 = pyramid3->bounding_box();
00180   min.set(-4.619, -1.847, -5.0);
00181   max.set(4.619, 1.847, 5.0);
00182   test_box.reset(min, max);
00183   assert(box1 >= test_box);
00184   test_box *= 1.02;
00185   assert( box1 <= test_box );
00186 
00187   box1 = pyramid4->bounding_box();
00188   min.set(-4.619, -4.619, -5.0);
00189   max.set(4.619, 4.619, 5.0);
00190   test_box.reset(min, max);
00191   assert(box1 >= test_box);
00192   test_box *= 1.02;
00193   assert( box1 <= test_box ); 
00194 
00195   box1 = pyramid5->bounding_box();
00196   min.set(-3.535, -1.414, -5.0);
00197   max.set(3.535, 1.414, 5.0);
00198   test_box.reset(min, max);
00199   assert(box1 >= test_box);
00200   test_box *= 1.02;
00201   assert( box1 <= test_box );
00202 
00203   box1 = pyramid6->bounding_box(); 
00204   min.set(-3.535, -3.535, -5.0);
00205   max.set(3.535, 3.535, 5.0);
00206   test_box.reset(min, max);
00207   assert(box1 >= test_box);
00208   test_box *= 1.02;
00209   assert( box1 <= test_box );
00210 
00211   bodies.clean_out();
00212   gti->bodies(bodies);
00213   gti->delete_Body(bodies);
00214 
00215   //Create sphere
00216   RefEntity* sphereEnt= GeometryModifyTool::instance()->sphere(1.5);
00217   sphereEnt->entity_name("sphere");
00218 
00219   box1 = sphereEnt->bounding_box();
00220   min.set(-1.5,-1.5,-1.5);
00221   max.set(1.5,1.5,1.5);
00222   test_box.reset(min, max);
00223   assert(box1 >= test_box);
00224   test_box *= 1.02;
00225   assert( box1 <= test_box );
00226 
00227   //TopoDS_Compound* objOCC;
00228   Body* tmpBd = GeometryQueryTool::instance()->get_first_body();
00229   DLIList<RefVertex*> vertices;
00230   tmpBd->ref_vertices(vertices);
00231   DLIList<RefEdge*> ref_edges;
00232   tmpBd->ref_edges(ref_edges);
00233   DLIList<RefFace*> sphere_faces;
00234   tmpBd->ref_faces(sphere_faces);
00235   for(int i = 0; i < ref_edges.size(); i++) 
00236   {
00237     vertices.clean_out();
00238     ref_edges.get()->ref_vertices(vertices);
00239     ref_edges.get_and_step()->measure();
00240   }
00241   //BodySM* tmpBdSM = tmpBd->get_body_sm_ptr();
00242   //objOCC = ( (OCCBody*) tmpBdSM )->get_TopoDS_Shape(); //Opencascade Object
00243   //OCCDrawTool::instance()->draw_TopoDS_Shape(objOCC, 200);
00244 
00245   bodies.clean_out();
00246   gti->bodies(bodies);
00247   DLIList<RefEntity*>  free_entities;
00248   gti->get_free_ref_entities(free_entities);
00249   gti->delete_Body(bodies);
00250      
00251   for (int j = free_entities.size(); j--;)
00252   {
00253      gti->delete_RefEntity( free_entities.get_and_step());
00254   }
00255   // Read in the geometry from files specified on the command line
00256   const char *argv = "66_shaver3.brep";
00257   CubitStatus status = read_geometry(1, &argv);
00258   if (status == CUBIT_FAILURE) exit(1);
00259 
00260   const char *argv2 = "62_shaver1.brep";
00261   status = read_geometry(1, &argv2);
00262   if (status == CUBIT_FAILURE) exit(1);
00263 
00264   const char *argv3 = "72_shaver6.brep";
00265   status = read_geometry(1, &argv3);
00266   if (status == CUBIT_FAILURE) exit(1);
00267    
00268   DLIList<Body*> test_bodies;
00269   gti->bodies(test_bodies);
00270   CubitVector vi, vii;
00271   vi = test_bodies.get()->center_point(); 
00272 
00273   CubitVector axis(10,0,0);
00274 
00275   DLIList<Body*> bods;
00276   bods.append(test_bodies.get());
00277   gti->translate(bods,axis);
00278   vii = test_bodies.get()->center_point();
00279   assert(vii - vi == axis);
00280   // After parellel move, center point moved by x (10)
00281 
00282   CubitVector vector1(10,10,10);
00283   CubitVector vector2(-10,-10,10);
00284   CubitVector vector3(10, -10, 10);
00285   free_entities.clean_out();
00286 
00287   // Make two vertices.
00288   gmti->make_RefVertex(vector1,5);
00289   gmti->make_RefVertex(vector2,5);
00290   gmti->make_RefVertex(vector3,5);
00291   gti->get_free_ref_entities(free_entities);
00292 
00293   ref_entity_list.clean_out();
00294   num_ents_exported=0;
00295   filename = "point.occ";
00296   filetype = "OCC";
00297   
00298   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype, 
00299                                 num_ents_exported, cubit_version);
00300  
00301   remove(filename);
00302   //check for vertex
00303   bodies.clean_out();
00304   gti->bodies(bodies);
00305   free_entities.clean_out();// get_free_ref_entities directly append
00306   //without checking for duplicates, so clean_out first. 
00307   gti->get_free_ref_entities(free_entities);
00308  
00309   RefVertex* vertex1 = CAST_TO(free_entities.step_and_get(),RefVertex);
00310   RefVertex* vertex2 = CAST_TO(free_entities.step_and_get(),RefVertex);
00311   RefVertex* vertex3 = CAST_TO(free_entities.step_and_get(),RefVertex); 
00312   CubitBoolean is_equal = gti->
00313         about_spatially_equal(vertex1,vertex2);
00314   assert(is_equal == CUBIT_FAILURE);
00315  
00316   double d;
00317   gti->entity_entity_distance(vertex1,vertex2,vi, vii,d);
00318   assert(d > 28.284 && d < 28.2843);
00319   // distance (d) between vertex1,vertex2.  
00320  
00321   //check for body
00322   d = bodies.get()->measure(); 
00323   assert( d > 2237.75 && d < 2237.752);
00324   // first body's volume.
00325 
00326   vi = bodies.get()->center_point();
00327   //first body's bounding box's center point.
00328   min.set(6.67, 0, 14.58);
00329   assert(vi.distance_between(min) < 0.01 );
00330  
00331   CubitBox box = bodies.get()->bounding_box();
00332   min.set(-11.5894,-11.58944, 7.79849);
00333   max.set(24.9303,11.58944,21.3615);
00334   test_box.reset(min,max);
00335   assert(box >= test_box);
00336   test_box *= 1.01;
00337   assert(box <= test_box);
00338   //first body's bounding box.
00339 
00340   gti->entity_entity_distance(gti->get_first_ref_volume(), vertex2,vi, vii,d);
00341   //first body and vertex2 's minimum distance(d) and locations for the minimum.
00342   assert(d <3.64214  && d > 3.64213);
00343 
00344   // test create a Compound body.
00345   test_bodies.clean_out();
00346   gti->bodies(test_bodies);
00347 
00348   bodies.clean_out();
00349   gmti->unite(test_bodies, bodies );
00350   assert(bodies.size() == 1);
00351 
00352   Body* CompBody = bodies.get();
00353   BodySM* body = CompBody->get_body_sm_ptr();
00354   OCCBody* occ_body = CAST_TO(body, OCCBody);
00355   occ_body->mass_properties(vi, d);
00356 
00357   bodies.last();
00358   vi = bodies.get()->center_point();
00359   CubitVector ref_point(0,0,0);
00360   gti->reflect(bodies, ref_point, axis);
00361   vii = bodies.pop()->center_point();
00362   assert(vi.x() == -vii.x() && vi.y() == vii.y() && vi.z() == vii.z());
00363   // After reflection, only x value should change.
00364 
00365   vi = CompBody->center_point();
00366   double volume1 = CompBody->measure();
00367   gti->scale(CompBody,vi, 2);
00368   vii = CompBody->center_point();
00369   double volume2 = CompBody->measure();
00370   assert(fabs(volume2 - 8 * volume1) < 0.0000001);
00371   assert(vii.distance_between(vi) < 0.0000001);
00372   // After scale, center point not moved and volume increased by 8 times 
00373 
00374   vi = CompBody->center_point();
00375   bods.clean_out();
00376   bods.append(CompBody);
00377   gti->translate(bods,axis);
00378   vii =CompBody->center_point();
00379   assert(axis.about_equal(vii - vi) );
00380   // After parellel move, center point moved by x (10)
00381 
00382   vi = CompBody->center_point();
00383   gti->rotate(bods, axis, 3.14/6);
00384   vii = CompBody->center_point();
00385   assert(vi.x() == vii.x() && vi.y() != vii.y() && vi.z() != vii.z());
00386   // After rotation, center point changed in y and z value.
00387 
00388   double d_;
00389   occ_body->mass_properties(vii, d_);
00390   assert(fabs(d_ - 8*d) < 0.0001);
00391   //true center and volume, volume should be 8 times of the original one.
00392 
00393   vi = occ_body->get_bounding_box().center(); 
00394   // bounding box center.
00395   assert(vi != vii);
00396 
00397   //check for surface
00398   DLIList<OCCSurface*> surfaces;
00399   occ_body->get_all_surfaces(surfaces);
00400   assert(surfaces.size() == 981);
00401   OCCSurface* surface = NULL;
00402   GeometryType type;
00403 
00404   DLIList<RefFace*> ref_faces;
00405   gti->ref_faces(ref_faces);
00406   for(int i = 0; i < ref_faces.size(); i++)
00407   {
00408     surface = CAST_TO(ref_faces.step_and_get()->get_surface_ptr(), OCCSurface);
00409     type = surface->geometry_type();
00410     if (type == CONE_SURFACE_TYPE)
00411       break;
00412   }
00413   RefFace* ref_face = ref_faces.get();
00414   box = surface->bounding_box();
00415   // bounding box
00416 
00417   //make a new refface out of existing refface.
00418   RefFace* new_face = gmti->make_RefFace(ref_face);
00419 
00420   ref_entity_list.clean_out();
00421   ref_entity_list.append(new_face);
00422   filename = "surface.brep";
00423   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00424                                  num_ents_exported, cubit_version);
00425   remove(filename);
00426 
00427   DLIList<DLIList<RefEdge*> > ref_edge_loops;
00428   new_face->ref_edge_loops(ref_edge_loops);
00429 
00430   DLIList<RefEdge*> ref_edge_list;
00431   ref_edge_list = ref_edge_loops.get();
00432 
00433   //RefVertex* start = NULL;
00434   //RefVertex* end = NULL;
00435   for (int i = 0; i < ref_edge_list.size(); i++)
00436   {
00437     RefEdge * edge = ref_edge_list.get_and_step();
00438     if (edge) {
00439       //double d = edge->measure();
00440       //start = edge->start_vertex();
00441       //end = edge->end_vertex();
00442     }
00443   }
00444 
00445   RefFace* new_face2 = gmti->make_RefFace(CONE_SURFACE_TYPE, 
00446                          ref_edge_list, CUBIT_TRUE, new_face, CUBIT_TRUE);
00447   assert(new_face2 == NULL);
00448   //2 Errors here for failing making a surface. negtive test here.
00449 
00450   bodies.clean_out();
00451   gti->bodies(bodies);
00452   //translate the new face by (20,20,20)
00453   for(int i = 1; i <= bodies.size(); i++)
00454   {
00455      bodies.step();
00456      if( i != 2)
00457         continue;
00458      Body * entity = bodies.get();
00459      vi = entity->center_point();
00460      bods.clean_out();
00461      bods.append(entity);
00462      gti->translate(bods, i*vector1);
00463      vii = entity->center_point();
00464   }
00465 
00466   //center point should moved by (20,20,20) compared with the original one below
00467   assert(fabs(vi.distance_between(vii)-vector1.length()*2) < 0.0001);
00468 
00469   double area = ref_face->measure();
00470   assert(fabs(area - 45.57587) < 0.0001);
00471 
00472   double lower, upper;
00473   ref_face->get_param_range_U(lower, upper);
00474   assert(fabs(lower) < 0.0001 && fabs(upper - 1.57079) < 0.0001);
00475 
00476   ref_face->get_param_range_V(lower, upper);
00477   assert(fabs(lower - 1.81177) < 0.01 && fabs(upper - 6.64752) < 0.01 );
00478   // get surface V direction boundaries. here it's (24,24.5)
00479 
00480   double u = 1;      
00481   double v = 3;
00482   vi = ref_face->position_from_u_v(u,v);
00483   vii.set(27.88436, 37.66955, 127.69491);
00484   assert(fabs(vi.distance_between(vii)) < 0.0001);
00485   // get location on surface for it's u,v
00486 
00487   ref_face->u_v_from_position(vi, u, v);
00488   assert(fabs(u - 1) < 0.0001 && fabs(v - 3) < 0.00001);
00489   // get (u,v) from this vi.
00490 
00491   CubitBoolean periodic = ref_face->is_periodic();
00492   assert(periodic == CUBIT_TRUE);
00493   // found if surface is periodic.
00494 
00495   double p = 0; //period
00496   periodic = ref_face->is_periodic_in_U(p); 
00497   assert(periodic == CUBIT_TRUE  );
00498   assert(fabs(p - 6.28318) < 0.0001);
00499   // found if surface is periodic in U and its period.
00500 
00501   periodic = ref_face->is_periodic_in_V(p);
00502   assert(periodic == CUBIT_FALSE );
00503 
00504   //All OCC entities are parametric.
00505 
00506   CubitBoolean closed = ref_face->is_closed_in_U();
00507   assert(closed == CUBIT_FALSE);
00508 
00509   closed = ref_face->is_closed_in_V();
00510   assert(closed == CUBIT_FALSE);
00511 
00512   CubitPointContainment pc = ref_face->point_containment(7,25);
00513   assert(pc == CUBIT_PNT_OUTSIDE);
00514 
00515   CubitPointContainment pc2 = ref_face->point_containment(1,3);
00516   assert(pc2 == CUBIT_PNT_INSIDE);
00517 
00518   ref_edge_loops.clean_out();
00519   //int num_loops = ref_face->ref_edge_loops(ref_edge_loops);
00520   DLIList<RefEdge*> ref_edges1;
00521   ref_edges1 = ref_edge_loops.get();
00522   RefEdge* edge1 = ref_edges1.pop();
00523   RefEdge* edge2 = ref_edges1.pop();
00524   double angle = edge2->angle_between(edge1, ref_face);
00525   assert(fabs(angle - 4.71238) < 0.001);
00526 
00527   //test for curve
00528   CubitVector c_point, tangent, center;
00529 
00530   //make all kinds of curves.
00531   CubitVector center_pnt(0,0,10);
00532   DLIList<CubitVector*> list;
00533   CubitVector center_pnt1(5,8,10);
00534   CubitVector center_pnt2(1,2,10);
00535   CubitVector center_pnt3(-2,-3.5,10);
00536   CubitVector start_pt = vertex1->coordinates();
00537   CubitVector end_pt = vertex2->coordinates();
00538   list.append(&start_pt);
00539   list.append(&center_pnt1);
00540   list.append(&center_pnt2);
00541   list.append(&center_pnt);
00542   list.append(&center_pnt3);
00543   list.append(&end_pt);
00544   RefEdge* new_edge_1 = gmti->make_RefEdge(SPLINE_CURVE_TYPE, vertex1,
00545                                           vertex2, list);
00546   d = new_edge_1->measure();
00547   assert(fabs(d - 29.55)<0.01);
00548   CubitVector closest_location;
00549   new_edge_1->closest_point_trimmed(center_pnt1, closest_location);
00550   assert(center_pnt1.distance_between(closest_location) < 1.E-6);
00551   new_edge_1->closest_point_trimmed(center_pnt2,closest_location);
00552   assert(center_pnt2.distance_between(closest_location) < 1.E-6);
00553 
00554   //Spline with points and tangents
00555   DLIList<CubitVector*> tangents;
00556   for (int i = 0; i< 6; i++)
00557     tangents.append(NULL);
00558 
00559   GeometryModifyEngine* gme = gmti->get_engine(new_edge_1);
00560   Curve* new_curve = gme->make_Curve(list, tangents);
00561   RefEdge * new_edge_11 = gti->make_free_RefEdge(new_curve);
00562   d = new_edge_11->measure();
00563   assert(fabs(d - 29.5517) <0.001);
00564 
00565   CubitVector v11(-1,-1,0);
00566   CubitVector v12(3,1,0);
00567   tangents.clean_out();
00568   tangents.append(&v11);
00569   for (int i = 0; i< 4; i++)
00570     tangents.append(NULL);
00571   tangents.append(&v12);
00572 
00573   new_curve = gme->make_Curve(list, tangents);
00574   RefEdge * new_edge_12 = gti->make_free_RefEdge(new_curve);
00575   d = new_edge_12->measure(); 
00576   assert(fabs(d - 34.33967) < 0.0001);
00577 
00578   num_ents_exported=0;
00579   filename = "BsplineCurve.occ";
00580   ref_entity_list.clean_out();
00581   ref_entity_list.append(new_edge_11);
00582   ref_entity_list.append(new_edge_12);
00583   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00584                                  num_ents_exported, cubit_version);
00585   remove(filename);
00586 
00587   //straight line
00588   RefEdge* new_edge_2 = gmti->make_RefEdge(STRAIGHT_CURVE_TYPE, vertex1,
00589                                         vertex2, &center_pnt);
00590   d = new_edge_2->measure();
00591   assert(fabs(d - 28.284) <0.001);
00592 
00593   vi.set(-9.374537, 7.2082, 51.8845);
00594   new_edge_2->closest_point_trimmed(vi, c_point);
00595   vii.set(-1.083148, -1.083148, 10);
00596   assert(vii.distance_between( c_point ) < 0.0001);
00597 
00598   //arc curve
00599   RefEdge* new_edge_3 = gmti->make_RefEdge(ARC_CURVE_TYPE, vertex1,
00600                                         vertex3, &center_pnt);
00601   d = new_edge_3->measure();
00602   assert(fabs(d - 31.4159) < 0.0001);
00603   new_edge_3->closest_point_trimmed(vi, c_point);
00604   vii.set(0.62764, 3.486959, 10);
00605   assert(vii.distance_between( c_point ) < 0.0001);
00606 
00607   //ellipse curve
00608   CubitVector ellps_cnt(0.4, 2.8, 10);
00609   RefEdge* new_edge_4 = gmti->make_RefEdge(ELLIPSE_CURVE_TYPE, vertex1,
00610                                         vertex3, &ellps_cnt);
00611   d = new_edge_4->measure();
00612   assert(fabs(d - 66.31) < 0.01);
00613   new_edge_4->closest_point_trimmed(vi, c_point);
00614   vii.set(-13.163, 7.367 , 10);
00615   assert(vii.distance_between( c_point ) < 0.001);
00616 
00617   RefEdge* new_edge_5 = gmti->make_RefEdge(ELLIPSE_CURVE_TYPE, vertex3,
00618                                         vertex1, &ellps_cnt);
00619   d = new_edge_5->measure();
00620   assert(fabs(d-22.103) < 0.001);
00621 
00622 
00623   filename = "ellipses.occ";
00624   ref_entity_list.clean_out();
00625   ref_entity_list.append(new_edge_5);
00626   ref_entity_list.append(new_edge_4);
00627  
00628   rsl = CubitCompat_export_solid_model(ref_entity_list, filename, filetype,
00629                                  num_ents_exported, cubit_version);
00630   remove(filename);
00631 
00632   new_edge_5->closest_point_trimmed(vi, c_point);
00633   vii.set(10, -10, 10);
00634   assert(vii.distance_between( c_point ) < 0.0001);
00635 
00636   //PARABOLA_CURVE_TYPE
00637   RefEdge* new_edge_6 = gmti->make_RefEdge(PARABOLA_CURVE_TYPE, vertex1,
00638                                         vertex3, &center_pnt);
00639   d = new_edge_6->measure();
00640   assert(fabs(d-29.56546) < 0.0001);
00641   new_edge_6->closest_point_trimmed(vi, c_point);
00642   vii.set(0.58077, 2.41, 10);
00643   assert(vii.distance_between( c_point ) < 0.0001);
00644 
00645   //HYPERBOLA_CURVE_TYPE
00646   RefEdge* new_edge_7 = gmti->make_RefEdge(HYPERBOLA_CURVE_TYPE, vertex1,
00647                                         vertex3, &center_pnt);
00648   d = new_edge_7->measure();
00649   assert(fabs(d-21.6815) < 0.0001);
00650 
00651   new_edge_7->closest_point_trimmed(vi, c_point);
00652   vii.set( 6.5835, 2.8855, 10);
00653   assert(vii.distance_between( c_point ) < 0.0001);
00654 
00655   //delete all free vertices and edges
00656   for (int j = free_entities.size(); j--;)
00657   {
00658      gti->delete_RefEntity( free_entities.get_and_step());
00659   }
00660 
00661   ref_edges.clean_out();
00662   gti->ref_edges(ref_edges);
00663 
00664   //make a new refedge out of existing refedge.
00665   RefEdge* ref_edge = ref_edges.step_and_get();
00666 
00667   //RefEdge* new_edge = gmti->make_RefEdge(ref_edge);
00668 
00669   free_entities.clean_out();
00670   gti->get_free_ref_entities(free_entities);
00671 
00672   //translate the new curve by (10,10,10)
00673   RefEntity * entity = free_entities.get();
00674   box = entity->bounding_box();
00675   DLIList<BasicTopologyEntity*> btes;
00676   btes.append((BasicTopologyEntity*)entity);
00677   gti->translate(btes, vector1);
00678   test_box = entity->bounding_box();
00679   assert(fabs(test_box.minimum().distance_between( box.minimum()) -vector1.length())<0.001 &&
00680          fabs(test_box.maximum().distance_between( box.maximum()) -vector1.length())< 0.001);
00681   //general query
00682   DLIList<OCCCurve*> curves;
00683   CAST_TO(body, OCCBody)->get_all_curves(curves);
00684 
00685   OCCCurve *curve = NULL;
00686   for(int i = 0; i < curves.size(); i ++)
00687   {
00688     curve = curves.step_and_get();
00689     type = curve->geometry_type();
00690     if(type == ARC_CURVE_TYPE)
00691       break;
00692   }
00693 
00694   box = curve-> bounding_box();
00695   min.set(26.4388, 41.2872, 124.4865);
00696   max.set(32.9331, 41.3465, 130.9806);
00697   assert(min.distance_between(box.minimum()) < 0.001 &&
00698          max.distance_between(box.maximum()) < 0.001);
00699   // bounding box
00700 
00701   d = ref_edge->measure();
00702   assert(fabs(d - 21.6815) < 0.001);
00703 
00704   ref_edge->get_param_range(lower,upper);
00705   assert(lower + 1.06127 <= 0.0001 && fabs(upper-1.06127) < 0.001);
00706   // paremeter range.
00707 
00708   d = ref_edge->length_from_u(lower,upper);
00709   assert(fabs(d - 21.6815) < 0.001);
00710 
00711   d = ref_edge->length_from_u(lower/2+upper/2, upper);
00712   assert(fabs(d-10.8407) < 0.0001);
00713   // half curve length.
00714 
00715   periodic = ref_edge->is_periodic(p);
00716   assert(periodic == CUBIT_FALSE);
00717   // if curve is periodic and its period (p). here it's not.
00718 
00719   ref_edge->position_from_u(lower/2+upper/2, vi);
00720   // middle point.
00721 
00722   u = ref_edge->u_from_position(vi); 
00723   assert(fabs(u ) < 0.001);
00724   // middle point's u value.
00725 
00726   //double radius;
00727   CubitVector curvature1_ptr;
00728   ref_edge->closest_point(vi, c_point, &tangent, & curvature1_ptr);
00729   vii.set(0, -1, 0);
00730   assert(tangent.distance_between(vii) < 0.001);
00731   // Closed point on middle point.
00732 
00733   ref_edge->tangent(vi, tangent);
00734   assert(tangent.distance_between(vii) < 0.001);
00735   // tangent at middle point.
00736 
00737   ref_edge->get_point_direction(c_point, tangent);
00738   assert(tangent.distance_between(vii) < 0.001);
00739   // double check tangent
00740 
00741   pc = ref_edge->point_containment(c_point);
00742   assert(pc == CUBIT_PNT_INSIDE);
00743   // middle point should be on the curve.
00744 
00745   //delete all entities
00746   gti->delete_Body(bodies);
00747 
00748   for (int j = free_entities.size(); j--;)
00749     {
00750       gti->delete_RefEntity( free_entities.get_and_step());
00751     }
00752 
00753   return rsl;
00754 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines