3D pipe drawing in Python/Matlab - python

I'm working on this paper in which I'm simulating Vibration of Pipe Elbows with FEM, originally I made this in Matlab but then I migrated to Python.
Basically my data is stored in nodes, like this, where I have the coordinates of the node on the centerline of the pipe and the coordinates of the centerline of the cross-section.
I would like to use these data to make a smooth surface plot like this other one from this paper. But I'm not really sure about what function of Matplotlib I could use to work this out.
Somebody has an idea for this?

Related

Triangle mesh generation of 3D objects using Python

Hey everyone I'm pretty new to graphics programming and I want some guidance or working samples, I want to make any 3D objects but for starters I want to make a 3D cube using triangle mesh with given coordinates via python, and export all the mesh in an .obj file so I can load the mesh and view it in meshlab.
I would really love some guidance on this thanks.
if you are comfortable with meshlab you could find useful pymeshlab
https://pymeshlab.readthedocs.io
Here is a simple tutorial on how to create a mesh from just array of coords and indexes...
https://pymeshlab.readthedocs.io/en/latest/tutorials/import_mesh_from_arrays.html

Noisy 3D point cloud to interpolated surface mesh in python

My general goal is going from a noisy point cloud describing a surface, to a regular surface mesh, in Python. I have found a few solution to this problem, none of which apply to my case well enough. The best ones I found:
B-spline -> sample it -> get new points. This calculates the z values of a function based on a regular set of x,y coordinates, which won't work well for near-vertical surfaces, of which I have a lot.
Rolling ball / convex hull algorithms. My data is noisy along the normal to the surface, so I would get a surface that's "inflated". I would need first to denoise it, which itself requires the calculation of a spline, or something similar.
I feel like there must be an "easy" way to do this, but I just don't know what to look for. Can someone point me in the right direction?
My best guess is that there should be a way to sample a spline surface "regularly" relatively to itself, but I can't figure out how.
The problem which you describe is named surface reconstruction. There is many algorithms and software (standalone program or libraries) able to reconstruct one surface from a set of sample points. There is important differences depending if you have only the XYZ coordinates of the points, or you have more information as the color or the normal to the surface.
Naming some examples, you can use:
Screened Poisson, by Kazhdan and Bolitho. Which is implemented in meshlab, and many other python libraries. Probably your best option.
PowerCRUST, by Nina Amenta, Sunghee Choi and Ravi Kolluri.
Ball Pivoting, by Bernardini, Mittleman, et al. Quite simple and easy to implement by yourself.

Projecting a 3D surface onto a 2D plane (unfolding/unwrapping) in Python

I don't know if I am just searching for the wrong terms but I cannot find any examples of code to do this. I have a surface that is almost flat but not quite and would like to "unfold" or "unwrap" it so that it is all in one plane while keeping the distance between points the same. From what I understand this process is called developing a surface, but all I can find are old mathematical papers on the process would be quite a bit of work trying to recreate.
Can't really provide any code for it but I have data in the form of points like
coords = [(x_1, y_1, z_1), (x_2, y_2, z_2),..., (x_n, y_n, z_n)]
It doesn't seem like it should be that hard to do but maybe I am mistaken, any input?

Map a texture onto a model in Python

To frame this question: I am a complete beginner in terms of 3d rendering, and I would like to get my feet wet.
My goal is to create a command-line script (ideally in Python) which takes some kind of 3d model file (e.g. a sphere), maps a texture onto it, and outputs the result as an image file. That is, I would like my program to essentially be able to "do" the following:
From my reading, this appears to be something known as "uv mapping", but almost everything I've found on the subject in on how to do this using Blender, and I would prefer avoiding this: in a 2d analogy, it seems to me that Blender is like Photoshop where I'm looking for something like ImageMagick. Beyond that, I haven't been able to find much.
The closest I have found is this other stackoverflow question:
uv mapping works bad on low resolution (warning: lot of images)
But I don't quite understand what's going on there, because it doesn't import a 3d model at all -- it is my [perhaps mistaken?] understanding that EXR is a 2d image format.
Any guidance on how to get started would be greatly appreciated!

Pipeline to create Voronoi Meshes

I would like to implement a Maya plugin (this question is independent from Maya) to create 3D Voronoi patterns, Something like
I just know that I have to start from point sampling (I implemented the adaptive poisson sampling algorithm described in this paper).
I thought that, from those points, I should create the 3D wire of the mesh applying Voronoi but the result was something different from what I expected.
Here are a few example of what I get handling the result i get from scipy.spatial.Voronoi like this (as suggested here):
vor = Voronoi(points)
for vpair in vor.ridge_vertices:
for i in range(len(vpair) - 1):
if all(x >= 0 for x in vpair):
v0 = vor.vertices[vpair[i]]
v1 = vor.vertices[vpair[i+1]]
create_line(v0.tolist(), v1.tolist())
The grey vertices are the sampled points (the original shape was a simple sphere):
Here is a more complex shape (an arm)
I am missing something? Can anyone suggest the proper pipeline and algorithms I have to implement to create such patterns?
I saw your question since you posted it but didn’t have a real answer for you, however as I see you still didn’t get any response I’ll at least write down some ideas from me. Unfortunately it’s still not a full solution for your problem.
For me it seems you’re mixing few separate problems in this question so it would help to break it down to few pieces:
Voronoi diagram:
The diagram is by definition infinite, so when you draw it directly you should expect a similar mess you’ve got on your second image, so this seems fine. I don’t know how the SciPy does that, but the implementation I’ve used flagged some edge ends as ‘infinite’ and provided me the edges direction, so I could clip it at some distance by myself. You’ll need to check the exact data you get from SciPy.
In the 3D world you’ll almost always want to remove such infinite areas to get any meaningful rendering, or at least remove the area that contains your camera.
Points generation:
The Poisson disc is fine as some sample data or for early R&D but it’s also the most boring one :). You’ll need more ways to generate input points.
I tried to imagine the input needed for your ball-like example and I came up with something like this:
Create two spheres of points, with the same center but different radius.
When you create a Voronoi diagram out of it and remove infinite areas you should end up with something like a football ball.
If you created both spheres randomly you’ll get very irregular boundaries of the ‘ball’, but if you scale the points of one sphere, to use for the 2nd one you should get a regular mesh, similar to ball. You can also use similar points, but add some random offset to control the level of surface irregularity.
Get your computed diagram and for each edge create few points along this edge - this will give you small areas building up the edges of bigger areas. Play with random offsets again. Try to ignore edges, that doesn't touch any infinite region to get result similar to your image.
Get the points from both stages and compute the diagram once more.
Mesh generation:
Up to now it didn’t look like your target images. In fact it may be really hard to do it with production quality (for a Maya plugin) but I see some tricks that may help.
What I would try first would be to get all my edges and extrude some circle along them. You may modulate circle size to make it slightly bigger at the ends. Then do Boolean ‘OR’ between all those meshes and some Mesh Smooth at the end.
This way may give you similar results but you’ll need to be careful at mesh intersections, they can get ugly and need some special treatment.

Categories