PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
Plane.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 "Plane.h"
10 
12 {
13  this->Type = "Plane";
14 }
15 
16 //-----------------------------------------------------------------------------
17 
18 Plane::Plane( std::vector<double> newBasePoint, std::vector<double> newEndPoint1, std::vector<double> newEndPoint2 )
19 {
20  this->Type = "Plane";
21  this->BasePoint = newBasePoint;
22  this->EndPoint1 = newEndPoint1;
23  this->EndPoint2 = newEndPoint2;
24 }
25 
26 //-----------------------------------------------------------------------------
27 
29 {
30  this->EndPoint1.clear();
31  this->EndPoint2.clear();
32 }
33 
34 //-----------------------------------------------------------------------------
35 
36 std::vector<double> Plane::GetNormal()
37 {
38  std::vector<double> vector = Cross( Subtract( this->EndPoint1, this->BasePoint ), Subtract( this->EndPoint2, this->BasePoint ) );
39  vector = Multiply( 1 / Norm( vector ), vector );
40  return vector;
41 }
42 
43 //-----------------------------------------------------------------------------
44 
45 std::vector<double> Plane::ProjectVector( std::vector<double> vector )
46 {
47  std::vector<double> outVec = Subtract( vector, this->BasePoint );
48  return Subtract( vector, Multiply( Dot( this->GetNormal(), outVec ), this->GetNormal() ) );
49 }
50 
51 //-----------------------------------------------------------------------------
52 
53 void Plane::Translate( std::vector<double> vector )
54 {
55  for ( unsigned int i = 0; i < vector.size(); i++ )
56  {
57  this->BasePoint.at(i) = this->BasePoint.at(i) + vector.at(i);
58  this->EndPoint1.at(i) = this->EndPoint1.at(i) + vector.at(i);
59  this->EndPoint2.at(i) = this->EndPoint2.at(i) + vector.at(i);
60  }
61 }
62 
63 //-----------------------------------------------------------------------------
64 
65 std::string Plane::ToXMLString() const
66 {
67  std::ostringstream xmlstring;
68 
69  xmlstring << " <Plane";
70  xmlstring << " Name=\"" << this->Name << "\"";
71  xmlstring << " BasePoint=\"" << VectorToString( this->BasePoint ) << "\"";
72  xmlstring << " EndPoint1=\"" << VectorToString( this->EndPoint1 ) << "\"";
73  xmlstring << " EndPoint2=\"" << VectorToString( this->EndPoint2 ) << "\"";
74  xmlstring << " />" << std::endl;
75 
76  return xmlstring.str();
77 }
78 
79 //-----------------------------------------------------------------------------
80 
81 void Plane::FromXMLElement( vtkXMLDataElement* element )
82 {
83 
84  if ( strcmp( element->GetName(), "Plane" ) != 0 )
85  {
86  return; // If it's not a "log" or is the wrong tool jump to the next.
87  }
88 
89  this->Name = std::string( element->GetAttribute( "Name" ) );
90  this->BasePoint = StringToVector( std::string( element->GetAttribute( "BasePoint" ) ), 3 );
91  this->EndPoint1 = StringToVector( std::string( element->GetAttribute( "EndPoint1" ) ), 3 );
92  this->EndPoint2 = StringToVector( std::string( element->GetAttribute( "EndPoint2" ) ), 3 );
93 
94 }
virtual void FromXMLElement(vtkXMLDataElement *element)
Definition: Plane.cxx:81
static double Norm(std::vector< double > vector)
void Translate(std::vector< double > vector)
Definition: Plane.cxx:53
std::vector< double > BasePoint
Definition: LinearObject.h:23
for i
Plane()
Definition: Plane.cxx:11
virtual std::string ToXMLString() const
Definition: Plane.cxx:65
std::vector< double > EndPoint2
Definition: Plane.h:34
std::vector< double > EndPoint1
Definition: Plane.h:33
static double Dot(std::vector< double > v1, std::vector< double > v2)
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
std::vector< double > GetNormal()
Definition: Plane.cxx:36
static std::vector< double > Cross(std::vector< double > v1, std::vector< double > v2)
std::vector< double > ProjectVector(std::vector< double > vector)
Definition: Plane.cxx:45
static std::vector< double > Multiply(double c, std::vector< double > vector)
static std::vector< double > Subtract(std::vector< double > v1, std::vector< double > v2)
~Plane()
Definition: Plane.cxx:28
std::string Type
Definition: LinearObject.h:21