18 #include "PlusConfigure.h" 19 #include "vtkCallbackCommand.h" 20 #include "vtkChartXY.h" 21 #include "vtkCommand.h" 22 #include "vtkContextScene.h" 23 #include "vtkContextView.h" 24 #include "vtkFloatArray.h" 25 #include "vtkImageData.h" 26 #include "vtkImageViewer.h" 27 #include "vtkInformation.h" 28 #include "vtkInformationVector.h" 31 #include "vtkRenderWindow.h" 32 #include "vtkRenderWindowInteractor.h" 33 #include "vtkRenderer.h" 34 #include "vtkSmartPointer.h" 37 #include "vtkTableAlgorithm.h" 39 #include "vtkXMLUtilities.h" 40 #include "vtksys/CommandLineArguments.hxx" 47 class vtkExtractImageRow :
public vtkTableAlgorithm
50 static vtkExtractImageRow* New();
51 vtkTypeMacro(vtkExtractImageRow,vtkTableAlgorithm);
52 void PrintSelf(ostream& os, vtkIndent indent)
54 this->Superclass::PrintSelf(os, indent);
59 int FillInputPortInformation(
int port, vtkInformation* info)
63 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
72 this->SetNumberOfInputPorts(1);
74 virtual ~vtkExtractImageRow()
78 int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector)
80 vtkImageData* inputImage = vtkImageData::GetData(inputVector[0]);
81 vtkInformation* outInfo = outputVector->GetInformationObject(0);
82 vtkTable* outputTable = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
86 LOG_ERROR(
"No input image is available");
91 if (outputTable->GetColumnByName(
"time")==NULL)
93 vtkSmartPointer<vtkFloatArray> arrXnew = vtkSmartPointer<vtkFloatArray>::New();
94 arrXnew->SetName(
"time");
95 outputTable->AddColumn(arrXnew);
97 if (outputTable->GetColumnByName(
"RF value")==NULL)
99 vtkSmartPointer<vtkFloatArray> arrRfValNew = vtkSmartPointer<vtkFloatArray>::New();
100 arrRfValNew->SetName(
"RF value");
101 outputTable->AddColumn(arrRfValNew);
104 int rowCount=inputImage->GetDimensions()[1];
105 int numPoints=inputImage->GetDimensions()[0];
106 int selectedRow=rowCount/2;
108 outputTable->SetNumberOfRows(numPoints);
109 if (inputImage->GetScalarType()==VTK_SHORT)
111 short* pixelBuffer=reinterpret_cast<short*>(inputImage->GetScalarPointer())+selectedRow*numPoints;
112 for (
int i = 0;
i < numPoints; ++
i)
114 outputTable->SetValue(
i, 0,
i);
115 outputTable->SetValue(
i, 1, *(pixelBuffer++));
118 else if (inputImage->GetScalarType()==VTK_UNSIGNED_CHAR)
120 unsigned char* pixelBuffer=reinterpret_cast<unsigned char*>(inputImage->GetScalarPointer())+selectedRow*numPoints;
121 for (
int i = 0;
i < numPoints; ++
i)
123 outputTable->SetValue(
i, 0,
i);
124 outputTable->SetValue(
i, 1, *(pixelBuffer++));
129 LOG_ERROR(
"Plotting is only supported for unsigned char and signed short data");
137 vtkExtractImageRow(
const vtkExtractImageRow&);
138 void operator=(
const vtkExtractImageRow&);
145 class vtkMyPlotCallback :
public vtkCommand
148 static vtkMyPlotCallback *New() {
return new vtkMyPlotCallback; }
150 virtual void Execute(vtkObject *caller,
unsigned long eventId,
void* callData)
152 if (eventId==vtkCommand::KeyPressEvent)
154 if (m_Interactor->GetKeyCode()==
'q')
156 m_Interactor->ExitCallback();
161 m_ImageToTableAdaptor->Update();
164 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
167 vtkRenderWindowInteractor *m_Interactor;
168 vtkContextView *m_Viewer;
169 vtkExtractImageRow *m_ImageToTableAdaptor;
177 m_ImageToTableAdaptor=NULL;
185 vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
186 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
187 view->GetRenderWindow()->SetSize(400, 300);
188 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
189 view->GetScene()->AddItem(chart);
191 vtkSmartPointer<vtkExtractImageRow> imageToTableAdaptor=vtkSmartPointer<vtkExtractImageRow>::New();
192 imageToTableAdaptor->SetInputConnection(
sonixGrabber->GetOutputPort());
193 imageToTableAdaptor->Update();
196 vtkPlot *
line = chart->AddPlot(vtkChart::LINE);
197 line->SetInputData(imageToTableAdaptor->GetOutput(), 0, 1);
198 line->SetColor(0, 255, 0, 255);
201 vtkSmartPointer<vtkMyPlotCallback> call = vtkSmartPointer<vtkMyPlotCallback>::New();
202 call->m_Interactor=view->GetInteractor();
204 call->m_ImageToTableAdaptor=imageToTableAdaptor;
206 view->GetInteractor()->Initialize();
208 view->GetInteractor()->AddObserver(vtkCommand::TimerEvent, call);
209 view->GetInteractor()->CreateTimer(VTKI_TIMER_FIRST);
211 view->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, call);
213 view->GetInteractor()->Start();
219 class vtkMyCallback :
public vtkCommand
222 static vtkMyCallback *New() {
return new vtkMyCallback; }
224 virtual void Execute(vtkObject *caller,
unsigned long,
void*)
229 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
232 vtkRenderWindowInteractor *m_Interactor;
233 vtkImageViewer *m_Viewer;
246 int main(
int argc,
char* argv[])
248 bool printHelp(
false);
249 bool renderingOff(
false);
250 bool renderingAsPlot(
false);
251 bool printParams(
false);
252 std::string inputConfigFileName;
253 std::string inputSonixIp;
255 vtksys::CommandLineArguments args;
256 args.Initialize(argc, argv);
258 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
260 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
261 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
262 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).");
263 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
264 args.AddArgument(
"--rendering-as-plot", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingAsPlot,
"Show the result as a line plot of the values in middle row (recommended for RF output). If not set then acquired data is displayed as a grayscale image.");
265 args.AddArgument(
"--print-params", vtksys::CommandLineArguments::NO_ARGUMENT, &printParams,
"Print all the supported imaging parameters (for diagnostic purposes only).");
266 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
270 std::cerr <<
"Problem parsing arguments" << std::endl;
271 std::cout <<
"\n\nvtkPlusSonixVideoSourceTest1 help:" << args.GetHelp() << std::endl;
279 std::cout <<
"\n\nvtkPlusSonixVideoSourceTest1 help:" << args.GetHelp() << std::endl;
284 LOG_DEBUG(
"Reading config file...");
285 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
288 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
292 vtkSmartPointer<vtkPlusSonixVideoSource>
sonixGrabber = vtkSmartPointer<vtkPlusSonixVideoSource>::New();
296 if (!inputSonixIp.empty())
303 LOG_ERROR(
"Unable to connect to Sonix RP machine at: " <<
sonixGrabber->GetSonixIP() );
309 LOG_INFO(
"List of supported imaging parameters:");
318 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
330 std::string firstChannelName;
331 std::string allChannelNames;
332 int numberOfVideoOutputChannels=0;
335 if ((*it)->HasVideoSource())
337 if (numberOfVideoOutputChannels==0)
340 firstChannelName = (*it)->GetChannelId();
341 allChannelNames = (*it)->GetChannelId();
345 allChannelNames += std::string(
", ") + (*it)->GetChannelId();
347 numberOfVideoOutputChannels++;
350 if (numberOfVideoOutputChannels>1)
352 LOG_WARNING(
"Multiple output channels contain video data: "<<allChannelNames<<
". Only the first one ("<<firstChannelName<<
") will be displayed");
364 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
366 viewer->SetColorWindow(255);
367 viewer->SetColorLevel(127.5);
371 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
372 iren->SetRenderWindow(
viewer->GetRenderWindow());
378 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
379 call->m_Interactor=
iren;
381 iren->AddObserver(vtkCommand::TimerEvent, call);
382 iren->CreateTimer(VTKI_TIMER_FIRST);
vtkStandardNewMacro(vtkExtractImageRow)
int main(int argc, char *argv[])
vtkRenderWindowInteractor * iren
vtkSmartPointer< vtkPlusSonixVideoSource > sonixGrabber
void TestLinePlot(vtkPlusSonixVideoSource *sonixGrabber)
VTK interface for video input from Ultrasonix machine.
static vtkIGSIOLogger * Instance()
ChannelContainer::iterator ChannelContainerIterator
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)