1
22package ee.ut.mrz.volumest;
23
24
29public class Calculations {
30
31
34 public static double getGridArea(int activePointsCount) {
35 return Math.pow(Settings.getInstance().getGridWidth(), 2) * activePointsCount;
36 }
37
38
39 public static double getObjectVolume(int[] grids) {
40 int sumPoints = 0;
41 for (int c = 0; c < grids.length; c++) {
42 sumPoints = sumPoints + grids[c];
43 }
44
45 return Math.pow(Settings.getInstance().getGridWidth(), 2) *
46 Settings.getInstance().getSliceThickness() *
47 Settings.getInstance().getNumberOfSteps() * sumPoints;
48
49 }
50
51
52 public static double getRegularObjectCE(int[] grids, int wholeObjectIntersections) {
53 long sumPoints = 0;
54 long pointsCountSquares = 0;
55 for (int c = 0; c < grids.length; c++) {
56 sumPoints = sumPoints + grids[c];
57 pointsCountSquares = pointsCountSquares + grids[c] * grids[c];
58 }
59
60 double shapeCoefficent = (Math.PI * wholeObjectIntersections) /
61 (4 * Math.sqrt(sumPoints) * Math.sqrt(grids.length));
62
63 long sumovertwo = 0;
64 for (int c = 0; c < grids.length - 2; c++) {
65 int pi = grids[c];
66 int piplus2 = grids[c + 2];
67 sumovertwo = sumovertwo + pi * piplus2;
68 }
69
70 long sumoverone = 0;
71 for (int c = 0; c < grids.length - 1; c++) {
72 int pi = grids[c];
73 int piplus1 = grids[c + 1];
74 sumoverone = sumoverone + pi * piplus1;
75 }
76
77 double gridDifImpact = 3 * pointsCountSquares + sumovertwo - 4 * sumoverone;
78
79 double CE = Math.sqrt((gridDifImpact / 240) + 0.0715 * shapeCoefficent *
80 Math.sqrt(grids.length * sumPoints)) / sumPoints;
81
82 return CE;
83
84 }
85
86
87 public static double getIrregularObjectCE(int[] grids, int wholeObjectIntersections) {
88 long sumPoints = 0;
89 long pointsCountSquares = 0;
90 for (int c = 0; c < grids.length; c++) {
91 sumPoints = sumPoints + grids[c];
92 pointsCountSquares = pointsCountSquares + grids[c] * grids[c];
93 }
94
95 double shapeCoefficent = (Math.PI * wholeObjectIntersections) /
96 (4 * Math.sqrt(sumPoints) * Math.sqrt(grids.length));
97
98 long sumovertwo = 0;
99 for (int c = 0; c < grids.length - 2; c++) {
00 int pi = grids[c];
01 int piplus2 = grids[c + 2];
02 sumovertwo = sumovertwo + pi * piplus2;
03 }
04
05 long sumoverone = 0;
06 for (int c = 0; c < grids.length - 1; c++) {
07 int pi = grids[c];
08 int piplus1 = grids[c + 1];
09 sumoverone = sumoverone + pi * piplus1;
10 }
11
12 double gridDifImpact = 3 * pointsCountSquares + sumovertwo - 4 * sumoverone;
13
14 double CE = Math.sqrt((gridDifImpact / 12) + 0.0543 * shapeCoefficent *
15 Math.sqrt(grids.length * sumPoints)) / sumPoints;
16
17 return CE;
18
19 }
20}
21