13 #include "PlusConfigure.h" 20 #ifdef PLUS_USE_ULTRASONIX_VIDEO 25 #include <vtkCallbackCommand.h> 26 #include <vtkCommand.h> 27 #include <vtkImageData.h> 28 #ifdef PLUS_RENDERING_ENABLED 29 #include <vtkImageViewer.h> 31 #include <vtkMatrix4x4.h> 32 #include <vtkRenderWindowInteractor.h> 33 #include <vtkRenderer.h> 34 #include <vtkSmartPointer.h> 35 #include <vtkTextActor.h> 36 #include <vtkTextProperty.h> 37 #include <vtkXMLUtilities.h> 38 #include <vtksys/CommandLineArguments.hxx> 40 class vtkMyCallback :
public vtkCommand
43 static vtkMyCallback* New()
45 return new vtkMyCallback;
48 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
50 vtkSmartPointer<vtkMatrix4x4> tFrame2Tracker = vtkSmartPointer<vtkMatrix4x4>::New();
52 igsioTrackedFrame trackedFrame;
53 if (this->BroadcastChannel->GetTrackedFrame(trackedFrame) !=
PLUS_SUCCESS)
55 LOG_WARNING(
"Unable to get tracked frame!");
59 if (trackedFrame.GetImageData()->IsImageValid())
62 if (trackedFrame.GetImageData()->GetImageType() == US_IMG_BRIGHTNESS || trackedFrame.GetImageData()->GetImageType() == US_IMG_RGB_COLOR)
65 this->ImageData->DeepCopy(trackedFrame.GetImageData()->GetImage());
70 RfProcessor->SetRfFrame(trackedFrame.GetImageData()->GetImage(), trackedFrame.GetImageData()->GetImageType());
71 this->ImageData->ShallowCopy(RfProcessor->GetBrightnessScanConvertedImage());
73 #ifdef PLUS_RENDERING_ENABLED 74 this->Viewer->SetInputData(this->ImageData);
75 this->Viewer->Modified();
79 if (TransformName.IsValid())
81 std::ostringstream ss;
83 ToolStatus status(TOOL_INVALID);
84 if (trackedFrame.GetFrameTransformStatus(TransformName, status) ==
PLUS_SUCCESS && status == TOOL_OK)
86 trackedFrame.GetFrameTransform(TransformName, tFrame2Tracker);
88 << tFrame2Tracker->GetElement(0, 0) <<
" " << tFrame2Tracker->GetElement(0, 1) <<
" " << tFrame2Tracker->GetElement(0, 2) <<
" " << tFrame2Tracker->GetElement(0, 3) <<
"\n" 89 << tFrame2Tracker->GetElement(1, 0) <<
" " << tFrame2Tracker->GetElement(1, 1) <<
" " << tFrame2Tracker->GetElement(1, 2) <<
" " << tFrame2Tracker->GetElement(1, 3) <<
"\n" 90 << tFrame2Tracker->GetElement(2, 0) <<
" " << tFrame2Tracker->GetElement(2, 1) <<
" " << tFrame2Tracker->GetElement(2, 2) <<
" " << tFrame2Tracker->GetElement(2, 3) <<
"\n" 91 << tFrame2Tracker->GetElement(3, 0) <<
" " << tFrame2Tracker->GetElement(3, 1) <<
" " << tFrame2Tracker->GetElement(3, 2) <<
" " << tFrame2Tracker->GetElement(3, 3) <<
"\n";
95 std::string strTransformName;
96 TransformName.GetTransformName(strTransformName);
97 ss <<
"Transform '" << strTransformName <<
"' is invalid ...";
99 this->StepperTextActor->SetInput(ss.str().c_str());
100 this->StepperTextActor->Modified();
103 #ifdef PLUS_RENDERING_ENABLED 104 this->Viewer->Render();
107 this->RenderWindowInteractor->CreateTimer(VTKI_TIMER_UPDATE);
113 #ifdef PLUS_RENDERING_ENABLED 114 vtkImageViewer* Viewer;
116 vtkRenderWindowInteractor* RenderWindowInteractor;
117 vtkTextActor* StepperTextActor;
118 igsioTransformName TransformName;
119 vtkImageData* ImageData;
123 int main(
int argc,
char** argv)
125 std::string inputConfigFileName;
126 bool renderingOff(
false);
127 std::string inputVideoBufferMetafile;
128 std::string inputTrackerBufferMetafile;
129 std::string inputTransformName;
130 bool inputRepeat(
false);
131 std::string inputSonixIp;
133 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
135 vtksys::CommandLineArguments args;
136 args.Initialize(argc, argv);
138 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Name of the input configuration file.");
139 #ifdef PLUS_USE_ULTRASONIX_VIDEO 140 args.AddArgument(
"--sonix-ip", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputSonixIp,
"IP address of the Ultrasonix scanner (overrides the IP address parameter defined in the config file; only applicable if VideoDevice is SonixVideo).");
142 args.AddArgument(
"--video-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputVideoBufferMetafile,
"Video buffer sequence metafile.");
143 args.AddArgument(
"--tracker-buffer-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTrackerBufferMetafile,
"Tracker buffer sequence metafile.");
144 args.AddArgument(
"--transform", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputTransformName,
"Name of the transform displayed.");
146 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
147 args.AddArgument(
"--repeat", vtksys::CommandLineArguments::NO_ARGUMENT, &inputRepeat,
"Repeat tracked frames after reached the latest one.");
148 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level (1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
152 std::cerr <<
"Problem parsing arguments" << std::endl;
153 std::cout <<
"Help: " << args.GetHelp() << std::endl;
159 if (inputConfigFileName.empty())
161 std::cerr <<
"input-config-file-name is required" << std::endl;
167 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
170 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
176 vtkSmartPointer<vtkPlusDataCollector> dataCollector = vtkSmartPointer<vtkPlusDataCollector>::New();
178 if (dataCollector->ReadConfiguration(configRootElement) !=
PLUS_SUCCESS)
180 LOG_ERROR(
"Configuration incorrect for vtkPlusDataCollectorTest1.");
186 if (! inputVideoBufferMetafile.empty())
188 if (dataCollector->GetDevice(videoDevice,
"VideoDevice") !=
PLUS_SUCCESS)
190 LOG_ERROR(
"Unable to locate the device with Id=\"VideoDevice\". Check config file.");
194 if (videoSource == NULL)
196 LOG_ERROR(
"Unable to cast video source to vtkPlusSavedDataSource.");
202 #ifdef PLUS_USE_ULTRASONIX_VIDEO 203 else if (!inputSonixIp.empty())
205 if (dataCollector->GetDevice(videoDevice,
"VideoDevice") !=
PLUS_SUCCESS)
207 LOG_ERROR(
"Unable to locate the device with Id=\"VideoDevice\". Check config file.");
211 if (videoSource == NULL)
213 LOG_ERROR(
"Video source is not SonixVideo. Cannot set IP address.");
216 videoSource->
SetSonixIP(inputSonixIp.c_str());
220 if (! inputTrackerBufferMetafile.empty())
222 if (dataCollector->GetDevice(trackerDevice,
"TrackerDevice") !=
PLUS_SUCCESS)
224 LOG_ERROR(
"Unable to locate the device with Id=\"TrackerDevice\". Check config file.");
230 LOG_ERROR(
"Unable to cast tracker to vtkPlusSavedDataSource");
239 LOG_ERROR(
"Failed to connect to devices!");
245 LOG_ERROR(
"Failed to start data collection!");
251 LOG_DEBUG(
"Rendering is disabled");
255 #ifdef PLUS_RENDERING_ENABLED 256 if (dataCollector->GetDevice(videoDevice,
"TrackedVideoDevice") !=
PLUS_SUCCESS)
258 LOG_ERROR(
"Unable to locate the device with Id=\"TrackedVideoDevice\". Check config file.");
264 LOG_ERROR(
"Unable to locate the channel with Id=\"TrackedVideoStream\". Check config file.");
268 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
269 viewer->SetColorWindow(255);
270 viewer->SetColorLevel(127.5);
272 viewer->SetSize(800, 600);
275 vtkSmartPointer<vtkTextActor> stepperTextActor = vtkSmartPointer<vtkTextActor>::New();
276 vtkSmartPointer<vtkTextProperty> textprop = stepperTextActor->GetTextProperty();
277 textprop->SetColor(1, 0, 0);
278 textprop->SetFontFamilyToArial();
279 textprop->SetFontSize(15);
280 textprop->SetJustificationToLeft();
281 textprop->SetVerticalJustificationToTop();
282 stepperTextActor->VisibilityOn();
283 stepperTextActor->SetDisplayPosition(20, 65);
284 viewer->GetRenderer()->AddActor(stepperTextActor);
287 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
288 iren->SetRenderWindow(
viewer->GetRenderWindow());
294 vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
296 vtkSmartPointer<vtkPlusRfProcessor> rfProc = vtkSmartPointer<vtkPlusRfProcessor>::New();
297 rfProc->ReadConfiguration(configRootElement);
300 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
301 call->DataCollector = dataCollector;
302 call->BroadcastChannel = aChannel;
304 call->RenderWindowInteractor =
iren;
305 call->StepperTextActor = stepperTextActor;
306 call->ImageData = imageData;
307 call->RfProcessor = rfProc;
309 if (!inputTransformName.empty())
311 if (call->TransformName.SetTransformName(inputTransformName.c_str()) !=
PLUS_SUCCESS)
313 LOG_ERROR(
"Transform name '" << inputTransformName <<
"' is invalid!");
318 iren->AddObserver(vtkCommand::TimerEvent, call);
319 iren->CreateTimer(VTKI_TIMER_FIRST);
325 LOG_WARNING(
"Cannot perform rendering when VTK_RENDERING_BACKEND is None!");
329 dataCollector->Disconnect();
331 std::cout <<
"vtkPlusDataCollectorTest1 completed successfully!" << std::endl;
Abstract interface for tracker and video devices.
vtkRenderWindowInteractor * iren
static vtkPlusConfig * GetInstance()
PlusStatus GetOutputChannelByName(vtkPlusChannel *&aChannel, const char *aChannelId)
int main(int argc, char **argv)
Manages devices that record image or positional data.
virtual void SetRepeatEnabled(bool)
VTK interface for video input from Ultrasonix machine.
virtual void SetSequenceFile(const char *)
Convenience class to combine multiple algorithms to compute a displayable B-mode frame from RF data.
Class for providing VTK video input interface from sequence fileAttributes:
static vtkIGSIOLogger * Instance()
Contains an optional timestamped circular buffer containing the video images and a number of timestam...
virtual void SetSonixIP(const char *)
void SetDeviceSetConfigurationData(vtkXMLDataElement *deviceSetConfigurationData)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)