Visualising Volume Object Data

2 views (last 30 days)
Hey everyone,
I know there's a lot of questions on this problem but I can't find anything which quite works the way I'd like it to. I have a set of upper and lower bounds in spherical coordinates which as a pair each describe some small volume region. The result is 3 matrices R, Theta, Phi of size [Ntheta x Nphi x Nr] for both the upper and lower bounds. Corresponding to these individual bounds is then some scalar value in another matrix of size [Ntheta x Nphi x Nr].
What I would like to do is plot the individual volume elements i.e from [Tlow:Tup , Plow:Pup , Rlow : Rup] as filled blocks with color chosen by the value in the matrix. Some example code for the data I'm working with is given though these are just simplified pieces of data (I'm aware I can vectorise the for loops but again this is just example data):
Nr=3; Nt=20; Np=20;
Rq = linspace(0,1,Nr); Thetaq = linspace(0,pi,Nt); Phiq = linspace(-pi,pi,Np);
[Thetaq,Phiq,Rq] = meshgrid(Thetaq,Phiq,Rq);
delR = (max(Rq(:))-min(Rq(:)))./Nr;
delT = (max(Thetaq(:))-min(Thetaq(:)))./Nt;
delP = (max(Phiq(:))-min(Phiq(:)))./Np;
for Rind = 1:Nr
for Tind = 1:Nt
for Pind = 1:Np
Rlow(Tind,Pind,Rind) = delR.*(Rind-1); Rup(Tind,Pind,Rind) = delR.*Rind;
Tlow(Tind,Pind,Rind) = delT.*(Tind-1); Tup(Tind,Pind,Rind) = delT.*Tind;
Plow(Tind,Pind,Rind) = delP.*(Pind-1); Pup(Tind,Pind,Rind) = delP.*Pind;
mockobjprop = ones(Nt,Np,Nr); %Object With Correct Sized Matrix
mockobjprop(:,:,1:2) = 10; %First 2 Radial Shells Have Value 10
The object I envisage here is a spherical object with 3 radial shells, such all volume elements in the inner two shells will have one colour and the 3rd shell will be a different colour. I'm hoping to utalise matlabs inbuilt colormaps as the general data is much more complicated than this two colour scheme. I have seen a few suggestions using the slice function however even if I convert my volume bounds to cartesian it finds the data to be defined on an invalid meshgrid.
The best solution I have so far is using a point at the centre of each volume chunk, converting to cartesian and plotting a scatter3 plot with the color set by the propety matrix. However visually this is appalling at best.
Xq = Rq.*sin(Thetaq).*cos(Phiq); Yq = Rq.*sin(Phiq).*sin(Thetaq); Zq =Rq.*cos(Thetaq);
Any advise or suggestions would be greatly appreciated. Even if it isn't exactly what I'm searching for anything would be an improvement. I had one suggestion of exporting the data to paraviewer however I cannot figure out how to export this type of data mind render it within paraviewer.
darova on 7 Jul 2019
I give up. Sorry

Sign in to comment.

Accepted Answer

Bjorn Gustavsson
Bjorn Gustavsson on 8 Jul 2019
Edited: Bjorn Gustavsson on 8 Jul 2019
You could work with surf on each radial layer and set the surface property facealpha to something transparent. Perhaps something like this:
for iR = 1:Nr,
ph{iR} = surf(Xq(:,:,iR),Yq(:,:,iR),Zq(:,:,iR),mockobjprop(:,:,iR));
hold on
shading flat
set(ph{iR},'facealpha',.45) % this you might modify...
You might modify the facealpha value to be proportional to the value of mockobjprop or something suitable to illustrate your volume. Another trick to do is to do this in all three dimensions with surfaces also for all theta and phi values, but that is just an extension of the general idea...
  1 Comment
ADSW121365 on 8 Jul 2019
Brilliant basically exactly what I was looking for. Thankyou!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!