cgma
AngleCalc.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 "RefEdge.hpp"
00018 #include "RefVertex.hpp"
00019 #include "CoEdge.hpp"
00020 #include "RefFace.hpp"
00021 #include "CubitDefines.h"
00022 #include "CubitBox.hpp"
00023 #include "InitCGMA.hpp"
00024 #include "TestUtilities.hpp"
00025 
00026 #ifndef SRCDIR
00027 # define SRCDIR .
00028 #endif
00029 
00030 
00031 #if defined (TEST_OCC)
00032 #  define ENGINE "OCC"
00033 #else
00034 #  error "Which engine to test?"
00035 #endif
00036 
00037 #define STRINGIFY_(X) #X
00038 #define STRINGIFY(X) STRINGIFY_(X)
00039 #define SRCPATH STRINGIFY(SRCDIR) "/"
00040 
00041 // forward declare some functions used and defined later
00042 int AngleCalc();
00043 
00044 // macro for printing a separator line
00045 #define PRINT_SEPARATOR   PRINT_INFO("=======================================\n");
00046 
00047 
00048 // main program - initialize, then send to proper function
00049 int main (int argc, char **argv)
00050 {
00051   CubitStatus s = InitCGMA::initialize_cgma( ENGINE );
00052   if (CUBIT_SUCCESS != s) return 1;
00053 
00054   //Do tests.
00055   int rsl = AngleCalc();
00056   if (rsl == 1) 
00057      PRINT_INFO("Operation Failed");
00058 
00059   int ret_val = ( CubitMessage::instance()->error_count() );
00060   if ( ret_val != 0 )
00061   {
00062     PRINT_ERROR("Errors found during Mergechk session.\n");
00063   }
00064   else
00065     ret_val = 0;
00066 
00067   return ret_val;
00068   
00069 }
00070 
00071 int AngleCalc()
00072 {
00073   Body* brick = GeometryModifyTool::instance()->brick(1,2,4);
00074   if(!brick)
00075   {
00076     printf("failed to make brick\n");
00077     return 1;
00078   }
00079 
00080   // compute angles at each vertex and be sure they are 90 degrees
00081   DLIList<RefFace*> faces;
00082   GeometryQueryTool::instance()->ref_faces(faces);
00083 
00084   bool errors = false;
00085 
00086   for(int i=0; i<faces.size(); i++)
00087   {
00088     // get loops
00089     DLIList<DLIList<CoEdge*> > loops;
00090     RefFace* face = faces.get_and_step();
00091     face->co_edge_loops(loops);
00092 
00093     for(int j=0; j<loops.size(); j++)
00094     {
00095       for(int k=0; k<loops[j].size(); k++)
00096       {
00097         CoEdge* edge1 = loops[j].next(k);
00098         CoEdge* edge2 = loops[j].next(k+1);
00099 
00100         double angle = GeometryQueryTool::instance()->geometric_angle(edge1, edge2);
00101         angle = angle * (180/CUBIT_PI);
00102         if(fabs(90 - angle) > 0.01)
00103         {
00104           RefEdge* redge1 = edge1->get_ref_edge_ptr();
00105           RefEdge* redge2 = edge2->get_ref_edge_ptr();
00106           RefVertex* vert = redge1->common_ref_vertex(redge2);
00107 
00108           printf("wrong angle at vertex (%f) %i with surface %i\n",
00109               angle, vert->id(), face->id());
00110           errors = true;
00111         }
00112       }
00113     }
00114   }
00115 
00116   return errors ? 1 : 0;
00117 }
00118 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines