PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
LinearObject.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 "LinearObject.h"
10 
11 //-----------------------------------------------------------------------------
12 
14 {
15  this->Name = "";
16  this->Type = "LinearObject";
17 }
18 
19 //-----------------------------------------------------------------------------
20 
22 {
23  this->BasePoint.clear();
24  this->Signature.clear();
25 }
26 
27 //-----------------------------------------------------------------------------
28 
29 double LinearObject::DistanceToVector( std::vector<double> vector )
30 {
31  return Distance( vector, this->ProjectVector( vector ) );
32 }
33 
34 //-----------------------------------------------------------------------------
35 
36 double LinearObject::Distance( std::vector<double> v1, std::vector<double> v2 )
37 {
38  if ( v1.size() != v2.size() )
39  {
40  return -1;
41  }
42 
43  double distance = 0.0;
44  for ( unsigned int i = 0; i < v1.size(); i++ )
45  {
46  distance += ( v1.at(i) - v2.at(i) ) * ( v1.at(i) - v2.at(i) );
47  }
48 
49  return sqrt( distance );
50 }
51 
52 //-----------------------------------------------------------------------------
53 
54 double LinearObject::Norm( std::vector<double> vector )
55 {
56  double norm = 0.0;
57  for ( unsigned int i = 0; i < vector.size(); i++ )
58  {
59  norm += vector.at(i) * vector.at(i);
60  }
61 
62  return sqrt( norm );
63 }
64 
65 //-----------------------------------------------------------------------------
66 
67 double LinearObject::Dot( std::vector<double> v1, std::vector<double> v2 )
68 {
69  if ( v1.size() != v2.size() )
70  {
71  return -1;
72  }
73 
74  double dot = 0.0;
75  for ( unsigned int i = 0; i < v1.size(); i++ )
76  {
77  dot += v1.at(i) * v2.at(i);
78  }
79 
80  return dot;
81 }
82 
83 //-----------------------------------------------------------------------------
84 
85 std::vector<double> LinearObject::Cross( std::vector<double> v1, std::vector<double> v2 )
86 {
87  if ( v1.size() != 3 || v2.size() != 3 )
88  {
89  return std::vector<double>( 0, 0.0 );
90  }
91 
92  std::vector<double> result( 3, 0.0 );
93  result.at(0) = v1.at(1) * v2.at(2) - v1.at(2) * v2.at(1);
94  result.at(1) = v1.at(2) * v2.at(0) - v1.at(0) * v2.at(2);
95  result.at(2) = v1.at(0) * v2.at(1) - v1.at(1) * v2.at(0);
96 
97  return result;
98 }
99 
100 //-----------------------------------------------------------------------------
101 
102 std::vector<double> LinearObject::Add( std::vector<double> v1, std::vector<double> v2 )
103 {
104  if ( v1.size() != v2.size() )
105  {
106  return std::vector<double>( 0, 0.0 );
107  }
108 
109  std::vector<double> result( v1.size(), 0.0 );
110  for ( unsigned int i = 0; i < v1.size(); i++ )
111  {
112  result.at(i) = v1.at(i) + v2.at(i);
113  }
114 
115  return result;
116 }
117 
118 //-----------------------------------------------------------------------------
119 
120 std::vector<double> LinearObject::Subtract( std::vector<double> v1, std::vector<double> v2 )
121 {
122  if ( v1.size() != v2.size() )
123  {
124  return std::vector<double>( 0, 0.0 );
125  }
126 
127  std::vector<double> result( v1.size(), 0.0 );
128  for ( unsigned int i = 0; i < v1.size(); i++ )
129  {
130  result.at(i) = v1.at(i) - v2.at(i);
131  }
132 
133  return result;
134 }
135 
136 //-----------------------------------------------------------------------------
137 
138 std::vector<double> LinearObject::Multiply( double c, std::vector<double> vector )
139 {
140  std::vector<double> result( vector.size(), 0.0 );
141  for ( unsigned int i = 0; i < vector.size(); i++ )
142  {
143  result.at(i) = c * vector.at(i);
144  }
145 
146  return result;
147 }
148 
149 //-----------------------------------------------------------------------------
150 
151 std::string LinearObject::VectorToString( std::vector<double> vector )
152 {
153  std::ostringstream s;
154 
155  for ( unsigned int i = 0; i < vector.size(); i++ )
156  {
157  s << vector.at(i) << " ";
158  }
159 
160  return s.str();
161 }
162 
163 //-----------------------------------------------------------------------------
164 
165 std::vector<double> LinearObject::StringToVector( std::string s, int size )
166 {
167  std::stringstream ss( s );
168  double value;
169  std::vector<double> vector( size, 0.0 );
170 
171  for ( int i = 0; i < size; i++ )
172  {
173  ss >> value;
174  vector.at(i) = value;
175  }
176 
177  return vector;
178 }
static double Distance(std::vector< double > v1, std::vector< double > v2)
static double Norm(std::vector< double > vector)
static std::vector< double > Add(std::vector< double > v1, std::vector< double > v2)
std::vector< double > BasePoint
Definition: LinearObject.h:23
uint32_t * distance
Definition: phidget22.h:4650
for i
virtual std::vector< double > ProjectVector(std::vector< double > vector)=0
virtual ~LinearObject()
static double Dot(std::vector< double > v1, std::vector< double > v2)
const char const char * value
Definition: phidget22.h:5111
std::vector< double > Signature
Definition: LinearObject.h:22
double DistanceToVector(std::vector< double > vector)
static std::vector< double > StringToVector(std::string s, int size)
static std::string VectorToString(std::vector< double > vector)
std::string Name
Definition: LinearObject.h:20
static std::vector< double > Cross(std::vector< double > v1, std::vector< double > v2)
static std::vector< double > Multiply(double c, std::vector< double > vector)
static std::vector< double > Subtract(std::vector< double > v1, std::vector< double > v2)
std::string Type
Definition: LinearObject.h:21