cgma
CreateGeometry.cpp
Go to the documentation of this file.
00001 
00010 #undef NDEBUG
00011 #include <cassert>
00012 
00013 #include "stdio.h"
00014 
00015 #include "GeometryQueryTool.hpp"
00016 #include "GeometryModifyTool.hpp"
00017 #include "Body.hpp"
00018 #include "RefEdge.hpp"
00019 #include "RefVertex.hpp"
00020 #include "CubitDefines.h"
00021 #include "CubitBox.hpp"
00022 #include "InitCGMA.hpp"
00023 #include "TestUtilities.hpp"
00024 
00025 #ifndef SRCDIR
00026 # define SRCDIR .
00027 #endif
00028 
00029 #if defined (TEST_OCC)
00030 #  define ENGINE "OCC"
00031 #else
00032 #  error "Which engine to test?"
00033 #endif
00034 
00035 #define STRINGIFY_(X) #X
00036 #define STRINGIFY(X) STRINGIFY_(X)
00037 #define SRCPATH STRINGIFY(SRCDIR) "/"
00038 
00039 // forward declare some functions used and defined later
00040 int CreateGeometry();
00041 
00042 // macro for printing a separator line
00043 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00044 
00045 
00046 // main program - initialize, then send to proper function
00047 int main (int argc, char **argv)
00048 {
00049   CubitStatus s = InitCGMA::initialize_cgma( ENGINE );
00050   if (CUBIT_SUCCESS != s) return 1;
00051 
00052   //Do tests.
00053   int rsl = CreateGeometry();
00054   if (rsl == 1) 
00055      PRINT_INFO("Operation Failed");
00056 
00057   int ret_val = ( CubitMessage::instance()->error_count() );
00058   if ( ret_val != 0 )
00059   {
00060     PRINT_ERROR("Errors found during Mergechk session.\n");
00061   }
00062   else
00063     ret_val = 0;
00064 
00065   return ret_val;
00066   
00067 }
00068 
00069 static int test_brick()
00070 {
00071   Body* brick = GeometryModifyTool::instance()->brick(1,2,4);
00072   if(!brick)
00073   {
00074     printf("failed to make brick\n");
00075     return 1;
00076   }
00077   if(!cubit_box_identical(brick->bounding_box(),
00078         CubitBox(CubitVector(-0.5,-1,-2), CubitVector(0.5,1,2)),
00079         GEOMETRY_RESABS*2.0, true))
00080   {
00081     printf("boxes not identical\n");
00082     return 1;
00083   }
00084   return 0;
00085 }
00086 
00087 static int test_oriented_brick()
00088 {
00089   CubitVector center(1, 2, 4);
00090   CubitVector axes[3] = {
00091     CubitVector(0.707, 0.707, 0),
00092     CubitVector(-0.707, 0.707, 0),
00093     CubitVector(0, 0, 1)
00094   };
00095   CubitVector extension(3, 5, 7);
00096 
00097   Body* brick = GeometryModifyTool::instance()->brick(center, axes, extension);
00098   if(!brick)
00099   {
00100     printf("failed to make brick\n");
00101     return 1;
00102   }
00103   CubitBox comp_box(CubitVector(-4.656854, -3.656854, -3.),
00104           CubitVector(6.656854, 7.656854, 11.));
00105   CubitBox bnd_box = brick->bounding_box();
00106 
00107   bool identical =  cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true);
00108   if (identical)
00109     return 0;
00110 
00111   if( bnd_box < comp_box || bnd_box > comp_box*1.09)
00112   {
00113     printf("boxes not identical\n");
00114     return 1;
00115   }
00116   return 0;
00117 }
00118 
00119 static int test_sphere()
00120 {
00121   Body* sphere = GeometryModifyTool::instance()->sphere(1);
00122   if(!sphere)
00123   {
00124     printf("failed to make sphere\n");
00125     return 1;
00126   }
00127   CubitBox comp_box( CubitVector(-1,-1,-1), CubitVector(1,1,1));
00128   CubitBox bnd_box = sphere->bounding_box();
00129 
00130   bool identical =  cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true);
00131   if (identical)
00132     return 0;
00133 
00134   if( bnd_box < comp_box || bnd_box > comp_box*1.09)
00135   {
00136     printf("boxes not identical\n");
00137     return 1;
00138   }
00139   return 0;
00140 }
00141 
00142 static int test_torus()
00143 {
00144   printf("making torus\n");
00145   Body* torus = GeometryModifyTool::instance()->torus(1, .2);
00146   if(!torus)
00147   {
00148     printf("failed to make torus\n");
00149     return 1;
00150   }
00151   CubitBox comp_box(CubitVector(-1.2,-1.2,-0.2), CubitVector(1.2,1.2,0.2));
00152   CubitBox bnd_box = torus->bounding_box();
00153 
00154   bool identical =  cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true);
00155   if (identical)
00156     return 0;
00157 
00158   if( bnd_box < comp_box || bnd_box > comp_box*1.09)
00159   {
00160     printf("boxes not identical\n");
00161     return 1;
00162   }
00163   return 0;
00164 }
00165 
00166 static int test_planar_sheet()
00167 {
00168   CubitVector axes[2] = {
00169     CubitVector(1,0,0),
00170     CubitVector(.1,.9,0)
00171     };
00172 
00173   Body* body = GeometryModifyTool::instance()->planar_sheet(CubitVector(1,1,1),
00174       axes, 2, 3);
00175 
00176   if(!body)
00177   {
00178     printf("failed to make planar sheet\n");
00179     return 1;
00180   }
00181 
00182   CubitBox comp_box(CubitVector(-0.165647,-0.490826,1.0),
00183         CubitVector(2.165647,2.490826,1.0));
00184   CubitBox bnd_box = body->bounding_box();
00185 
00186   bool identical =  cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true);
00187   if (identical)
00188     return 0;
00189 
00190   if( bnd_box < comp_box || bnd_box > comp_box*1.09)
00191   {
00192     printf("boxes not identical\n");
00193     return 1;
00194   }
00195 
00196 
00197   body = GeometryModifyTool::instance()->planar_sheet(
00198       CubitVector(0,0,0),
00199       CubitVector(1,0,0),
00200       CubitVector(1,1,0),
00201       CubitVector(0,1,.2)
00202       );
00203 
00204   if(body)
00205   {
00206     printf("should have failed to make planar sheet out of non-planar points\n");
00207     return 1;
00208   }
00209 
00210   body = GeometryModifyTool::instance()->planar_sheet(
00211       CubitVector(0,0,0),
00212       CubitVector(0,0,0),
00213       CubitVector(1,1,0),
00214       CubitVector(0,1,0)
00215       );
00216 
00217   if(body)
00218   {
00219     printf("should have failed to make planar sheet with coincident input points\n");
00220     return 1;
00221   }
00222 
00223   return 0;
00224 }
00225 
00226 static int test_arc()
00227 {
00228   RefVertex* pt1 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(0,0,0));
00229   RefVertex* pt2 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(1,1,0));
00230   RefVertex* pt3 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(2,0,0));
00231 
00232   RefEdge* arc = GeometryModifyTool::instance()->create_arc_three(pt1, pt2, pt3, false);
00233   if(!arc)
00234   {
00235     printf("failed to make arc\n");
00236     return 1;
00237   }
00238 
00239   CubitBox comp_box(CubitVector(0, 0, 0), CubitVector(2, 1, 0));
00240   CubitBox bnd_box = arc->bounding_box();
00241 
00242   bool identical =  cubit_box_identical(bnd_box, comp_box, GEOMETRY_RESABS*2.0, true);
00243   if (!identical)
00244   {
00245     if( bnd_box < comp_box || bnd_box > comp_box*1.09)
00246     {
00247       printf("boxes not identical\n");
00248       return 1;
00249     }
00250   }
00251 
00252   // previously free curves at end points must be consumed
00253   DLIList<RefVertex*> all_verts;
00254   GeometryQueryTool::instance()->ref_vertices(all_verts);
00255   if(all_verts.size() != 3)
00256   {
00257     printf("vertices not consumed properly with curve creation\n");
00258     return 1;
00259   }
00260 
00261   GeometryQueryTool::instance()->delete_RefVertex(pt2);
00262 
00263   RefVertex* pt4 = GeometryModifyTool::instance()->make_RefVertex(CubitVector(1,-1,0));
00264   RefEdge* arc2 = GeometryModifyTool::instance()->create_arc_three(pt1, pt4, pt3, true);
00265 
00266   CubitBox comp_box2(CubitVector(0, -1, 0), CubitVector(2, 1, 0));
00267   bnd_box = arc2->bounding_box();
00268 
00269   identical =  cubit_box_identical(bnd_box, comp_box2, GEOMETRY_RESABS*2.0, true);
00270   if (identical)
00271     return 0;
00272 
00273   if( bnd_box < comp_box2 || bnd_box > comp_box2*1.09)
00274   {
00275     printf("boxes not identical\n");
00276     return 1;
00277   }
00278 
00279   all_verts.clean_out();
00280   GeometryQueryTool::instance()->ref_vertices(all_verts);
00281   if(all_verts.size() != 4)
00282   {
00283     printf("vertices not consumed properly with curve creation\n");
00284     return 1;
00285   }
00286 
00287   return 0;
00288 }
00289 
00290 int CreateGeometry()
00291 {
00292   int ret = 0;
00293 
00294   ret |= test_brick();
00295   GeometryQueryTool::instance()->delete_geometry();
00296 
00297   ret |= test_oriented_brick();
00298   GeometryQueryTool::instance()->delete_geometry();
00299 
00300   ret |= test_sphere();
00301   GeometryQueryTool::instance()->delete_geometry();
00302 
00303   ret |= test_torus();
00304   GeometryQueryTool::instance()->delete_geometry();
00305 
00306   ret |= test_planar_sheet();
00307   GeometryQueryTool::instance()->delete_geometry();
00308 
00309   ret |= test_arc();
00310   GeometryQueryTool::instance()->delete_geometry();
00311 
00312   return ret;
00313 }
00314 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines