13 #include "PlusConfigure.h" 14 #include "vtkCallbackCommand.h" 15 #include "vtkCommand.h" 16 #include "vtkImageViewer.h" 19 #include "vtkRenderWindowInteractor.h" 20 #include "vtkSmartPointer.h" 23 #include "vtksys/CommandLineArguments.hxx" 34 #include "vtkRenderer.h" 35 #include "vtkRenderWindow.h" 36 #include "vtkChartXY.h" 39 #include "vtkFloatArray.h" 40 #include "vtkContextView.h" 41 #include "vtkContextScene.h" 42 #include "vtkTableAlgorithm.h" 43 #include "vtkInformation.h" 44 #include "vtkInformationVector.h" 45 #include "vtkImageData.h" 50 class vtkExtractImageRow :
public vtkTableAlgorithm
53 static vtkExtractImageRow* New();
54 vtkTypeMacro(vtkExtractImageRow,vtkTableAlgorithm);
55 void PrintSelf(ostream& os, vtkIndent indent)
57 this->Superclass::PrintSelf(os, indent);
62 int FillInputPortInformation(
int port, vtkInformation* info)
66 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
75 this->SetNumberOfInputPorts(1);
77 virtual ~vtkExtractImageRow()
81 int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector)
83 vtkImageData* inputImage = vtkImageData::GetData(inputVector[0]);
84 vtkInformation* outInfo = outputVector->GetInformationObject(0);
85 vtkTable* outputTable = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
89 LOG_ERROR(
"No input image is available");
94 if (outputTable->GetColumnByName(
"time")==NULL)
96 vtkSmartPointer<vtkFloatArray> arrXnew = vtkSmartPointer<vtkFloatArray>::New();
97 arrXnew->SetName(
"time");
98 outputTable->AddColumn(arrXnew);
100 if (outputTable->GetColumnByName(
"RF value")==NULL)
102 vtkSmartPointer<vtkFloatArray> arrRfValNew = vtkSmartPointer<vtkFloatArray>::New();
103 arrRfValNew->SetName(
"RF value");
104 outputTable->AddColumn(arrRfValNew);
107 if (inputImage->GetScalarType()!=VTK_SHORT)
109 LOG_ERROR(
"Plotting is only supported for signed short data");
112 int rowCount=inputImage->GetDimensions()[1];
113 int numPoints=inputImage->GetDimensions()[0];
114 int selectedRow=rowCount/2;
115 short* pixelBuffer=reinterpret_cast<short*>(inputImage->GetScalarPointer())+selectedRow*numPoints;
117 outputTable->SetNumberOfRows(numPoints);
118 int timeIndex=numPoints-1;
119 for (
int i = 0;
i < numPoints; ++
i)
121 outputTable->SetValue(
i, 0, timeIndex);
122 short value=*pixelBuffer;
123 outputTable->SetValue(
i, 1,
value);
132 vtkExtractImageRow(
const vtkExtractImageRow&);
133 void operator=(
const vtkExtractImageRow&);
140 class vtkMyPlotCallback :
public vtkCommand
143 static vtkMyPlotCallback *New() {
return new vtkMyPlotCallback; }
145 virtual void Execute(vtkObject *caller,
unsigned long eventId,
void* callData)
147 if (eventId==vtkCommand::KeyPressEvent)
149 if (m_Interactor->GetKeyCode()==
'q')
151 m_Interactor->ExitCallback();
156 m_ImageToTableAdaptor->Update();
159 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
162 vtkRenderWindowInteractor *m_Interactor;
163 vtkContextView *m_Viewer;
164 vtkExtractImageRow *m_ImageToTableAdaptor;
172 m_ImageToTableAdaptor=NULL;
180 vtkSmartPointer<vtkContextView> view = vtkSmartPointer<vtkContextView>::New();
181 view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
182 view->GetRenderWindow()->SetSize(400, 300);
183 vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
184 view->GetScene()->AddItem(chart);
186 vtkSmartPointer<vtkExtractImageRow> imageToTableAdaptor=vtkSmartPointer<vtkExtractImageRow>::New();
187 imageToTableAdaptor->SetInputConnection(portaGrabber->GetOutputPort());
188 imageToTableAdaptor->Update();
191 vtkPlot *
line = chart->AddPlot(vtkChart::LINE);
192 line->SetInputData(imageToTableAdaptor->GetOutput(), 0, 1);
193 line->SetColor(0, 255, 0, 255);
196 vtkSmartPointer<vtkMyPlotCallback> call = vtkSmartPointer<vtkMyPlotCallback>::New();
197 call->m_Interactor=view->GetInteractor();
199 call->m_ImageToTableAdaptor=imageToTableAdaptor;
201 view->GetInteractor()->Initialize();
203 view->GetInteractor()->AddObserver(vtkCommand::TimerEvent, call);
204 view->GetInteractor()->CreateTimer(VTKI_TIMER_FIRST);
206 view->GetInteractor()->AddObserver(vtkCommand::KeyPressEvent, call);
208 view->GetInteractor()->Start();
214 class vtkMyCallback :
public vtkCommand
217 static vtkMyCallback *New() {
return new vtkMyCallback; }
219 virtual void Execute(vtkObject *caller,
unsigned long,
void*)
224 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
227 vtkRenderWindowInteractor *m_Interactor;
228 vtkImageViewer *m_Viewer;
241 int main(
int argc,
char* argv[])
243 std::string LUTPath(
"C:/luts");
244 std::string PortaSettingPath(
"D:/devel/pltools/Ultrasonix/sdk-5.6.4/porta/dat/");
245 std::string LicensePath(
"D:/Ultrasonix Settings/licenses.txt");
246 std::string PortaFirmwarePath(
"D:/devel/pltools/Ultrasonix/sdk-5.6.4/porta/fw/");
247 int stepPerFrame = 16;
248 int FramePerVolume = 20;
249 bool renderingOff(
false);
252 vtksys::CommandLineArguments args;
253 args.Initialize(argc, argv);
255 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
257 args.AddArgument(
"--setting-path", vtksys::CommandLineArguments::NO_ARGUMENT, &PortaSettingPath,
"Setting path.");
258 args.AddArgument(
"--lut-path", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &LUTPath,
"LUT Path." );
259 args.AddArgument(
"--firmware-path", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &PortaFirmwarePath,
"Firmware path.");
260 args.AddArgument(
"--license-path", vtksys::CommandLineArguments::NO_ARGUMENT, &LicensePath,
"License path.");
261 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
265 std::cerr <<
"Problem parsing arguments" << std::endl;
266 std::cout <<
"\n\nvtkPlusSonixPortaVideoSourceTest help:" << args.GetHelp() << std::endl;
272 vtkSmartPointer<vtkPlusSonixPortaVideoSource> portaGrabber = vtkSmartPointer<vtkPlusSonixPortaVideoSource>::New();
274 portaGrabber->SetStepPerFrame(stepPerFrame);
275 portaGrabber->SetFramePerVolume(FramePerVolume);
276 portaGrabber->SetPortaLUTPath(LUTPath.c_str());
277 portaGrabber->SetPortaFirmwarePath(PortaFirmwarePath.c_str());
278 portaGrabber->SetPortaLicensePath(LicensePath.c_str());
279 portaGrabber->SetPortaSettingPath(PortaSettingPath.c_str());
283 LOG_DEBUG(
"Acquisition mode: B");
287 portaGrabber->CreateDefaultOutputChannel();
289 if (portaGrabber->GetFirstActiveOutputVideoSource(aSource) !=
PLUS_SUCCESS )
291 LOG_ERROR(
"Unable to retrieve the video source.");
298 LOG_ERROR(
"Unable to connect to Porta" );
302 portaGrabber->StartRecording();
307 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
309 portaGrabber->StopRecording();
310 portaGrabber->Disconnect();
317 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
318 viewer->SetInputConnection(portaGrabber->GetOutputPort(0));
319 viewer->SetColorWindow(255);
320 viewer->SetColorLevel(127.5);
324 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
325 iren->SetRenderWindow(
viewer->GetRenderWindow());
331 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
332 call->m_Interactor=
iren;
334 iren->AddObserver(vtkCommand::TimerEvent, call);
335 iren->CreateTimer(VTKI_TIMER_FIRST);
343 portaGrabber->Disconnect();
vtkRenderWindowInteractor * iren
virtual PlusStatus SetInputImageOrientation(US_IMAGE_ORIENTATION imageOrientation)
int main(int argc, char *argv[])
Class providing VTK video input interface for SonixRP.
void TestLinePlot(vtkPlusSonixPortaVideoSource *portaGrabber)
const char const char * value
static vtkIGSIOLogger * Instance()
vtkStandardNewMacro(vtkExtractImageRow)
Interface to a 3D positioning tool, video source, or generalized data stream.