18 #include "PlusConfigure.h" 22 #include "vtkCallbackCommand.h" 24 #include "vtkChartXY.h" 26 #include "vtkCommand.h" 28 #include "vtkContextScene.h" 29 #include "vtkContextView.h" 30 #include "vtkFloatArray.h" 32 #include "vtkImageData.h" 33 #include "vtkImageViewer.h" 35 #include "vtkInformation.h" 37 #include "vtkInformationVector.h" 39 #include "vtkRenderWindow.h" 40 #include "vtkRenderWindowInteractor.h" 41 #include "vtkRenderer.h" 42 #include "vtkSmartPointer.h" 47 #include "vtkTableAlgorithm.h" 49 #include "vtkXMLUtilities.h" 50 #include "vtksys/CommandLineArguments.hxx" 63 class vtkExtractImageRow :
public vtkTableAlgorithm
66 static vtkExtractImageRow* New();
67 vtkTypeMacro(vtkExtractImageRow, vtkTableAlgorithm);
68 void PrintSelf(ostream& os, vtkIndent indent)
70 this->Superclass::PrintSelf(os, indent);
75 int FillInputPortInformation(
int port, vtkInformation* info)
79 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),
"vtkImageData");
88 this->SetNumberOfInputPorts(1);
90 virtual ~vtkExtractImageRow()
94 int RequestData(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector, vtkInformationVector* outputVector)
96 vtkImageData* inputImage = vtkImageData::GetData(inputVector[0]);
97 vtkInformation* outInfo = outputVector->GetInformationObject(0);
98 vtkTable* outputTable = vtkTable::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
102 LOG_ERROR(
"No input image is available");
107 if (outputTable->GetColumnByName(
"time") == NULL)
109 vtkSmartPointer<vtkFloatArray> arrXnew = vtkSmartPointer<vtkFloatArray>::New();
110 arrXnew->SetName(
"time");
111 outputTable->AddColumn(arrXnew);
113 if (outputTable->GetColumnByName(
"RF value") == NULL)
115 vtkSmartPointer<vtkFloatArray> arrRfValNew = vtkSmartPointer<vtkFloatArray>::New();
116 arrRfValNew->SetName(
"RF value");
117 outputTable->AddColumn(arrRfValNew);
120 if (inputImage->GetScalarType() != VTK_SHORT)
122 LOG_ERROR(
"Plotting is only supported for signed short data");
125 int rowCount = inputImage->GetDimensions()[1];
126 int numPoints = inputImage->GetDimensions()[0];
127 int selectedRow = rowCount / 2;
128 short* pixelBuffer = reinterpret_cast<short*>(inputImage->GetScalarPointer()) + selectedRow * numPoints;
130 outputTable->SetNumberOfRows(numPoints);
131 int timeIndex = numPoints - 1;
132 for (
int i = 0;
i < numPoints; ++
i)
134 outputTable->SetValue(
i, 0, timeIndex);
135 short value = *pixelBuffer;
136 outputTable->SetValue(
i, 1,
value);
145 vtkExtractImageRow(
const vtkExtractImageRow&);
146 void operator=(
const vtkExtractImageRow&);
154 class vtkMyPlotCallback :
public vtkCommand
157 static vtkMyPlotCallback* New()
159 return new vtkMyPlotCallback;
162 virtual void Execute(vtkObject* caller,
unsigned long eventId,
void* callData)
164 if (eventId == vtkCommand::KeyPressEvent)
166 if (m_Interactor->GetKeyCode() ==
'q')
168 m_Interactor->ExitCallback();
173 m_ImageToTableAdaptor->Update();
176 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
179 vtkRenderWindowInteractor* m_Interactor;
180 vtkContextView* m_Viewer;
181 vtkExtractImageRow* m_ImageToTableAdaptor;
189 m_ImageToTableAdaptor = NULL;
195 class vtkMyCallback :
public vtkCommand
198 static vtkMyCallback* New()
200 return new vtkMyCallback;
203 virtual void Execute(vtkObject* caller,
unsigned long,
void*)
208 m_Interactor->CreateTimer(VTKI_TIMER_UPDATE);
211 vtkRenderWindowInteractor* m_Interactor;
212 vtkImageViewer* m_Viewer;
225 int main(
int argc,
char* argv[])
229 int startX_01 = left < 0 ? 0 : left;
231 int startX_02 = left < 0 ? 0 : left;
233 bool printHelp(
false);
234 bool renderingOff(
false);
236 bool printParams(
false);
238 std::string inputConfigFileName;
239 std::string outputFileName(
"CapistranoTest.mha");
242 double dynRangeDb = -1;
244 double frequencyMhz = -1;
247 std::string acqMode(
"B");
249 vtksys::CommandLineArguments args;
250 args.Initialize(argc, argv);
252 int verboseLevel = vtkPlusLogger::LOG_LEVEL_UNDEFINED;
254 args.AddArgument(
"--help", vtksys::CommandLineArguments::NO_ARGUMENT, &printHelp,
"Print this help.");
255 args.AddArgument(
"--config-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &inputConfigFileName,
"Config file containing the device configuration.");
257 args.AddArgument(
"--acq-mode", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &acqMode,
"Acquisition mode: B or RF (Default: B).");
258 args.AddArgument(
"--depth", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &depthCm,
"Depth in cm.");
260 args.AddArgument(
"--frequencyMhz", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &frequencyMhz,
"Frequency in MHz");
262 args.AddArgument(
"--dynRangeDb", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &dynRangeDb,
"BMode Dynamic Range. 1 corresponds to the maximum dynamic range.");
264 args.AddArgument(
"--rendering-off", vtksys::CommandLineArguments::NO_ARGUMENT, &renderingOff,
"Run test without rendering.");
265 args.AddArgument(
"--output-seq-file", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &outputFileName,
"Filename of the output video buffer sequence metafile (Default: CapistranoTest.mha)");
266 args.AddArgument(
"--print-params", vtksys::CommandLineArguments::NO_ARGUMENT, &printParams,
"Print all the supported imaging parameters (for diagnostic purposes only).");
267 args.AddArgument(
"--verbose", vtksys::CommandLineArguments::EQUAL_ARGUMENT, &verboseLevel,
"Verbose level 1=error only, 2=warning, 3=info, 4=debug, 5=trace)");
271 std::cerr <<
"Problem parsing arguments" << std::endl;
272 std::cout <<
"\n\nvtkPlusCapistranoVideoSourceTest1 help:" << args.GetHelp() << std::endl;
281 std::cout <<
"\n\nvtkPlusCapistranoVideoSourceTest help:" << args.GetHelp() << std::endl;
286 vtkSmartPointer< vtkPlusCapistranoVideoSource > capistranoDevice =
287 vtkSmartPointer< vtkPlusCapistranoVideoSource >::New();
288 capistranoDevice->SetDeviceId(
"VideoDevice");
294 if (STRCASECMP(inputConfigFileName.c_str(),
"") != 0)
296 LOG_DEBUG(
"Reading config file...");
297 vtkSmartPointer<vtkXMLDataElement> configRootElement = vtkSmartPointer<vtkXMLDataElement>::New();
301 LOG_ERROR(
"Unable to read configuration from file " << inputConfigFileName.c_str());
305 capistranoDevice->ReadConfiguration(configRootElement);
307 capistranoDevice->PrintSelf(std::cout, indent);
312 if (STRCASECMP(acqMode.c_str(),
"B") == 0)
314 LOG_DEBUG(
"Acquisition mode: B");
319 LOG_ERROR(
"Unsupported Acquisition mode requested: " << acqMode);
326 LOG_ERROR(
"Unable to connect to Capistrano Probe");
330 LOG_INFO(
"SDK version: " << capistranoDevice->GetSdkVersion());
333 #if defined(CAPISTRANO_SDK2023) || defined(CAPISTRANO_SDK2019_3) || defined(CAPISTRANO_SDK2019_2) || defined(CAPISTRANO_SDK2019) || defined(CAPISTRANO_SDK2018) 334 capistranoDevice->GetHardwareVersion(retval);
335 LOG_INFO(
"Hardware version: " << retval);
340 LOG_INFO(
"List of supported imaging parameters:");
345 capistranoDevice->StartRecording();
350 LOG_DEBUG(
"Rendering disabled. Wait for just a few seconds to acquire data before exiting");
352 capistranoDevice->StopRecording();
353 capistranoDevice->Disconnect();
355 capistranoDevice->GetVideoSource(
"Video",
source);
356 source->WriteToSequenceFile(outputFileName.c_str());
362 vtkSmartPointer<vtkImageViewer>
viewer = vtkSmartPointer<vtkImageViewer>::New();
363 viewer->SetInputConnection(capistranoDevice->GetOutputPort());
364 viewer->SetColorWindow(255);
365 viewer->SetColorLevel(127.5);
369 vtkSmartPointer<vtkRenderWindowInteractor>
iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
370 iren->SetRenderWindow(
viewer->GetRenderWindow());
376 vtkSmartPointer<vtkMyCallback> call = vtkSmartPointer<vtkMyCallback>::New();
377 call->m_Interactor =
iren;
379 iren->AddObserver(vtkCommand::TimerEvent, call);
380 iren->CreateTimer(VTKI_TIMER_FIRST);
387 capistranoDevice->Disconnect();
int main(int argc, char *argv[])
vtkStandardNewMacro(vtkExtractImageRow)
vtkRenderWindowInteractor * iren
const char const char * value
static vtkIGSIOLogger * Instance()
static PlusStatus ReadDeviceSetConfigurationFromFile(vtkXMLDataElement *config, const char *filename)
Interface to a 3D positioning tool, video source, or generalized data stream.