how to make the height map for c++ image buffer

Hi all
I want to make the height map for c++ image buffer.
image
to
image

This is what I have done upto now.

  1. using vtkDelaunay2D
int nImageWidth = 500, nImageHeight = 1000;
BYTE* pBuffer = new BYTE[nImageWidth*nImageHeight];

vtkNew<vtkPoints> points;
for (int y = 0; y < nImageHeight ; y++) {
	for (int x = 0; x < nImageWidth ; x++) {
		double dData = (double)pBuffer[(nImageWidth * y) + x];
		points->InsertNextPoint(x, y, dData);	
	}
}

vtkNew<vtkPolyData> inputPolyData;
inputPolyData->SetPoints(points);

vtkNew<vtkDelaunay2D> delaunay;
delaunay->SetInputData(inputPolyData);
delaunay->Update();

vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(delaunay->GetOutput());

vtkNew<vtkActor> actor;
actor->SetMapper(mapper);

vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor);
renderer->SetBackground(.1, .2, .3);
renderer->ResetCamera();

m_vtkRenderWindow->AddRenderer(renderer);
m_vtkRenderWindow->Render();

The above method has two problems.
First: ‘delaunay->Update()’ takes too much time.
Second: Large images cannot use the above method.

  1. using vtkImageImport
int nImageWidth = 500, nImageHeight = 1000;
BYTE* pBuffer = new BYTE[nImageWidth*nImageHeight];

vtkNew<vtkImageImport> imageImport;
imageImport->SetDataSpacing(1, 1, 1);
imageImport->SetDataOrigin(0, 0, 0);
imageImport->SetWholeExtent(0, pImage->GetFrameWidth() - 1, 0, pImage->GetFrameHeight() - 1, 0, 0);
imageImport->SetDataExtentToWholeExtent();
imageImport->SetNumberOfScalarComponents(1);
imageImport->SetDataScalarTypeToUnsignedChar();
imageImport->SetImportVoidPointer(pBuffer);
imageImport->Update();

// Here i need to convert to height map.
// but, i have no idea..

Please advise on solution.
Thank you in advance.

Hi @J_Kim

Have you looked at the vtkWarpScalar filter?
https://vtk.org/doc/nightly/html/classvtkWarpScalar.html#details

I am very grateful for your advice.
I was able to succeed using vtkWarpScalar filter as per your advice.

Great to read that you’ve figured out your issue!