Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nurbs-interpolated coloring of SoNurbsSurface #413

Open
looooo opened this issue Sep 25, 2020 · 8 comments
Open

nurbs-interpolated coloring of SoNurbsSurface #413

looooo opened this issue Sep 25, 2020 · 8 comments
Labels
question Further information is requested

Comments

@looooo
Copy link

looooo commented Sep 25, 2020

I am looking for a way to put a color-distribution onto a SoNurbsSurface using the same basis for the color interpolation? I tried to do this the same way as it is done for IndexedFaceSets but it didn't work.

trying to visualize the z-value for this python example:

knots = ...
pts = ...

surf_sep = SoSeparator()
surface    = SoIndexedNurbsSurface()
vertex_property = SoVertexProperty()
complexity = SoComplexity()
complexity.value = 0.7
surface.numUControlPoints = 4
surface.numVControlPoints = 4
surface.uKnotVector.setValues(0, 8, knots)
surface.vKnotVector.setValues(0, 8, knots)
vertex_property.materialBinding = SoMaterialBinding.PER_VERTEX

for i, pt in enumerate(pts):
    color = SbColor(pt[2],1, 1).getPackedValue()
    vertex_property.vertex.set1Value(i, pt)
    vertex_property.orderedRGBA.set1Value(i, color)

surf_sep += [complexity, vertex_property, surface]
@VolkerEnderlein
Copy link
Collaborator

This is a limitation of the original Inventor specification. See Inventor documentation . I agree, that we should improve the Coin documentation of the SoNurbsCurve/Surface classes to pinpoint those limitations.

@looooo
Copy link
Author

looooo commented Sep 27, 2020

@VolkerEnderlein any chance we can add such a functionality? but I am also not sure if the glu library supports coloring nurbs this way.

@VolkerEnderlein
Copy link
Collaborator

I would not recommend it as it breaks the intention of the original hierarchy. If you look to the hierarchy under SoShape you'll see primitives like Cone, Cylinder, Cube, Sphere, NurbsCurve, NurbsSurface, Text2 and Text3 as well as VertexShapes and VRMLGeometry. The materials for primitives can be specified PER_FACE or OVERALL, but not PER_VERTEX, as the vertices of primitives do not have to be specified. They are generated according to the complexity value and the ObjectSpace and ViewSpace setting. The coordinates/vertices you specify for the NURBS are control points and in general neither do coincide with vertices on the surface of the NURBS shape nor can be easily mapped onto the surface. I think you get far better results in coloring an arbitrary surface when creating an IndexedFaceSet or an FaceSet (or TriangleStrips) with given colors for the vertices.

@veelo
Copy link
Member

veelo commented Sep 28, 2020

Just throwing this out there:

trying to visualize the z-value

If this is your goal, you'll be able to do that for any shape by writing a shader. Admittedly, it is not a straightforward solution.

A 3D texture is also an option (for a simple linear gradient you only need two pixels). This is rather straightforward.

@looooo
Copy link
Author

looooo commented Sep 28, 2020

If this is your goal, you'll be able to do that for any shape by writing a shader. Admittedly, it is not a straightforward solution.

No, it is meant as an easy example. I would like to visualize a solution of a PDE solved directly for nurbs-surfaces. So every controlpoint has a result (eg. pressure) which is mapped onto the surface via the nurbs-basis functions.

@veelo
Copy link
Member

veelo commented Sep 28, 2020

I would like to visualize a solution of a PDE solved directly for nurbs-surfaces. So every controlpoint has a result (eg. pressure) which is mapped onto the surface via the nurbs-basis functions.

Maybe you can derive from SoNurbsSurface and implement that functionality there. Otherwise you can discretize the NURBS to an IndexedFaceSet like Volker suggests.

@looooo
Copy link
Author

looooo commented Sep 30, 2020

A 3D texture is also an option (for a simple linear gradient you only need two pixels). This is rather straightforward.

This is an interesting idea. But how to generate a texture from a nurbs. If the control points are given by [u, v, z], I need to generate a texture where u, v are the pixel coordinates and z generates the color.

@veelo
Copy link
Member

veelo commented Sep 30, 2020

A 3D texture is also an option (for a simple linear gradient you only need two pixels). This is rather straightforward.

This is an interesting idea. But how to generate a texture from a nurbs. If the control points are given by [u, v, z], I need to generate a texture where u, v are the pixel coordinates and z generates the color.

This was only a suggestion for when the color should map to the z component of the geometry. I don't think it can be applied to your use case.

However, you can use SoTextureCoordinate2 to visualize for example pressure over a surface (you'd have to check if this includes SoNurbsSurface). I am using a 1x2 pixel texture, and by varying the texture coordinate between (0.5, 0.5) and (0.5, 1.5) I can select any shade between twose two pixel values, varying over the surface. I use this to color a triangle strip to visualize curvature. So, texture coordinates need not be proportional to (u, v) parameters at all, which is pretty cool. You can cover all rainbow colours with only a handful pixels. But I guess you'd still have to discretise the surface into a SoIndexedFaceSet. Or, maybe you can implement a custom node that produces texture coordinates for a SoNurbsSurface. That may be the most elegant solution.

@VolkerEnderlein VolkerEnderlein added the question Further information is requested label Oct 28, 2020
@VolkerEnderlein VolkerEnderlein changed the title nurbs-interpolated coloring of SoNurbsSurface (question) nurbs-interpolated coloring of SoNurbsSurface Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants