PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusRfProcessor.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4 See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #include "PlusConfigure.h"
8 #include "PlusMath.h"
9 #include "vtkPlusRfProcessor.h"
10 #include "vtkObjectFactory.h"
14 #include "vtkImageData.h"
15 
16 //----------------------------------------------------------------------------
18 //----------------------------------------------------------------------------
19 const char* vtkPlusRfProcessor::RF_PROCESSOR_TAG_NAME = "RfProcessing";
20 //----------------------------------------------------------------------------
21 
22 //----------------------------------------------------------------------------
24 {
26  this->ScanConverter=NULL;
27 }
28 
29 //----------------------------------------------------------------------------
31 {
32  SetScanConverter(NULL);
33  this->RfToBrightnessConverter->Delete();
34  this->RfToBrightnessConverter=NULL;
35 }
36 
37 //----------------------------------------------------------------------------
38 void vtkPlusRfProcessor::PrintSelf(ostream& os, vtkIndent indent)
39 {
40  this->Superclass::PrintSelf(os,indent);
41 }
42 
43 //-----------------------------------------------------------------------------
44 PlusStatus vtkPlusRfProcessor::SetRfFrame(vtkImageData* rfFrame, US_IMAGE_TYPE imageType)
45 {
46  this->RfToBrightnessConverter->SetInputData(rfFrame);
47  this->RfToBrightnessConverter->SetImageType(imageType);
48  return PLUS_SUCCESS;
49 }
50 
51 //-----------------------------------------------------------------------------
53 {
54  this->RfToBrightnessConverter->Update();
55  return this->RfToBrightnessConverter->GetOutput();
56 }
57 
58 //-----------------------------------------------------------------------------
60 {
61  if (this->ScanConverter==NULL)
62  {
63  LOG_ERROR("Scan converter is not defined, skipping scan conversion");
65  }
66  this->ScanConverter->Update();
67  return this->ScanConverter->GetOutput();
68 }
69 
70 //-----------------------------------------------------------------------------
72 {
73  if (scanConverter==this->ScanConverter)
74  {
75  return;
76  }
77  if (this->ScanConverter!=NULL)
78  {
79  this->ScanConverter->UnRegister(this);
80  this->ScanConverter=NULL;
81  }
82  this->ScanConverter=scanConverter;
83  if (scanConverter!=NULL)
84  {
85  this->ScanConverter->Register(this);
86  this->ScanConverter->SetInputConnection(this->RfToBrightnessConverter->GetOutputPort());
87  }
88 }
89 
90 //-----------------------------------------------------------------------------
91 PlusStatus vtkPlusRfProcessor::ReadConfiguration(vtkXMLDataElement* rfProcessingElement)
92 {
93  XML_VERIFY_ELEMENT(rfProcessingElement, "RfProcessing");
94 
95  PlusStatus status=PLUS_SUCCESS;
96 
97  vtkXMLDataElement* brightnessConversionElement = rfProcessingElement->FindNestedElementWithName("RfToBrightnessConversion");
98  if (brightnessConversionElement)
99  {
100  if (this->RfToBrightnessConverter->ReadConfiguration(brightnessConversionElement)!=PLUS_SUCCESS)
101  {
102  status=PLUS_FAIL;
103  }
104  }
105 
106  // Create a UsScanConversion object of the subclass that corresponds to the TransducerGeometry element
107  vtkXMLDataElement* scanConversionElement = rfProcessingElement->FindNestedElementWithName("ScanConversion");
108  if (scanConversionElement != NULL)
109  {
110  const char* transducerGeometryStr = scanConversionElement->GetAttribute("TransducerGeometry");
111  if ( transducerGeometryStr != NULL)
112  {
113  if (this->ScanConverter!=NULL && STRCASECMP(transducerGeometryStr, this->ScanConverter->GetTransducerGeometry())==0)
114  {
115  // we already have a scan converter object of the correct type
116  }
117  else
118  {
119  // need to create a new scan converter object
120  vtkSmartPointer<vtkPlusUsScanConvertLinear> scanConvertLinear=vtkSmartPointer<vtkPlusUsScanConvertLinear>::New();
121  vtkSmartPointer<vtkPlusUsScanConvertCurvilinear> scanConvertCurvilinear=vtkSmartPointer<vtkPlusUsScanConvertCurvilinear>::New();
122  if (STRCASECMP(transducerGeometryStr, scanConvertLinear->GetTransducerGeometry())==0)
123  {
124  SetScanConverter(scanConvertLinear);
125  }
126  else if (STRCASECMP(transducerGeometryStr, scanConvertCurvilinear->GetTransducerGeometry())==0)
127  {
128  SetScanConverter(scanConvertCurvilinear);
129  }
130  else
131  {
132  LOG_ERROR("Failed to create scan converter for geometry: "<<transducerGeometryStr);
133  SetScanConverter(NULL);
134  status=PLUS_FAIL;
135  }
136  }
137  if (this->ScanConverter != NULL && this->ScanConverter->ReadConfiguration(scanConversionElement)!=PLUS_SUCCESS)
138  {
139  status=PLUS_FAIL;
140  }
141  }
142  else
143  {
144  LOG_ERROR("TransducerGeometry attribute of scan conversion is missing, no scan conversion will be performed");
145  SetScanConverter(NULL);
146  status=PLUS_FAIL;
147  }
148  }
149  else
150  {
151  LOG_WARNING("ScanConversion element is missing, no scan conversion will be performed");
152  SetScanConverter(NULL);
153  }
154 
155  return status;
156 }
157 
158 //-----------------------------------------------------------------------------
160 {
161  // RfProcessing = rfElement
162  // - BrightnessConversion
163  // - ScanConversion
164 
165  XML_VERIFY_ELEMENT(rfElement, "RfProcessing");
166  XML_FIND_NESTED_ELEMENT_CREATE_IF_MISSING(brightnessConversionElement, rfElement, "RfToBrightnessConversion");
167  XML_FIND_NESTED_ELEMENT_CREATE_IF_MISSING(scanConversionElement, rfElement, "ScanConversion");
168 
169  PlusStatus status(PLUS_SUCCESS);
170 
171  if ( this->RfToBrightnessConverter->WriteConfiguration(brightnessConversionElement) != PLUS_SUCCESS )
172  {
173  status = PLUS_FAIL;
174  }
175 
176  if (this->ScanConverter != NULL)
177  {
178  if ( this->ScanConverter->WriteConfiguration(scanConversionElement) != PLUS_SUCCESS)
179  {
180  status = PLUS_FAIL;
181  }
182  }
183  else
184  {
185  scanConversionElement->SetAttribute("TransducerGeometry", "UNKNOWN");
186  LOG_ERROR("Unknown transducer geometry");
187  status = PLUS_FAIL;
188  }
189 
190  return status;
191 }
192 
193 //-----------------------------------------------------------------------------
195 {
197 }
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *rfElement)
vtkPlusRfToBrightnessConvert * RfToBrightnessConverter
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *scanConversionElement)
virtual void SetScanConverter(vtkPlusUsScanConvert *scanConverter)
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *rfToBrightnessElement)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *rfElement)
virtual vtkImageData * GetBrightnessScanConvertedImage()
#define PLUS_FAIL
Definition: PlusCommon.h:43
static vtkPlusRfToBrightnessConvert * New()
virtual PlusStatus SetRfFrame(vtkImageData *rfFrame, US_IMAGE_TYPE imageType)
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
vtkStandardNewMacro(vtkPlusRfProcessor)
virtual void SetImageType(US_IMAGE_TYPE)
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *rfToBrightnessElement)
Convenience class to combine multiple algorithms to compute a displayable B-mode frame from RF data.
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual const char * GetTransducerGeometry()=0
static const char * GetRfProcessorTagName()
static const char * RF_PROCESSOR_TAG_NAME
This is a base class for defining a common scan conversion algorithm interface for all kinds of probe...
virtual vtkImageData * GetOutput()=0
virtual vtkImageData * GetBrightnessConvertedImage()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *scanConversionElement)
vtkPlusUsScanConvert * ScanConverter