I have triangulated geometry (STL file) and I have the values of a vector field for each triangle. I want to plot the triangles with the vector field on each triangle and also color the triangle according to the magnitude of the vector.
Is there any way of accomplishing this using languages like python or any open-source software such as gnuplot,etc.?
If not, what about software like MATLAB?
According to http://en.wikipedia.org/wiki/STL_%28file_format%29 you can store color and normal informations in a STL binary file. I'd make a python script that creates a new binary STL where each facet (triangle) has a color and use the normal to store the vector. Then I'd import this file in Blender and ask it to display the normals and the flat face colors. You'll then do an OpenGL render (it is just a button to push) to export a PNG file of the view you want to see.
Do you have a sample scene ?
Related
I have a stl model which consists of a cube that was heated. I wrote a software which calculates the temperature distribution at every voxel in the cube, so it is essentially like a heat map where blue colored voxel is colder region and red colored voxel is warmer region on the cube.
The user provides how many voxels the cube stl model will be divided into and the code calculates the temperature at each voxel in the cube. This information is provided to me in an hd5f file which I can turn into a numpy array with 3 dimensions that indicates the temp at each x,y,z voxel. I want to display this 3d heatmap in the browser using Three Js so the user can rotate and section through the distribution to see how the temperature is distributed in the cube.
So I am trying to figure out how to display this hd5f file or convert the numpy array into something that can be displayed in the browser so that the user can see the temperature distribution on the cube. I found an example where they display a nrrd file in Three Js here. I thought maybe I could convert the numpy array I had into an nrrd file and also display it in the browser like the example using the following code:
import nrrd
import os
nrrd_file_name = os.path.dirname(__file__) +'\\test.nrrd'
nrrd.write(nrrd_file_name, temp_distribution_array, index_order='C') # array is size (61,61,61)
However, when I use the example code and replace their nrrd file with mine, I simply get a black screen with the console stating WebGL: INVALID_OPERATION: texSubImage3D: type FLOAT but ArrayBufferView not Float32Array. So I am unsure how to convert my 3d numpy array or my hd5f file into something that can be visualized in three js.
Hence, I was wondering if there is a better way to approach this or if anyone knows how to display hd5f files into the canvas or is there some other format I could use to display a 3d temperature heatmap in three js?
My goal is to project feature vectors I have on an image pixel level onto voxels (via ray casting/marching). The ideal output would be to cast a ray and get the first intersected voxel as output. I have the camera intrinsics, extrinsics and the voxels. So I should have everything that is needed to do it. Currently my voxels are in a sparse format, i.e. an array of coordinates and feature vectors associated with each coordinate.
But unfortunately I couldn't find a simple way to do it. Is there some performant python library, that should work well for this usecase?
I know of open3d but it only seems to support my usecase for meshes.
I have vector graphics. (In my first case, it's the epigraph of a function whose formula is given. So it is a shape whose outline is given by a parametric curve.)
I want to rasterize this image with anti-aliasing. So I want raster graphics, i.e. a numpy array. I want to obtain this array in a low-level way, avoiding libraries that are meant for object-oriented interactive GUI visualizations with plot axes, etc.. I just want an array. The only problem with doing something like Y,X=np.ogrid(...) and then picture = Y>f(X) is that that's not anti-aliased. (Note that blurring that binary picture is worse than a good dedicated anti-aliasing algorithm.) How to rasterize with anti-aliasing in Python without any overkill GUI-centered libraries?
If the curve is given by an implicit equation F(x,y)=0, evaluate the value of the function at the four corners of every pixel. If the signs are the same, the pixel is wholly outside or inside. If the signs vary, the area inside the polygon formed by the corners and the points along the edges where the function vanishes (find these by a mere linear interpolation) tells you the mixture of background and foreground colors (alpha blending coefficient).
Tracing the polygon isn't that difficult: traverse the four edges of the square and keep the positive vertices and zero points in the order you meet them. You will get from a triangle to an hexagon. The area is obtained by the shoelace formula.
The case of a parametric function is a little harder. You need to find the intersections of the curve with the grid lines, and perform the area estimation in all cells that are traversed. For this, draw the curve as a polyline (this is called flattening), and slice the polyline with horizontals, then verticals.
Manim might be able to rasterize epigraphs and parametric curves well and fast. Its community edition seems actively maintained.
Edits/comments with details are welcome.
i have a shirt displayed as a 3D model in the file format „obj“ or „fbx“ . I would like to calculate the object width at a specific height. It would be best, when i have the coordinates from all points at a specific height. Can anyone tell me, a python or javascript framework for that or a suggestion, how i can calculate this manually.
enter image description here
If you're using the OBJ format, then you have no unit data. It's triangles but no absolute scale.
What you're looking for should be easy to moderately difficult to determine. 3D Printing slicing software does exactly what you want to calculate the path for 3d printers. You'll take your 3D model and make sure it's oriented so "up" makes sense - the neck of the shirt in your example, then run the slicer on it at various heights.
You'll get a 2D slice of a 3D object as the intersection of a plane with the model at that height. You'll then have to compute the bounding box around the slices and adjust the width to fit whatever units high your model is.
A good place to start might be this library: https://pypi.org/project/meshcut/
or else look for open source 3D printer slicing software.
I have a series of images of a structure with different z values (each photo is taken 5µm higher than the last one).
I wrote a programm that calculates the area of the structure for each photo. I also have a list that stores this area for each photo as a binary image (background = black, area = white).
Since I basically have all 3 coordinates for my structure I think it should be possible to create a STL file to plot this structre in 3D space.
Since I never did anything in terms of 3D programming I don't really know how to do this.
I would appreciate any help