Visualising Volume Object Data
조회 수: 3 (최근 30일)
이전 댓글 표시
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;
end
end
end
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);
scatter3(Xq(:),Yq(:),Zq(:),1e3,mockobjprop(:))
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.
댓글 수: 5
채택된 답변
Bjorn Gustavsson
2019년 7월 8일
편집: Bjorn Gustavsson
2019년 7월 8일
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...
end
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...
HTH
추가 답변 (0개)
참고 항목
카테고리
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!