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 "igtlOSUtil.h" 33 void PrintLogsCallback(vtkObject* obj,
unsigned long eid,
void* clientdata,
void* calldata);
37 class vtkMyImageViewerCallback :
public vtkCommand
40 static vtkMyImageViewerCallback* New()
42 return new vtkMyImageViewerCallback;
45 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
47 if (m_Channel->GetVideoDataAvailable())
49 m_Viewer->SetInputData(m_Channel->GetBrightnessOutput());
54 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
57 vtkRenderWindowInteractor* m_Interactor{
nullptr};
58 vtkImageViewer* m_Viewer{
nullptr};
61 class vtkMyMeshViewerCallback :
public vtkCommand
64 static vtkMyMeshViewerCallback* New()
66 return new vtkMyMeshViewerCallback;
69 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
71 static bool firstDisplay{
true};
73 if (m_Channel->GetVideoDataAvailable())
75 m_Mapper->SetInputData(ConvertToPCL(m_Channel->GetBrightnessOutput()));
80 m_Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->ResetCamera();
85 m_Interactor->Render();
88 vtkRenderWindowInteractor* m_Interactor{
nullptr};
90 vtkPolyDataMapper* m_Mapper{
nullptr};
93 vtkSmartPointer<vtkPolyData> ConvertToPCL(vtkImageData* imageData)
95 if (imageData->GetNumberOfScalarComponents() != 3)
100 int* dims = imageData->GetDimensions();
101 vtkNew<vtkPoints> points;
103 for (
int x = 0;
x < dims[0];
x++)
105 for (
int y = 0;
y < dims[1];
y++)
107 for (
int z = 0; z < dims[2]; z++)
110 static_cast<float*>(imageData->GetScalarPointer(
x,
y, z));
117 points->InsertNextPoint(coords[0], coords[1], coords[2]);
122 vtkNew<vtkPolyData> poly;
123 poly->SetPoints(points);
125 vtkNew<vtkVertexGlyphFilter> vertexGenerator;
126 vertexGenerator->SetInputData(poly);
127 vertexGenerator->Update();
129 return vertexGenerator->GetOutput();
134 int main(
int argc,
char** argv)
137 bool printHelp(
false);
138 std::string inputConfigFileName =
"Testing/PlusDeviceSet_DataCollectionOnly_Revopoint3DCamera.xml";
140 vtksys::CommandLineArguments args;
141 args.Initialize(argc, argv);
143 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
144 bool renderingOff(
false);
146 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
147 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
148 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
149 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
153 std::cerr <<
"Problem parsing arguments" << std::endl;
154 std::cout <<
"\n\nHelp:" << args.GetHelp() << std::endl;
162 std::cout <<
"\n\nHelp:" << args.GetHelp() << std::endl;
166 vtkNew<vtkPlusRevopoint3DCamera> revopoint3DCameraDevice;
167 revopoint3DCameraDevice->SetDeviceId(
"VideoDevice");
169 if (!vtksys::SystemTools::FileExists(inputConfigFileName))
171 LOG_ERROR(
"Bad configuration file: " << inputConfigFileName);
175 LOG_DEBUG(
"Reading config file: " << inputConfigFileName);
176 auto* configRead = vtkXMLUtilities::ReadElementFromFile(inputConfigFileName.c_str());
180 LOG_ERROR(
"Failed to read configuration file");
184 LOG_TRACE(
"Config file: " << *configRead);
185 if (revopoint3DCameraDevice->ReadConfiguration(configRead) !=
PLUS_SUCCESS)
187 LOG_ERROR(
"Failed to read configuration");
191 if (revopoint3DCameraDevice->NotifyConfigured() !=
PLUS_SUCCESS)
193 LOG_ERROR(
"Invalid configuration");
198 revopoint3DCameraDevice->GetOutputChannelByName(depthChannel,
"VideoStreamDEPTH");
202 revopoint3DCameraDevice->GetOutputChannelByName(pclChannel,
"VideoStreamPCL");
205 revopoint3DCameraDevice->PrintSelf(std::cout, indent);
208 vtkNew<vtkCallbackCommand> callbackCommand;
210 revopoint3DCameraDevice->AddObserver(
"WarningEvent", callbackCommand);
211 revopoint3DCameraDevice->AddObserver(
"ErrorEvent", callbackCommand);
215 LOG_ERROR(
"Failed to connect");
219 if (revopoint3DCameraDevice->StartRecording() !=
PLUS_SUCCESS)
221 LOG_INFO(
"Failed to start recording");
227 vtkNew<vtkImageViewer> imageViewer;
228 imageViewer->SetColorWindow(255);
229 imageViewer->SetColorLevel(127.5);
230 imageViewer->SetZSlice(0);
233 vtkNew<vtkRenderWindowInteractor> imageInteractor;
234 imageInteractor->SetRenderWindow(imageViewer->GetRenderWindow());
235 imageViewer->SetupInteractor(imageInteractor);
237 imageViewer->Render();
240 vtkNew<vtkMyImageViewerCallback> call;
241 call->m_Interactor = imageInteractor;
242 call->m_Viewer = imageViewer;
243 imageInteractor->AddObserver(vtkCommand::TimerEvent, call);
244 imageInteractor->CreateTimer(VTKI_TIMER_FIRST);
249 call->m_Channel = depthChannel;
250 imageInteractor->Initialize();
251 imageInteractor->Start();
254 imageInteractor->GetRenderWindow()->Finalize();
259 vtkNew<vtkRenderer> pclRenderer;
260 vtkNew<vtkRenderWindow> pclRenderWindow;
261 pclRenderWindow->SetSize(640, 480);
262 pclRenderWindow->AddRenderer(pclRenderer);
263 vtkNew<vtkRenderWindowInteractor> pclInteractor;
264 pclInteractor->SetRenderWindow(pclRenderWindow);
266 vtkNew<vtkPolyDataMapper> mapper;
267 mapper->SetInputData(vtkSmartPointer<vtkPolyData>::New());
268 vtkNew<vtkActor> actor;
269 actor->SetMapper(mapper);
270 pclRenderer->SetBackground(0., 0., 0.);
271 pclRenderer->AddActor(actor);
273 pclRenderWindow->Render();
274 pclInteractor->Initialize();
276 vtkNew<vtkMyMeshViewerCallback> call2;
277 call2->m_Interactor = pclInteractor;
278 call2->m_Mapper = mapper;
279 call2->m_Channel = pclChannel;
281 pclInteractor->AddObserver(vtkCommand::TimerEvent, call2);
282 pclInteractor->CreateRepeatingTimer(100);
284 pclInteractor->Start();
285 pclInteractor->GetRenderWindow()->Finalize();
293 if (revopoint3DCameraDevice->StopRecording() !=
PLUS_SUCCESS)
295 LOG_INFO(
"Failed to stop recording");
299 if (revopoint3DCameraDevice->Disconnect() !=
PLUS_SUCCESS)
301 LOG_ERROR(
"Failed to disconnect");
305 LOG_INFO(
"Exit successfully");
313 if (eid == vtkCommand::GetEventIdFromString(
"WarningEvent"))
315 LOG_WARNING((
const char*)calldata);
317 else if (eid == vtkCommand::GetEventIdFromString(
"ErrorEvent"))
319 LOG_ERROR((
const char*)calldata);
int main(int argc, char **argv)
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
Direction vectors of rods y