12 #include "PlusConfigure.h" 15 #include "vtkCallbackCommand.h" 16 #include "vtkChartXY.h" 17 #include "vtkCommand.h" 18 #include "vtkContextScene.h" 19 #include "vtkContextView.h" 20 #include "vtkFloatArray.h" 21 #include "vtkImageData.h" 22 #include "vtkImageViewer.h" 23 #include "vtkInformation.h" 24 #include "vtkInformationVector.h" 26 #include "vtkRenderWindow.h" 27 #include "vtkRenderWindowInteractor.h" 28 #include "vtkRenderer.h" 29 #include "vtkSmartPointer.h" 31 #include "vtkTableAlgorithm.h" 32 #include "vtkXMLUtilities.h" 33 #include "vtksys/CommandLineArguments.hxx" 46 class vtkExtractImageRow :
public vtkTableAlgorithm
49 static vtkExtractImageRow* New();
50 vtkTypeMacro(vtkExtractImageRow, vtkTableAlgorithm);
51 void PrintSelf(ostream& os, vtkIndent indent)
53 this->Superclass::PrintSelf(os, indent);
58 int FillInputPortInformation(
int port, vtkInformation* info)
62 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
71 this->SetNumberOfInputPorts(1);
73 virtual ~vtkExtractImageRow()
77 int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector)
79 vtkImageData* inputImage = vtkImageData::GetData(inputVector[0]);
80 vtkInformation* outInfo = outputVector->GetInformationObject(0);
81 vtkTable* outputTable = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
85 LOG_ERROR(
"No input image is available");
90 if (outputTable->GetColumnByName(
"time") == NULL)
92 vtkSmartPointer<vtkFloatArray> arrXnew = vtkSmartPointer<vtkFloatArray>::New();
93 arrXnew->SetName(
"time");
94 outputTable->AddColumn(arrXnew);
96 if (outputTable->GetColumnByName(
"RF value") == NULL)
98 vtkSmartPointer<vtkFloatArray> arrRfValNew = vtkSmartPointer<vtkFloatArray>::New();
99 arrRfValNew->SetName(
"RF value");
100 outputTable->AddColumn(arrRfValNew);
103 if (inputImage->GetScalarType() != VTK_SHORT)
105 LOG_ERROR(
"Plotting is only supported for signed short data");
108 int rowCount = inputImage->GetDimensions()[1];
109 int numPoints = inputImage->GetDimensions()[0];
110 int selectedRow = rowCount / 2;
111 short* pixelBuffer = reinterpret_cast<short*>(inputImage->GetScalarPointer()) + selectedRow * numPoints;
113 outputTable->SetNumberOfRows(numPoints);
114 int timeIndex = numPoints - 1;
115 for (
int i = 0;
i < numPoints; ++
i)
117 outputTable->SetValue(
i, 0, timeIndex);
118 short value = *pixelBuffer;
119 outputTable->SetValue(
i, 1,
value);
128 vtkExtractImageRow(
const vtkExtractImageRow&);
129 void operator=(
const vtkExtractImageRow&);
136 class vtkMyPlotCallback :
public vtkCommand
139 static vtkMyPlotCallback *New() {
return new vtkMyPlotCallback; }
141 virtual void Execute(vtkObject *caller,
unsigned long eventId,
void* callData)
143 if (eventId == vtkCommand::KeyPressEvent)
145 if (m_Interactor->GetKeyCode() ==
'q')
147 m_Interactor->ExitCallback();
152 m_ImageToTableAdaptor->Update();
155 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
158 vtkRenderWindowInteractor *m_Interactor;
159 vtkContextView *m_Viewer;
160 vtkExtractImageRow *m_ImageToTableAdaptor;
168 m_ImageToTableAdaptor = NULL;
176 vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
177 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
178 view->GetRenderWindow()->SetSize(640, 480);
179 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
180 view->GetScene()->AddItem(chart);
182 vtkSmartPointer<vtkExtractImageRow> imageToTableAdaptor = vtkSmartPointer<vtkExtractImageRow>::New();
183 imageToTableAdaptor->SetInputConnection(ClariusDevice->GetOutputPort());
184 imageToTableAdaptor->Update();
187 vtkPlot *
line = chart->AddPlot(vtkChart::LINE);
188 line->SetInputData(imageToTableAdaptor->GetOutput(), 0, 1);
189 line->SetColor(0, 255, 0, 255);
192 vtkSmartPointer<vtkMyPlotCallback> call = vtkSmartPointer<vtkMyPlotCallback>::New();
193 call->m_Interactor = view->GetInteractor();
194 call->m_Viewer = view;
195 call->m_ImageToTableAdaptor = imageToTableAdaptor;
197 view->GetInteractor()->Initialize();
199 view->GetInteractor()->AddObserver(vtkCommand::TimerEvent, call);
200 view->GetInteractor()->CreateTimer(VTKI_TIMER_FIRST);
202 view->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, call);
204 view->GetInteractor()->Start();
210 class vtkMyCallback :
public vtkCommand
213 static vtkMyCallback *New() {
return new vtkMyCallback; }
215 virtual void Execute(vtkObject *caller,
unsigned long,
void*)
220 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
223 vtkRenderWindowInteractor *m_Interactor;
224 vtkImageViewer *m_Viewer;
237 int main(
int argc,
char* argv[])
239 bool printHelp(
false);
241 bool printParams(
true);
242 std::string inputConfigFile =
"Testing/PlusDeviceSet_DataCollectionOnly_Clarius.xml";
244 std::string acqMode(
"B");
246 vtksys::CommandLineArguments args;
247 args.Initialize(argc, argv);
249 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
251 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
252 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFile,
"Config file containing the device configuration.");
253 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
257 std::cerr <<
"Problem parsing arguments" << std::endl;
258 std::cout <<
"\n\nvtkPlusSonixVideoSourceTest1 help:" << args.GetHelp() << std::endl;
265 vtkSmartPointer<vtkPlusClarius> ClariusDevice = vtkSmartPointer<vtkPlusClarius>::New();
266 ClariusDevice->SetDeviceId(
"VideoDevice");
269 if (STRCASECMP(inputConfigFile.c_str(),
"") != 0)
271 LOG_DEBUG(
"Reading config file...");
272 vtkSmartPointer<vtkXMLDataElement> configRead = vtkSmartPointer<vtkXMLDataElement>::Take(::vtkXMLUtilities::ReadElementFromFile(inputConfigFile.c_str()));
273 LOG_DEBUG(
"Reading config file finished.");
274 if (configRead != NULL)
276 ClariusDevice->ReadConfiguration(configRead);
280 ClariusDevice->CreateDefaultOutputChannel(NULL,
true);
282 if (ClariusDevice->GetFirstActiveOutputVideoSource(videoSource) !=
PLUS_SUCCESS)
284 LOG_ERROR(
"Unable to retrieve the video source.");
292 if (STRCASECMP(acqMode.c_str(),
"B") == 0)
294 LOG_DEBUG(
"Acquisition mode: B");
301 LOG_ERROR(
"Unsupported AcquisitionDataType requested: " << acqMode);
307 LOG_ERROR(
"Unable to connect to Telemed device");
313 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
314 viewer->SetInputConnection(ClariusDevice->GetOutputPort());
315 viewer->SetColorWindow(255);
316 viewer->SetColorLevel(127.5);
320 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
321 iren->SetRenderWindow(
viewer->GetRenderWindow());
327 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
328 call->m_Interactor =
iren;
330 iren->AddObserver(vtkCommand::TimerEvent, call);
331 iren->CreateTimer(VTKI_TIMER_FIRST);
339 ClariusDevice->Disconnect();
vtkStandardNewMacro(vtkExtractImageRow)
vtkRenderWindowInteractor * iren
void TestLinePlot(vtkPlusClarius *ClariusDevice)
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
int main(int argc, char *argv[])
const char const char * value
static vtkIGSIOLogger * Instance()
Interface to the Clarius ultrasound scans This class talks with a Clarius Scanner over the Clarius AP...
Interface to a 3D positioning tool, video source, or generalized data stream.