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" 30 #include "vtkRenderWindow.h" 31 #include "vtkRenderWindowInteractor.h" 32 #include "vtkRenderer.h" 33 #include "vtkSmartPointer.h" 36 #include "vtkTableAlgorithm.h" 37 #include "vtkXMLUtilities.h" 38 #include "vtksys/CommandLineArguments.hxx" 51 class vtkExtractImageRow :
public vtkTableAlgorithm
54 static vtkExtractImageRow* New();
55 vtkTypeMacro(vtkExtractImageRow,vtkTableAlgorithm);
56 void PrintSelf(ostream& os, vtkIndent indent)
58 this->Superclass::PrintSelf(os, indent);
63 int FillInputPortInformation(
int port, vtkInformation* info)
67 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
76 this->SetNumberOfInputPorts(1);
78 virtual ~vtkExtractImageRow()
82 int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector)
84 vtkImageData* inputImage = vtkImageData::GetData(inputVector[0]);
85 vtkInformation* outInfo = outputVector->GetInformationObject(0);
86 vtkTable* outputTable = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
90 LOG_ERROR(
"No input image is available");
95 if (outputTable->GetColumnByName(
"time")==NULL)
97 vtkSmartPointer<vtkFloatArray> arrXnew = vtkSmartPointer<vtkFloatArray>::New();
98 arrXnew->SetName(
"time");
99 outputTable->AddColumn(arrXnew);
101 if (outputTable->GetColumnByName(
"RF value")==NULL)
103 vtkSmartPointer<vtkFloatArray> arrRfValNew = vtkSmartPointer<vtkFloatArray>::New();
104 arrRfValNew->SetName(
"RF value");
105 outputTable->AddColumn(arrRfValNew);
108 if (inputImage->GetScalarType()!=VTK_SHORT)
110 LOG_ERROR(
"Plotting is only supported for signed short data");
113 int rowCount=inputImage->GetDimensions()[1];
114 int numPoints=inputImage->GetDimensions()[0];
115 int selectedRow=rowCount/2;
116 short* pixelBuffer=reinterpret_cast<short*>(inputImage->GetScalarPointer())+selectedRow*numPoints;
118 outputTable->SetNumberOfRows(numPoints);
119 int timeIndex=numPoints-1;
120 for (
int i = 0;
i < numPoints; ++
i)
122 outputTable->SetValue(
i, 0, timeIndex);
123 short value=*pixelBuffer;
124 outputTable->SetValue(
i, 1,
value);
133 vtkExtractImageRow(
const vtkExtractImageRow&);
134 void operator=(
const vtkExtractImageRow&);
141 class vtkMyPlotCallback :
public vtkCommand
144 static vtkMyPlotCallback *New() {
return new vtkMyPlotCallback; }
146 virtual void Execute(vtkObject *caller,
unsigned long eventId,
void* callData)
148 if (eventId==vtkCommand::KeyPressEvent)
150 if (m_Interactor->GetKeyCode()==
'q')
152 m_Interactor->ExitCallback();
157 m_ImageToTableAdaptor->Update();
160 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
163 vtkRenderWindowInteractor *m_Interactor;
164 vtkContextView *m_Viewer;
165 vtkExtractImageRow *m_ImageToTableAdaptor;
173 m_ImageToTableAdaptor=NULL;
181 vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
182 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
183 view->GetRenderWindow()->SetSize(400, 300);
184 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
185 view->GetScene()->AddItem(chart);
187 vtkSmartPointer<vtkExtractImageRow> imageToTableAdaptor=vtkSmartPointer<vtkExtractImageRow>::New();
188 imageToTableAdaptor->SetInputConnection(intersonDevice->GetOutputPort());
189 imageToTableAdaptor->Update();
192 vtkPlot *
line = chart->AddPlot(vtkChart::LINE);
193 line->SetInputData(imageToTableAdaptor->GetOutput(), 0, 1);
194 line->SetColor(0, 255, 0, 255);
197 vtkSmartPointer<vtkMyPlotCallback> call = vtkSmartPointer<vtkMyPlotCallback>::New();
198 call->m_Interactor=view->GetInteractor();
200 call->m_ImageToTableAdaptor=imageToTableAdaptor;
202 view->GetInteractor()->Initialize();
204 view->GetInteractor()->AddObserver(vtkCommand::TimerEvent, call);
205 view->GetInteractor()->CreateTimer(VTKI_TIMER_FIRST);
207 view->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, call);
209 view->GetInteractor()->Start();
215 class vtkMyCallback :
public vtkCommand
218 static vtkMyCallback *New() {
return new vtkMyCallback; }
220 virtual void Execute(vtkObject *caller,
unsigned long,
void*)
225 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
228 vtkRenderWindowInteractor *m_Interactor;
229 vtkImageViewer *m_Viewer;
242 int main(
int argc,
char* argv[])
244 bool printHelp(
false);
245 bool renderingOff(
false);
246 bool printParams(
false);
247 std::string inputConfigFileName;
249 double gainPercent = -1;
250 double zoomFactor = -1;
251 double frequencyMhz = -1;
254 std::string acqMode(
"B");
256 vtksys::CommandLineArguments args;
257 args.Initialize(argc, argv);
259 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
261 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
262 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
263 args.AddArgument(
"--depth", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &depthCm,
"Depth in cm.");
264 args.AddArgument(
"--frequencyMhz", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &frequencyMhz,
"Frequency in MHz");
265 args.AddArgument(
"--gain", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &gainPercent,
"Gain in percentage. 100 corresponds to the maximum gain");
266 args.AddArgument(
"--zoomFactor", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &zoomFactor,
"Zoom used to display de US Image");
267 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
268 args.AddArgument(
"--print-params", vtksys::CommandLineArguments::NO_ARGUMENT, &printParams,
"Print all the supported imaging parameters (for diagnostic purposes only).");
269 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
273 std::cerr <<
"Problem parsing arguments" << std::endl;
274 std::cout <<
"\n\nvtkPlusSonixVideoSourceTest1 help:" << args.GetHelp() << std::endl;
282 std::cout <<
"\n\nvtkPlusIntersonVideoSourceTest help:" << args.GetHelp() << std::endl;
286 vtkSmartPointer<vtkPlusIntersonVideoSource> intersonDevice = vtkSmartPointer<vtkPlusIntersonVideoSource>::New();
287 intersonDevice->SetDeviceId(
"VideoDevice");
290 if (STRCASECMP(inputConfigFileName.c_str(),
"")!=0)
292 LOG_DEBUG(
"Reading config file...");
293 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
296 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
299 intersonDevice->ReadConfiguration(configRootElement);
302 intersonDevice->CreateDefaultOutputChannel();
306 if (STRCASECMP(acqMode.c_str(),
"B")==0)
308 LOG_DEBUG(
"Acquisition mode: B");
313 else if (STRCASECMP(acqMode.c_str(),
"RF")==0)
315 LOG_DEBUG(
"Acquisition mode: RF");
322 LOG_ERROR(
"Unsupported AcquisitionDataType requested: "<<acqMode);
336 LOG_INFO(
"List of supported imaging parameters:");
340 intersonDevice->StartRecording();
345 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
347 intersonDevice->StopRecording();
348 intersonDevice->Disconnect();
360 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
361 viewer->SetInputConnection(intersonDevice->GetOutputPort());
362 viewer->SetColorWindow(255);
363 viewer->SetColorLevel(127.5);
367 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
368 iren->SetRenderWindow(
viewer->GetRenderWindow());
374 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
375 call->m_Interactor=
iren;
377 iren->AddObserver(vtkCommand::TimerEvent, call);
378 iren->CreateTimer(VTKI_TIMER_FIRST);
386 intersonDevice->Disconnect();
int main(int argc, char *argv[])
vtkRenderWindowInteractor * iren
void TestLinePlot(vtkPlusIntersonVideoSource *intersonDevice)
vtkStandardNewMacro(vtkExtractImageRow)
const char const char * value
static vtkIGSIOLogger * Instance()
Class for acquiring ultrasound images from Interson USB ultrasound systems.
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)