How can I get the image plane of a rendered 3D mesh?
조회 수: 3 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
George Abrahams
2024년 1월 23일
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.
댓글 수: 0
추가 답변 (1개)
George Abrahams
2024년 2월 10일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!