Hello,
I am having trouble getting some imaging data to appear correctly using the VTK C++ API. When I run the code below and read in my image, all I get is a blank white box where the image should be. The image is a “.png”. The values at each pixel are unsigned short. Their range is [8738, 61937]. When I load the image in Paraview it shows up correctly with the “Cool to Warm” colormap. I want to display the same thing, but all I see is a blank white box where the image should be (the box is the correct size for the image, it is obviously reading the image, but for some reason not displaying correctly).
If you know what the problem is and could help I would greatly appreciate it. I am sure it is some dumb mistake.
Here is my minimal reproducable code:
int main(int argc, char **argv) {
vtkNew colors;
//For setting the background color.
std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
colors->SetColor(“BkgColor”, bkg.data());
std::string inputFilePath("/my/in/path/here1.png");
// Read the image file
vtkNew reader;
reader->SetFileName(inputFilePath.data());
reader->Update();
//Initialize the image actor
vtkNew imageViewer;
imageViewer->SetInputConnection(reader->GetOutputPort());
std::cout << std::endl << std::endl;
// Visualize
vtkNew iren;
imageViewer->SetupInteractor(iren);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->GetRenderer()->SetBackground(colors->GetColor3d(“DarkSlateGray”).GetData());
imageViewer->GetRenderWindow()->SetWindowName(“PNGReader”);
imageViewer->Render();
iren->Start();
return EXIT_SUCCESS;
}
PS: I am not sure if it is my browser or what, but the preformatted text in the editor is not letting me copy code.