How to get the global ids in many different dataset?

Dear all.
I have many different datasets, and their topological structures are stored in different datasets, but the numbering of points and cells are unified.

How to find global points and cell ids in different datasets?

As shown in my example below, there are two unstructured grids, but the numbering of points is uniform. How to find their global numbers in each dataset. For example, the point number displayed in the first unstructured grid should be {0, 1, 4, 3, 6, 7, 10, 9}, the unit number should be {0}, and the second should be {1, 2, 5, 4, 7, 8, 11, 10}, and the unit number should be {1}.

But my example only shows the local points and unit numbers.

#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkNamedColors.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCamera.h>
#include <vtkStaticCleanUnstructuredGrid.h>
#include <vtkPointData.h>
#include <vtkIdFilter.h>
#include <vtkCellCenters.h>
#include <vtkLabeledDataMapper.h>
#include <vtkTextProperty.h>
#include <vtkActor2D.h>

int CleanUnstructuredGrid(int, char*[])
{
// Create a set of points
vtkNew points;
points->InsertNextPoint(0, 0, 0);
points->InsertNextPoint(1, 0, 0);
points->InsertNextPoint(2, 0, 0);
points->InsertNextPoint(0, 1, 0);
points->InsertNextPoint(1, 1, 0);
points->InsertNextPoint(2, 1, 0);
points->InsertNextPoint(0, 0, 1);
points->InsertNextPoint(1, 0, 1);
points->InsertNextPoint(2, 0, 1);
points->InsertNextPoint(0, 1, 1);
points->InsertNextPoint(1, 1, 1);
points->InsertNextPoint(2, 1, 1);

vtkIdType id1[8] = {0, 1, 4, 3, 6, 7, 10, 9};
vtkIdType id2[8] = {1, 2, 5, 4, 7, 8, 11, 10};

vtkNew<vtkNamedColors> colors;

vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
renderer->ResetCamera();
renderer->GetActiveCamera()->Elevation(60.0);
renderer->GetActiveCamera()->Azimuth(30.0);
renderer->GetActiveCamera()->Dolly(1.2);
renWin->SetSize(640, 480);
renWin->SetWindowName("UGrid)");

//first_grid
vtkNew<vtkUnstructuredGrid> ugrid_1;
ugrid_1->InsertNextCell(VTK_HEXAHEDRON, 8, id1);
ugrid_1->SetPoints(points);
vtkNew<vtkStaticCleanUnstructuredGrid> clean_1;
clean_1->SetInputData(ugrid_1);
clean_1->Update();
vtkNew<vtkDataSetMapper> ugridMapper_1;
ugridMapper_1->SetInputData(clean_1->GetOutput());
vtkNew<vtkActor> ugridActor_1;
ugridActor_1->SetMapper(ugridMapper_1);
ugridActor_1->GetProperty()->SetColor(colors->GetColor3d("red").GetData());
ugridActor_1->GetProperty()->EdgeVisibilityOn();
//ids
vtkNew<vtkIdFilter> ids_1;
ids_1->SetInputData(clean_1->GetOutput());
ids_1->PointIdsOn();
ids_1->CellIdsOn();
ids_1->FieldDataOff();

vtkNew<vtkCellCenters> cc_1_elem;
cc_1_elem->SetInputConnection(ids_1->GetOutputPort());
vtkNew<vtkLabeledDataMapper> labelMapper_1_elem;
labelMapper_1_elem->SetInputConnection(cc_1_elem->GetOutputPort());
labelMapper_1_elem->SetLabelModeToLabelIds();
labelMapper_1_elem->GetLabelTextProperty()->SetColor(colors->GetColor3d("blue").GetData());
labelMapper_1_elem->GetLabelTextProperty()->SetFontSize(12);
vtkNew<vtkActor2D> highlight_1_elem;
highlight_1_elem->SetMapper(labelMapper_1_elem);

vtkNew<vtkLabeledDataMapper> labelMapper_1_point;
labelMapper_1_point->SetInputConnection(ids_1->GetOutputPort());
labelMapper_1_point->SetLabelModeToLabelIds();
labelMapper_1_point->GetLabelTextProperty()->SetColor(colors->GetColor3d("blue").GetData());
labelMapper_1_point->GetLabelTextProperty()->SetFontSize(12);
vtkNew<vtkActor2D> highlight_1_point;
highlight_1_point->SetMapper(labelMapper_1_point);
renderer->AddActor(ugridActor_1);
renderer->AddActor2D(highlight_1_elem);
renderer->AddActor2D(highlight_1_point);

//second_grid
vtkNew<vtkUnstructuredGrid> ugrid_2;
ugrid_2->InsertNextCell(VTK_HEXAHEDRON, 8, id2);
ugrid_2->SetPoints(points);
vtkNew<vtkStaticCleanUnstructuredGrid> clean_2;
clean_2->SetInputData(ugrid_2);
clean_2->Update();
vtkNew<vtkDataSetMapper> ugridMapper_2;
ugridMapper_2->SetInputData(clean_2->GetOutput());
vtkNew<vtkActor> ugridActor_2;
ugridActor_2->SetMapper(ugridMapper_2);
ugridActor_2->GetProperty()->SetColor(colors->GetColor3d("red").GetData());
ugridActor_2->GetProperty()->EdgeVisibilityOn();
//ids
vtkNew<vtkIdFilter> ids_2;
ids_2->SetInputData(clean_2->GetOutput());
ids_2->PointIdsOn();
ids_2->CellIdsOn();
ids_2->FieldDataOff();

vtkNew<vtkCellCenters> cc_2_elem;
cc_2_elem->SetInputConnection(ids_2->GetOutputPort());
vtkNew<vtkLabeledDataMapper> labelMapper_2_elem;
labelMapper_2_elem->SetInputConnection(cc_2_elem->GetOutputPort());
labelMapper_2_elem->SetLabelModeToLabelIds();
labelMapper_2_elem->GetLabelTextProperty()->SetColor(colors->GetColor3d("blue").GetData());
labelMapper_2_elem->GetLabelTextProperty()->SetFontSize(12);
vtkNew<vtkActor2D> highlight_2_elem;
highlight_2_elem->SetMapper(labelMapper_2_elem);

vtkNew<vtkLabeledDataMapper> labelMapper_2_point;
labelMapper_2_point->SetInputConnection(ids_2->GetOutputPort());
labelMapper_2_point->SetLabelModeToLabelIds();
labelMapper_2_point->GetLabelTextProperty()->SetColor(colors->GetColor3d("blue").GetData());
labelMapper_2_point->GetLabelTextProperty()->SetFontSize(12);
vtkNew<vtkActor2D> highlight_2_point;
highlight_2_point->SetMapper(labelMapper_2_point);
renderer->AddActor(ugridActor_2);
renderer->AddActor2D(highlight_2_elem);
renderer->AddActor2D(highlight_2_point);


// interact with data
renWin->Render();

iren->Start();
return EXIT_SUCCESS;

}


That’s my results.

Hi!
If you look at the docs for vtkStaticCleanUnstructuredGrid, you can see that it is merging points and removing unused points. So it will compact your point arrays so they start from zero for each grid.

If you don’t use this filter, and instead examine the original UG, your results will be different. If you want to track the original points or cells as they pass through filters, take a look at Global IDs or Pedigree IDs in DataSetAttributes for something that can do that.

Dear Aron Helser, thank you for your reply.
Clean unused point is what I want to do. As you say, after cleaning, the point id changed form 0 to N.
But I want to know its original point ID.
My plan is to use an array to remember all the original IDs, and then use SetGlobalID to the output of CleanUnstructuredGrid, such as clean_1->GetOutput()->GetPointData()->SetGlobalIds(??);
My question is how do I display the point ID without using the local ID and instead using the globalID that I set?