
Overlaying a spherical surface on a graphics object
3 次查看(过去 30 天)
显示 更早的评论
f1 = uifigure('Name','Dose 2 Cell');
g1 = uigridlayout(f1,[1 1],Padding=[0 0 0 0]);
viewer = viewer3d(g1);
viewer.BackgroundGradient="off";
viewer.BackgroundColor="white";
doseV = volshow(DoseCube,Parent = viewer);
doseV.Colormap = jet;
The above chunk of code renders a 3D volumetric dataset DoseCube that has dimensions 100x100x100 in graphics object created by viewer3d. I want to overlay a spherical surface geometry onto this graphics object. I can create an appropriate sized sphere using the sphere() and surf() functions but can't work out how to get it to display in the same graphics object window?
0 个评论
回答(1 个)
akshatsood
2023-9-1
编辑:akshatsood
2023-9-1
Hi Andrew,
I understand that you desire to overlay a spherical surface on a graphics object. As per my understanding of the your requirements, I believe that using volshow to render a spherical surface and setting Parent = viewer would solve the purpose. I am aware that spherical surface can be achieved using sphere and surf function, yet in such a case overlay might not be possible as the MATLAB would not allow you to pass in viewer3d handle as parent to surf function and will result into an error which is as follows
Error using matlab.graphics.chart.primitive.Surface
Surface cannot be a child of Viewer3D.
I have detailed the possible workaround in a MATLAB script by considering a random 100x100x100 dataset for DoseCube. Tweak it using your very own data and try it out. Here is the code snippet for your reference
DoseCube = rand(100,100,100)*100;
f1 = uifigure('Name','Dose 2 Cell');
g1 = uigridlayout(f1, [1,1], Padding=[0 0 0 0]);
viewer = viewer3d(g1);
viewer.BackgroundGradient="off";
viewer.BackgroundColor="white";
doseV = volshow(DoseCube,Parent = viewer);
doseV.Colormap = jet;
r = 5; % radius of the sphere
coordRange = -10:0.1:10;
% create a grid of points in 3D space
[x, y, z] = meshgrid(coordRange, coordRange, coordRange);
% calculate the distance from each point to the sphere's center
distance = sqrt(x.^2 + y.^2 + z.^2);
% create a binary mask for the sphere
sphere_mask = distance <= r;
% visualize the spherical surface using volshow
volshow(sphere_mask, Parent = viewer);

I hope this helps.
2 个评论
Kurt
2023-12-5
This requires the use of the Image Processing Toolbox and the Industrial Communication Toolbox. Not everyone has those.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!