Beispiel #1
0
    void SetUp() override
    {
        dem = vtkSmartPointer<vtkImageData>::New();
        dem->SetExtent(extent.data());
        dem->AllocateScalars(VTK_FLOAT, 1);
        dem->GetIncrements(incs.GetData());
        auto elevations = dem->GetPointData()->GetScalars();
        elevations->SetName("Elevations");
        for (vtkIdType i = 0; i < elevations->GetNumberOfTuples(); ++i)
        {
            elevations->SetComponent(i, 0, 0.f);
        }

        dem->SetScalarComponentFromFloat(2, 3, 0, 0, 1.0);
        dem->SetScalarComponentFromFloat(2, 4, 0, 0, 1.0);
        dem->SetScalarComponentFromFloat(2, 5, 0, 0, 2.0);
    }
void ItkAndVtkImageTestHelper::createItkAndVtkImages(int dimensions[3], int startIndex[3], double spacing[3], double origin[3],
                                                     VolumePixelData::ItkImageTypePointer &itkImage, vtkSmartPointer<vtkImageData> &vtkImage)
{
    VolumePixelData::ItkImageType::SizeType size = { dimensions[0], dimensions[1], dimensions[2] };
    VolumePixelData::ItkImageType::IndexType index = { startIndex[0], startIndex[1], startIndex[2] };
    VolumePixelData::ItkImageType::RegionType region;
    region.SetSize(size);
    region.SetIndex(index);
    itkImage = VolumePixelData::ItkImageType::New();
    itkImage->SetRegions(region);
    itkImage->SetSpacing(spacing);
    itkImage->SetOrigin(origin);
    itkImage->Allocate();

    vtkImage = vtkSmartPointer<vtkImageData>::New();
    vtkImage->SetDimensions(dimensions);
    int extent[6] = { startIndex[0], startIndex[0] + dimensions[0] - 1, startIndex[1], startIndex[1] + dimensions[1] - 1, startIndex[2],
                      startIndex[2] + dimensions[2] - 1 };
    vtkImage->SetExtent(extent);
    vtkImage->SetSpacing(spacing);
    vtkImage->SetOrigin(origin);
    vtkImage->AllocateScalars(VTK_SHORT, 1);

    itk::ImageRegionIterator<VolumePixelData::ItkImageType> itkIterator(itkImage, itkImage->GetLargestPossibleRegion());
    itkIterator.GoToBegin();
    VolumePixelData::ItkPixelType *vtkPointer = static_cast<VolumePixelData::ItkPixelType*>(vtkImage->GetScalarPointer());
    VolumePixelData::ItkPixelType value = 0;

    while (!itkIterator.IsAtEnd())
    {
        itkIterator.Set(value);
        *vtkPointer = value;
        ++itkIterator;
        ++vtkPointer;
        ++value;
    }
}