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

Related pages

tessellation of Geom_BSplineSurface from opennurbs

Cong Ye's picture
Forums: 

Hi, I am trying to use Opencascade to tessellate opennurbs surface. I converted opennurbs datastructure to Geom_BSplineSurface via the following code. The conversion looks promising to me. However, if i ran BRepBuilderAPI_MakeFace and meshing on the converted BSplineSurface, it wouldn't contain any mesh in there. I included a brep file. 

I am new to opencascade, Thanks very much for any help.

/**
* @brief Convert OpenNURBS NURBS surface to OpenCASCADE Geom_BSplineSurface.
* @param [in] theSurface opennurbs nurbs surface;
* @note pay attention to the knots of opennurbs nurbs curve/surface.
*/
Handle_Geom_BSplineSurface ConvertSurface(const ON_NurbsSurface* theSurface)
{
    TColgp_Array2OfPnt poles(1, theSurface->CVCount(0), 1, theSurface->CVCount(1));
    TColStd_Array2OfReal weights(1, theSurface->CVCount(0), 1, theSurface->CVCount(1));

    TColStd_Array1OfReal UKnotSequence(1, theSurface->KnotCount(0) + 2);
    TColStd_Array1OfReal VKnotSequence(1, theSurface->KnotCount(1) + 2);

    bool IsRational = theSurface->IsRational();
    bool IsUPeriodic = (theSurface->IsPeriodic(0)) ? true : false;
    bool IsVPeriodic = (theSurface->IsPeriodic(1)) ? true : false;

    // control point and its weight.
    for (int i = 0; i < theSurface->CVCount(0); ++i)
    {
        for (int j = 0; j < theSurface->CVCount(1); ++j)
        {
            if (IsRational)
            {
                ON_4dPoint pole;
                theSurface->GetCV(i, j, pole);
                poles.SetValue(i + 1, j + 1, gp_Pnt(pole.x / pole.w, pole.y / pole.w, pole.z / pole.w));
                weights.SetValue(i + 1, j + 1, pole.w);
                printf("rational %f, %f, %f, %f\n", pole.x, pole.y, pole.z, pole.w);
            }
            else
            {
                ON_3dPoint pole;
                theSurface->GetCV(i, j, pole);
                poles.SetValue(i + 1, j + 1, gp_Pnt(pole.x, pole.y, pole.z));
                // non-rational has equally weights
                weights.SetValue(i + 1, j + 1, 1.0);
                printf("non-rational %f, %f, %f, %f\n", pole.x, pole.y, pole.z, 1.0);
            }

        }
    }

    // Knot vector and its multiplicity.
    for (int i = 0; i < theSurface->KnotCount(0); ++i)
    {
        UKnotSequence.SetValue(i + 2, theSurface->Knot(0, i));
    }

    // FIXME control point order
    UKnotSequence.SetValue(UKnotSequence.Lower(), theSurface->Knot(0, 0));
    UKnotSequence.SetValue(UKnotSequence.Upper(), theSurface->Knot(0, theSurface->KnotCount(0) - 1));

    TColStd_Array1OfReal UKnots(1, BSplCLib::KnotsLength(UKnotSequence, IsUPeriodic));
    TColStd_Array1OfInteger UMults(1, UKnots.Upper());

    BSplCLib::Knots(UKnotSequence, UKnots, UMults);

    for (int j = 0; j < theSurface->KnotCount(1); ++j)
    {
        VKnotSequence.SetValue(j + 2, theSurface->Knot(1, j));
    }

    VKnotSequence.SetValue(VKnotSequence.Lower(), theSurface->Knot(1, 0));
    VKnotSequence.SetValue(VKnotSequence.Upper(), theSurface->Knot(1, theSurface->KnotCount(1) - 1));

    TColStd_Array1OfReal VKnots(1, BSplCLib::KnotsLength(VKnotSequence, IsVPeriodic));
    TColStd_Array1OfInteger VMults(1, VKnots.Upper());

    BSplCLib::Knots(VKnotSequence, VKnots, VMults);

    Handle_Geom_BSplineSurface BSplineSurface = new Geom_BSplineSurface(poles,
        weights, UKnots, VKnots, UMults, VMults,
        theSurface->Degree(0), theSurface->Degree(1),
        IsUPeriodic, IsVPeriodic);

    GeomTools_SurfaceSet::PrintSurface(BSplineSurface, std::cout);
    TopoDS_Face face = BRepBuilderAPI_MakeFace(BSplineSurface, Precision::Confusion()).Face();
    //BRepMesh_IncrementalMesh inMesh(face, 1, false, 1);

    // Dump in brep format
    std::filebuf aFileBuf;
    std::ostream aStream(&aFileBuf);
    if (aFileBuf.open("C:\\temp\\trimmedNurbsShape.brep", ios::out)) {
        BRepTools::Write(face, aStream);
    }
    aFileBuf.close();
    return BSplineSurface;
}

Attachments: 

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.