VTK - different types of datasets

Preface: This blog post mainly explains the different types of data sets in vtk and the relationship between them, how to convert them, etc.

Table of contents

vtkImageData

vtkRectilinearGrid

vtkStructuredGrid

vtkUnstructuredPoints

vtkPolyData

vtkUnstructuredGrid

vtkPolyData->vtkImageData

vtkPolyData->vtkUnstructuredGrid

vtkUnstructuredGrid->vtkPolyData

About the converted interface:


The data set in vtk consists of organizational structure and data data. The organizational structure is divided into topological structure and geometric structure, and different organizational structures correspond to different types of data sets.

 

vtkImageData

Description: The vtkImageData type is a collection of points and units regularly arranged in a rectangular grid. As shown in Figure a above.

vtkRectilinearGrid

Description: The data of type vtkRectilinearGrid is a collection of points and cells arranged in a rectangular grid. As shown in Figure b above. The topology of a linear structure is regular, but its geometry is only partially regular.

vtkStructuredGrid

Description: Structured grid data with regular topology and irregular geometry, but with no overlapping or crossing of cells. As shown in Figure c above. The elements of the structured grid are composed of quadrilaterals or hexahedrons, which are usually used in finite element analysis.

vtkUnstructuredPoints

Description: An unstructured point set is a point set that is irregularly distributed in space. It has an irregular geometry and no topology. Unstructured point sets are represented by discrete points. As shown in Figure d above.

vtkPolyData

Description: vtkPolyData (polygon data structure) is composed of units such as vertex, Polyvertex, Line, PolyLine, and TriangleStrip. As shown in Figure e above.

vtkUnstructuredGrid

Description: Unstructured grid data is the most common data set type. Its topology and geometry are unstructured. All cell types can be combined arbitrarily. The topology of all cells extends from zero-dimensional to three-dimensional. As shown in Figure f above. In VTK, any type of data set can be expressed by unstructured grid, but its storage requires a lot of space, and the calculation needs to consume a lot of resources. Unless it is absolutely necessary, this type of data set is generally seldom used. It is mainly used in the fields of finite element analysis, computational geometry and graphical representation.

See VTK-Dataset vtkUnstructuredGrid for details_Xueyi's Blog-CSDN Blog

vtkPolyData->vtkImageData

    vtkPolyData* pd = ...
    vtkNew<vtkImageData> whiteImage;
    double bounds[6];
    pd->GetBounds(bounds);
    double spacing[3]; // 所需的体积间距
    spacing[0] = 0.5;
    spacing[1] = 0.5;
    spacing[2] = 0.5;
    whiteImage->SetSpacing(spacing);
    // 计算尺寸
    int dim[3];
    for (int i = 0; i < 3; i++) {
        dim[i] = static_cast<int>(ceil((bounds[i * 2 + 1] - bounds[i * 2]) / spacing[i]));
    }
    whiteImage->SetDimensions(dim);
    //whiteImage->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1);
    //whiteImage->SetExtent(0, 500, 0, 500, 0, 500);
    double origin[3];
//    origin[0] = bounds[0] + spacing[0] / 2;
//    origin[1] = bounds[2] + spacing[1] / 2;
//    origin[2] = bounds[4] + spacing[2] / 2;
    origin[0] = -100 + bounds[0] + spacing[0] / 2;
    origin[1] = -100 + bounds[2] + spacing[1] / 2;
    origin[2] = bounds[4] + spacing[2] / 2;
    whiteImage->SetExtent((bounds[0] - origin[0]) / spacing[0], (bounds[0] - origin[0]) / spacing[0] + dim[0] - 1,
                          (bounds[2] - origin[1]) / spacing[1], (bounds[2] - origin[1]) / spacing[1] + dim[1] - 1,
                          (bounds[4] - origin[2]) / spacing[2], (bounds[4] - origin[2]) / spacing[2] + dim[2] - 1);
    whiteImage->SetOrigin(origin);
    whiteImage->AllocateScalars(VTK_SHORT, 1);
    // 用前景体素填充图像:
    unsigned char inval = 255;
    vtkIdType count = whiteImage->GetNumberOfPoints();
    for (vtkIdType i = 0; i < count; ++i) {
        whiteImage->GetPointData()->GetScalars()->SetTuple1(i, inval);
    }
    // 多边形数据->图像模具:
    vtkNew<vtkPolyDataToImageStencil> pol2stenc;
    pol2stenc->SetInputData(pd);
    pol2stenc->SetOutputOrigin(origin);
    pol2stenc->SetOutputSpacing(spacing);
    pol2stenc->SetOutputWholeExtent(whiteImage->GetExtent());
    pol2stenc->Update();
    auto imgstenc = vtkSmartPointer<vtkImageStencil>::New();
    imgstenc->SetInputData(whiteImage);
    imgstenc->SetStencilConnection(pol2stenc->GetOutputPort());
    imgstenc->ReverseStencilOn();
    imgstenc->SetBackgroundValue(0);
    imgstenc->SetBackgroundColor(0, 0.8, 1.0, 0.5);
    imgstenc->Update();

vtkPolyData->vtkUnstructuredGrid

vtkPolyData * pd = ...
vtkUnstructuredGrid * unSGrid = vtkUnstructuredGrid::New();
unSGrid->ShallowCopy(pd);

vtkUnstructuredGrid->vtkPolyData

vtkUnstructuredGrid* unSGrid = ...
vtkDataSetSurfaceFilter * filter = vtkDataSetSurfaceFilter::New();
filter->SetInputData(unSGrid);
filter->Update();
vtkPolyData* pd = filter->GetOutput();

About the converted interface:

vtkPolyDataToImageStencil

vtkImageDataToUniformGrid

vtkUnstructuredGridToExplicitStructuredGrid

Reference: Advanced VTK Graphics and Image Development

Study-VTK: Mutual conversion between PolyData and UnstructuredGrid_Beyond Xin's blog-CSDN blog_vtkunstructuredgrid conversion

Guess you like

Origin blog.csdn.net/qq_40041064/article/details/128641182