17 #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" 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(TelemedDevice->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(
true);
247 std::string inputConfigFile;
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, &inputConfigFile,
"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\nvtkPlusTelemedVideoSourceTest help:" << args.GetHelp() << std::endl;
286 vtkSmartPointer<vtkPlusTelemedVideoSource> TelemedDevice = vtkSmartPointer<vtkPlusTelemedVideoSource>::New();
287 TelemedDevice->SetDeviceId(
"VideoDevice");
290 if (STRCASECMP(inputConfigFile.c_str(),
"")!=0)
292 LOG_DEBUG(
"Reading config file...");
293 vtkSmartPointer<vtkXMLDataElement> configRead = vtkSmartPointer<vtkXMLDataElement>::Take(::vtkXMLUtilities::ReadElementFromFile(inputConfigFile.c_str()));
294 LOG_DEBUG(
"Reading config file finished.");
295 if ( configRead != NULL )
297 TelemedDevice->ReadConfiguration(configRead);
305 if(gainPercent != -1)
307 TelemedDevice->SetGainPercent(gainPercent);
309 if(frequencyMhz != -1)
314 TelemedDevice->CreateDefaultOutputChannel(NULL,
true);
317 if (TelemedDevice->GetFirstActiveOutputVideoSource(videoSource) !=
PLUS_SUCCESS )
319 LOG_ERROR(
"Unable to retrieve the video source.");
327 if (STRCASECMP(acqMode.c_str(),
"B")==0)
329 LOG_DEBUG(
"Acquisition mode: B");
342 LOG_ERROR(
"Unsupported AcquisitionDataType requested: "<<acqMode);
348 LOG_ERROR(
"Unable to connect to Telemed device");
352 TelemedDevice->StartRecording();
357 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
359 TelemedDevice->StopRecording();
360 TelemedDevice->Disconnect();
372 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
373 viewer->SetInputConnection(TelemedDevice->GetOutputPort());
374 viewer->SetColorWindow(255);
375 viewer->SetColorLevel(127.5);
379 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
380 iren->SetRenderWindow(
viewer->GetRenderWindow());
386 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
387 call->m_Interactor=
iren;
389 iren->AddObserver(vtkCommand::TimerEvent, call);
390 iren->CreateTimer(VTKI_TIMER_FIRST);
398 TelemedDevice->Disconnect();
vtkRenderWindowInteractor * iren
void TestLinePlot(vtkPlusTelemedVideoSource *TelemedDevice)
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
vtkStandardNewMacro(vtkExtractImageRow)
const char const char * value
static vtkIGSIOLogger * Instance()
int main(int argc, char *argv[])
Class for interfacing the device manager class, and the PLUS library. The devices are Telemed ultraso...
Interface to a 3D positioning tool, video source, or generalized data stream.