Overlaying a spherical surface on a graphics object

3 visualizaciones (últimos 30 días)
Andrew Fielding
Andrew Fielding el 1 de Sept. de 2023
Comentada: Kurt el 5 de Dic. de 2023
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?

Respuestas (1)

akshatsood
akshatsood el 1 de Sept. de 2023
Editada: akshatsood el 1 de Sept. de 2023
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 comentarios
Andrew Fielding
Andrew Fielding el 4 de Sept. de 2023
Thankyou very much. That does exactly what I want.
Kurt
Kurt el 5 de Dic. de 2023
This requires the use of the Image Processing Toolbox and the Industrial Communication Toolbox. Not everyone has those.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by