[cgma-dev] r1558 - cgm/trunk/geom/OCC

janehu at mcs.anl.gov janehu at mcs.anl.gov
Thu Jan 24 15:56:18 CST 2008


Author: janehu
Date: 2008-01-24 15:56:18 -0600 (Thu, 24 Jan 2008)
New Revision: 1558

Modified:
   cgm/trunk/geom/OCC/OCCCurve.cpp
   cgm/trunk/geom/OCC/OCCCurve.hpp
   cgm/trunk/geom/OCC/OCCModifyEngine.cpp
   cgm/trunk/geom/OCC/OCCModifyEngine.hpp
Log:
Added make_Curve for ModifyEngine and project_curve for OCCCurve, not finished yet because of some tech issue. Builds fine.

Modified: cgm/trunk/geom/OCC/OCCCurve.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.cpp	2008-01-24 21:28:09 UTC (rev 1557)
+++ cgm/trunk/geom/OCC/OCCCurve.cpp	2008-01-24 21:56:18 UTC (rev 1558)
@@ -48,6 +48,9 @@
 #include <BRepLProp_CLProps.hxx>
 #include <BRep_Tool.hxx>
 #include <TopoDS.hxx>
+#include "GeomAPI_ProjectPointOnCurve.hxx"
+#include "TopTools_ListOfShape.hxx"
+#include "BRepAlgo_NormalProjection.hxx"
 #include "TopExp_Explorer.hxx"
 #include "GeomLProp_CurveTool.hxx"
 #include "GeomAPI_ExtremaCurveCurve.hxx"
@@ -904,6 +907,115 @@
   set_TopoDS_Edge(curve);
 }
 
+//===============================================================================
+// Function   : project_curve
+// Member Type: PUBLIC
+// Description: project a curve onto a surface, if closed is true,
+//              make sure it projected as two segment, then combine them
+//              into a closed shape, third_point is used to determine
+//              which segment to use if having two projections.
+// Author     : Jane Hu
+// Date       : 01/08
+//===============================================================================
+Curve* OCCCurve::project_curve(Surface* face_ptr, 
+                                      CubitBoolean closed,
+                                      const CubitVector* third_point)
+{
+   TopoDS_Edge* edge = get_TopoDS_Edge();
+   if (edge == NULL)
+   {
+        PRINT_ERROR("Cannot project the curve .\n"
+                 "Possible incompatible geometry engines.\n");
+        return (Curve*) NULL;
+   }
+
+   TopoDS_Face* face = CAST_TO(face_ptr, OCCSurface)->get_TopoDS_Face();
+   if(face == NULL)
+   {
+        PRINT_ERROR("Cannot project the curve to the surface.\n"
+                 "Possible incompatible geometry engines.\n");
+        return (Curve*) NULL;
+   }
+
+   BRepAlgo_NormalProjection aProjection(*face);
+   aProjection.Add(*edge);
+   aProjection.Build();
+   if (!aProjection.IsDone())
+   {
+        PRINT_ERROR("Cannot project the curve to the surface.\n"
+                 "OCC engine failure.\n");
+        return (Curve*) NULL;
+   }
+
+   TopTools_ListOfShape projections;
+   projections = aProjection.Generated(*edge);
+   int num_projection = projections.Extent();
+   if (num_projection == 0)
+   {
+       PRINT_ERROR("Cannot project the curve to the surface.\n");
+       return (Curve*) NULL;
+   }
+
+   else if ( num_projection == 1 )
+   {
+      if(closed == true)
+       PRINT_WARNING("Cannot project the curve to create a closed projection.\n"                 "There is only one projection segment.\n");
+
+      TopoDS_Shape new_shape = aProjection.Projection();//compound shape
+      TopoDS_Edge new_edge = TopoDS::Edge(new_shape);
+      return OCCQueryEngine::instance()->populate_topology_bridge(new_edge);
+   }
+
+   else if (num_projection == 2)
+   {
+      //If the surface is periodic, so it has 2 projections, we just need to
+      //find the segment to which the third_point is closer.
+      if(closed == CUBIT_FALSE && third_point != NULL)
+      {
+        double d;
+        double first, last;
+        TopoDS_Shape shape = projections.First();
+        TopoDS_Edge edge = TopoDS::Edge(shape);
+        Handle(Geom_Curve) myCurve =
+                        BRep_Tool::Curve(edge,first,last);
+        gp_Pnt P (third_point->x(), third_point->y(), third_point->z());
+        GeomAPI_ProjectPointOnCurve projOncurve(P, myCurve);
+        if (projOncurve.NbPoints() == 0)
+        {
+          PRINT_ERROR("Cannot project the curve to the surface.\n"
+                 "OCC engine failure.\n");
+          return (Curve*) NULL;
+        }
+        d = projOncurve.LowerDistance();
+
+        //Compare with the second solution
+        shape = projections.Last();
+        edge = TopoDS::Edge(shape);
+        myCurve = BRep_Tool::Curve(edge, first, last);
+        GeomAPI_ProjectPointOnCurve projOncurve2(P, myCurve);
+        if (projOncurve2.NbPoints() == 0)
+        {
+           PRINT_ERROR("Cannot project the curve to the surface.\n"
+                 "OCC engine failure.\n");
+          return (Curve*) NULL;
+        }
+
+        double d2 = projOncurve2.LowerDistance();
+        TopoDS_Shape new_shape =
+                d > d2 ? projections.Last() : projections.First() ;
+        TopoDS_Edge new_edge = TopoDS::Edge(new_shape);
+        return OCCQueryEngine::instance()->populate_topology_bridge(new_edge);
+      }
+
+
+      else if (closed == CUBIT_TRUE)
+      {
+        //connect the two segment into a closed shape.
+
+      }
+   }
+}
+
 // ********** END PRIVATE FUNCTIONS        **********
 
 // ********** BEGIN HELPER CLASSES         **********

Modified: cgm/trunk/geom/OCC/OCCCurve.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.hpp	2008-01-24 21:28:09 UTC (rev 1557)
+++ cgm/trunk/geom/OCC/OCCCurve.hpp	2008-01-24 21:56:18 UTC (rev 1558)
@@ -324,7 +324,10 @@
   void set_TopoDS_Edge(TopoDS_Edge edge){*myTopoDSEdge = edge;}
 
   void update_OCC_entity( BRepBuilderAPI_Transform &aBRepTrsf);
-
+ 
+  Curve* project_curve(Surface* face_ptr,
+                       CubitBoolean closed,
+                       const CubitVector* third_point);
 protected: 
   
 private:

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-01-24 21:28:09 UTC (rev 1557)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.cpp	2008-01-24 21:56:18 UTC (rev 1558)
@@ -3,15 +3,14 @@
 
 // Filename      : OCCModifyEngine.cpp
 //
-// Purpose       : ModifyEngine for faceted geometry
+// Purpose       : ModifyEngine for OCC geometry
 //
 // Special Notes : Modeled after GeometryModifyEngine and AcisModifyEngine.
 //
-// Creator       : John Fowler
+// Author        : Jane Hu
 //
-// Creation Date : 6/02
+// Creation Date : 1/08
 //
-// Owner         : John Fowler
 //-------------------------------------------------------------------------
 #include "config.h"
 #include "gp_Pnt.hxx"
@@ -139,33 +138,75 @@
 //===============================================================================
 // Function   : make_Curve
 // Member Type: PUBLIC
-// Description: make a curve
-// Author     : John Fowler
-// Date       : 10/02
+// Description: make a curve by projecting a straight line defined by 
+//              point1_ptr, and point2_ptr onto face_ptr, third_point
+//              is used for curves that could be periodic to dertermine
+//              the correct direction.
+// Author     : Jane Hu
+// Date       : 01/08
 //===============================================================================
-Curve* OCCModifyEngine::make_Curve( Point const* /*point1_ptr*/,
-                             Point const* /*point2_ptr*/,
-                             Surface* /*ref_face_ptr*/,
-                             const CubitVector * /*third_point*/) const
+Curve* OCCModifyEngine::make_Curve( Point const* point1_ptr,
+                             Point const* point2_ptr,
+                             Surface* face_ptr,
+                             const CubitVector * third_point) const
 {
-  PRINT_ERROR("Option not supported for mesh based geometry.\n");
-  return (Curve*) NULL;
+  assert (point1_ptr != NULL && point2_ptr != NULL);
+  GeometryType type = STRAIGHT_CURVE_TYPE;
+  CubitBoolean closed = CUBIT_FALSE;
+  DLIList<CubitVector*> mid_points;
+  Curve* curve = NULL;
+  if (point1_ptr != point2_ptr)
+    curve = make_Curve(type, point1_ptr, point2_ptr, mid_points);
+  else //could be a closed shape
+  {
+    if(third_point != NULL && face_ptr != NULL) 
+    {
+       closed = CUBIT_TRUE;
+       //curve = make_Curve(type, point1_ptr, third_point, mid_points);
+    }
+  }
+
+  Curve* new_curve = NULL;
+  if(face_ptr == NULL)
+    return curve;
+ 
+  new_curve = 
+	CAST_TO(curve, OCCCurve)->project_curve(face_ptr, closed, third_point); 
+
+  delete curve;
+  return new_curve;
 }
 
 //===============================================================================
 // Function   : make_Curve
 // Member Type: PUBLIC
 // Description: make a curve
-// Author     : John Fowler
-// Date       : 10/02
+// Author     : Jane Hu
+// Date       : 01/08
 //===============================================================================
-Curve* OCCModifyEngine::make_Curve( GeometryType /*curve_type*/,
-                             Point const* /*point1_ptr*/,
-                             Point const* /*point2_ptr*/,
-                             DLIList<CubitVector*>& /*vector_list*/,
-                             Surface* /*ref_face_ptr*/) const
+Curve* OCCModifyEngine::make_Curve( GeometryType curve_type,
+                             Point const* point1_ptr,
+                             Point const* point2_ptr,
+                             DLIList<CubitVector*>& vector_list,
+                             Surface* face_ptr) const
 {
-  PRINT_ERROR("Option not supported for mesh based geometry.\n");
+  assert(point1_ptr != NULL && point2_ptr != NULL);
+ /* 
+  OCCPoint const* occ_point1 = CAST_TO(point1_ptr, OCCPoint);
+  OCCPoint const* occ_point2 = CAST_TO(point2_ptr, OCCPoint);
+
+  if (occ_point1 == NULL || occ_point2 == NULL)
+  {
+     PRINT_ERROR("Cannot create an OCC curve from the given points.\n"
+                 "Possible incompatible geometry engines.\n");
+     return (Curve *)NULL;
+  }
+ */   
+  //project all points on the surface
+  if (face_ptr != NULL)
+  {
+  }    
+     
   return (Curve*) NULL;
 }
 
@@ -173,17 +214,28 @@
 // Function   : make_Curve
 // Member Type: PUBLIC
 // Description: make a curve
-// Author     : John Fowler
-// Date       : 10/02
+// Author     : Jane Hu 
+// Date       : 01/08
 //===============================================================================
-Curve* OCCModifyEngine::make_Curve( GeometryType /*curve_type*/,
-                             Point const* /*point1_ptr*/,
-                             Point const* /*point2_ptr*/,
-                             CubitVector const* /*intermediate_point_ptr*/,
-                             CubitSense /*sense*/) const
+Curve* OCCModifyEngine::make_Curve( GeometryType curve_type,
+                             Point const* point1_ptr,
+                             Point const* point2_ptr,
+                             CubitVector const* intermediate_point_ptr,
+                             CubitSense sense) const
 {
-  PRINT_ERROR("Option not supported for mesh based geometry.\n");
-  return (Curve*) NULL;
+  assert (point1_ptr != NULL && point2_ptr != NULL);
+  DLIList<CubitVector*> mid_points;
+  CubitVector mid_point = *intermediate_point_ptr;
+  if (intermediate_point_ptr != NULL )
+    mid_points.append(&mid_point);
+
+  Point const* tmp_point = point1_ptr;
+  if (sense == CUBIT_REVERSED)
+  {
+     point1_ptr = point2_ptr;
+     point2_ptr = tmp_point;
+  }   
+  return make_Curve(curve_type, point1_ptr, point2_ptr, mid_points);
 }
 
 //===============================================================================

Modified: cgm/trunk/geom/OCC/OCCModifyEngine.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCModifyEngine.hpp	2008-01-24 21:28:09 UTC (rev 1557)
+++ cgm/trunk/geom/OCC/OCCModifyEngine.hpp	2008-01-24 21:56:18 UTC (rev 1558)
@@ -648,7 +648,7 @@
                                            Surface *ref_face1, double leg1, Surface *ref_face2, double leg2,
                                            BodySM *&new_body ) const;
 
-    CubitStatus tolerant_imprint( DLIList<BodySM*> &bodies_in,
+  CubitStatus tolerant_imprint( DLIList<BodySM*> &bodies_in,
                                   DLIList<BodySM*> &new_bodies,
                                   DLIList<TopologyBridge*>*,
                                   DLIList<TopologyBridge*>* ) const; 




More information about the cgma-dev mailing list