]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMeasureLength.cxx
11326b71782d94761eedbf00dafaa786d40c418e
[bbtk.git] / packages / vtk / src / bbvtkMeasureLength.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbvtkMeasureLength.h"
5 #include "bbvtkPackage.h"
6 namespace bbvtk
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,MeasureLength)
10 BBTK_BLACK_BOX_IMPLEMENTATION(MeasureLength,bbtk::AtomicBlackBox);
11 //===== 
12 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
13 //===== 
14 void MeasureLength::Process()
15 {
16         std::cout << "RaC MeasureLength::Process START"<< std::endl;
17
18         _points = bbGetInputPoints();
19         _image  = bbGetInputImageData();
20
21         double sumLength                = 0 ;
22         double sumLengthVoxels  = 0 ;
23         if(_image != NULL && _points->GetNumberOfPoints()>1)
24         {
25
26                 double spc[3];
27                 double origin[3];
28
29                 double XFactor;
30                 double YFactor;
31                 double ZFactor;
32
33                 _image->GetSpacing(spc);
34                 _image->GetOrigin(origin);
35
36                 double* first;
37                 double firstWorld[3];
38                 int i;
39
40 //--Length
41                 first = _points->GetPoint(0);
42                 firstWorld[0] = first[0]*spc[0] + origin[0];
43                 firstWorld[1] = first[1]*spc[1] + origin[1];
44                 firstWorld[2] = first[2]*spc[2] + origin[2];
45                 for(i = 1; i<_points->GetNumberOfPoints();i++)
46                 {
47                         double* second;
48                         second = _points->GetPoint(i);
49                         double secondWorld[3];
50                         secondWorld[0] = second[0]*spc[0] + origin[0];
51                         secondWorld[1] = second[1]*spc[1] + origin[1];
52                         secondWorld[2] = second[2]*spc[2] + origin[2];
53
54                         XFactor = secondWorld[0]-firstWorld[0];
55                         YFactor = secondWorld[1]-firstWorld[1];
56                         ZFactor = secondWorld[2]-firstWorld[2];
57                         sumLength += XFactor*XFactor + YFactor*YFactor + ZFactor*ZFactor;
58
59                         firstWorld[0] = secondWorld[0];
60                         firstWorld[1] = secondWorld[1];
61                         firstWorld[2] = secondWorld[2];
62                 } // for
63
64 //--Length Voxels
65                 first = _points->GetPoint(0);
66                 firstWorld[0] = first[0];
67                 firstWorld[1] = first[1];
68                 firstWorld[2] = first[2];
69                 for(i = 1; i<_points->GetNumberOfPoints();i++)
70                 {
71                         double* second;
72                         second = _points->GetPoint(i);
73                         double secondWorld[3];
74                         secondWorld[0] = second[0];
75                         secondWorld[1] = second[1];
76                         secondWorld[2] = second[2];
77
78                         XFactor = secondWorld[0]-firstWorld[0];
79                         YFactor = secondWorld[1]-firstWorld[1];
80                         ZFactor = secondWorld[2]-firstWorld[2];
81                         sumLengthVoxels += XFactor*XFactor + YFactor*YFactor + ZFactor*ZFactor;
82
83                         firstWorld[0] = secondWorld[0];
84                         firstWorld[1] = secondWorld[1];
85                         firstWorld[2] = secondWorld[2];
86                 } // for
87
88         } // if
89
90         bbSetOutputLength( sqrt(sumLength) );
91         bbSetOutputLengthVoxels( sqrt(sumLengthVoxels) );
92
93         std::cout << "RaC MeasureLength::Process END"<< std::endl;
94 }
95 //===== 
96 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
97 //===== 
98 void MeasureLength::bbUserSetDefaultValues()
99 {
100         bbSetOutputLength(0);
101 }
102 //===== 
103 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
104 //===== 
105 void MeasureLength::bbUserInitializeProcessing()
106 {
107
108
109
110   
111 }
112 //===== 
113 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
114 //===== 
115 void MeasureLength::bbUserFinalizeProcessing()
116 {
117
118
119   
120 }
121 }
122 // EO namespace bbvtk
123
124