- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发一个使用 VTK 的 C++ 应用程序一些可视化。我需要读取一个 .vtr 文件 (RectilinearGrid) 并使用 VTK 体积渲染功能渲染它。
我试着用 Paraview 来做到这一点。这非常简单,我只需要应用一个“IsoVolume”过滤器,结果正是我需要的:
问题是……我如何在 C++ 中做到这一点? IsoVolume 过滤器属于 extension of VTK made by the ParaView guys ,所以它不在我的库中,而且我没有找到一种方法来导入这些类而不会出现链接错误。
有更容易的方法吗? VTK 中是否有可用于直线网格数据的 IsoVolume 过滤器的替代方案?
最佳答案
我自己想出来的:
#define vtkp vtkSmartPointer
// Read the file.
vtkp<vtkXMLRectilinearGridReader> vtrReader = vtkp<vtkXMLRectilinearGridReader>::New();
vtrReader->SetFileName("../models/my_grid_model.vtr");
vtrReader->Update();
vtkp<vtkRectilinearGrid> grid = vtrReader->GetOutput();
vtkp<vtkDataArray> scalars = grid->GetPointData()->GetArray("temperatures");
// Convert the vtkRectilinearGrid to vtkUnstructuredGrid.
vtkp<vtkUnstructuredGrid> ugrid = vtkp<vtkUnstructuredGrid>::New();
vtkp<vtkPoints> points = vtkp<vtkPoints>::New();
grid->GetPoints(points);
ugrid->SetPoints(points);
ugrid->GetPointData()->SetScalars(scalars);
for (unsigned int i = 0; i < grid->GetNumberOfCells(); i++){
vtkCell* cell = grid->GetCell(i);
ugrid->InsertNextCell(cell->GetCellType(), cell->GetPointIds());
}
// Make sure we have only tetrahedra. (may be slow for big data. tip: save the result to a file)
vtkp<vtkDataSetTriangleFilter> trifilter = vtkp<vtkDataSetTriangleFilter>::New();
trifilter->SetInputData(ugrid);
// The mapper that renders the volume data.
vtkp<vtkOpenGLProjectedTetrahedraMapper> volumeMapper = vtkp<vtkOpenGLProjectedTetrahedraMapper>::New();
volumeMapper->SetInputConnection(trifilter->GetOutputPort());
// Create transfer mapping scalar value to opacity.
vtkp<vtkPiecewiseFunction> opacityTransferFunction = vtkp<vtkPiecewiseFunction>::New();
opacityTransferFunction->AddPoint(range[0], 0.05);
opacityTransferFunction->AddPoint(range[1], 0.5);
// Create transfer mapping scalar value to color.
vtkp<vtkColorTransferFunction> colorTransferFunction = vtkp<vtkColorTransferFunction>::New();
colorTransferFunction->AddRGBPoint(range[0], 0.0, 0.0, 1.0);
colorTransferFunction->AddRGBPoint(range[1], 1.0, 0.0, 0.0);
// The property describes how the data will look.
vtkp<vtkVolumeProperty> volumeProperty = vtkp<vtkVolumeProperty>::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->SetScalarOpacityUnitDistance(300);
volumeProperty->ShadeOff();
// Creation of the volume.
vtkp<vtkVolume> volume = vtkp<vtkVolume>::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
// Usual visualization.
vtkp<vtkRenderer> renderer = vtkp<vtkRenderer>::New();
renderer->AddVolume(volume);
vtkp<vtkRenderWindow> window = vtkp<vtkRenderWindow>::New();
window->Render();
vtkp<vtkInteractorStyleTrackballCamera> style = vtkp<vtkInteractorStyleTrackballCamera>::New();
vtkp<vtkRenderWindowInteractor> interactor = vtkRenderWindowInteractor::New();
interactor->SetRenderWindow(window);
interactor->SetInteractorStyle(style);
interactor->Initialize();
interactor->Start();
关于c++ - VTK - 直线网格的体积渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33913044/
我正在尝试让这段代码计算盒子的表面积和体积。它编译但不输出正确的数据。我认为问题可能出在 void Box::零件内,但碰壁了。或者它可能是 Height = Height 但我无法以任何其他方式让它
我需要一个使用 kinect 计算 body 体积(以立方米为单位)的算法。我知道我可以提取云和深度框架(通过使用骨架 NUI 的一些方法隔离 body )但我不知道如何从这个矩阵计算体积值。导出卷
我是 d3 的新手,并试图根据节点之间的连接数使链接的宽度动态化。比方说,我们有: "links": [ { "source": a, "target": b},
我要渲染 3D 数据,它是一个一维数组。此数据在将进行可视化的同一程序中预先计算。数据表示统一的 3D 网格。网格的每个单元格都由一个 vector 组成。 GridSize = dx * dy *
我尝试在 jupyter notebook 中使用 mayavi 渲染体积来测试下面的示例 from mayavi import mlab mlab.init_notebook() x, y, z =
我尝试了几种不同的方法。我需要使用继承来扩展这些类。每次我运行该程序时,它都会输出 0.0 的体积和面积。半径显示正确。输出在底部。 public class Base_HW04Q1 { pu
我参与了一个项目,我需要根据体积的一系列图像渲染 3D 体积。这些图像是通过多种技术创建的,因此它们是所讨论对象的垂直切片。 数据集类似于this question , 但提问者正在寻找 Matlab
已关闭。此问题旨在寻求有关书籍、工具、软件库等的建议。不符合Stack Overflow guidelines准则。它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,
我想知道是否有任何基于 numpy 的工具可以: 给定一个二值输入的 3D numpy 图像,找到它的凸包; 并返回索引列表或此 3D 凸包内的体素(3D 像素)的类似物。 一种可能是使用skimag
我要使用 Matlab 从灰度图像集创建一个 3D 体积。一组包含二维灰度图像的连续量化切片。我仍然认为自己是 Matlab 的菜鸟,但这是我目前的想法: 为 3D 体积创建一个空白空间。 在每张图片
我有一个 3D 体积和一个 2D 图像以及两者之间的近似映射(没有倾斜的仿射变换,已知缩放,旋转和平移近似已知并且需要拟合)。因为这个映射有错误,我想进一步将 2D 图像注册到 3D 体积。我以前没有
更新: 我创建了一个文档齐全的 ipython 笔记本。如果您只想要代码,请查看第一个答案。 问题 我有一个 40x40x40 体积的灰度值。这需要旋转/移动/剪切。 这是一组有用的齐次变换:http
看似简单的问题,没有图像处理/处理经验的人其实没那么容易。 我不只是想将 2D 阵列堆叠在一起,而是通过合并多个由空白分隔的二进制 2D 切片来创建 3D 体积。 例子: 用零定义一个 3D 矩阵:
我非常沮丧,因为几个小时后,我似乎无法在 python 中进行看似简单的 3D 插值。在 Matlab 中,我所要做的就是 Vi = interp3(x,y,z,V,xi,yi,zi) 使用 scip
我是一名优秀的程序员,十分优秀!