For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

trimming NURBS and rendering using OpenGL

vijay's picture
Forums: 

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 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::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 {
int curve_loc = ordering.Ordered(index);
Handle_Geom2d_BSplineCurve edge_curve = trimming_curves[abs(curve_loc)-1];
if(curve_loc edge_curve -> Reverse();
}
gluNurbsCurve(nurbs_obj,...,GLU_MAP1_TRIM_3);
gluEndTrim(nurbs_obj);

gluEndSurface(nurbs_obj);
gluDeleteNurbsRenderer(nurbs_obj);
}
}