# ON_NurbsSurface control vertices

Hi!

I am using opennurbs library, and I’m trying to create a simple square surface taken from an image:

https://postimg.org/image/4jvelpjn5/

I am setting the C & V vector sizes to the image height and width:

ON_NurbsSurface *surf = ON_NurbsSurface::New(3, false, 4, 4, im_height, im_width);

Then, for each white pixel in the image, I add a control point/vertex:

surf -> SetCV(x, y, ON_3dPoint(x, y, 0));

Now the result I’m getting is this:

https://postimg.org/image/lc6cy0mrr/

For some reason it is connecting all control points to the origin (0,0), I have no idea why.

Is there a fix for this please?

Kind regards.

Hi Elias,

Here is some useful background information on NURBS geometry.

http://developer.rhino3d.com/guides/opennurbs/nurbs_geometry_overview/

You can create a “square” NURBS surface as follows:

``````// The degree must be >= 1
int degree = 1;

// The order = degree + 1
int order = degree + 1;

// The number of control points must be >= (degree + 1)
int cv_count = 2;

// Create a non-rational degree 1 NURBS curve with 2x2 control points
ON_NurbsSurface nurbs(3, FALSE, order, order, cv_count, cv_count);

// Add "Euclidean",or world 3-D, locations for the control points
nurbs.SetCV(0, 0, ON_3dPoint(0, 0, 0));
nurbs.SetCV(0, 1, ON_3dPoint(0, 10, 0));
nurbs.SetCV(1, 0, ON_3dPoint(10, 0, 0));
nurbs.SetCV(1, 1, ON_3dPoint(10, 10, 0));

// The number of knots must be = degree + cv_count - 1
nurbs.SetKnot(0, 0, 0);
nurbs.SetKnot(0, 1, 10);
nurbs.SetKnot(1, 0, 0);
nurbs.SetKnot(1, 1, 10);

if (nurbs.IsValid())
// TODO...
``````

Does this help?

– Dale

Dear Dale,

I have already tried drawing simple shapes, and it works just fine.

But my problem is this: instead of a square, say we want to produce an ‘L’ shape.

The code given above introduces a problem in this special case:

https://postimg.org/image/fjnv85yx3/

To create the nurbs surface I do:

``````ON_NurbsSurface nurbs(3, false, 2, 2, 3, 3);

nurbs.SetCV(0, 0, ON_3dPoint(0, 0, 0));
nurbs.SetCV(0, 1, ON_3dPoint(0, 10, 0));
nurbs.SetCV(1, 0, ON_3dPoint(10, 0, 0));
nurbs.SetCV(1, 1, ON_3dPoint(10, 10, 0));
nurbs.SetCV(1, 2, ON_3dPoint(10, 20, 0));
nurbs.SetCV(2, 0, ON_3dPoint(20, 0, 0));
nurbs.SetCV(2, 1, ON_3dPoint(20, 10, 0));
nurbs.SetCV(2, 2, ON_3dPoint(20, 20, 0));

nurbs.MakeClampedUniformKnotVector(0);
nurbs.MakeClampedUniformKnotVector(1);

//Export to ply using pcl:
pcl::PolygonMesh m;
pcl::on_nurbs::Triangulation::convertSurface2PolygonMesh (nurbs, m, 256);
pcl::io::savePLYFile("m.ply", m);
``````

The code above produces this result:

https://postimg.org/image/xdfh6sd1z/

Which is false. I hope I provided enough information.

Kind regards,
Elias.

P.S. I am not providing any knot values, which I believe get generated automatically. However, I don’t think they are the cause of this.

Hi Elias,

It is not possible to define a NURBS surface with that kind of shape.

What you will need to to is create the planar surface and then defined the trimmed area using an `ON_Brep` object.

Rolling your own breps can be challenging. But there is plenty of good information in the openNURBS headers (opennurbs_brep.h) that will help you with this.

Also, here are a couple of samples that might be worth studying. Note, these samples are from the Rhino SDK samples repository. But the use openNURBS…

Let me know if this helps.

– Dale

Mr. Dale,

Now I’m using a different method to create the nurbs surface.

Thank you!