PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusPolydataForce.cxx
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2 Program: Plus
3 Copyright (c) John SH Baxter, Robarts Research Institute. All rights reserved.
4 See License.txt for details.
5 =========================================================================*/
6 
7 #include "PlusConfigure.h"
8 
9 #include "vtkObjectFactory.h"
10 #include "vtkPolyData.h"
11 #include "vtkPlusPolydataForce.h"
12 #include "vtkMatrix4x4.h"
13 
14 //----------------------------------------------------------------------------
15 
17 
18 //----------------------------------------------------------------------------
20 {
21  // Constant for sigmoid function
22  this->gammaSigmoid = 2;
23  this->scaleForce = 20.0;
24  lastPos[0] = 0;
25  lastPos[1] = 0;
26  lastPos[2] = 0;
27 }
28 
29 //----------------------------------------------------------------------------
30 void vtkPlusPolydataForce::PrintSelf( ostream& os, vtkIndent indent )
31 {
32  this->Superclass::PrintSelf( os, indent.GetNextIndent() );
33  os << indent.GetNextIndent() << "Gamma Sigmoid: " << this->gammaSigmoid << endl;
34 }
35 
36 //----------------------------------------------------------------------------
38 {
39 
40 }
41 
42 //----------------------------------------------------------------------------
43 void vtkPlusPolydataForce::SetInput( vtkPolyData* poly )
44 {
45  this->poly = poly;
46 }
47 
48 //----------------------------------------------------------------------------
49 int vtkPlusPolydataForce::GenerateForce( vtkMatrix4x4* transformMatrix, double force[3] )
50 {
51  double distance;
52  distance = CalculateDistance( transformMatrix->GetElement( 0, 3 ), transformMatrix->GetElement( 1, 3 ), transformMatrix->GetElement( 2, 3 ) );
53 
54  if ( distance <= 5 )
55  {
56  CalculateForce( transformMatrix->GetElement( 0, 3 ), transformMatrix->GetElement( 1, 3 ), transformMatrix->GetElement( 2, 3 ), force );
57  }
58  else
59  {
60  force[0] = ( 0 );
61  force[1] = ( 0 );
62  force[2] = ( 0 );
63  }
64  cout << " FORCE: " << force[0] << ", " << force[1] << ", " << force[2] << endl;
65  return 1;
66 }
67 
68 //----------------------------------------------------------------------------
69 double vtkPlusPolydataForce::CalculateDistance( double x, double y, double z )
70 {
71  int pointID;
72  double distance;
73  double position[3];
74  position[0] = x;
75  position[1] = y;
76  position[2] = z;
77  pointID = this->poly->FindPoint(position);
78  this->poly->GetPoint( pointID, this->lastPos );
79 
80  double tmp = pow( ( x - lastPos[0] ), 2 ) + pow( ( y - lastPos[1] ), 2 ) + pow( ( z - lastPos[2] ), 2 );
81  distance = sqrt( tmp );
82  return distance;
83 }
84 
85 //----------------------------------------------------------------------------
86 int vtkPlusPolydataForce::SetGamma( double gamma )
87 {
88  gammaSigmoid = gamma;
89 
90  return 0;
91 }
92 
93 //----------------------------------------------------------------------------
94 void vtkPlusPolydataForce::CalculateForce( double x, double y, double z, double force[3] )
95 {
96  double vector[3];
97 
98  vector[0] = fabs( x - this->lastPos[0] );
99  vector[1] = fabs( y - this->lastPos[1] );
100  vector[2] = fabs( z - this->lastPos[2] );
101 
102  cout << "vector[0]: " << vector[0] << endl;
103  cout << "vector[1]: " << vector[1] << endl;
104  cout << "vector[2]: " << vector[2] << endl;
105 
106  for ( int i = 0; i < 3; i++ )
107  {
108  if ( vector[i] > 0 )
109  {
110  force[i] = ( 0.1 / ( vector[i] * vector[i] ) ) * .6;
111  }
112  }
113  cout << "X: " << force[0] << endl;
114  cout << "Y: " << force[1] << endl;
115  cout << "Z: " << force[2] << endl;
116 
117  if ( force[0] > 1 )
118  {
119  force[0] = .6;
120  }
121  if ( force[1] > 1 )
122  {
123  force[1] = .6;
124  }
125  if ( force[2] > 1 )
126  {
127  force[2] = .6;
128  }
129 }
double CalculateDistance(double x, double y, double z)
void CalculateForce(double x, double y, double z, double force[3])
uint32_t * distance
Definition: phidget22.h:4650
int SetGamma(double gamma)
for i
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
void SetInput(vtkPolyData *poly)
virtual void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
int x
Definition: phidget22.h:4265
int GenerateForce(vtkMatrix4x4 *transformMatrix, double force[3])
Direction vectors of rods y
Definition: algo3.m:15
double * position
Definition: phidget22.h:3303
vtkStandardNewMacro(vtkPlusPolydataForce) vtkPlusPolydataForce