Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using image actor #11

Open
pwm1234-sri opened this issue Jun 18, 2021 · 6 comments
Open

using image actor #11

pwm1234-sri opened this issue Jun 18, 2021 · 6 comments

Comments

@pwm1234-sri
Copy link

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.)

@trlsmax
Copy link
Owner

trlsmax commented Oct 7, 2022

It should work on current master

@bumjuncho
Copy link

Hello!
I made some different using the imgui-vtk. Also, I have same problems. In my case, I got a nullpointException in SetupDemoPipeline(). [line no 106]

@bumjuncho
Copy link

Hello! I made some different using the imgui-vtk. Also, I have same problems. In my case, I got a nullpointException in SetupDemoPipeline(). [line no 106]

I solved it. It occurred vtk files[using the cmake]. (vtk version latest version 9.2)

@bumjuncho
Copy link

I'm faced with another problem as below.
As you can see, it does not appear on the screen. So, I tried to vtk sample code on the vtk homepage.

==============================
#include <vtkAutoInit.h>

#define vtkRenderingCore_AUTOINIT 3(vtkRenderingOpenGL2,vtkInteractionStyle, vtkRenderingFreeType)
#define vtkRenderingContext2D_AUTOINIT 1(vtkRenderingContextOpenGL2)

#include <vtkActor.h>
#include <vtkCylinderSource.h>
#include <vtkSmartPointer.h>
#include <vtkContourFilter.h>
#include <vtkMath.h>
#include <vtkNamedColors.h>
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkShortArray.h>
#include <vtkStructuredPoints.h>

static vtkSmartPointer SetupDemoCylinder()
{
auto colors = vtkSmartPointer::New();

// Set the background color.
std::array<unsigned char, 4> bkg{ {26, 51, 102, 255} };
colors->SetColor("BkgColor", bkg.data());

// This creates a polygonal cylinder model with eight circumferential facets
// (i.e, in practice an octagonal prism).
auto cylinder = vtkSmartPointer<vtkCylinderSource>::New();
cylinder->SetResolution(8);

// The mapper is responsible for pushing the geometry into the graphics
// library. It may also do color mapping, if scalars or other attributes are
// defined.
auto cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

// The actor is a grouping mechanism: besides the geometry (mapper), it
// also has a property, transformation matrix, and/or texture map.
// Here we set its color and rotate it around the X and Y axes.

auto cylinderActor = vtkSmartPointer<vtkActor>::New();
cylinderActor->SetMapper(cylinderMapper);
//cylinderActor->GetProperty()->SetColor(colors->GetColor4d("Tomato").GetData());
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45.0);


return cylinderActor;

}

image

@rajkundu
Copy link
Collaborator

rajkundu commented Jan 6, 2023

What system are you using? I can't seem to replicate your issue on my 16" Intel MacBook Pro (macOS 12.5), as the cylinder works fine for me:
imgui-vtk demo with cylinder successfully rendered

@GengGode
Copy link

GengGode commented Jul 7, 2024

I encountered the same issue while running the demo.
The viewer area does not display anything, and the button to adjust the background color does not respond.
I am using Windows+vcpkg+vtk9.3.
I am a beginner in VTK, is it due to platform differences?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants