Skip to content

using image actor #11

@pwm1234-sri

Description

@pwm1234-sri

Thanks for this excellent example using vtk with imgui+glfw. Unfortunately, I am a novice at both, and I am having problems adapting it to use a ``vtkImageActor`. In the snippet below, the reader and actor code (up to the dynamic_cast) came from the vtk example ImageReader2Factory. But when I use the actor returned by my SetupImagePipeline() instead of your SetupDemoPipeline(), I do not get the image shown in the imgui window. (I am able to run the standalone vtk example, so my vtk+glfw environment is working.)

Is there something special that is needed to make your example work with a vtkImageActor?
I appreciate any help, and, of course, I will be glad to provide you a PR if I able to get this to work. (By the way, I am doing this on windows with a vcpkg build of imgui and vtk.)

static vtkSmartPointer<vtkActor> SetupImagePipeline()
{
    // Read a file
    std::string inputFilename = "/tmp/foo.bmp";
    vtkNew<vtkImageReader2Factory> readerFactory;
    vtkSmartPointer<vtkImageReader2> imageReader;
    imageReader.TakeReference(
        readerFactory->CreateImageReader2(inputFilename.c_str()));
    imageReader->SetFileName(inputFilename.c_str());
    imageReader->Update();

    // create actor
    static auto actor = vtkSmartPointer<vtkImageActor>::New();
    actor->GetMapper()->SetInputConnection(imageReader->GetOutputPort());
    vtkSmartPointer<vtkActor> actor2(dynamic_cast<vtkActor*>(actor.Get()));
    return actor2;
}

(Note: in the snippet above I have a hack where the initial actor is static. I do this because I am trying to focus on the main problem where the image actor is not showing the image in the imgui window. This is here to avoid the secondary problem to correct my ignorance of how to work with both vtkNew and vtkSmartPointer. I thought a vtkSmartPointer would automatcally convert to a vtkSmartPointer but that does not seem to compile. So the last two lines in the snippet are a hack to make the compiler happy and avoid crashing when the inital actor goes out of scope. I will fix that if/when I am able to get the vtkImageActor to work.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions