PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
PlusFidPatternRecognitionCommon.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"
9 #include "vtkMath.h"
10 
11 //-----------------------------------------------------------------------------
13  : DotsFound(false)
14  , Intensity(-1)
15  , NumDots(-1)
16 {
17 }
18 
19 //-----------------------------------------------------------------------------
21 {
22  //atan2 return the angle between the line and the x-axis from -Pi to Pi
23  double angleRad = atan2(line.GetDirectionVector()[1], line.GetDirectionVector()[0]);
24  return angleRad;
25 }
26 
27 //-----------------------------------------------------------------------------
28 double PlusFidLine::ComputeAngleRad(const PlusFidLine& line1, const PlusFidLine& line2)
29 {
30  // a * b = |a| * |b| * cos(alpha)
31  const double* a = line1.GetDirectionVector();
32  const double* b = line2.GetDirectionVector();
33  double angleBetweenLines = acos(a[0] * b[0] + a[1] * b[1] / sqrt(a[0] * a[0] + a[1] * a[1]) / sqrt(b[0] * b[0] + b[1] * b[1]));
34  // Normalize between -pi/2 .. +pi/2
35  if (angleBetweenLines > vtkMath::Pi() / 2)
36  {
37  angleBetweenLines -= vtkMath::Pi();
38  }
39  else if (angleBetweenLines < -vtkMath::Pi() / 2)
40  {
41  angleBetweenLines += vtkMath::Pi();
42  }
43  // Return the absolute value (0..+pi/2)
44  return fabs(angleBetweenLines);
45 }
46 
47 
48 //----------------------------------------------------------------------------
49 void PlusFidLine::SetPoint(int aIndex, int aValue)
50 {
51  Points[aIndex] = aValue;
52 }
53 
54 //----------------------------------------------------------------------------
55 int PlusFidLine::GetPoint(int aIndex) const
56 {
57  return Points[aIndex];
58 }
59 
60 //----------------------------------------------------------------------------
61 unsigned int PlusFidLine::GetNumberOfPoints() const
62 {
63  return Points.size();
64 }
65 
66 //----------------------------------------------------------------------------
68 {
69  Intensity = value;
70 }
71 
72 //----------------------------------------------------------------------------
74 {
75  return Intensity;
76 }
77 
78 //----------------------------------------------------------------------------
80 {
81  Length = value;
82 }
83 
84 //----------------------------------------------------------------------------
85 void PlusFidLine::SetDirectionVector(int aIndex, double aValue)
86 {
87  DirectionVector[aIndex] = aValue;
88 }
89 
90 //----------------------------------------------------------------------------
91 const double* PlusFidLine::GetDirectionVector() const
92 {
93  return DirectionVector;
94 }
95 
96 //----------------------------------------------------------------------------
98 {
99  StartPointIndex = index;
100 }
101 
102 //----------------------------------------------------------------------------
104 {
105  return StartPointIndex;
106 }
107 
108 //----------------------------------------------------------------------------
110 {
111  EndPointIndex = index;
112 }
113 
114 //----------------------------------------------------------------------------
116 {
117  return EndPointIndex;
118 }
119 
120 //----------------------------------------------------------------------------
121 void PlusFidLine::ResizePoints(int aNewSize)
122 {
123  Points.resize(aNewSize);
124 }
125 
126 //----------------------------------------------------------------------------
127 void PlusFidLine::AddPoint(int aPoint)
128 {
129  Points.push_back(aPoint);
130 }
131 
132 //-----------------------------------------------------------------------------
134 {
135  /* Use > to get descending. */
136  return dot1.GetDotIntensity() > dot2.GetDotIntensity();
137 }
138 
139 //-----------------------------------------------------------------------------
140 bool PlusFidDot::PositionLessThan(std::vector<PlusFidDot>::iterator b1, std::vector<PlusFidDot>::iterator b2)
141 {
142  /* Use > to get descending. */
143  return b1->GetX() > b2->GetX();
144 }
145 
146 //----------------------------------------------------------------------------
148 {
149  m_X = value;
150 }
151 
152 //----------------------------------------------------------------------------
153 double PlusFidDot::GetX() const
154 {
155  return m_X;
156 }
157 
158 //----------------------------------------------------------------------------
160 {
161  m_Y = value;
162 }
163 
164 //----------------------------------------------------------------------------
165 double PlusFidDot::GetY() const
166 {
167  return m_Y;
168 }
169 
170 //----------------------------------------------------------------------------
172 {
174 }
175 
176 //----------------------------------------------------------------------------
178 {
179  return m_DotIntensity;
180 }
181 
182 //-----------------------------------------------------------------------------
184 {
185  return sqrt((m_X - d.m_X) * (m_X - d.m_X) + (m_Y - d.m_Y) * (m_Y - d.m_Y));
186 }
187 
188 //----------------------------------------------------------------------------
190 {
191  return (m_X == data.m_X && m_Y == data.m_Y) ;
192 }
193 
194 //-----------------------------------------------------------------------------
195 bool PlusFidLine::lessThan(const PlusFidLine& line1, const PlusFidLine& line2)
196 {
197  /* Use > to get descending. */
198  return line1.GetIntensity() > line2.GetIntensity();
199 }
200 
201 //-----------------------------------------------------------------------------
202 bool PlusFidLine::compareLines(const PlusFidLine& line1, const PlusFidLine& line2)
203 {
204  //make sure the lines are not the same, dot-wise
205  for (unsigned int i = 0; i < line1.GetNumberOfPoints(); i++)
206  {
207  if (line1.GetPoint(i) < line2.GetPoint(i))
208  {
209  return true;
210  }
211  else if (line1.GetPoint(i) > line2.GetPoint(i))
212  {
213  return false;
214  }
215  }
216  return false;
217 }
218 
219 //-----------------------------------------------------------------------------
221 {
222  DotsFound = false;
223  Intensity = -1;
224  FoundDotsCoordinateValue.clear();
225  NumDots = 1;
226  CandidateFidValues.clear();
227 }
228 
229 //----------------------------------------------------------------------------
231 {
232  DotsFound = value;
233 }
234 
235 //----------------------------------------------------------------------------
237 {
238  return DotsFound;
239 }
240 
241 //----------------------------------------------------------------------------
242 void PlusPatternRecognitionResult::SetFoundDotsCoordinateValue(std::vector< std::vector<double> > value)
243 {
245 }
246 
247 //----------------------------------------------------------------------------
249 {
251 }
252 
253 //----------------------------------------------------------------------------
255 {
257 }
258 
259 //----------------------------------------------------------------------------
260 const std::vector<PlusFidDot>& PlusPatternRecognitionResult::GetCandidateFidValues() const
261 {
262  return CandidateFidValues;
263 }
264 
265 //----------------------------------------------------------------------------
267 {
268 
269 }
270 
271 //----------------------------------------------------------------------------
272 const std::vector<PlusFidWire>& PlusFidPattern::GetWires() const
273 {
274  return Wires;
275 }
276 
277 //----------------------------------------------------------------------------
278 const std::vector<double>& PlusFidPattern::GetDistanceToOriginMm() const
279 {
280  return DistanceToOriginMm;
281 }
282 
283 //----------------------------------------------------------------------------
284 const std::vector<double>& PlusFidPattern::GetDistanceToOriginToleranceMm() const
285 {
287 }
288 
289 //----------------------------------------------------------------------------
291 {
292  this->Wires.push_back(wire);
293 }
294 
295 //----------------------------------------------------------------------------
297 {
298  this->DistanceToOriginMm.push_back(aElement);
299 }
300 
301 //----------------------------------------------------------------------------
302 void PlusFidPattern::SetDistanceToOriginElementMm(int index, double aElement)
303 {
304  this->DistanceToOriginMm[index] = aElement;
305 }
306 
307 //----------------------------------------------------------------------------
309 {
310  this->DistanceToOriginToleranceMm.push_back(aElement);
311 }
312 
313 //----------------------------------------------------------------------------
315 {
316  this->DistanceToOriginMm[index] = aElement;
317 }
318 
319 //----------------------------------------------------------------------------
320 void PlusFidWire::SetName(const std::string& aName)
321 {
322  this->Name = aName;
323 }
324 
325 //----------------------------------------------------------------------------
326 std::string PlusFidWire::GetName() const
327 {
328  return Name;
329 }
330 
331 //----------------------------------------------------------------------------
333 {
334 
335 }
336 
337 //----------------------------------------------------------------------------
339 {
340 
341 }
std::vector< std::vector< double > > FoundDotsCoordinateValue
const uint32_t * data
Definition: phidget22.h:3971
double GetDistanceFrom(PlusFidDot &d)
static bool lessThan(const PlusFidLine &line1, const PlusFidLine &line2)
std::vector< double > DistanceToOriginToleranceMm
These tolerances are in mm.
unsigned int GetNumberOfPoints() const
void ResizePoints(int aNewSize)
const char int line
Definition: phidget22.h:2458
std::vector< PlusFidWire > Wires
const std::vector< PlusFidDot > & GetCandidateFidValues() const
void AddDistanceToOriginToleranceElementMm(double aElement)
void SetName(const std::string &aName)
for i
void SetDistanceToOriginElementMm(int index, double aElement)
void SetIntensity(double value)
std::vector< double > DistanceToOriginMm
These distances are in mm.
Initial rotation matrix b
Definition: algo3.m:25
void SetPoint(int aIndex, int aValue)
static bool compareLines(const PlusFidLine &line1, const PlusFidLine &line2)
void SetLength(double value)
void SetCandidateFidValues(std::vector< PlusFidDot > value)
std::vector< std::vector< double > > & GetFoundDotsCoordinateValue()
int StartPointIndex
index of start point of the line, all the other line points are towards the positive m_DirectionVecto...
void AddDistanceToOriginElementMm(double aElement)
int EndPointIndex
Index of the endpoint of the line.
void SetStartPointIndex(int index)
const std::vector< PlusFidWire > & GetWires() const
const double * GetDirectionVector() const
const char const char * value
Definition: phidget22.h:5111
void SetFoundDotsCoordinateValue(std::vector< std::vector< double > > value)
void AddWire(const PlusFidWire &wire)
int GetPoint(int aIndex) const
static double ComputeAngleRad(const PlusFidLine &line1)
static bool IntensityLessThan(const PlusFidDot &dot1, const PlusFidDot &dot2)
const std::vector< double > & GetDistanceToOriginMm() const
const std::vector< double > & GetDistanceToOriginToleranceMm() const
void SetDirectionVector(int aIndex, double aValue)
bool operator==(const PlusFidDot &data) const
void SetDistanceToOriginToleranceElementMm(int index, double aElement)
void SetDotIntensity(double value)
static bool PositionLessThan(std::vector< PlusFidDot >::iterator b1, std::vector< PlusFidDot >::iterator b2)