VTK卷渲染,SmartVolumeMapper->找不到请求的vtkDataArray

时间:2019-12-14 17:13:44

标签: c++ vtk

我正在尝试对一组点进行体积渲染。

首先,我将它们插值到统一网格中:

//// Create the grid
vtkSmartPointer<vtkUniformGrid> grid = vtkSmartPointer<vtkUniformGrid>::New();

// Set the parameters of the grid
double o = 0;
double s = 60;
int d = 120 / s;
double origin[3] = {o, o, o};
int dimensions[3] = {d, d, d};
double spacing[3] = {s, s, s};
vtkAMRBox box(origin, dimensions, spacing, origin);
// NOTE: potential error here, why we give them twice origin?
grid->Initialize(&box, origin, spacing);

// Get the Scalars we need
vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput();
vtkSmartPointer<vtkDataArray> t_mass = polydata->GetPointData()->GetArray("mass");
vtkSmartPointer<vtkDataArray> t_rho = polydata->GetPointData()->GetArray("rho");
vtkSmartPointer<vtkDataArray> t_sph = polydata->GetPointData()->GetArray("hh");
int numPoints = t_mass->GetNumberOfValues();

// Vector of interpolation entries
std::vector<a> t_a;

// Fill entries with each points of the dataset
for (vtkIdType i = 0; i < numPoints; i++)
{
    double mass;
    double rho;
    double sph;
    double p[3];
    t_mass->GetTuple(i, &mass);
    t_rho->GetTuple(i, &rho);
    t_sph->GetTuple(i, &sph);
    polydata->GetPoint(i, p);

    if (t_sph > 0)
    {
        t_a.push_back(a(mass / rho, sph, p));
    }
}

// FIll the scalars of the uniform grid (supposedly)
int n_grid = grid->GetNumberOfPoints();
for (vtkIdType i = 0; i < n_grid; i++)
{
    double *grid_point = grid->GetPoint(i);
    double tmpInterp = 0;

    for (auto entry : t_a)
    {
        double d = distance(grid_point, entry.p);

        // NOTE: use this if need be
        // if (d == 0) {
        if (d < 0.0001f)
        {
            ;
        }
        else
        {
            double eta = d / entry.h;

            if (eta >= 1)
            {
                ;
            }
            else
            {
                // TODO: implement W
                // tmpInterp += entry.x * W(eta, entry.h);
                tmpInterp += entry.x * 1 / eta;
            }
        }

        // TODO: attach a scalar to the grid point, supposedly
        grid->SetScalarComponentFromDouble(
            grid_point[0],
            grid_point[1],
            grid_point[2],
            0, // TODO: I don't really know what to put here
            tmpInterp);
    }
}

完成后,我尝试对网格进行体积渲染:

// The volume will be displayed by ray - cast alpha compositing.
// A ray-cast mapper is needed to do the ray-casting.
vtkSmartPointer<vtkSmartVolumeMapper>
    volumeMapper =
        vtkSmartPointer<vtkSmartVolumeMapper>::New();
volumeMapper->SetInputData(grid);

不幸的是,我收到此错误:

vtkSmartVolumeMapper (0x7f8654526d20): Could not find the requested vtkDataArray

我不太了解这个错误,因为似乎我创建网格的代码的最后一行正在添加这些标量。 Google搜索效果不佳...

我在这里发生什么错误?

0 个答案:

没有答案