7 #include "PlusConfigure.h" 8 #include "vtkCallbackCommand.h" 9 #include "vtkCommand.h" 11 #include "vtkImageData.h" 12 #include "vtkImageViewer2.h" 13 #include "vtkRenderWindowInteractor.h" 14 #include "vtkRenderer.h" 15 #include "vtkSmartPointer.h" 16 #include "vtksys/CommandLineArguments.hxx" 19 void PrintLogsCallback(vtkObject* obj,
unsigned long eid,
void* clientdata,
void* calldata);
21 class vtkMyCallback :
public vtkCommand
24 static vtkMyCallback* New()
25 {
return new vtkMyCallback;}
26 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
32 iren->CreateTimer(VTKI_TIMER_UPDATE);
35 vtkRenderWindowInteractor*
iren;
44 int main(
int argc,
char** argv)
46 std::string iniFile =
"BkSettings/IniFile.ini";
47 double frameRate = 30;
48 bool printHelp(
false);
49 bool renderingOff(
false);
51 vtksys::CommandLineArguments args;
52 args.Initialize(argc, argv);
54 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
56 args.AddArgument(
"--ini-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &iniFile,
"Path to the BK ini file, relative to the configuration file directory. Default: BkSettings/IniFile.ini");
57 args.AddArgument(
"--frame-rate", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &frameRate,
"Requested acquisition frame rate (in FPS, default = 30)");
58 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
59 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
60 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
64 std::cerr <<
"Problem parsing arguments" << std::endl;
65 std::cout <<
"\n\nvtkPlusBkProFocusOemVideoSource help:" << args.GetHelp() << std::endl;
73 std::cout <<
"\n\nvtkPlusBkProFocusOemVideoSource help:" << args.GetHelp() << std::endl;
77 vtkSmartPointer<vtkPlusBkProFocusOemVideoSource> frameGrabber = vtkSmartPointer<vtkPlusBkProFocusOemVideoSource>::New();
79 frameGrabber->SetAcquisitionRate(frameRate);
81 frameGrabber->CreateDefaultOutputChannel();
84 vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
86 frameGrabber->AddObserver(
"WarningEvent", callbackCommand);
87 frameGrabber->AddObserver(
"ErrorEvent", callbackCommand);
89 LOG_INFO(
"Initialize...");
90 frameGrabber->Connect();
92 if (frameGrabber->GetConnected())
94 LOG_INFO(
"Start recording...");
95 frameGrabber->StartRecording();
99 frameGrabber->Disconnect();
100 LOG_ERROR(
"Unable to connect to IC capture device");
108 if (frameGrabber->GetFirstActiveOutputVideoSource(videoSource) !=
PLUS_SUCCESS)
110 LOG_ERROR(
"Unable to retrieve the video source.");
113 for (
int retries = 0; retries < 50; retries++)
120 vtkIGSIOAccurateTimer::Delay(0.1);
124 LOG_ERROR(
"Frames are not received from the device for several seconds");
129 LOG_INFO(
"No need for rendering, stop the device...");
130 frameGrabber->StopRecording();
131 frameGrabber->Disconnect();
132 LOG_INFO(
"Exit successfully");
136 vtkSmartPointer<vtkImageViewer2>
viewer = vtkSmartPointer<vtkImageViewer2>::New();
138 viewer->SetColorWindow(255);
139 viewer->SetColorLevel(100.5);
140 viewer->SetSize(1024, 768);
142 viewer->SetInputConnection(frameGrabber->GetOutputPort());
145 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
146 iren->SetRenderWindow(
viewer->GetRenderWindow());
152 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
155 iren->AddObserver(vtkCommand::TimerEvent, call);
156 iren->CreateTimer(VTKI_TIMER_FIRST);
162 LOG_INFO(
"Exit successfully");
170 if (eid == vtkCommand::GetEventIdFromString(
"WarningEvent"))
172 LOG_WARNING((
const char*)calldata);
174 else if (eid == vtkCommand::GetEventIdFromString(
"ErrorEvent"))
176 LOG_ERROR((
const char*)calldata);
vtkRenderWindowInteractor * iren
int main(int argc, char **argv)
static vtkIGSIOLogger * Instance()
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
virtual int GetNumberOfItems()
Interface to a 3D positioning tool, video source, or generalized data stream.