简体   繁体   English

在MATLAB中的3D立方体上执行2D切割

[英]Performing 2D cut on 3D cube in MATLAB

I have a 3D cube that's filled with small cubes. 我有一个充满小立方体的3D立方体。 After filling it with small cubes, I can see its faces. 用小方块填充它后,我可以看到它的面孔。 I want to perform a cut through x, y, or z axis, so that I can see the internal structure at some points. 我想对x,y或z轴进行切割,以便可以在某些点看到内部结构。 Here is an image of the cube, 这是立方体的图像,

在此处输入图片说明

I want to see the internal structure of this cube. 我想看看这个立方体的内部结构。 After search I found that slice can be used. 搜索后,我发现可以使用slice I used this code, 我用了这段代码,

figure
  [x,y,z] = meshgrid(1:100);
 v = repmat(magic(100),[1 1 100]);
% 
% % Define the slice plane
 [xi, yi] = meshgrid(1:100);
 zi = xi;
% 
% % Slice it
slice(x,y,z,v,xi,yi,zi);
 drawnow

But I get a result with completely different colors. 但是我得到的结果是完全不同的颜色。 Here is the result, 结果是这样

在此处输入图片说明

Can you please tell me how to fix the code above to produce a cut through an axis? 您能告诉我如何修复上面的代码以产生穿过轴的切口吗? Also, I would really appreciate it if you could explain how this process is done as I don't completely understand the code above. 另外,如果您能解释一下此过程是如何完成的,因为我不完全理解上面的代码,我将不胜感激。

Re. 回覆。 the first question - I don't know of a straightforward way to slice your multicube off-hand with Hoki's code (but see below). 第一个问题-我不知道直接使用Hoki的代码分割多多维数据集的简单方法(但请参见下文)。 polyxpoly might be helpful, but still requires projection onto the plane of the slice. polyxpoly可能会有所帮助,但仍然需要投影到切片的平面上。

Re. 回覆。 the second question - slice is cutting "volumetric data," meaning something like density that has a value at each point in the volume. 第二个问题-切片正在切割“体积数据”,这意味着诸如密度之类的东西在体积的每个点上都有值。 The repmat(magic(...)) line is making a 100x100x100 (3-d) array that has a number at each of the 100*100*100=1,000,000 grid points in the array. repmat(magic(...))行正在制作一个100x100x100(3-d)数组,该数组在数组的100 * 100 * 100 = 1,000,000个网格点中的每个点都有一个数字。 It so happens that those points have different values between 1 and 100^2, so you're getting different colors. 碰巧这些点的值在1到100 ^ 2之间,因此您得到的颜色也不同。

Hoki's code doesn't play well with slice because it uses patch to make polygons instead of using volumetric data. Hoki的代码不适用于slice因为它使用patch制作多边形而不是使用体积数据。 An alternative would be to make your cubes volumetrically. 另一种方法是按体积制作多维数据集。 This code should run by itself but - caution - is not tested. 该代码应自行运行,但是-注意-未经测试。 it is independent of Hoki's code you mentioned. 它独立于您提到的Hoki的代码。

face=ones(10,10);        %make a small cube, 10x10x10
middle=zeros(10,10);
middle(1,1:10)=1;
middle(10,1:10)=1;
middle(1:10,1)=1;
middle(1:10,10)=1;
small_cube=cat(3,face,repmat(middle,1,1,8),face);

% Now make an array of them - ten in each direction, so 100x100x100
v=repmat(small_cube,10,10,10);

% Now define the slice plane and slice as above.
[xi, yi] = meshgrid(1:100);
zi = xi;

figure;
slice(x,y,z,v,xi,yi,zi);
drawnow

Edit : In the above, 0 is for points that are not part of the cube and 1 is for points that are. 编辑 :在上面, 0表示不属于多维数据集的一部分, 1表示属于立方体的点。 This is a voxel representation of a cube. 这是多维数据集的体素表示。 face is for the top and bottom, and middle is for a slice of the edges between the top and bottom. face用于顶部和底部, middle用于顶部和底部之间的一部分边缘。 The first repmat stacks up eight slices of the middle like a burger patty. 第一个repmat像汉堡肉饼一样堆积了八层中间的东西。 The cat puts a face on the top and bottom of that stack like the two halves of the bun. cat在面包堆的顶部和底部都放了一张face ,就像面包的两半一样。 Then the second repmat makes the 999 other small cubes in the big cube. 然后第二个repmat在大立方体中制作出其他999个小立方体。

Edit 2 : Replacing zeros with NaN in the above code should make the insides of the cube transparent. 编辑2 :在上面的代码中用NaN替换zeros应使多维数据集的内部透明。 (Also not tested!) (也未测试!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM