7 #include "PlusConfigure.h" 8 #include "vtkCallbackCommand.h" 9 #include "vtkCommand.h" 10 #include "vtkImageData.h" 11 #include "vtkImageViewer2.h" 13 #include "vtkRenderWindowInteractor.h" 14 #include "vtkRenderer.h" 15 #include "vtkSmartPointer.h" 17 #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*)
31 iren->CreateTimer(VTKI_TIMER_UPDATE);
34 vtkRenderWindowInteractor *
iren;
43 int main(
int argc,
char **argv)
46 bool printHelp(
false);
47 bool renderingOff(
false);
48 bool showDialogs(
false);
50 vtksys::CommandLineArguments args;
51 args.Initialize(argc, argv);
53 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
55 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
56 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
57 args.AddArgument(
"--show-dialogs", vtksys::CommandLineArguments::NO_ARGUMENT, &showDialogs,
"Show video source and format dialogs");
58 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
62 std::cerr <<
"Problem parsing arguments" << std::endl;
63 std::cout <<
"\n\nvtkWin32VideoSourceTest help:" << args.GetHelp() << std::endl;
71 std::cout <<
"\n\nvtkWin32VideoSourceTest help:" << args.GetHelp() << std::endl;
76 vtkSmartPointer<vtkPlusWin32VideoSource2> frameGrabber = vtkSmartPointer<vtkPlusWin32VideoSource2>::New();
78 frameGrabber->CreateDefaultOutputChannel();
81 vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
83 frameGrabber->AddObserver(
"WarningEvent", callbackCommand);
84 frameGrabber->AddObserver(
"ErrorEvent", callbackCommand);
86 LOG_INFO(
"Initialize...");
87 frameGrabber->Connect();
91 frameGrabber->VideoSourceDialog();
92 frameGrabber->VideoFormatDialog();
95 if ( frameGrabber->GetConnected() )
97 LOG_INFO(
"Start recording...");
98 frameGrabber->StartRecording();
102 frameGrabber->Disconnect();
103 LOG_ERROR(
"Unable to connect to IC capture device");
110 LOG_INFO(
"No need for rendering, stop the device...");
111 frameGrabber->StopRecording();
112 frameGrabber->Disconnect();
113 LOG_INFO(
"Exit successfully");
117 vtkSmartPointer<vtkImageViewer2>
viewer = vtkSmartPointer<vtkImageViewer2>::New();
119 viewer->SetColorWindow(255);
120 viewer->SetColorLevel(100.5);
122 if (frameGrabber->GetFirstActiveOutputVideoSource(videoSource) !=
PLUS_SUCCESS )
124 LOG_ERROR(
"Unable to retrieve the video source.");
129 viewer->SetInputConnection(frameGrabber->GetOutputPort());
132 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
133 iren->SetRenderWindow(
viewer->GetRenderWindow());
139 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
142 iren->AddObserver(vtkCommand::TimerEvent, call);
143 iren->CreateTimer(VTKI_TIMER_FIRST);
149 LOG_INFO(
"Exit successfully");
157 if ( eid == vtkCommand::GetEventIdFromString(
"WarningEvent") )
159 LOG_WARNING((
const char*)calldata);
161 else if ( eid == vtkCommand::GetEventIdFromString(
"ErrorEvent") )
163 LOG_ERROR((
const char*)calldata);
int main(int argc, char **argv)
vtkRenderWindowInteractor * iren
void PrintLogsCallback(vtkObject *obj, unsigned long eid, void *clientdata, void *calldata)
virtual FrameSizeType GetOutputFrameSize() const
static vtkIGSIOLogger * Instance()
Interface to a 3D positioning tool, video source, or generalized data stream.