Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
 

trimming NURBS and rendering using OpenGL

trimming NURBS and rendering using OpenGL
vijay 2012/07/10 17:20
Hello Everyone.

I'm using OpenCASCADE to read some geometries in IGES and STEP format. I'm using OpenGL to render these geometries but I'm having tough time with the trimming curves of NURBS surfaces. I don't know how to find the orientation of the trimming curves. OpenGL trims off the nurbs surface on the right of trimming curves. Can someone please help me with the evaluation of the orientation of the trimming curves?

The code below shows how I evaluated the trimming curves and how they are ordered.

void draw_face_geometry(const TopoDS_Face & face)
{
BRepAdaptor_Surface face_adapt(face);
const Handle_Geom_Surface & geom_surface = face_adapt.Surface().Surface();
if(geom_surface.IsNull())
     return;
Handle_Geom_Surface transformed_surface = Handle_Geom_Surface::DownCast(geom_surface->Transformed(face.Location().Transformation()));
if(transformed_surface.IsNull())
     return;

std::vector<Handle_Geom2d_BSplineCurve> trimming_curves;
for (TopExp_Explorer edge_Expl(face, TopAbs_EDGE); edge_Expl.More(); edge_Expl.Next())
{
     const TopoDS_Edge & edge = TopoDS::Edge(edge_Expl.Current());
     Standard_Real first,last;
     Handle_Geom2d_Curve curve_on_surface = BRep_Tool::CurveOnSurface(edge, face, first, last);
     ShapeConstruct_Curve c;
     Handle_Geom2d_BSplineCurve bspline_curve = c.ConvertToBSpline(curve_on_surface, first, last, 1e-10);
     trimming_curves.push_back(bspline_curve);
}

if(transformed_surface -> DynamicType == STANDARD_TYPE(Geom_BSplineSurface))
{
     Handle(Geom_BSplineSurface) face_surface = Handle(Geom_BSplineSurface)::DownCast(transformed_surface);
     if(face_surface.IsNull())
      return;
     
     GLUnurbsObj * nurbs_obj = gluNewNurbsRenderer();
     gluNurbsCallback(nurbs_obj, GLU_ERROR, (GLvoid (*)()) nurbsError);     
     glEnable(GL_AUTO_NORMAL);
     gluBeginSurface(nurbs_obj);
     gluNurbsSurface(nurbs_obj,..., GL_MAP2_VERTEX_4);
     
     // *** not sure how to find the orientation of the curves. OpenGL trims off the surface on the right side of trimming curves
     // ordering the trimming curves
     ShapeAnalysis_WireOrder ordering(false, Precision::Confusion());
     ordering.KeepLoopsMode() = true;
     for(std::vector<Handle_Geom2d_BSplineCurve>::const_iterator curve_iter = trimming_curves.begin();
      curve_iter != trimming_curves.end(); ++curve_iter)
     {
      gp_Pnt2d first_point, last_point;
      first_point = (*curve_iter) -> StartPoint();
      last_point = (*curve_iter) -> EndPoint();
      ordering.Add(first_point.XY(), last_point.XY());
     }
     ordering.Perform();
     
     // trimming nurbs surface using the trimming curves
     gluBeginTrim(nurbs_obj);
     for(unsigned int index = 1; index <= trimming_curves.size(); ++index)
     {
      int curve_loc = ordering.Ordered(index);
      Handle_Geom2d_BSplineCurve edge_curve = trimming_curves[abs(curve_loc)-1];
      if(curve_loc < 0)
          edge_curve -> Reverse();
     }
     gluNurbsCurve(nurbs_obj,...,GLU_MAP1_TRIM_3);
     gluEndTrim(nurbs_obj);
     
     gluEndSurface(nurbs_obj);
     gluDeleteNurbsRenderer(nurbs_obj);     
}
}
 
 
Latest news
  • Open CASCADE Technology 6.8.0 is available for download!
  • New features to enhance the development process
  • Open CASCADE Technology 6.7.1 is available for download!

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map