ILNumerics:将场景的一部分导出为图像而不影响原始场景
ILNumerics: Export part of a scene as image without affecting original scene
我用 ILNumerics 创建了一个场景,它由 3 个 PlotCube 和一个 Colorbar 组成。
我想添加一种以两种方式将场景导出为图像的方法,第一种是您在上面看到的屏幕截图。
第二次导出应该只显示中心立方体。
我试图遵循 scene management 的 ILNumerics 指南。
我写了下面的代码:
public void ExportAsImage(int resolutionWidth, int resolutionHeight, string path, bool includeSubCubes)
{
using (ILScope.Enter())
{
ILGDIDriver backgroundDriver = new ILGDIDriver(resolutionWidth, resolutionHeight, ilPanel1.Scene);
if (includeSubCubes)
{
// code for standard export here
}
else
{
// setting left and top cube and color bar invisible and
// adjusting main cube size is affecting the ilPanel.Scene
backgroundDriver.Scene.First<ILColorbar>().Visible = false;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _leftCubeTag).Visible = false;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _topCubeTag).Visible = false;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _mainCubeTag).ScreenRect = new RectangleF(0, 0, 1, 1);
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _mainCubeTag).DataScreenRect = new RectangleF.Empty;
backgroundDriver.Scene.Configure();
backgroundDriver.Render();
// save image
backgroundDriver.BackBuffer.Bitmap.Save(path,System.Drawing.Imaging.ImageFormat.Png);
// revert changes done to cubes and color bar
backgroundDriver.Scene.First<ILColorbar>().Visible = true;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _leftCubeTag).Visible = true;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _topCubeTag).Visible = true;
AdjustCubeSizes();
}
}
}
注意:"GetElementByTag" 是在 ILNumerics 场景中检索对象的自己的实现。
我最初预计新驱动程序基本上会创建一个我可以处理的场景副本,但就像代码显示的那样,我必须在导出后还原所有更改,或者显示的 ilPanel 仅以我导出的方式显示场景它。
是否可以在不影响真实场景的情况下导出图像?我是不是漏掉了一些细节?
此致,
弗洛里安 S.
Florian,它确实 制作了一份副本。但是您需要将有趣的部分添加到新场景中。魔法发生在 Add() 方法中:
var scene4render = new ILScene();
scene4render.Add(oldScene.First<ILPlotCube>(mytag));
// ... configure scene4render here, it will be detached from the original scene
// with the exception of shared buffers.
// ... proceed with rendering
为了还包括 + 渲染原始绘图立方体的交互状态更改(假设用户鼠标旋转),您将使用类似的东西:
scene4render.Add(panel.SceneSyncRoot.First<ILPlotCube>(mytag));
此外,我想知道 GetElementByTag
比 ILGroup.First<T>(tag, predicate)
或 ILGroup.Find<T>(...)
有什么优势?
我用 ILNumerics 创建了一个场景,它由 3 个 PlotCube 和一个 Colorbar 组成。
我想添加一种以两种方式将场景导出为图像的方法,第一种是您在上面看到的屏幕截图。 第二次导出应该只显示中心立方体。
我试图遵循 scene management 的 ILNumerics 指南。
我写了下面的代码:
public void ExportAsImage(int resolutionWidth, int resolutionHeight, string path, bool includeSubCubes)
{
using (ILScope.Enter())
{
ILGDIDriver backgroundDriver = new ILGDIDriver(resolutionWidth, resolutionHeight, ilPanel1.Scene);
if (includeSubCubes)
{
// code for standard export here
}
else
{
// setting left and top cube and color bar invisible and
// adjusting main cube size is affecting the ilPanel.Scene
backgroundDriver.Scene.First<ILColorbar>().Visible = false;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _leftCubeTag).Visible = false;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _topCubeTag).Visible = false;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _mainCubeTag).ScreenRect = new RectangleF(0, 0, 1, 1);
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _mainCubeTag).DataScreenRect = new RectangleF.Empty;
backgroundDriver.Scene.Configure();
backgroundDriver.Render();
// save image
backgroundDriver.BackBuffer.Bitmap.Save(path,System.Drawing.Imaging.ImageFormat.Png);
// revert changes done to cubes and color bar
backgroundDriver.Scene.First<ILColorbar>().Visible = true;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _leftCubeTag).Visible = true;
GetElementByTag<ILPlotCube>(backgroundDriver.Scene, _topCubeTag).Visible = true;
AdjustCubeSizes();
}
}
}
注意:"GetElementByTag" 是在 ILNumerics 场景中检索对象的自己的实现。
我最初预计新驱动程序基本上会创建一个我可以处理的场景副本,但就像代码显示的那样,我必须在导出后还原所有更改,或者显示的 ilPanel 仅以我导出的方式显示场景它。
是否可以在不影响真实场景的情况下导出图像?我是不是漏掉了一些细节?
此致, 弗洛里安 S.
Florian,它确实 制作了一份副本。但是您需要将有趣的部分添加到新场景中。魔法发生在 Add() 方法中:
var scene4render = new ILScene();
scene4render.Add(oldScene.First<ILPlotCube>(mytag));
// ... configure scene4render here, it will be detached from the original scene
// with the exception of shared buffers.
// ... proceed with rendering
为了还包括 + 渲染原始绘图立方体的交互状态更改(假设用户鼠标旋转),您将使用类似的东西:
scene4render.Add(panel.SceneSyncRoot.First<ILPlotCube>(mytag));
此外,我想知道 GetElementByTag
比 ILGroup.First<T>(tag, predicate)
或 ILGroup.Find<T>(...)
有什么优势?