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  pointID = this->poly->FindPoint( x, y, z );
74  this->poly->GetPoint( pointID, this->lastPos );
75 
76  double tmp = pow( ( x - lastPos[0] ), 2 ) + pow( ( y - lastPos[1] ), 2 ) + pow( ( z - lastPos[2] ), 2 );
77  distance = sqrt( tmp );
78  return distance;
79 }
80 
81 //----------------------------------------------------------------------------
82 int vtkPlusPolydataForce::SetGamma( double gamma )
83 {
84  gammaSigmoid = gamma;
85 
86  return 0;
87 }
88 
89 //----------------------------------------------------------------------------
90 void vtkPlusPolydataForce::CalculateForce( double x, double y, double z, double force[3] )
91 {
92  double vector[3];
93 
94  vector[0] = fabs( x - this->lastPos[0] );
95  vector[1] = fabs( y - this->lastPos[1] );
96  vector[2] = fabs( z - this->lastPos[2] );
97 
98  cout << "vector[0]: " << vector[0] << endl;
99  cout << "vector[1]: " << vector[1] << endl;
100  cout << "vector[2]: " << vector[2] << endl;
101 
102  for ( int i = 0; i < 3; i++ )
103  {
104  if ( vector[i] > 0 )
105  {
106  force[i] = ( 0.1 / ( vector[i] * vector[i] ) ) * .6;
107  }
108  }
109  cout << "X: " << force[0] << endl;
110  cout << "Y: " << force[1] << endl;
111  cout << "Z: " << force[2] << endl;
112 
113  if ( force[0] > 1 )
114  {
115  force[0] = .6;
116  }
117  if ( force[1] > 1 )
118  {
119  force[1] = .6;
120  }
121  if ( force[2] > 1 )
122  {
123  force[2] = .6;
124  }
125 }
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
vtkStandardNewMacro(vtkPlusPolydataForce) vtkPlusPolydataForce