Visualising 3D Cubes with a colour map

12 visualizaciones (últimos 30 días)
ADSW121365
ADSW121365 el 26 de Mayo de 2020
Respondida: ADSW121365 el 26 de Mayo de 2020
As part of a model I'm working on, I have discretised a problem into "brick elements" or "cubic voxels". The assumption then is that some property is a piecewise constant inside each element which is mapped by a colourmap. My aim is to visulise this akin to a rubix cube, with transparency so I can see the internal faces, however any improvement on my current approach would be good. Something like this without the spacing between elements:
This isn't an proper FEM problem, so coordinates are generated like:
Nx = 3; Ny = 3; Nz = 3; Xstar = -0.6; Xend = 0.6; Ystar = -0.6; Yend = 0.6; Zstar = -0.6; Zend = 0.6;
Xq = linspace(Xstar,Xend,Nx); Yq = linspace(Ystar,Yend,Ny); Zq = linspace(Zstar,Zend,Nz);
[Xq,Yq,Zq] = meshgrid(Xq,Yq,Zq);
dX = (max(Xq(:))-min(Xq(:)))./Nx; dY = (max(Yq(:))-min(Yq(:)))./Ny; dZ = (max(Zq(:))-min(Zq(:)))./Nz;
for Xind = 1:Nx; for Yind = 1:Ny; for Zind = 1:Nz;
Xlow(Xind,Yind,Zind) = Xstar+dX.*(Xind-1); Xup(Xind,Yind,Zind) = Xstar+dX.*Xind;
Ylow(Xind,Yind,Zind) = Ystar+dY.*(Yind-1); Yup(Xind,Yind,Zind) = Ystar+dY.*Yind;
Zlow(Xind,Yind,Zind) = Zstar+dZ.*(Zind-1); Zup(Xind,Yind,Zind) = Zstar+dZ.*Zind;
end; end; end
where Xlow gives the min corners of the specific cube, while Xup gives the max corners of the specific cube.
Given a test object, my best attempt at visulising this is:
mockobj = ones(Ny,Nx,Nz); mockobj(:,:,1) = 1e6; figure(); Nr = size(Xq,3);
for iR = 1:Nr; ph{iR} = surf(Xq(:,:,iR),Yq(:,:,iR),Zq(:,:,iR),objprop(:,:,iR)); hold on; shading flat; end;
c= colorbar; c.Label.String = 'Object Properties'; clearvars c; colormap jet
The results from the above are okay - I end up with 3 slices along Z, but the grid in XY is only 2x2 (which makes sense given the coordinates input to be plot, but isn't what I'm trying to plot and I can't find a way to usefully represent the 3D structure):
The other approach I have seen suggested is using patch, but my niave attempt using the coordinates and setup above was pretty useless (and many users note patch is particularily slow as the visulisation gets more complex):
patch(Xq(:),Yq(:),Zq(:),mockobj(:))
Any thoughts, directions or suggestions are greatly appreciated.

Respuesta aceptada

darova
darova el 26 de Mayo de 2020
Here is the idea:
  • create cylinder
  • but only for theta = 0:90:360
  • make modifications
Change X,Y data Change Z data
  • use for loop, create more cubes

Más respuestas (1)

ADSW121365
ADSW121365 el 26 de Mayo de 2020
This can be achieved nicely using plotcube from the file exchange and a for loop: Plot Cube
facealpha = .5;
for index = 1:length(Xlow(:))
plotcube([dX;dY;dZ]',[Xlow(index);Ylow(index);Zlow(index)]',facealpha,mockobj(index)); hold on;
end

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by