18 #include "PlusConfigure.h" 20 #include "vtkCallbackCommand.h" 21 #include "vtkChartXY.h" 22 #include "vtkCommand.h" 23 #include "vtkContextScene.h" 24 #include "vtkContextView.h" 25 #include "vtkFloatArray.h" 26 #include "vtkImageData.h" 27 #include "vtkImageViewer.h" 28 #include "vtkInformation.h" 29 #include "vtkInformationVector.h" 31 #include "vtkRenderWindow.h" 32 #include "vtkRenderWindowInteractor.h" 33 #include "vtkRenderer.h" 34 #include "vtkSmartPointer.h" 37 #include "vtkTableAlgorithm.h" 38 #include "vtkXMLUtilities.h" 39 #include "vtksys/CommandLineArguments.hxx" 52 class vtkExtractImageRow :
public vtkTableAlgorithm
55 static vtkExtractImageRow* New();
56 vtkTypeMacro(vtkExtractImageRow,vtkTableAlgorithm);
57 void PrintSelf(ostream& os, vtkIndent indent)
59 this->Superclass::PrintSelf(os, indent);
64 int FillInputPortInformation(
int port, vtkInformation* info)
68 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
77 this->SetNumberOfInputPorts(1);
79 virtual ~vtkExtractImageRow()
83 int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector)
85 vtkImageData* inputImage = vtkImageData::GetData(inputVector[0]);
86 vtkInformation* outInfo = outputVector->GetInformationObject(0);
87 vtkTable* outputTable = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
91 LOG_ERROR(
"No input image is available");
96 if (outputTable->GetColumnByName(
"time")==NULL)
98 vtkSmartPointer<vtkFloatArray> arrXnew = vtkSmartPointer<vtkFloatArray>::New();
99 arrXnew->SetName(
"time");
100 outputTable->AddColumn(arrXnew);
102 if (outputTable->GetColumnByName(
"RF value")==NULL)
104 vtkSmartPointer<vtkFloatArray> arrRfValNew = vtkSmartPointer<vtkFloatArray>::New();
105 arrRfValNew->SetName(
"RF value");
106 outputTable->AddColumn(arrRfValNew);
109 if (inputImage->GetScalarType() != VTK_SHORT)
111 LOG_ERROR(
"Plotting is only supported for signed short data");
114 int rowCount=inputImage->GetDimensions()[1];
115 int numPoints=inputImage->GetDimensions()[0];
116 int selectedRow=rowCount/2;
117 short* pixelBuffer=reinterpret_cast<short*>(inputImage->GetScalarPointer())+selectedRow*numPoints;
119 outputTable->SetNumberOfRows(numPoints);
120 int timeIndex=numPoints-1;
121 for (
int i = 0;
i < numPoints; ++
i)
123 outputTable->SetValue(
i, 0, timeIndex);
124 short value=*pixelBuffer;
125 outputTable->SetValue(
i, 1,
value);
134 vtkExtractImageRow(
const vtkExtractImageRow&);
135 void operator=(
const vtkExtractImageRow&);
142 class vtkMyPlotCallback :
public vtkCommand
145 static vtkMyPlotCallback *New() {
return new vtkMyPlotCallback; }
147 virtual void Execute(vtkObject *caller,
unsigned long eventId,
void* callData)
149 if (eventId==vtkCommand::KeyPressEvent)
151 if (m_Interactor->GetKeyCode()==
'q')
153 m_Interactor->ExitCallback();
158 m_ImageToTableAdaptor->Update();
161 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
164 vtkRenderWindowInteractor *m_Interactor;
165 vtkContextView *m_Viewer;
166 vtkExtractImageRow *m_ImageToTableAdaptor;
174 m_ImageToTableAdaptor=NULL;
182 vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
183 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
184 view->GetRenderWindow()->SetSize(1200, 400);
185 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
186 view->GetScene()->AddItem(chart);
188 vtkSmartPointer<vtkExtractImageRow> imageToTableAdaptor=vtkSmartPointer<vtkExtractImageRow>::New();
189 imageToTableAdaptor->SetInputConnection(intersonDevice->GetOutputPort());
190 imageToTableAdaptor->Update();
193 vtkPlot *
line = chart->AddPlot(vtkChart::LINE);
194 line->SetInputData(imageToTableAdaptor->GetOutput(), 0, 1);
195 line->SetColor(0, 255, 0, 255);
198 vtkAxis * yAxis =
line->GetYAxis();
199 yAxis->SetBehavior(vtkAxis::FIXED);
200 yAxis->SetMinimumLimit( -32768 );
201 yAxis->SetMaximumLimit( 32767 );
202 yAxis->SetMinimum( -32768 );
203 yAxis->SetMaximum( 32767 );
205 vtkSmartPointer<vtkMyPlotCallback> call = vtkSmartPointer<vtkMyPlotCallback>::New();
206 call->m_Interactor=view->GetInteractor();
208 call->m_ImageToTableAdaptor=imageToTableAdaptor;
210 view->GetInteractor()->Initialize();
212 view->GetInteractor()->AddObserver(vtkCommand::TimerEvent, call);
213 view->GetInteractor()->CreateTimer(VTKI_TIMER_FIRST);
215 view->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, call);
217 view->GetInteractor()->Start();
223 class vtkMyCallback :
public vtkCommand
226 static vtkMyCallback *New() {
return new vtkMyCallback; }
228 virtual void Execute(vtkObject *caller,
unsigned long,
void*)
233 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
236 vtkRenderWindowInteractor *m_Interactor;
237 vtkImageViewer *m_Viewer;
250 int main(
int argc,
char* argv[])
252 bool printHelp(
false);
253 bool renderingOff(
false);
254 std::string inputConfigFileName;
256 double dynRangeDb = -1;
257 double frequencyMhz = -1;
259 std::string acqMode(
"B");
261 vtksys::CommandLineArguments args;
262 args.Initialize(argc, argv);
264 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
266 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
267 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
268 args.AddArgument(
"--acq-mode", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &acqMode,
"Acquisition mode: B or RF (Default: B).");
269 args.AddArgument(
"--depth", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &depthCm,
"Depth in cm.");
270 args.AddArgument(
"--frequencyMhz", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &frequencyMhz,
"Frequency in MHz");
271 args.AddArgument(
"--dynRangeDb", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &dynRangeDb,
"BMode Dynamic Range. 1 corresponds to the maximum dynamic range.");
272 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
273 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
277 std::cerr <<
"Problem parsing arguments" << std::endl;
278 std::cout <<
"\n\nvtkPlusIntersonSDKCxxVideoSourceTest help:" << args.GetHelp() << std::endl;
286 std::cout <<
"\n\nvtkPlusIntersonSDKCxxVideoSourceTest help:" << args.GetHelp() << std::endl;
290 vtkSmartPointer<vtkPlusIntersonSDKCxxVideoSource> intersonDevice =
291 vtkSmartPointer<vtkPlusIntersonSDKCxxVideoSource>::New();
292 intersonDevice->SetDeviceId(
"VideoDevice");
295 if( STRCASECMP(inputConfigFileName.c_str(),
"") != 0 )
297 LOG_DEBUG(
"Reading config file...");
298 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
301 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
304 intersonDevice->ReadConfiguration(configRootElement);
309 if (STRCASECMP(acqMode.c_str(),
"B")==0)
311 LOG_DEBUG(
"Acquisition mode: B");
314 else if (STRCASECMP(acqMode.c_str(),
"RF")==0)
316 LOG_DEBUG(
"Acquisition mode: RF");
321 LOG_ERROR(
"Unsupported Acquisition mode requested: " << acqMode);
327 LOG_ERROR(
"Unable to connect to Interson Probe" );
331 intersonDevice->StartRecording();
336 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
348 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
349 viewer->SetInputConnection(intersonDevice->GetOutputPort());
350 viewer->SetColorWindow(255);
351 viewer->SetColorLevel(127.5);
355 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
356 iren->SetRenderWindow(
viewer->GetRenderWindow());
362 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
363 call->m_Interactor=
iren;
365 iren->AddObserver(vtkCommand::TimerEvent, call);
366 iren->CreateTimer(VTKI_TIMER_FIRST);
374 intersonDevice->StopRecording();
375 intersonDevice->Disconnect();
int main(int argc, char *argv[])
vtkRenderWindowInteractor * iren
Class for acquiring ultrasound images from Interson USB ultrasound systems with C++ Wrapped SDK.
void TestLinePlot(vtkPlusIntersonSDKCxxVideoSource *intersonDevice)
const char const char * value
static vtkIGSIOLogger * Instance()
vtkStandardNewMacro(vtkExtractImageRow)
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)