18 #include "PlusConfigure.h" 19 #include "vtkCallbackCommand.h" 20 #include "vtkCommand.h" 22 #include "vtkContextScene.h" 23 #include "vtkContextView.h" 24 #include "vtkFloatArray.h" 26 #include "vtkImageData.h" 27 #include "vtkImageViewer.h" 29 #include "vtkInformation.h" 30 #include "vtkInformationVector.h" 31 #include "vtkRenderWindow.h" 32 #include "vtkRenderWindowInteractor.h" 33 #include "vtkRenderer.h" 34 #include "vtkSmartPointer.h" 37 #include "igtlOSUtil.h" 39 #include "vtkXMLUtilities.h" 40 #include "vtksys/CommandLineArguments.hxx" 43 class vtkMyCallback :
public vtkCommand
46 static vtkMyCallback* New()
48 return new vtkMyCallback;
51 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
56 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
59 vtkRenderWindowInteractor* m_Interactor;
60 vtkImageViewer* m_Viewer;
72 int main(
int argc,
char* argv[])
76 int startX_01 = left < 0 ? 0 : left;
78 int startX_02 = left < 0 ? 0 : left;
80 bool printHelp(
false);
81 bool renderingOff(
false);
83 std::string inputConfigFileName;
84 std::string outputFileName(
"AndorCameraTest.mha");
85 std::string flatCorrectionPath;
86 std::string biasDarkCorrectionPath;
88 vtksys::CommandLineArguments args;
89 args.Initialize(argc, argv);
91 int verboseLevel = vtkPlusLogger::LOG_LEVEL_INFO;
93 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
94 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
95 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
96 args.AddArgument(
"--output-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputFileName,
"Filename of the output video buffer sequence metafile (Default: AndorCameraTest.mha)");
97 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
98 args.AddArgument(
"--flat-correction-image", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &flatCorrectionPath,
"Image file (.png) containing the flat field correction.");
99 args.AddArgument(
"--bias-correction-image", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &biasDarkCorrectionPath,
"Image file (.png) containing the combined bias+dark and dark correction.");
103 std::cerr <<
"Problem parsing arguments" << std::endl;
104 std::cout <<
"\n\nvtkPlusAndorVideoSourceTest1 help:" << args.GetHelp() << std::endl;
113 std::cout <<
"\n\nvtkPlusAndorVideoSourceTest help:" << args.GetHelp() << std::endl;
118 vtkSmartPointer< vtkPlusAndorVideoSource > andorCamDevice = vtkSmartPointer< vtkPlusAndorVideoSource >::New();
119 andorCamDevice->SetDeviceId(
"BLICamera");
123 LOG_DEBUG(
"Reading config file...");
124 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
128 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
132 andorCamDevice->ReadConfiguration(configRootElement);
136 LOG_ERROR(
"Unable to connect to Andor camera");
140 LOG_INFO(andorCamDevice->GetSdkVersion());
142 andorCamDevice->PrintSelf(std::cout, indent);
144 andorCamDevice->PrepareAcquisition();
145 andorCamDevice->StartBLIFrameAcquisition(-1, -1, -1, 2.0);
146 andorCamDevice->WaitForAcquisitionWithTimeout(100.0);
147 andorCamDevice->StartGrayscaleFrameAcquisition(-1, -1, -1, 2.0);
148 andorCamDevice->WaitForAcquisitionWithTimeout(100.0);
149 andorCamDevice->StartRecording();
154 if(andorCamDevice->GetOutputChannelByName(raw,
"BLIRawStream") !=
PLUS_SUCCESS)
156 LOG_ERROR(
"Unable to locate the channel with Id=\"BLIRawStream\". Check config file.");
161 if(andorCamDevice->GetOutputChannelByName(rectified,
"BLICorrectedStream") !=
PLUS_SUCCESS)
163 LOG_WARNING(
"Unable to locate the channel with Id=\"BLICorrectedStream\". Additional mode will not be used.");
166 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
167 andorCamDevice->StartBLIFrameAcquisition(-1, -1, -1, 2.0);
168 andorCamDevice->WaitForAcquisitionWithTimeout(100.0);
169 andorCamDevice->StartGrayscaleFrameAcquisition(-1, -1, -1, 2.0);
170 andorCamDevice->WaitForAcquisitionWithTimeout(100.0);
171 andorCamDevice->StartBLIFrameAcquisition(-1, -1, -1, 2.0);
172 andorCamDevice->WaitForAcquisitionWithTimeout(100.0);
173 andorCamDevice->StartGrayscaleFrameAcquisition(-1, -1, -1, 2.0);
174 andorCamDevice->WaitForAcquisitionWithTimeout(100.0);
191 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
192 viewer->SetInputConnection(andorCamDevice->GetOutputPort());
193 viewer->SetColorWindow(256);
194 viewer->SetColorLevel(400);
196 viewer->SetSize(1024, 1024);
199 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
200 iren->SetRenderWindow(
viewer->GetRenderWindow());
206 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
207 call->m_Interactor =
iren;
209 iren->AddObserver(vtkCommand::TimerEvent, call);
210 iren->CreateTimer(VTKI_TIMER_FIRST);
217 andorCamDevice->Disconnect();
220 andorCamDevice->WriteConfiguration(configRootElement);
221 std::string outConfigFilename = inputConfigFileName +
"-updated.xml";
222 bool success = vtkXMLUtilities::WriteElementToFile(configRootElement, outConfigFilename.c_str());
225 LOG_ERROR(
"Unable to write configuration to: " << outConfigFilename +
".xml");
229 LOG_INFO(
"Configuration file written to: " << outConfigFilename +
".xml");
virtual PlusStatus WriteToSequenceFile(const char *filename, bool useCompression=false)
vtkRenderWindowInteractor * iren
static vtkIGSIOLogger * Instance()
int main(int argc, char *argv[])
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
PlusStatus GetVideoSource(vtkPlusDataSource *&aVideoSource) const
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Interface to a 3D positioning tool, video source, or generalized data stream.