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" 18 void PrintLogsCallback(vtkObject* obj,
unsigned long eid,
void* clientdata,
void* calldata);
20 class vtkMyCallback :
public vtkCommand
23 static vtkMyCallback* New()
24 {
return new vtkMyCallback;}
25 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
30 iren->CreateTimer(VTKI_TIMER_UPDATE);
33 vtkRenderWindowInteractor*
iren;
42 int main(
int argc,
char** argv)
44 std::string grabberLocation;
45 double frameRate = 30;
46 std::vector<int> clipRectOrigin;
47 std::vector<int> clipRectSize;
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(
"--grabber-location", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &grabberLocation,
"Location of the of the Epiphan device to connect (use the format sn:SERIAL for the specification of serial number)");
57 args.AddArgument(
"--frame-rate", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &frameRate,
"Requested acquisition frame rate (in FPS, default = 30)");
58 args.AddArgument(
"--clip-rect-origin", vtksys::CommandLineArguments::MULTI_ARGUMENT, &clipRectOrigin,
"Origin of the clipping rectangle");
59 args.AddArgument(
"--clip-rect-size", vtksys::CommandLineArguments::MULTI_ARGUMENT, &clipRectSize,
"Size of the clipping rectangle");
60 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
61 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
62 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
66 std::cerr <<
"Problem parsing arguments" << std::endl;
67 std::cout <<
"\n\nvtkPlusEpiphanVideoSourceTest help:" << args.GetHelp() << std::endl;
75 std::cout <<
"\n\nvtkPlusEpiphanVideoSourceTest help:" << args.GetHelp() << std::endl;
80 vtkSmartPointer<vtkPlusEpiphanVideoSource> frameGrabber = vtkSmartPointer<vtkPlusEpiphanVideoSource>::New();
81 if (!grabberLocation.empty())
83 frameGrabber->SetGrabberLocation(grabberLocation.c_str());
85 frameGrabber->SetAcquisitionRate(frameRate);
87 if (clipRectOrigin.size() > 0 || clipRectSize.size() > 0)
89 if (clipRectOrigin.size() != 2 || clipRectSize.size() != 2)
91 LOG_ERROR(
"Invalid clip rectangle origin and/or size");
94 std::array<int, 3> clipRectangleOrigin = {clipRectOrigin[0], clipRectOrigin[1], igsioCommon::NO_CLIP};
95 frameGrabber->SetClipRectangleOrigin(clipRectangleOrigin);
96 std::array<int, 3> clipRectangleSize = {clipRectSize[0], clipRectSize[1], igsioCommon::NO_CLIP};
97 frameGrabber->SetClipRectangleSize(clipRectangleSize);
100 frameGrabber->CreateDefaultOutputChannel();
103 vtkSmartPointer<vtkCallbackCommand> callbackCommand = vtkSmartPointer<vtkCallbackCommand>::New();
105 frameGrabber->AddObserver(
"WarningEvent", callbackCommand);
106 frameGrabber->AddObserver(
"ErrorEvent", callbackCommand);
108 LOG_INFO(
"Initialize...");
109 frameGrabber->Connect();
111 if (frameGrabber->GetConnected())
113 LOG_INFO(
"Start recording...");
114 frameGrabber->StartRecording();
118 frameGrabber->Disconnect();
119 LOG_ERROR(
"Unable to connect to IC capture device");
126 LOG_INFO(
"No need for rendering, stop the device...");
127 frameGrabber->StopRecording();
128 frameGrabber->Disconnect();
129 LOG_INFO(
"Exit successfully");
133 vtkSmartPointer<vtkImageViewer2>
viewer = vtkSmartPointer<vtkImageViewer2>::New();
135 viewer->SetColorWindow(255);
136 viewer->SetColorLevel(100.5);
137 viewer->SetSize(1024, 768);
139 viewer->SetInputConnection(frameGrabber->GetOutputPort());
142 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
143 iren->SetRenderWindow(
viewer->GetRenderWindow());
149 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
152 iren->AddObserver(vtkCommand::TimerEvent, call);
153 iren->CreateTimer(VTKI_TIMER_FIRST);
159 LOG_INFO(
"Exit successfully");
167 if (eid == vtkCommand::GetEventIdFromString(
"WarningEvent"))
169 LOG_WARNING((
const char*)calldata);
171 else if (eid == vtkCommand::GetEventIdFromString(
"ErrorEvent"))
173 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)