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

janehu at mcs.anl.gov janehu at mcs.anl.gov
Fri Oct 19 13:18:57 CDT 2007


Author: janehu
Date: 2007-10-19 13:18:57 -0500 (Fri, 19 Oct 2007)
New Revision: 1315

Modified:
   cgm/trunk/geom/OCC/OCCBody.hpp
   cgm/trunk/geom/OCC/OCCCurve.hpp
   cgm/trunk/geom/OCC/OCCLump.hpp
   cgm/trunk/geom/OCC/OCCPoint.cpp
   cgm/trunk/geom/OCC/OCCPoint.hpp
   cgm/trunk/geom/OCC/OCCQueryEngine.cpp
   cgm/trunk/geom/OCC/OCCQueryEngine.hpp
   cgm/trunk/geom/OCC/OCCSurface.hpp
Log:
Added entity-entity-distance and get-TopoDS-Shape-of_entity in Query functions, and make some small changes.

Modified: cgm/trunk/geom/OCC/OCCBody.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCBody.hpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCBody.hpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -62,6 +62,8 @@
     //- This function returns a pointer to the geometric modeling engine
     //- associated with the object.
   
+  TopoDS_Shape *get_TopoDS_Shape() {return myTopoDSShape; }
+
   virtual void append_simple_attribute_virt(CubitSimpleAttrib*);
     //R void
     //I 

Modified: cgm/trunk/geom/OCC/OCCCurve.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCCurve.hpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCCurve.hpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -339,8 +339,8 @@
   void reset_length();
     //- update the length of the facet curve
 
-  TopoDS_Edge get_TopoDS_Edge( )
-    { return *myTopoDSEdge; } 
+  TopoDS_Edge *get_TopoDS_Edge( )
+    { return myTopoDSEdge; } 
 
   Point *start_point()
     { assert(0);return myStartPoint; }

Modified: cgm/trunk/geom/OCC/OCCLump.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCLump.hpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCLump.hpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -55,6 +55,8 @@
   void add_body(BodySM* new_body)
     {myBodyPtr = new_body;}
     
+  TopoDS_Solid *get_TopoDS_Solid(){ return myTopoDSSolid; }
+
   virtual void append_simple_attribute_virt(CubitSimpleAttrib*);
     //R void
     //I 

Modified: cgm/trunk/geom/OCC/OCCPoint.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCPoint.cpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCPoint.cpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -44,10 +44,26 @@
 OCCPoint::OCCPoint( const CubitVector &location )
 {
   gp_Pnt pt = gp_Pnt( location.x(), location.y(), location.z());
-  myPoint = BRepBuilderAPI_MakeVertex(pt);
+  TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(pt);
+  myTopoDSVertex = new TopoDS_Vertex(theVertex);
 }
 
 //-------------------------------------------------------------------------
+// Purpose       : The constructor with a gp_Pnt point
+//
+// Special Notes :
+//
+// Creator       : Jane Hu
+//
+// Creation Date : 10/19/07
+//-------------------------------------------------------------------------
+OCCPoint::OCCPoint( gp_Pnt& thePoint )
+{
+  TopoDS_Vertex theVertex = BRepBuilderAPI_MakeVertex(thePoint);
+  myTopoDSVertex = new TopoDS_Vertex(theVertex);
+}
+
+//-------------------------------------------------------------------------
 // Purpose       : The destructor. 
 //
 // Special Notes :
@@ -133,16 +149,6 @@
   { return attribSet.restore_attributes(file_ptr, endian); 
   }
 
-
-TopoDS_Vertex OCCPoint::get_pnt()const
-{
-  return myPoint;
-}
-
-void OCCPoint::set_pnt( TopoDS_Vertex &v_point)
-{
-  myPoint = v_point;
-}
 //-------------------------------------------------------------------------
 // Purpose       : Returns the coordinates of this Point. 
 //
@@ -154,27 +160,29 @@
 //-------------------------------------------------------------------------
 CubitVector OCCPoint::coordinates() const
 {
-  gp_Pnt pt = BRep_Tool::Pnt(myPoint);
+  gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
   CubitVector p(pt.X(), pt.Y(), pt.Z());
   return p;
 }
 
-CubitBoolean OCCPoint::is_equal(const OCCPoint & other, double Tol)
+CubitBoolean OCCPoint::is_equal(OCCPoint & other, double Tol)
 {
-  gp_Pnt pt = BRep_Tool::Pnt(myPoint);
-  return pt.IsEqual(BRep_Tool::Pnt(other.get_pnt()), Tol);
+  gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
+  TopoDS_Vertex otherVertex = *(other.get_TopoDS_Vertex());
+  const gp_Pnt otherPnt = BRep_Tool::Pnt(otherVertex);
+  return pt.IsEqual(otherPnt, Tol);
 }   
   
-double OCCPoint::distance(const OCCPoint & other)
+double OCCPoint::distance(OCCPoint & other)
 {
-  gp_Pnt pt = BRep_Tool::Pnt(myPoint);
-  return pt.Distance(BRep_Tool::Pnt(other.get_pnt()));
+  gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
+  return pt.Distance(BRep_Tool::Pnt(*(other.get_TopoDS_Vertex())));
 }
 
-double OCCPoint::SquareDistance (const OCCPoint & other)
+double OCCPoint::SquareDistance (OCCPoint & other)
 {
-  gp_Pnt pt = BRep_Tool::Pnt(myPoint);
-  return pt.SquareDistance(BRep_Tool::Pnt(other.get_pnt()));
+  gp_Pnt pt = BRep_Tool::Pnt(*myTopoDSVertex);
+  return pt.SquareDistance(BRep_Tool::Pnt(*(other.get_TopoDS_Vertex())));
 }
 //-------------------------------------------------------------------------
 // Purpose       : Get geometry modeling engine: AcisGeometryEngine

Modified: cgm/trunk/geom/OCC/OCCPoint.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCPoint.hpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCPoint.hpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -35,7 +35,7 @@
 {
 private:
 
-  TopoDS_Vertex myPoint;
+  TopoDS_Vertex *myTopoDSVertex;
  
   OCCAttribSet attribSet;
 
@@ -47,13 +47,13 @@
     //I- DLIList<Curve*> curves
     //I- curves attaced to point
 
-  OCCPoint(TopoDS_Vertex& thePoint ):myPoint(thePoint){};
+  OCCPoint(TopoDS_Vertex* thePoint ):myTopoDSVertex(thePoint){};
     //I- gp_Pnt *thePoint
     //I- pointer to the TopoDS_Vertex associated with OCCPoint
     //I- DLIList<Curve*> curves
     //I- curves attaced to point
 
-  OCCPoint(gp_Pnt& thePoint ):myPoint(BRepBuilderAPI_MakeVertex(thePoint)){};
+  OCCPoint(gp_Pnt& thePoint );
     //I- gp_Pnt *thePoint
     //I- pointer to the TopoDS_Vertex associated with OCCPoint
     //I- DLIList<Curve*> curves
@@ -62,9 +62,7 @@
   virtual ~OCCPoint();
     //- The destructor
 
-  TopoDS_Vertex get_pnt()const;
-  void set_pnt( TopoDS_Vertex& gp_pnt);
-  // - get/set the gp_Pnt associated with this object
+  TopoDS_Vertex *get_TopoDS_Vertex(){return myTopoDSVertex; }
 
 #ifdef BOYD14
   OCCPoint *copy();
@@ -116,10 +114,10 @@
     //R- Contains the coordinate values {x y z} of this Point
     //- Returns the spatial coordinates of this Point.
   
-  CubitBoolean is_equal(const OCCPoint & other, double Tol);
+  CubitBoolean is_equal( OCCPoint & other, double Tol);
 
-  double distance(const OCCPoint & other);
-  double SquareDistance (const OCCPoint & other);
+  double distance( OCCPoint & other);
+  double SquareDistance ( OCCPoint & other);
 
   virtual CubitBox bounding_box() const ;
     // see comments in GeometryEntity.hpp

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.cpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -341,8 +341,9 @@
   }
 
   //currently, there's no effect on 'closest' argument or bounded.
-  BRepExtrema_DistShapeShape distShapeShape(occ_curve1->get_TopoDS_Edge(),
-                                            occ_curve2->get_TopoDS_Edge());
+  BRepExtrema_DistShapeShape distShapeShape(
+                                            *(occ_curve1->get_TopoDS_Edge()),
+                                            *(occ_curve2->get_TopoDS_Edge()));
 
   distShapeShape.Perform();
   if (!distShapeShape.IsDone())
@@ -351,7 +352,7 @@
      return CUBIT_FAILURE;
   }
   
-  if (distShapeShape.Value() < 1e-6)
+  if (distShapeShape.Value() < get_sme_resabs_tolerance())
   {
      int numPnt = distShapeShape.NbSolution();
      for (int i = 1; i <= numPnt; i++)
@@ -386,8 +387,8 @@
   }
    
   //currently, there's no effect on 'closest' argument or bounded.
-  BRepExtrema_DistShapeShape distShapeShape(occ_curve->get_TopoDS_Edge(),
-                                            occ_surface->get_TopoDS_Face());
+  BRepExtrema_DistShapeShape distShapeShape(*(occ_curve->get_TopoDS_Edge()),
+                                            *(occ_surface->get_TopoDS_Face()));
 
   distShapeShape.Perform();
   if (!distShapeShape.IsDone())
@@ -396,7 +397,7 @@
      return CUBIT_FAILURE;
   }
   
-  if (distShapeShape.Value() < 1e-6)
+  if (distShapeShape.Value() < get_sme_resabs_tolerance())
   {
      int numPnt = distShapeShape.NbSolution();
      for (int i = 1; i <= numPnt; i++)
@@ -430,19 +431,114 @@
 
 //================================================================================
 // Description: Find distance between two entities and closest positions.
-// Author     :
-// Date       :
+// Author     : Jane Hu
+// Date       : 10/19/07
 //================================================================================
 CubitStatus
-OCCQueryEngine::entity_entity_distance( GeometryEntity *,
-                                          GeometryEntity *,
-                                          CubitVector &, CubitVector &,
-                                          double & )
+OCCQueryEngine::entity_entity_distance( GeometryEntity *entity1,
+                                          GeometryEntity *entity2,
+                                          CubitVector &pos1, CubitVector &pos2,
+                                          double &distance )
 {
-  PRINT_ERROR("Option not supported for mesh based geometry.\n");
-  return CUBIT_FAILURE;
+  TopoDS_Shape * shape1;
+  TopoDS_Shape * shape2;
+  if ((shape1 = get_TopoDS_Shape_of_entity(entity1)) == NULL)
+  {
+    PRINT_ERROR( "problem occured getting OCC entity.\n"
+      "       Aborting.\n" );
+    return CUBIT_FAILURE;
+  }
+
+  if( (shape2 = get_TopoDS_Shape_of_entity( entity2 )) == NULL )
+  {
+    PRINT_ERROR( "problem occured getting OCC entity.\n"
+      "       Aborting.\n");
+    return CUBIT_FAILURE;
+  }
+
+  BRepExtrema_DistShapeShape distShapeShape(*shape1, *shape2);
+  distShapeShape.Perform();
+  
+  if (!distShapeShape.IsDone())
+  {
+    PRINT_ERROR( "problem occured getting distance between OCC entities.\n"
+      "       Aborting.\n");
+    return CUBIT_FAILURE;
+  }
+
+  distance = distShapeShape.Value();
+  gp_Pnt pnt1 = distShapeShape.PointOnShape1(1);
+  gp_Pnt pnt2 = distShapeShape.PointOnShape2(2);
+  pos1 = CubitVector(pnt1.X(), pnt1.Y(), pnt1.Z());
+  pos2 = CubitVector(pnt2.X(), pnt2.Y(), pnt2.Z());
+  return CUBIT_SUCCESS;
 }
 
+TopoDS_Shape* OCCQueryEngine::get_TopoDS_Shape_of_entity(TopologyBridge *entity_ptr)
+{
+  if (OCCBody *body_ptr = CAST_TO( entity_ptr, OCCBody))
+  {
+    TopoDS_Shape* theShape = body_ptr->get_TopoDS_Shape();
+    if (!theShape)
+    {
+      PRINT_ERROR("OCCBody without TopoDS_Shape at %s:%d.\n", __FILE__, __LINE__ );
+      return NULL;
+    }
+    return theShape;
+  }
+
+  else if (OCCLump * lump_ptr = CAST_TO( entity_ptr,OCCLump))
+  {
+    TopoDS_Solid * theSolid = lump_ptr->get_TopoDS_Solid();
+    if(theSolid)
+      return (TopoDS_Shape*) theSolid; 
+    else
+    {
+      PRINT_ERROR("OCCLump without TopoDS_Solid at %s:%d.\n", __FILE__, __LINE__ );
+      return NULL;
+    }
+  }
+
+  else if( OCCSurface *surface_ptr = CAST_TO( entity_ptr, OCCSurface))
+  {
+    TopoDS_Face *theFace = surface_ptr->get_TopoDS_Face();
+    if(!theFace)
+    {
+      PRINT_ERROR("OCCSurface without TopoDS_Face at %s:%d.\n", __FILE__, __LINE__ );
+      return NULL;
+    }
+
+    return (TopoDS_Shape*) theFace;
+  }
+
+  else if( OCCCurve *curve_ptr = CAST_TO( entity_ptr, OCCCurve))
+  {
+    TopoDS_Edge *theEdge = curve_ptr->get_TopoDS_Edge();
+    if (!theEdge)
+    {
+      PRINT_ERROR("OCCCurve without TopoDS_Edge at %s:%d.\n", __FILE__, __LINE__ );
+      return NULL;
+    }
+
+    return (TopoDS_Shape*) theEdge;
+  }
+
+  else if( OCCPoint *point_ptr = CAST_TO( entity_ptr, OCCPoint))
+  {
+    TopoDS_Vertex *thePoint = point_ptr->get_TopoDS_Vertex(); 
+    if (!thePoint)
+    {
+      PRINT_ERROR("OCCPoint without TopoDS_Point at %s:%d.\n", __FILE__, __LINE__ );
+      return NULL;
+    }
+
+    return (TopoDS_Shape*) thePoint;
+  }
+  
+  PRINT_ERROR("Non-OCC TopologyBridge at %s:%d.\n", __FILE__, __LINE__ );
+  return NULL;
+
+}
 //===========================================================================
 //Function Name: save_temp_geom_file
 //Member Type:  PUBLIC

Modified: cgm/trunk/geom/OCC/OCCQueryEngine.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCQueryEngine.hpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCQueryEngine.hpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -108,6 +108,7 @@
   const char* modeler_type()
      { return "OCC"; }
 
+  TopoDS_Shape *get_TopoDS_Shape_of_entity( TopologyBridge * entity);
   int get_major_version();
 
   int get_minor_version();

Modified: cgm/trunk/geom/OCC/OCCSurface.hpp
===================================================================
--- cgm/trunk/geom/OCC/OCCSurface.hpp	2007-10-18 19:37:21 UTC (rev 1314)
+++ cgm/trunk/geom/OCC/OCCSurface.hpp	2007-10-19 18:18:57 UTC (rev 1315)
@@ -340,7 +340,7 @@
     //- Determines the u and v derivitives from the given parameter
     //- values.
   
-  TopoDS_Face get_TopoDS_Face(){return *myTopoDSFace;}
+  TopoDS_Face *get_TopoDS_Face(){return myTopoDSFace;}
 
   virtual CubitBoolean is_parametric();
     //R CubitBoolean




More information about the cgma-dev mailing list