vtkSmartPointer<vtkImageData> MatricesToVtk::parseGrid2D(const io::InputVector & inputData, int vtk_dataType)
{
    auto image = vtkSmartPointer<vtkImageData>::New();
    if (inputData.empty() || inputData.front().empty())
    {
        return image;
    }

    const std::array<int, 3> dimensions = {
        static_cast<int>(inputData.size()),
        static_cast<int>(inputData.front().size()),
        1
    };

    image->SetDimensions(dimensions.data());
    auto scalars = createDataArray(vtk_dataType);
    scalars->SetName("Scalars");
    scalars->SetNumberOfValues(image->GetNumberOfPoints());
    image->GetPointData()->SetScalars(scalars);
    vtkIdType incX, incY, incZ;
    image->GetIncrements(incX, incY, incZ);
    vtkIdType scalarX = 0;
    for (int x = 0; x < dimensions[0]; ++x)
    {
        vtkIdType scalarY = 0;
        for (int y = 0; y < dimensions[1]; ++y)
        {
            scalars->SetComponent(scalarX + scalarY, 0,
                inputData[static_cast<size_t>(x)][static_cast<size_t>(y)]);
            scalarY += incY;
        }
        scalarX += incX;
    }

    return image;
}
Exemple #2
0
    void generateVectors(io::InputVector & data, size_t colCountBegin, size_t colCountEnd)
    {
        assert(data.size() >= colCountEnd && colCountBegin <= colCountEnd);
        if (colCountBegin == colCountEnd)
        {
            return;
        }

        const size_t numValues = data[colCountBegin].size();
        for (auto && col : data)
        {
            assert(col.size() == numValues);
        }

        for (size_t c = colCountBegin; c < colCountEnd; ++c)
        {
            for (size_t i = 0; i < numValues; ++i)
            {
                data[colCountBegin][i] = static_cast<io::t_FP>(c + 1) + static_cast<io::t_FP>(i + 1) / 10.0;
            }
        }
    }