Вот мое решение. Надеюсь, это поможет!
#include <Windows.h>
#include <iostream>
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkSphereSource.h>
#include <vtkElevationFilter.h>
#include <vtkVectorText.h>
#include <vtkCommand.h>
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingOpenGL);
#define w 400
//---------------------------------------------o0o---------------------------------------------//
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
//---------------------------------------------o0o---------------------------------------------//
using namespace std;
void* mutex;
void* handler_thread = 0;
VTK_CREATE(vtkRenderer, renDisplay3D);
VTK_CREATE(vtkRenderWindow, renderwindowDisplay3D);
VTK_CREATE(vtkRenderWindowInteractor, irenDisplay3D);
vtkInteractorStyleTrackballCamera *styleDisplay3D = vtkInteractorStyleTrackballCamera::New();
class CommandSubclass2 : public vtkCommand
{
public:
vtkTypeMacro(CommandSubclass2, vtkCommand);
static CommandSubclass2 *New()
{
return new CommandSubclass2;
}
void Execute(vtkObject *caller, unsigned long vtkNotUsed(eventId),
void *vtkNotUsed(callData))
{
vtkRenderWindowInteractor *iren = static_cast<vtkRenderWindowInteractor*>(caller);
iren->Render();
}
};
unsigned long __stdcall displayVTKThread(void* param)
{
//WaitForSingleObject(mutex, INFINITE);
renderwindowDisplay3D->SetSize(600, 400);
renderwindowDisplay3D->AddRenderer(renDisplay3D);
renderwindowDisplay3D->Render();
irenDisplay3D->SetRenderWindow(renderwindowDisplay3D);
irenDisplay3D->SetInteractorStyle(styleDisplay3D);
// Initialize must be called prior to creating timer events.
irenDisplay3D->Initialize();
vtkSmartPointer<CommandSubclass2> timerCallback = vtkSmartPointer<CommandSubclass2>::New();
irenDisplay3D->AddObserver ( vtkCommand::TimerEvent, timerCallback );
irenDisplay3D->CreateRepeatingTimer(100);
irenDisplay3D->Start();
//ReleaseMutex(mutex);
return 0;
}
int main (int argv, char* argc[])
{
mutex = CreateMutex(0, false, 0);
unsigned long id_thread;
VTK_CREATE(vtkVectorText, text);
text->SetText("Display 3D Point Clouds!");
VTK_CREATE(vtkElevationFilter, elevation);
elevation->SetInputConnection(text->GetOutputPort());
elevation->SetLowPoint(0,0,0);
elevation->SetHighPoint(10,0,0);
// Mapper
VTK_CREATE(vtkPolyDataMapper, mapper);
mapper->SetInputConnection(elevation->GetOutputPort());
mapper->Update();
// Actor in scene
VTK_CREATE(vtkActor, actor);
actor->SetMapper(mapper);
// Add Actor to renderer
renDisplay3D->AddActor(actor);
renDisplay3D->SetBackground(0.0, 0.0, 0.0);
handler_thread = CreateThread(0, 0, displayVTKThread, 0, 0, &id_thread);
if(!handler_thread)
{
printf("Cannot create thread. Error code = %d\n", GetLastError());
getchar();
return -1;
}
char myChar = ' ';
while(myChar != 'q') {
myChar = getchar();
if (myChar == 'v')
{
//WaitForSingleObject(mutex, INFINITE);
// Create a sphere
VTK_CREATE(vtkSphereSource, sphereSource);
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(5.0);
mapper->SetInputConnection(sphereSource->GetOutputPort());
actor->SetMapper(mapper);
renDisplay3D->ResetCamera();
renDisplay3D->AddActor(actor);
//ReleaseMutex(mutex);
}
}
CloseHandle(handler_thread);
printf("\n\nExit program\n");
Sleep(1000);
CloseHandle(mutex);
return 0;
}