[cgma-dev] r1597 - in cgm/trunk: geom/OCC test

janehu at mcs.anl.gov janehu at mcs.anl.gov
Wed Feb 13 14:37:41 CST 2008


Author: janehu
Date: 2008-02-13 14:37:41 -0600 (Wed, 13 Feb 2008)
New Revision: 1597

Modified:
   cgm/trunk/geom/OCC/OCCCurve.cpp
   cgm/trunk/geom/OCC/OCCModifyEngine.cpp
   cgm/trunk/test/makept.cpp
Log:
changed copy curve and surface methods by calling BRepBuilderAPI_Copy instead of EmptyCopied(); fixed bugs in make_curves.

Modified: cgm/trunk/geom/OCC/OCCCurve.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.cpp	2008-02-11 19:26:51 UTC (rev 1596)
+++ cgm/trunk/geom/OCC/OCCCurve.cpp	2008-02-13 20:37:41 UTC (rev 1597)
@@ -39,6 +39,8 @@
 
 #include <BRepAdaptor_Curve.hxx>
 #include <TopExp.hxx>
+#include "GProp_GProps.hxx"
+#include "BRepGProp.hxx"
 #include <TopTools_IndexedMapOfShape.hxx>
 #include <GCPnts_AbscissaPoint.hxx>
 #include <Bnd_Box.hxx>
@@ -228,8 +230,9 @@
 //-------------------------------------------------------------------------
 double OCCCurve::measure()
 {
-  BRepAdaptor_Curve acurve(*myTopoDSEdge);
-  return GCPnts_AbscissaPoint::Length(acurve);
+  GProp_GProps myProps;
+  BRepGProp::LinearProperties(*myTopoDSEdge, myProps);
+  return myProps.Mass();
 }
 
 //-------------------------------------------------------------------------

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-02-11 19:26:51 UTC (rev 1596)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-02-13 20:37:41 UTC (rev 1597)
@@ -38,6 +38,7 @@
 #include "BRepBuilderAPI_MakeEdge.hxx"
 #include "BRepAdaptor_Surface.hxx"
 #include "BRepBuilderAPI_MakeFace.hxx"
+#include "BRepBuilderAPI_Copy.hxx"
 #include "BRep_Tool.hxx"
 #include "TopoDS.hxx"
 #include "TopologyBridge.hpp"
@@ -153,7 +154,9 @@
  
   TopoDS_Edge *theEdge = occ_curve->get_TopoDS_Edge();  
  
-  TopoDS_Shape newShape = theEdge->EmptyCopied();
+  BRepBuilderAPI_Copy api_copy(*theEdge);
+
+  TopoDS_Shape newShape = api_copy.ModifiedShape(*theEdge);
  
   TopoDS_Edge newEdge = TopoDS::Edge(newShape);
 
@@ -340,9 +343,6 @@
   if (intermediate_point_ptr != NULL )
     mid_points.append(&mid_point);
 
-  if(curve_type == SPLINE_CURVE_TYPE)
-    return make_Curve(curve_type, point1_ptr, point2_ptr, mid_points);
-  
   CubitVector v1(point1_ptr->coordinates());
   CubitVector v2(point2_ptr->coordinates());
 
@@ -356,7 +356,7 @@
   Handle(Geom_TrimmedCurve) curve_ptr;
   if(intermediate_point_ptr != NULL)
   {
-    v3 = point1_ptr->coordinates();
+    v3 = *intermediate_point_ptr;
     pt3.SetCoord(v3.x(),v3.y(), v3.z());
   }
 
@@ -389,6 +389,8 @@
        return (Curve *)NULL;
      }
      N.normalize();
+     if (sense == CUBIT_REVERSED)
+       N = -N;
      gp_Dir N_dir(N.x(), N.y(), N.z());
 
      gp_Pnt center(v3.x(), v3.y(), v3.z());
@@ -401,6 +403,7 @@
      double minor = sqrt(major * major - c * c);
 
      gp_Elips ellipse(axis, major, minor);
+     CubitBoolean use_sense = (sense == CUBIT_FORWARD ? CUBIT_TRUE : CUBIT_FALSE); 
      curve_ptr = GC_MakeArcOfEllipse(ellipse, pt1, pt2, sense);
   }
 
@@ -483,6 +486,13 @@
     } 
   }
 
+  else
+  {
+      PRINT_ERROR("In OCCModifyEngine::make_Curve\n"
+                  "       Invalid curve type.\n");
+      return (Curve *)NULL;
+  }
+
   TopoDS_Edge new_edge = BRepBuilderAPI_MakeEdge(curve_ptr);
   return OCCQueryEngine::instance()->populate_topology_bridge(new_edge);
 }
@@ -526,26 +536,37 @@
 
   if (extended_from == CUBIT_TRUE)
   {
+     CubitBox bounding_box = GeometryQueryTool::instance()->model_bounding_box();
+     double const height = 2*(bounding_box.diagonal()).length();
+     CubitBox box = occ_surface->bounding_box();
+     double ratio = height/(box.diagonal().length());
+     double middleU = (UMin + UMax)/2.0;
+     double middleV = (VMin + VMax)/2.0;
+     double U1 = middleU - (UMax-UMin)/2.0 * ratio;
+     double U2 = middleU + (UMax-UMin)/2.0 * ratio;
+     double V1 = middleV - (VMax - VMin)/2.0 * ratio;
+     double V2 = middleV + (VMax - VMin)/2.0 * ratio;
      // We need to get the type of surface.
      GeometryType type = occ_surface->geometry_type();
      if (type  == PLANE_SURFACE_TYPE)
      {
         gp_Pln plane = asurface.Plane();
-        newFace = BRepBuilderAPI_MakeFace(plane);
+        newFace = BRepBuilderAPI_MakeFace(plane, U1, U2, V1, V2);
      }
      else if(type == CONE_SURFACE_TYPE)
      {
        //make an infinite cone.
        //Given this lets create another face that is extended from it.
+       double middle = (VMin + VMax)/2.0;
        if(asurface.GetType() == GeomAbs_Cone)
        {
          gp_Cone cone = asurface.Cone();
-         newFace = BRepBuilderAPI_MakeFace(cone);
+         newFace = BRepBuilderAPI_MakeFace(cone, 0, 2*CUBIT_PI, V1, V2);
        }
        else
        {
          gp_Cylinder cylinder = asurface.Cylinder();
-         newFace = BRepBuilderAPI_MakeFace(cylinder);
+         newFace = BRepBuilderAPI_MakeFace(cylinder, 0, 2*CUBIT_PI, V1, V2);
        } 
      }
      else if(type == SPHERE_SURFACE_TYPE)
@@ -564,13 +585,14 @@
      {
        //extend the surfaces using the equation if possible.
        Handle(Geom_BezierSurface) bezier = asurface.Bezier();
-       newFace = BRepBuilderAPI_MakeFace(bezier);
+       newFace = BRepBuilderAPI_MakeFace(bezier, U1, U2, V1, V2);
      }
   }
  
   else
   {
-    TopoDS_Shape newShape = theFace->EmptyCopied();
+    BRepBuilderAPI_Copy api_copy(*theFace);
+    TopoDS_Shape newShape = api_copy.ModifiedShape(*theFace);
     newFace = TopoDS::Face(newShape);
   }
   

Modified: cgm/trunk/test/makept.cpp
===================================================================
--- cgm/trunk/test/makept.cpp	2008-02-11 19:26:51 UTC (rev 1596)
+++ cgm/trunk/test/makept.cpp	2008-02-13 20:37:41 UTC (rev 1597)
@@ -109,7 +109,7 @@
   char *argv = "./66_shaver3.brep";
   CubitStatus status = read_geometry(1, &argv);
   if (status == CUBIT_FAILURE) exit(1);
-
+/*
   argv = "./62_shaver1.brep";
   status = read_geometry(1, &argv);
   if (status == CUBIT_FAILURE) exit(1);
@@ -117,9 +117,9 @@
   argv = "./72_shaver6.brep";
   status = read_geometry(1, &argv);
   if (status == CUBIT_FAILURE) exit(1);
-  
+*/  
   CubitVector vector1(10,10,10);
-  CubitVector vector2(15,15,15);
+  CubitVector vector2(10,-10,10);
   DLIList<RefEntity*> free_entities;
 
   // Make two vertices.
@@ -142,9 +142,10 @@
   const char * filename = "point.occ";
   const char * filetype = "OCC";
   
+  /*
   rsl = gti->export_solid_model(ref_entity_list, filename, filetype, 
                                  num_ents_exported, cubit_version);
-
+  */
  
   //check for vertex
   DLIList<Body*> bodies;
@@ -220,11 +221,26 @@
   RefFace* ref_face = ref_faces.step_and_get();
 
   //make a new refface out of existing refface.
-  RefFace* new_face = gmti->make_RefFace(ref_face);
+  CubitBoolean extended_from = CUBIT_FALSE;
+  RefFace* new_face = gmti->make_RefFace(ref_face, extended_from);
 
+  DLIList<DLIList<RefEdge*>*> ref_edge_loops;
+  new_face->ref_edge_loops(ref_edge_loops);
+
+  DLIList<RefEdge*>* ref_edge_list;
+  ref_edge_list = ref_edge_loops.get();
+
+  for (int i = 0; i < ref_edge_list->size(); i++)
+  {
+    RefEdge * edge = ref_edge_list->get_and_step();
+    double d = edge->measure();
+    RefVertex* start = edge->start_vertex();
+    RefVertex* end = edge->end_vertex();
+  }
+
   bodies.clean_out();
   gti->bodies(bodies);
-  //translate the new curve by (40,40,40)
+  //translate the new face by (40,40,40)
   for(int i = 1; i <= bodies.size(); i++)
   {
      bodies.step();
@@ -298,7 +314,7 @@
   CubitPointContainment pc2 = ref_face->point_containment(3,-20000);
   // this (u,v) location should be inside of the surface.
 
-  DLIList<DLIList<RefEdge*>*> ref_edge_loops;
+  ref_edge_loops.clean_out();
   int num_loops = ref_face->ref_edge_loops(ref_edge_loops);
   DLIList<RefEdge*> *ref_edges1;
   ref_edges1 = ref_edge_loops.get();
@@ -307,6 +323,50 @@
   double angle = edge1->angle_between(edge2, ref_face);
 
   //test for curve
+  CubitVector c_point, tangent, center;
+
+  //make all kinds of curves.
+  CubitVector center_pnt(0,0,0);
+  RefEdge* new_edge_1 = gmti->make_RefEdge(SPLINE_CURVE_TYPE, vertex1,
+					vertex2, &center_pnt);
+  //Gives invalid curve type error.
+
+  //straight line
+  RefEdge* new_edge_2 = gmti->make_RefEdge(STRAIGHT_CURVE_TYPE, vertex1,
+                                        vertex2, &center_pnt);
+  d = new_edge_2->measure();
+  new_edge_2->closest_point_trimmed(vi, c_point);
+
+  //arc curve
+  RefEdge* new_edge_3 = gmti->make_RefEdge(ARC_CURVE_TYPE, vertex1,
+                                        vertex2, &center_pnt);
+  d = new_edge_3->measure();
+  new_edge_3->closest_point_trimmed(vi, c_point);
+
+  //ellipse curve
+  RefEdge* new_edge_4 = gmti->make_RefEdge(ELLIPSE_CURVE_TYPE, vertex1,
+                                        vertex2, &center_pnt);
+  d = new_edge_4->measure();
+  new_edge_4->closest_point_trimmed(vi, c_point);
+
+  RefEdge* new_edge_5 = gmti->make_RefEdge(ELLIPSE_CURVE_TYPE, vertex1,
+                                        vertex2, &center_pnt, CUBIT_REVERSED);
+  d = new_edge_5->measure();
+  new_edge_5->closest_point_trimmed(vi, c_point);
+
+  //PARABOLA_CURVE_TYPE
+  RefEdge* new_edge_6 = gmti->make_RefEdge(PARABOLA_CURVE_TYPE, vertex1,
+                                        vertex2, &center_pnt);
+  d = new_edge_6->measure();
+  new_edge_6->closest_point_trimmed(vi, c_point);
+
+  //HYPERBOLA_CURVE_TYPE
+  RefEdge* new_edge_7 = gmti->make_RefEdge(HYPERBOLA_CURVE_TYPE, vertex1,
+                                        vertex2, &center_pnt);
+  d = new_edge_7->measure();
+  new_edge_7->closest_point_trimmed(vi, c_point);
+
+  //delete all free vertices and edges
   for (int j = free_entities.size(); j--;)
   {
      gti->delete_RefEntity( free_entities.get_and_step());
@@ -332,6 +392,7 @@
 
   box = ref_edge->get_curve_ptr()->bounding_box();
 
+  //general query
   DLIList<OCCCurve*> curves;
   CAST_TO(body, OCCBody)->get_all_curves(curves);
 
@@ -364,7 +425,6 @@
   u = ref_edge->u_from_position(vi); 
   // middle point's u value.
 
-  CubitVector c_point, tangent, center;
   double radius;
   ref_edge->closest_point(vi, c_point, &tangent, & curvature1_ptr);
   // Closed point on middle point.




More information about the cgma-dev mailing list