]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkMeasureLength.cxx
#3008 BBTK Feature New Normal - Active option in box vtk::IsoSurfaceExtractor
[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         _points = bbGetInputPoints();
17         _image  = bbGetInputImageData();
18         double sumLength                = 0 ;
19         double sumLengthVoxels  = 0 ;
20         if(_image != NULL && _points->GetNumberOfPoints()>1)
21         {
22
23                 double spc[3];
24                 double origin[3];
25
26                 double XFactor;
27                 double YFactor;
28                 double ZFactor;
29
30                 _image->GetSpacing(spc);
31                 _image->GetOrigin(origin);
32
33                 double* first;
34                 double firstWorld[3];
35                 int i;
36
37 //--Length
38                 first = _points->GetPoint(0);
39                 firstWorld[0] = first[0]*spc[0] + origin[0];
40                 firstWorld[1] = first[1]*spc[1] + origin[1];
41                 firstWorld[2] = first[2]*spc[2] + origin[2];
42                 for(i = 1; i<_points->GetNumberOfPoints();i++)
43                 {
44                         double* second;
45                         second = _points->GetPoint(i);
46                         double secondWorld[3];
47                         secondWorld[0] = second[0]*spc[0] + origin[0];
48                         secondWorld[1] = second[1]*spc[1] + origin[1];
49                         secondWorld[2] = second[2]*spc[2] + origin[2];
50
51                         XFactor = secondWorld[0]-firstWorld[0];
52                         YFactor = secondWorld[1]-firstWorld[1];
53                         ZFactor = secondWorld[2]-firstWorld[2];
54                         sumLength += XFactor*XFactor + YFactor*YFactor + ZFactor*ZFactor;
55
56                         firstWorld[0] = secondWorld[0];
57                         firstWorld[1] = secondWorld[1];
58                         firstWorld[2] = secondWorld[2];
59                 } // for
60
61 //--Length Voxels
62                 first = _points->GetPoint(0);
63                 firstWorld[0] = first[0];
64                 firstWorld[1] = first[1];
65                 firstWorld[2] = first[2];
66                 for(i = 1; i<_points->GetNumberOfPoints();i++)
67                 {
68                         double* second;
69                         second = _points->GetPoint(i);
70                         double secondWorld[3];
71                         secondWorld[0] = second[0];
72                         secondWorld[1] = second[1];
73                         secondWorld[2] = second[2];
74
75                         XFactor = secondWorld[0]-firstWorld[0];
76                         YFactor = secondWorld[1]-firstWorld[1];
77                         ZFactor = secondWorld[2]-firstWorld[2];
78                         sumLengthVoxels += XFactor*XFactor + YFactor*YFactor + ZFactor*ZFactor;
79
80                         firstWorld[0] = secondWorld[0];
81                         firstWorld[1] = secondWorld[1];
82                         firstWorld[2] = secondWorld[2];
83                 } // for
84
85         } // if
86         bbSetOutputLength( sqrt(sumLength) );
87         bbSetOutputLengthVoxels( sqrt(sumLengthVoxels) );
88 }
89 //===== 
90 // 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)
91 //===== 
92 void MeasureLength::bbUserSetDefaultValues()
93 {
94         bbSetOutputLength(0);
95 }
96 //===== 
97 // 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)
98 //===== 
99 void MeasureLength::bbUserInitializeProcessing()
100 {
101
102
103
104   
105 }
106 //===== 
107 // 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)
108 //===== 
109 void MeasureLength::bbUserFinalizeProcessing()
110 {
111
112
113   
114 }
115 }
116 // EO namespace bbvtk
117
118