寻找在 Ilnumerics 中绘制体积切片的示例

Looking for example for plotting Volumetric Slice in Ilnumerics

在 Ilnumerics 使用社区版本中是否有绘制体积切片的示例。这是我从 matlab 网站上得到的一个例子:

Volumetric slice image example of matlab

我将数组 X、Y、Z 作为位置,将 V(速度)作为颜色绘图的值。我所做的就是使用 Ilpoints 在 X、Y、Z 位置绘制 V,而不是表面。这是我的代码和结果,

ILArray<float> plotXY = ILMath.zeros<float>(3, XcoordinateXY.Length);
        plotXY["0;:"] = ILMath.tosingle(SurfaceXY[":;:;1"]);
        plotXY["1;:"] = ILMath.tosingle(SurfaceXY[":;:;2"]);
        plotXY["2;:"] = ILMath.tosingle(SurfaceXY[":;:;3"]);

        ILArray<float> ColorMap = ILMath.tosingle(SurfaceXY[":;:;0"]);

var ilsurfaceplotXY = new ILPoints()
        {

            /*Wireframe = { Color = Color.FromArgb(50, Color.LightGray) },
            Colormap = new ILColormap(dataXY),
            Children = { new ILColorbar() }*/
            Positions = plotXY,
            Colors = cm.Map(ColorMap).T,
            Color = null
        };

显示代码如下:

 var scene = new ILScene();
        scene.Add(
                new ILPlotCube
                {
                    TwoDMode = false,
                    Axes =
                    {

                        XAxis =
                        {
                            Label = { Text = "UTM X (Km)" },
                            GridMajor =
                            {
                                DashStyle = DashStyle.Dashed,
                                Color = Color.DarkGray,
                                Width = 1

                            }
                        },
                        YAxis =
                        {
                            Label = { Text = "UTM Y (Km)" },
                            GridMajor =
                            {
                                DashStyle = DashStyle.Dashed,
                                Color = Color.DarkGray,
                                Width = 1
                            }
                        },
                        ZAxis =
                        {
                            Label = { Text = "DEPTH (Km)" },
                            GridMajor =
                            {
                                DashStyle = DashStyle.Dashed,
                                Color = Color.DarkGray,
                                Width = 1
                            }
                        }
                    },

                    Children = { ilsurfaceplotXY, ilsurfaceplotXZ, ilsurfaceplotYZ },
                }
            );

        this.ilPanel1.Scene = scene;
        this.ilPanel1.Scene.Configure(); 
        this.ilPanel1.Refresh();

这是一张图片结果。

Result Image

很抱歉图像在 link 中。

关于可视化,这可以使用 regular surfaces, imagesc plots, or the new fast surface in the Drawing2 工具箱来完成。它们都允许为每个网格点或图块提供 X、Y 和 Z 值以及颜色。

关于点数的计算:看来你只是从可用的集合中挑选点数。在这些点之间进行插值会好得多。 Interpolation Toolbox 提供了网格化数据和散点数据的插值函数。 (在你的情况下,数据似乎是网格化的?)。这允许以任意方向/角度进行切片。插值工具箱对切片网格点的位置以及颜色值进行插值。

来自 online example

水平切片的设置如下:

ILArray<float> C; 
for (int i = 0; i < m_nrSlices; i += m_nrSlices / 4) {
    C = m_V[":",":", i];
    pc1.Add(new ILSurface(grid + i, C, colormap: Colormaps.Bone) 
    { 
        Wireframe = { Visible = false },
    });

}

此处,m_V 是您的 3D 数据集,作为 3D 数组处理。 pc 是绘图立方体。这些表面只是简单地添加到绘图立方体中。当用户移动红球时,会动态计算红色插值区域的点数:

// Points on the cutting area are considered scattered points, because the area is not (necessarily) plain. However, V 
// is a grid. interp3s interpolates the scattered points very efficiently. 
// Note how the shape of the coordinate arrays Xn, Yn and Zn is not important. interp3s takes their elements in sequential order. 
// The output is a vector of interpolated values. (We gonna reshape it below.)
ILArray < float> Z = Interpolation.interp3s(m_V, m_x, m_x, m_x, m_Xn, m_Yn, Zn, method: InterpolationMethod.cubic);

// let's plot! We get a reference to the fast surface
var fsurf = ilPanel1.Scene.First<ILFastSurface>("dynslice"); 
if (fsurf != null) {
    // first time setup only: provide the full coordinates of X and V. Here it is sufficient to provide grid vectors. 
    if (fsurf.Cols == 0) {
        fsurf.Update(X: m_xn * res, Y: m_xn * res, Z: Zn * res, C: ILMath.reshape(Z, Zn.S), colormap: Colormaps.Hot);
    } else {
        // the grid was configured already and did not change. we save some recomputing by ommiting the X and Y coordinates, prevent from reshaping buffers.
        fsurf.Update(Z: Zn * res, C: ILMath.reshape(Z, Zn.S), colormap: Colormaps.Hot);
    }
}
fsurf.Configure();
ilPanel1.Refresh(); 

深入细节超出了 SO 的范围。您可以下载该示例并将其 运行 安装到您的机器上。不过,您将需要一个 recent version 的 ILNumerics。

编辑:当然,您提供的图中轴对齐的切片只是一个子域。生成它们的工作方式完全相同: