How to interpolate colour or a triangulated surface - python

I am near my wits end with this problem. Please bear with me as I try to explain my problem. I have a 3D model with a triangulated surface. I then need to add some data (in the form of colour) to the surface of the 3D model. It should resemble something shown in this figure: http://user.cscs.ch/fileadmin/user_upload/customers/users_entry_point/pictures/Visualization/Gallery/Cardiac_Therapy.png.
My problem is that I don't really know how to interpolate data over a triangulated surface. I was wondering if someone might have an idea or possible point me in the right direction.
I should mention that I am using python and mayavi but I am also willing to work with MATLAB.

Matlab's trisurf may work for you. You give it (x,y,z) coordinates and a color for each vertex.

Related

Is it possible to create a thick Mesh?

I'm totally new to this field, I'm using python and Trimesh to create a 3D model of a bone and I need to figure out how can I create or represent the thickness of the bone I only have surface of the bone which is ok, but I need also to represent how the bone looks inside this surface, Anyone has a clue on how to approach this problem?
Ask me if you need more information, I'm not sure what you need to know to understand the problem.
Thanks in advance.
You can use gmsh along with mmg to mesh in volume your surface.
Depending on what you need.
if you want to display volumetric informations, you have 2 options:
generate a voxel filling the volume delimited by your surface
triangulate your volume with tetraedrons (I heard that gmsh was good for it)
if you just want to have successive inner surfaces, you can use offseted/deflated surfaces
this can simply be achieved by offsetting your first surface points along their normal
you can use for instance inflate or thicken here from the pymadcad module

How to determine if a set of co-planar points form a circle in 3D?

I have a set of co-planar points in 3D. Some of these points that are co-planar form a circle while some co-planar points do not.
Is there a way for me to program (ideally python) and determine what points are forming a circle and what points do not?
I have seen solutions for this problem in 2D space here which probably won't work in 3D while the solutions proposed here are "mathematica" focused that I am unable to apprehend fully.
Can someone please guide me towards the possible solution?
Any three points always lie on a circle. Find one circle, then test any other points. Doing that in 3D is almost the same as in 2D (https://www.gamedev.net/forums/topic/489058-how-to-draw-a-circle-given-three-points-in-3d-space/)

What is a method to create an jigsaw puzzled sphere in Blender?

I'm just a newbie in Blender.
Going to create an jigsaw puzzled sphere model, like wikipedia one, or these plastic 3D puzzles you have probably saw.
For now, i have created Python script which creates arbitrary plain 2D puzzles with Bezier curves, which later can be easy be converted to a mesh
But how to wrap it around a sphere ?
PS. Just had an idea -
to unwrap cube on the puzzle plane, copy edges as negative as shown below
(there no copy of edges on the picture yet).
Then with affine transformations, transform each 2D cube face to respective 3D place, and then apply Object->Transform->To Sphere modifier.
What do you think ? Is there a better way to create puzzled sphere ?
Thanks for your attention !
EDIT: You know, there is a dodecahedron, which can be also assembled from pentagon faces
Transformed code to blender add-on
https://bitbucket.org/ios29A/blender_puzzle_generator, maybe it will help someone
Actually 30Kb of Python code, and cube faces are transformed by hands
Just finished it with affine transformations of cube faces.
See a heart from 7x7x7 cube, so here is plain->cube->sphere->lattice transform
I think this method makes it possible to create any 3D shape from squares, even not sphere ones.
Was going to print it in plastic before metal.
Here it is 3х3х3 and was made right before 14' February
It's much simpler than you may imagine.
Download the addon from the given link above (https://bitbucket.org/ios29A/blender_puzzle_generator).
Install it (refer to the documentation).
In Blender, create a cuboid puzzle (add-curve-puzzle. Choose cuboid in the shape option).
Convert the curve into a mesh (object-convert to-mesh...)
Select the cuboid and enter edit mode (tab)
Select all (A)
Mesh-transform-to sphere.
Move your mouse.

3D colour interpolation Python

Firstly I'm sorry if this is a duplicate!
To explain the situation, I have developing an application that will display a 3D, real time model of an object. On this model I have a series of pressure sensors which will relay the information to my application. Each pressure will then be assigned a colour to produce a 3D pressure map on the surface of my model. I have 144 pressure sensors and around 21000 vertices on my mesh. Each sensor will be assigned an RGB colour.
Please can someone help me understand how I can use barycentric interpolation to interpolate the known colours (144 of them) across the rest of my model?
This website nicely shows what I'm trying to achieve: https://codeplea.com/triangular-interpolation however I cannot find anything that helps me in 3 dimensions.
Help! :)
Firstly, thank you for the nice page about barycentric interpolation you provided in the question!
Secondly, you may triangulate your model with the sensor in every point, and interpolate between sensor values inside every triangle, no matter if it's 2D or 3D -- triangle is a triangle. With barycentric you'll get nice matching colours along every edge, the whole model is going to look very cool.

Mapping a texture to a mayavi mesh

I'm using mayavi in python to visualize some data. I have a surface in 3D space and I want to map an image to it. I have looked at mayavi documentation and all I could find was this, which really doesn't help me much. Has anybody done something like this before?
I found that the mesh function actually does take a scalars argument, which then colors the corresponding point on the surface in accordance to the chosen colormap. I still however don't know how to map an arbitrary RGB image to the surface.
I guess you didn't saw the chapter "Python scripting for 3D plotting". There is a collection of the mayavi commands which can be used inside python. For example the section "3D Plotting functions for numpy arrays". If you follow the links you find some description about the functions and a small example for each of them.
For your case you should take mesh or surf. Both functions are kind of equal, but are different. For example the surf function is more a subfunction of mesh, which is my opinion. You don't really have to define x and y-coordinates, you just need the z-coordinates in a 2D array. If you want to use mesh you have to pass all three coordinates (x,y,z) as 2D arrays.
I would suggest to check the examples.
Is this an answer to your question? Maybe you should be more specific about what you want to do.
Have a nice day and Happy Holidays.

Categories

Resources