How can I get the image plane of a rendered 3D mesh?

4 visualizaciones (últimos 30 días)
Aura Munoz
Aura Munoz el 31 de Mzo. de 2015
Editada: Matt J el 10 de Feb. de 2024
I need to get the pixel value of a specific (x,y) 2D coordinate after rendering a 3D mesh into the image plane/ axes plot box.
I'm using the trimesh function to create the mesh based on the vertices and the faces and rendering using opengl and a perspective projection by setting the axis as
set(gca, ...
'DataAspectRatio', [ 1 1 1 ], ...
'PlotBoxAspectRatio', [ 1 1 1 ], ...
'Units', 'pixels', ...
'Position', [ 0 0 width height ], ... 'Projection', 'perspective');
and using
view(az,el);
Is there another way instead of calculating the perspective projection and all the matrices multiplications inside the my code?

Respuesta aceptada

George Abrahams
George Abrahams el 23 de En. de 2024
The most literal answer to your question is getframe. For example:
surf( peaks )
% Convert the plot to an image.
F = getframe;
% Show the image and the colour value of a sample point.
close
imshow( F.cdata )
center = ceil( size( F.cdata, 1:2 ) / 2 );
text( center(2), center(1), ...
"(" + strjoin( string( F.cdata(center(1),center(2),:) ), "," ) + ")", ...
"BackgroundColor", "w" )
Without more information, however, it's impossible to know if this meets your requirements.

Más respuestas (1)

George Abrahams
George Abrahams el 10 de Feb. de 2024
Me again. The alternative is to, like you said, render it yourself with perspective projection etc. This will give you full control over the camera, for example, so that you can set the image resolution, limit what's rendered according to field-of-view, and have no other graphic elements on the screen, such as the axes.
Thankfully people have already released code for this so you wouldn't be going from scratch. One option is my 3D Rendering Toolbox, but a few other options also exist on File Exchange.

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by