# How to get the global ids in many different dataset?

**URL:** https://discourse.vtk.org/t/how-to-get-the-global-ids-in-many-different-dataset/11863
**Category:** Support
**Tags:** code
**Created:** [July 2, 2023, 9:23am UTC](https://discourse.vtk.org/t/how-to-get-the-global-ids-in-many-different-dataset/11863 "2023-07-02T09:23:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rockydut](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rockydut/32/4261_2.png) [@rockydut](https://discourse.vtk.org/u/rockydut)
#### Post date: [July 2, 2023, 9:23am UTC](https://discourse.vtk.org/t/how-to-get-the-global-ids-in-many-different-dataset/11863/1 "2023-07-02T09:23:41Z")

</div>

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;

```

}

---

<div class="post-metadata">

### Author: ![rockydut](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rockydut/32/4261_2.png) [@rockydut](https://discourse.vtk.org/u/rockydut)
#### Post date: [July 2, 2023, 9:31am UTC](https://discourse.vtk.org/t/how-to-get-the-global-ids-in-many-different-dataset/11863/2 "2023-07-02T09:31:26Z")

</div>

![results](https://discourse.vtk.org/uploads/default/original/2X/6/659f04b01454a440914ff4ca54b84a213669ebd2.png)  
That’s my results.

---

<div class="post-metadata">

### Author: ![Aron\_Helser](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aron_helser/32/14_2.png) [@Aron\_Helser](https://discourse.vtk.org/u/Aron_Helser)
#### Post date: [July 3, 2023, 3:02pm UTC](https://discourse.vtk.org/t/how-to-get-the-global-ids-in-many-different-dataset/11863/3 "2023-07-03T15:02:00Z")

</div>

Hi!  
If you look at the docs for [vtkStaticCleanUnstructuredGrid](https://vtk.org/doc/nightly/html/classvtkStaticCleanUnstructuredGrid.html#details), 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](https://vtk.org/doc/nightly/html/classvtkDataSetAttributes.html#details) for something that can do that.

---

<div class="post-metadata">

### Author: ![rockydut](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rockydut/32/4261_2.png) [@rockydut](https://discourse.vtk.org/u/rockydut)
#### Post date: [July 8, 2023, 2:21am UTC](https://discourse.vtk.org/t/how-to-get-the-global-ids-in-many-different-dataset/11863/4 "2023-07-08T02:21:39Z")

</div>

> [@rockydut](#):
>
> `clean_1->GetOutput()`

Dear [Aron Helser](https://discourse.vtk.org/u/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?
