The problem about creating a NURBS plane

I modified the function about the writing NURBS surface.
Like this:
static bool write_surfaces_example( FILE* fp, int version )
const int bIsRational = false;
const int dim = 3;
const int u_degree = 2;
const int v_degree = 2;
const int u_cv_count = 3;
const int v_cv_count = 3;

double u_knot[ u_cv_count + u_degree - 1 ];
double v_knot[ v_cv_count + v_degree - 1 ];

u_knot[0] = u_knot[1] = 0;
u_knot[2] = u_knot[3] = 1;

v_knot[0] = v_knot[1] = 0;
v_knot[2] = v_knot[3] = 1;

ON_NurbsSurface nurbs_surface( dim, bIsRational, u_degree+1, v_degree+1, u_cv_count, v_cv_count );

    nurbs_surface.SetKnot(0 , 0 , 0);
nurbs_surface.SetKnot(0 , 1 , 0);
nurbs_surface.SetKnot(0 , 2 , 1);
nurbs_surface.SetKnot(0 , 3 , 1);
nurbs_surface.SetKnot(1 , 0 , 0);
nurbs_surface.SetKnot(1 , 1 , 0);
nurbs_surface.SetKnot(1 , 2 , 1);
nurbs_surface.SetKnot(1 , 3 , 1);

nurbs_surface.SetCV(0 , 0 , ON_3dPoint(0 , 0 , 1));
nurbs_surface.SetCV(0 , 1 , ON_3dPoint(1 , 0 , 1));
nurbs_surface.SetCV(0 , 2 , ON_3dPoint(2 , 0 , 1));
nurbs_surface.SetCV(1 , 0 , ON_3dPoint(0 , 1 , 1));
nurbs_surface.SetCV(1 , 1 , ON_3dPoint(1 , 1 , 1));
nurbs_surface.SetCV(1 , 2 , ON_3dPoint(2 , 1 , 1));
nurbs_surface.SetCV(2 , 0 , ON_3dPoint(0 , 2 , 1));
nurbs_surface.SetCV(2 , 1 , ON_3dPoint(1 , 2 , 1));
nurbs_surface.SetCV(2 , 2 , ON_3dPoint(2 , 2 , 1));

bool ok = false;
if ( nurbs_surface.IsValid() ) 
	ON_BinaryFile archive( ON::write3dm, fp );
	ok = ON_WriteOneObjectArchive( archive, version, nurbs_surface );

return ok;

but,whatever the function provided by the example_write.cpp and my modified function running. the result is a plane all the time.
like this.

I wonder know why. I have spend much time on this. :joy:
Best Regards

What you’ve created is neither a Plane nor a PlaneSurface, You created a NURBS surface.

 NURBS Surface
    "U":  degree =2  CV count = 3  (0.000 <= U <= 1.000)
    "V":  degree =2  CV count = 3  (0.000 <= V <= 1.000)

Use the What and List commands to examine.

Is there a question here?

Oh,thanks.I have already solve my problem.
But,there are three question.

At first, you said “use the what and list commands to examine”. Does it mean oprating it in the rhino software?

Then, I am confused about how to set the parameter domain of NURBS surface in the openNURBS.
I found that if I set the knot like this:

    nurbs_surface.SetKnot(0 , 0 , 1);
nurbs_surface.SetKnot(0 , 1 , 1);
nurbs_surface.SetKnot(0 , 2 , 3);
nurbs_surface.SetKnot(0 , 3 , 4);
nurbs_surface.SetKnot(0 , 4 , 5);

nurbs_surface.SetKnot(1 , 0 , 1);
nurbs_surface.SetKnot(1 , 1 , 1.5);
nurbs_surface.SetKnot(1 , 2 , 3);
nurbs_surface.SetKnot(1 , 3 , 4);
nurbs_surface.SetKnot(1 , 4 , 5);

but the domain shows as

NURBS Surface
"U": degree =2 CV count = 4 (1 <= U <= 4)
“V”: degree =2 CV count = 4 (1.5 <= V <= 4)

why?My u_knot’s value have reached 5, however , the domain of u direction is 1<=U<=4.

Finally, can I convert the trim nurbs surface to the T-splines?
ps. I have seen some other topic in the forum.You said the openNURBS can not mesh the surface? I can use gl.cpp to show the surface.why can not we mesh?



See opennurbs_nurbssurface.cpp for the definition of ON_NurbsSurface::Domain.

No, openNURBS is only a toolkit for reading and writing 3DM files.

This is correct.

two question:
At first, what is the function of the class ON_Mesh in the openNURBS toolkit?

Second, Can not I creat the data of the mesh and write it into the 3dm file?

I could not understand it absolutely. There are many functions about teimmed NURBS.Can I write an algorithm to convert trimmed nurbs to the T-spline and then use the toolkit write it into the 3dm file?

I don’t understand this question. Can you try again?

You can create your own meshes. See opennurbs_mesh.h for information on the ON_Mesh class. But, you cannot, with openNURBS, create meshes from surfaces.

No. T-Splines stores data on 3DM files as user data, and they are the only ones who know how this data is written and structured. If you (want to try) to read their data, you will need to contact Autodesk.

You said that there is no mesh in openNURBS tookit.But I see many funtions and classes about mesh.Such as ON_Mesh.So, I wonder why?

Now that it is unable to mesh.Why add these classes in it?

Please re-read my replies.

The openNURBS toolkit will not create meshes from Breps. That is, if you have a Brep, the toolkit will not create a mesh representation of it.

That said, Rhino can create meshes from Breps. Rhino can also create meshes from scratch, and it can import meshes from other file formats. All of these meshes are stored in the 3dm file and are represented by the ON_Mesh class.

Hi dale,

Can I get the point on the NURBS surface using the function in the openNURBS?

That is , if I want to get the point on the NURBS surface , what should I do ?


If you were using the Rhino C++ SDK, you would use ON_Surface::GetClosestPoint. But this function is not implemented in the free openNURBS toolkit.

If I just want to pick up some information of one nurbs surface.

For example, I define “double a” in my program.I want let the “a” = the value of the knot in the nurbs surface defined by the free opennurbs toolkit. Can I achieve it?

In addition, I want to get it when I read a model.Such as in the example_read.cpp.

To obtain the knot values of a NURBS surface, use ON_NurbsSurface::Knot. See opennurbs_nurbssurface.h for details.

I have read the ON_NurbsSurface again.But my problem is still unsolved.

ONX_Model model;

ON_BinaryFile archive( ON::read3dm, archive_fp );

// read the contents of the file into “model”
bool rc = model.Read( archive, &dump );

ON::CloseFile( archive_fp );

The above is from the example_read.cpp.I can not use model.knot to obtain the knot values.
Is the ON_NurbsSurface included in the ONX_Model ?

I use the cmd to run the example_read.exe to read a nurbs surface I wrote.It show many control vertices and knot values. I wonder how to get these values.

That is , when the read() function in the ONX_Model run ,where the model data go .

The output you are displaying is produced by ON_NurbsSurface::Dump. You might consider reading the source code found in opennurbs_nurbssurface.cpp.

Hello dale,

Can I get the information of the NURBSSurface in the ON_Brep class?Such as control point.

I have written a trimming NURBSSurface.But the information is all about the ON_Brep information.I do not know how to get the control point information about the NURBSSurface been trimmed.

The picture showed that a trimming NURBSSurface’s information but the conrtol point of it.

The underlying surfaces of a Brep are stored on the ON_Brep::m_S array. Does this help?