[cgma-dev] r2224 - in cgm/trunk: geom/OCC itaps

janehu at mcs.anl.gov janehu at mcs.anl.gov
Tue Nov 11 15:16:07 CST 2008


Author: janehu
Date: 2008-11-11 15:16:07 -0600 (Tue, 11 Nov 2008)
New Revision: 2224

Modified:
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/itaps/iGeom.h
   cgm/trunk/itaps/iGeom_CGMA.cc
   cgm/trunk/itaps/testgeom.cc
Log:
When geometryQueryTool passes angle for rotate, it passed degree instead of radian; changed to check for center and volume in checking cylinder and torus for OCC engine because OCC returns slightly large bounding box for non-planar surfaces.

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-11-07 22:02:32 UTC (rev 2223)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2008-11-11 21:16:07 UTC (rev 2224)
@@ -2422,7 +2422,9 @@
 }
 CubitStatus OCCQueryEngine::rotate( BodySM* body, const CubitVector& v, double a )
 {
+  // a is in degree.
   OCCBody* occ_bod = dynamic_cast<OCCBody*>(body);
+  a *= CUBIT_PI/180;
   return occ_bod ? occ_bod->rotate( v.x(), v.y(), v.z(), a ) : CUBIT_FAILURE;
 }
 CubitStatus OCCQueryEngine::scale( BodySM* body, double factor )

Modified: cgm/trunk/itaps/iGeom.h
===================================================================
--- cgm/trunk/itaps/iGeom.h	2008-11-07 22:02:32 UTC (rev 2223)
+++ cgm/trunk/itaps/iGeom.h	2008-11-11 21:16:07 UTC (rev 2224)
@@ -63,7 +63,7 @@
 
 #include "iBase.h"
 #include "iGeom_protos.h"
-
+class CubitVector;
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -2082,6 +2082,7 @@
                           double x,
                           double y,
                           double z,
+                          CubitVector* center,
                           iBase_EntityHandle* geom_entity,
                           int* err );
 
@@ -2092,6 +2093,7 @@
                              double height,
                              double major_rad,
                              double minor_rad,
+                             CubitVector* center,
                              iBase_EntityHandle* geom_entity,
                              int* err );
 
@@ -2101,6 +2103,7 @@
   void iGeom_createTorus( iGeom_Instance,
                           double major_rad,
                           double minor_rad,
+                          CubitVector* center,
                           iBase_EntityHandle* geom_entity,
                           int* err );
 

Modified: cgm/trunk/itaps/iGeom_CGMA.cc
===================================================================
--- cgm/trunk/itaps/iGeom_CGMA.cc	2008-11-07 22:02:32 UTC (rev 2223)
+++ cgm/trunk/itaps/iGeom_CGMA.cc	2008-11-11 21:16:07 UTC (rev 2224)
@@ -22,11 +22,12 @@
  */
 #include "iGeom.h"
 #include "InitCGMA.hpp"
+#include "CastTo.hpp"
 
 #include <iostream>
 #include <math.h>
 #include "GeometryQueryTool.hpp"
-
+#include "DLIList.hpp"
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -5197,6 +5198,7 @@
                    /*in*/ double x,
                    /*in*/ double y,
                    /*in*/ double z,
+                   /*out*/ CubitVector* center, 
                    /*out*/ iBase_EntityHandle *geom_entity,
                    int* err)
 {
@@ -5219,7 +5221,7 @@
   if (NULL == *geom_entity) {
     RETURN(iBase_FAILURE);
   }
-  
+  *center = temp_body->center_point();  
   RETURN(iBase_SUCCESS);
 }
           
@@ -5228,6 +5230,7 @@
                       /*in*/ double height,
                       /*in*/ double major_rad,
                       /*in*/ double minor_rad,
+                      /*out*/ CubitVector* center,
                       /*out*/ iBase_EntityHandle *geom_entity,
                       int* err)
 {
@@ -5236,11 +5239,34 @@
     gmt->cylinder(height, major_rad, tmp_minor, major_rad);
   *geom_entity = temp_body;
 
-
   if (NULL == *geom_entity) {
     RETURN(iBase_FAILURE);
   }
-  
+  Body *body = NULL;
+  body = CAST_TO(temp_body,Body);
+  DLIList<RefFace*> ref_faces;
+  body->ref_faces(ref_faces);
+  DLIList <CubitVector*> centers;
+  int i;
+  for ( i = 0; i < ref_faces.size(); i ++)
+  {
+    if (ref_faces.get()->num_ref_edges() > 1)
+    {
+      ref_faces.step();
+      continue;
+    }
+    CubitVector v = ref_faces.get_and_step()->center_point();
+    CubitVector *new_v = new CubitVector(v);
+    centers.append(new_v);
+  }
+
+  for( i = 0; i < centers.size(); i++)
+  {
+    *center += *centers.get() ;
+    delete centers.get();
+    centers.step();
+  }
+  *center /= i;
   RETURN(iBase_SUCCESS);
 }
           
@@ -5248,6 +5274,7 @@
 iGeom_createTorus (iGeom_Instance instance,
                    /*in*/ double major_rad,
                    /*in*/ double minor_rad,
+                   /*out*/ CubitVector* center,
                    /*out*/ iBase_EntityHandle *geom_entity,
                    int* err)
 {
@@ -5257,11 +5284,11 @@
   
   RefEntity *temp_body = gmt->torus(major_rad, minor_rad);
   *geom_entity = temp_body;
-
+   
   if (NULL == *geom_entity) {
     RETURN(iBase_FAILURE);
   }
-  
+  *center = temp_body->center_point(); 
   RETURN(iBase_SUCCESS);
 }
 

Modified: cgm/trunk/itaps/testgeom.cc
===================================================================
--- cgm/trunk/itaps/testgeom.cc	2008-11-07 22:02:32 UTC (rev 2223)
+++ cgm/trunk/itaps/testgeom.cc	2008-11-11 21:16:07 UTC (rev 2224)
@@ -16,6 +16,9 @@
  *
  */
 #include "iGeom.h"
+#include "CubitDefines.h"
+#include "CubitVector.hpp"
+#include "DLIList.hpp"
 #include <iostream>
 #include <set>
 #include <algorithm>
@@ -895,7 +898,8 @@
 
     // construct a cylinder, sweep it about an axis, and delete the result
   iBase_EntityHandle cyl = 0;
-  iGeom_createCylinder( geom, 1.0, 1.0, 0.0, &cyl, &err );
+  CubitVector center;
+  iGeom_createCylinder( geom, 1.0, 1.0, 0.0, &center , &cyl, &err );
     // Is the minor radius really supposed to be zero??? - JK
   CHECK( "Creating cylinder failed." );
   
@@ -945,6 +949,28 @@
   return true;
 }
 
+static bool compare_center_volume(int i, double volume, CubitVector * center)
+{
+  bool same = true;
+  double dtol = 1.0e-6;
+  double control_volume;
+  switch (i) {
+    case 0 :
+      control_volume = 6;
+      break;
+    case 1:
+      control_volume = 8 * CUBIT_PI;
+      break;
+    case 2:
+      control_volume = 4 * CUBIT_PI * CUBIT_PI; 
+  }
+  if((volume-control_volume) > dtol  ||
+     (control_volume - volume) > dtol)
+    return false;
+  if(center->length() > dtol)
+    return false;
+  return same;
+}
 static bool compare_box( const double* expected_min,
                          const double* expected_max,
                          const double* actual_min,
@@ -966,20 +992,50 @@
   int err;
   SimpleArray<iBase_EntityHandle> prims(3);
   iBase_EntityHandle prim;
-  
-  iGeom_createBrick( geom, 1.0, 2.0, 3.0, &prim, &err );
+  CubitVector center1, center2, center3;
+ 
+  iGeom_createBrick( geom, 1.0, 2.0, 3.0, &center1, &prim, &err );
   CHECK( "createBrick failed." );
   prims[0] = prim;
   
-  iGeom_createCylinder( geom, 1.0, 4.0, 2.0, &prim, &err );
+  iGeom_createCylinder( geom, 1.0, 4.0, 2.0, &center2, &prim, &err );
   CHECK( "createCylinder failed." );
   prims[1] = prim;
   
-  iGeom_createTorus( geom, 2.0, 1.0, &prim, &err );
+  iGeom_createTorus( geom, 2.0, 1.0, &center3, &prim, &err );
   CHECK( "createTorus failed." );
   prims[2] = prim;
   
-    // verify the bounding boxes
+  //For OCC based enities, non-planar entities gives enlarged bounding box which
+  //is larger than the linear tolerance, so checking geometry center and volume
+  //in stead of bounding boxes
+  const char* names[3] = {"brick","cylinder","torus"};
+  DLIList <CubitVector*> centers;
+  centers.append(&center1);
+  centers.append(&center2);
+  centers.append(&center3);
+#ifdef FORCE_OCC
+  SimpleArray<double> volume;
+
+  iGeom_measure(geom, ARRAY_IN(prims), ARRAY_INOUT(volume), &err);
+  for(int i = 0; i < 3; i++)
+    if(!compare_center_volume(i, volume[i], centers[i]))
+    {
+      std::cerr << "Box check failed for " << names[i] << std::endl;
+      return false;
+    }
+#elif defined(USE_OCC)
+  SimpleArray<double> volume;
+
+  iGeom_measure(geom, ARRAY_IN(prims), ARRAY_INOUT(volume), err);
+  for(int i = 0; i < 3; i++)
+    if(!compare_center_volume(i, volume[i), centers[i]))
+    {
+      std::cerr << "Box check failed for " << names[i] << std::endl;
+      return false;
+    }
+#else    
+    // verify the bounding boxes for Acis based entities
   SimpleArray<double> max_corn, min_corn;
   int so = iBase_INTERLEAVED;
   iGeom_getArrBoundBox( geom, ARRAY_IN(prims), &so, ARRAY_INOUT(min_corn), ARRAY_INOUT(max_corn), &err );
@@ -1019,7 +1075,7 @@
     std::cerr << "Box check failed for torus" << std::endl;
     return false;
   }
-  
+#endif  
     // must have worked; delete the entities then return
   for (int i = 0; i < 3; ++i) {
     iGeom_deleteEnt( geom, prims[i], &err );
@@ -1035,7 +1091,8 @@
   
     // construct a brick
   iBase_EntityHandle brick = 0;
-  iGeom_createBrick( geom, 1.0, 2.0, 3.0, &brick, &err );
+  CubitVector center;
+  iGeom_createBrick( geom, 1.0, 2.0, 3.0, &center, &brick, &err );
   CHECK( "Problems creating brick for transforms test." );
   
     // move it, then test bounding box
@@ -1103,9 +1160,10 @@
 
     // construct a brick size 1, and a cylinder rad 0.25 height 2
   iBase_EntityHandle brick = 0, cyl = 0;
-  iGeom_createBrick( geom, 1.0, 0.0, 0.0, &brick, &err );
+  CubitVector center;
+  iGeom_createBrick( geom, 1.0, 0.0, 0.0, &center, &brick, &err );
   CHECK( "Problems creating brick for booleans test." );
-  iGeom_createCylinder( geom, 1.0, 0.25, 0.0, &cyl, &err );
+  iGeom_createCylinder( geom, 1.0, 0.25, 0.0, &center, &cyl, &err );
   CHECK( "Problems creating cylinder for booleans test." );
 
     // subtract the cylinder from the brick
@@ -1124,7 +1182,7 @@
   CHECK( "Problems sectioning for booleans section test." );
 #endif
     // unite the section result with a new cylinder
-  iGeom_createCylinder( geom, 1.0, 0.25, 0.0, &cyl, &err );
+  iGeom_createCylinder( geom, 1.0, 0.25, 0.0, &center, &cyl, &err );
   CHECK( "Problems creating cylinder for unite test." );
   iBase_EntityHandle unite_results;
   iBase_EntityHandle unite_input[] = { section_result, cyl };




More information about the cgma-dev mailing list