9 #include "PlusConfigure.h" 10 #include "vtkCallbackCommand.h" 11 #include "vtkCommand.h" 13 #include "vtkSmartPointer.h" 15 #include "vtksys/CommandLineArguments.hxx" 16 #include "vtksys/SystemTools.hxx" 17 #include "vtkImageData.h" 18 #include "vtkImageViewer.h" 19 #include "vtkInformation.h" 20 #include "vtkInformationVector.h" 21 #include "vtkRenderWindow.h" 22 #include "vtkRenderWindowInteractor.h" 23 #include "vtkRenderer.h" 24 #include "vtkRendererCollection.h" 25 #include "vtkPolyDataMapper.h" 26 #include "vtkPolyData.h" 27 #include "vtkPoints.h" 28 #include "vtkVertexGlyphFilter.h" 29 #include "vtkPointData.h" 31 #include "vtkUnsignedCharArray.h" 32 #include "igtlOSUtil.h" 35 void PrintLogsCallback(vtkObject* obj,
unsigned long eid,
void* clientdata,
void* calldata);
39 class vtkMyImageViewerCallback :
public vtkCommand
42 static vtkMyImageViewerCallback* New()
44 return new vtkMyImageViewerCallback;
47 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
49 if (m_Channel->GetVideoDataAvailable())
51 m_Viewer->SetInputData(m_Channel->GetBrightnessOutput());
56 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
59 vtkRenderWindowInteractor* m_Interactor{
nullptr};
60 vtkImageViewer* m_Viewer{
nullptr};
64 class vtkMyMeshViewerCallback :
public vtkCommand
67 static vtkMyMeshViewerCallback* New()
69 return new vtkMyMeshViewerCallback;
72 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
74 static bool firstDisplay{
true};
75 vtkImageData* texture{
nullptr};
77 if (m_Texture && m_Texture->GetVideoDataAvailable())
82 if (m_Channel->GetVideoDataAvailable())
84 m_Mapper->SetInputData(ConvertToPCL(m_Channel->GetBrightnessOutput(), texture));
89 m_Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->ResetCamera();
94 m_Interactor->Render();
97 vtkRenderWindowInteractor* m_Interactor{
nullptr};
99 vtkPolyDataMapper* m_Mapper{
nullptr};
103 vtkSmartPointer<vtkPolyData> ConvertToPCL(vtkImageData* imageData, vtkImageData* texture)
105 if (imageData->GetNumberOfScalarComponents() != 3)
110 int* dims = imageData->GetDimensions();
111 vtkNew<vtkPoints> points;
112 vtkNew<vtkUnsignedCharArray> colors;
113 colors->SetNumberOfComponents(3);
114 colors->SetName(
"Colors");
116 for (
int x = 0;
x < dims[0];
x++)
118 for (
int y = 0;
y < dims[1];
y++)
120 for (
int z = 0; z < dims[2]; z++)
123 static_cast<int16_t*>(imageData->GetScalarPointer(
x,
y, z));
130 points->InsertNextPoint(coords[0], coords[1], coords[2]);
135 static_cast<uint8_t*>(texture->GetScalarPointer(
x,
y, z));
136 colors->InsertNextTypedTuple(color);
140 uint8_t color[3] = {255, 255, 255};
141 colors->InsertNextTypedTuple(color);
147 vtkNew<vtkPolyData> poly;
148 poly->SetPoints(points);
149 poly->GetPointData()->SetScalars(colors);
151 vtkNew<vtkVertexGlyphFilter> vertexGenerator;
152 vertexGenerator->SetInputData(poly);
153 vertexGenerator->Update();
155 return vertexGenerator->GetOutput();
160 int main(
int argc,
char** argv)
162 bool printHelp(
false);
163 std::string inputConfigFileName =
"Testing/PlusDeviceSet_DataCollectionOnly_AzureKinect.xml";
165 vtksys::CommandLineArguments args;
166 args.Initialize(argc, argv);
168 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
169 bool renderingOff(
false);
171 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
172 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
173 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
174 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
178 std::cerr <<
"Problem parsing arguments" << std::endl;
179 std::cout <<
"\n\nHelp:" << args.GetHelp() << std::endl;
187 std::cout <<
"\n\nHelp:" << args.GetHelp() << std::endl;
191 vtkNew<vtkPlusAzureKinect> azureKinectDevice;
192 azureKinectDevice->SetDeviceId(
"VideoDevice");
194 if (!vtksys::SystemTools::FileExists(inputConfigFileName))
196 LOG_ERROR(
"Bad configuration file: " << inputConfigFileName);
200 LOG_DEBUG(
"Reading config file: " << inputConfigFileName);
201 auto* configRead = vtkXMLUtilities::ReadElementFromFile(inputConfigFileName.c_str());
205 LOG_ERROR(
"Failed to read configuration file");
209 LOG_TRACE(
"Config file: " << *configRead);
210 if (azureKinectDevice->ReadConfiguration(configRead) !=
PLUS_SUCCESS)
212 LOG_ERROR(
"Failed to read configuration");
216 if (azureKinectDevice->NotifyConfigured() !=
PLUS_SUCCESS)
218 LOG_ERROR(
"Invalid configuration");
223 azureKinectDevice->GetOutputChannelByName(rgbChannel,
"VideoStreamRGB");
226 azureKinectDevice->GetOutputChannelByName(depthChannel,
"VideoStreamDEPTH");
230 azureKinectDevice->GetOutputChannelByName(pclChannel,
"VideoStreamPCL");
233 azureKinectDevice->PrintSelf(std::cout, indent);
236 vtkNew<vtkCallbackCommand> callbackCommand;
238 azureKinectDevice->AddObserver(
"WarningEvent", callbackCommand);
239 azureKinectDevice->AddObserver(
"ErrorEvent", callbackCommand);
243 LOG_ERROR(
"Failed to connect");
247 if (azureKinectDevice->StartRecording() !=
PLUS_SUCCESS)
249 LOG_INFO(
"Failed to start recording");
255 vtkNew<vtkImageViewer> imageViewer;
256 imageViewer->SetColorWindow(255);
257 imageViewer->SetColorLevel(127.5);
258 imageViewer->SetZSlice(0);
261 vtkNew<vtkRenderWindowInteractor> imageInteractor;
262 imageInteractor->SetRenderWindow(imageViewer->GetRenderWindow());
263 imageViewer->SetupInteractor(imageInteractor);
265 imageViewer->Render();
268 vtkNew<vtkMyImageViewerCallback> call;
269 call->m_Interactor = imageInteractor;
270 call->m_Viewer = imageViewer;
271 imageInteractor->AddObserver(vtkCommand::TimerEvent, call);
272 imageInteractor->CreateTimer(VTKI_TIMER_FIRST);
277 call->m_Channel = rgbChannel;
278 imageInteractor->Initialize();
279 imageInteractor->Start();
285 call->m_Channel = depthChannel;
286 imageInteractor->Start();
289 imageInteractor->GetRenderWindow()->Finalize();
294 vtkNew<vtkRenderer> pclRenderer;
295 vtkNew<vtkRenderWindow> pclRenderWindow;
296 pclRenderWindow->SetSize(640, 480);
297 pclRenderWindow->AddRenderer(pclRenderer);
298 vtkNew<vtkRenderWindowInteractor> pclInteractor;
299 pclInteractor->SetRenderWindow(pclRenderWindow);
301 vtkNew<vtkPolyDataMapper> mapper;
302 mapper->SetInputData(vtkSmartPointer<vtkPolyData>::New());
303 vtkNew<vtkActor> actor;
304 actor->SetMapper(mapper);
305 pclRenderer->SetBackground(0., 0., 0.);
306 pclRenderer->AddActor(actor);
308 pclRenderWindow->Render();
309 pclInteractor->Initialize();
311 vtkNew<vtkMyMeshViewerCallback> call2;
312 call2->m_Interactor = pclInteractor;
313 call2->m_Mapper = mapper;
314 call2->m_Channel = pclChannel;
318 call2->m_Texture = rgbChannel;
321 pclInteractor->AddObserver(vtkCommand::TimerEvent, call2);
322 pclInteractor->CreateRepeatingTimer(100);
324 pclInteractor->Start();
325 pclInteractor->GetRenderWindow()->Finalize();
335 LOG_INFO(
"Failed to stop recording");
341 LOG_ERROR(
"Failed to disconnect");
345 LOG_INFO(
"Exit successfully");
353 if (eid == vtkCommand::GetEventIdFromString(
"WarningEvent"))
355 LOG_WARNING((
const char*)calldata);
357 else if (eid == vtkCommand::GetEventIdFromString(
"ErrorEvent"))
359 LOG_ERROR((
const char*)calldata);
int main(int argc, char **argv)
vtkImageData * GetBrightnessOutput()
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
Direction vectors of rods y
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)