PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusUsScanConvert.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 
9 #include "vtkPlusUsScanConvert.h"
10 
11 #include "vtkObjectFactory.h"
12 
13 
14 //----------------------------------------------------------------------------
16 {
17  this->TransducerName = NULL;
18  this->InputImageExtent[0] = 0;
19  this->InputImageExtent[1] = -1;
20  this->InputImageExtent[2] = 0;
21  this->InputImageExtent[3] = -1;
22  this->InputImageExtent[4] = 0; // not used
23  this->InputImageExtent[5] = -1; // not used
24  this->OutputImageExtent[0] = 0;
25  this->OutputImageExtent[1] = 599;
26  this->OutputImageExtent[2] = 0;
27  this->OutputImageExtent[3] = 799;
28  this->OutputImageExtent[4] = 0; // not used
29  this->OutputImageExtent[5] = 0; // not used
30  this->OutputImageSpacing[0] = 0.2;
31  this->OutputImageSpacing[1] = 0.2;
32  this->OutputImageSpacing[2] = 1.0; // not used
33  this->TransducerCenterPixelSpecified = false;
34  this->TransducerCenterPixel[0] = 0;
35  this->TransducerCenterPixel[1] = 0;
36 }
37 
38 //----------------------------------------------------------------------------
40 {
41  SetTransducerName(NULL);
42 }
43 
44 void vtkPlusUsScanConvert::PrintSelf(ostream& os, vtkIndent indent)
45 {
46  this->Superclass::PrintSelf(os, indent);
47  os << indent << "TransducerName: (" << (this->TransducerName == NULL ? "" : this->TransducerName) << "\n";
48  os << indent << "OutputImageExtent: ("
49  << this->OutputImageExtent[0] << ", " << this->OutputImageExtent[1] << ", "
50  << this->OutputImageExtent[2] << ", " << this->OutputImageExtent[3] << ")\n";
51  os << indent << "OutputImageSpacing: (" << this->OutputImageSpacing[0] << ", " << this->OutputImageSpacing[1] << ")\n";
52 }
53 
54 //-----------------------------------------------------------------------------
55 PlusStatus vtkPlusUsScanConvert::ReadConfiguration(vtkXMLDataElement* scanConversionElement)
56 {
57  LOG_TRACE("vtkPlusUsScanConvert::ReadConfiguration");
58  XML_VERIFY_ELEMENT(scanConversionElement, "ScanConversion");
59 
60  const char* transducerGeometry = scanConversionElement->GetAttribute("TransducerGeometry");
61  if (transducerGeometry == NULL)
62  {
63  LOG_ERROR("Cannot read vtkPlusUsScanConvert configuration: TransducerGeometry is unknown");
64  return PLUS_FAIL;
65  }
66  if (STRCASECMP(transducerGeometry, this->GetTransducerGeometry()) != 0)
67  {
68  LOG_ERROR("Cannot read vtkPlusUsScanConvert configuration: TransducerGeometry is expected to be " << this->GetTransducerGeometry()
69  << ", but found " << transducerGeometry << " instead");
70  return PLUS_FAIL;
71  }
72 
73  XML_READ_CSTRING_ATTRIBUTE_OPTIONAL(TransducerName, scanConversionElement);
74 
75  double outputImageSpacing[2] = {0};
76  if (scanConversionElement->GetVectorAttribute("OutputImageSpacingMmPerPixel", 2, outputImageSpacing))
77  {
78  this->OutputImageSpacing[0] = outputImageSpacing[0];
79  this->OutputImageSpacing[1] = outputImageSpacing[1];
80  this->OutputImageSpacing[2] = 1;
81  }
82 
83  int outputImageSize[2] = {0};
84  if (scanConversionElement->GetVectorAttribute("OutputImageSizePixel", 2, outputImageSize))
85  {
86  this->OutputImageExtent[0] = 0;
87  this->OutputImageExtent[1] = outputImageSize[0] - 1;
88  this->OutputImageExtent[2] = 0;
89  this->OutputImageExtent[3] = outputImageSize[1] - 1;
90  this->OutputImageExtent[4] = 0;
91  this->OutputImageExtent[5] = 0;
92  }
93 
94  double transducerCenterPixel[2] = {0};
95  if (scanConversionElement->GetVectorAttribute("TransducerCenterPixel", 2, transducerCenterPixel))
96  {
97  this->TransducerCenterPixelSpecified = true;
98  this->TransducerCenterPixel[0] = transducerCenterPixel[0];
99  this->TransducerCenterPixel[1] = transducerCenterPixel[1];
100  }
101 
102  return PLUS_SUCCESS;
103 }
104 
105 //-----------------------------------------------------------------------------
106 PlusStatus vtkPlusUsScanConvert::WriteConfiguration(vtkXMLDataElement* scanConversionElement)
107 {
108  LOG_TRACE("vtkPlusUsScanConvert::WriteConfiguration");
109 
110  XML_VERIFY_ELEMENT(scanConversionElement, "ScanConversion");
111 
112  scanConversionElement->SetAttribute("TransducerGeometry", GetTransducerGeometry());
113  scanConversionElement->SetAttribute("TransducerName", this->TransducerName);
114  scanConversionElement->SetVectorAttribute("OutputImageSpacingMmPerPixel", 2, this->OutputImageSpacing);
115 
116  int outputImageSize[2] =
117  {
118  this->OutputImageExtent[1] - this->OutputImageExtent[0] + 1,
119  this->OutputImageExtent[3] - this->OutputImageExtent[2] + 1
120  };
121  scanConversionElement->SetVectorAttribute("OutputImageSizePixel", 2, outputImageSize);
122 
124  {
125  scanConversionElement->SetVectorAttribute("TransducerCenterPixel", 2, this->TransducerCenterPixel);
126  }
127 
128  return PLUS_SUCCESS;
129 }
130 
131 //-----------------------------------------------------------------------------
133 {
134  FrameSizeType frameSize = {static_cast<unsigned int>(this->OutputImageExtent[1] - this->OutputImageExtent[0] + 1),
135  static_cast<unsigned int>(this->OutputImageExtent[3] - this->OutputImageExtent[2] + 1),
136  static_cast<unsigned int>(this->OutputImageExtent[5] - this->OutputImageExtent[4] + 1)
137  };
138  return frameSize;
139 }
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *scanConversionElement)
igsioStatus PlusStatus
Definition: PlusCommon.h:40
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
#define PLUS_FAIL
Definition: PlusCommon.h:43
#define PLUS_SUCCESS
Definition: PlusCommon.h:44
virtual const char * GetTransducerGeometry()=0
virtual void SetTransducerName(const char *)
virtual FrameSizeType GetOutputImageSizePixel()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *scanConversionElement)