-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmathutility.h
187 lines (149 loc) · 5.05 KB
/
mathutility.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**************************************************************************
(c)Jothybasu Selvaraj
This program comes with no gaurantee of it accuracy.
Clinical decisions should not be made using this program
**************************************************************************/
#ifndef MATHUTILITY_H
#define MATHUTILITY_H
#include<vector>
#include<vtkMath.h>
#include<QDebug>
class MathUtility
{
public:
MathUtility();
inline int getGaussRandomInt(double mean,double std)
{
int rand=vtkMath::Round(vtkMath::Gaussian(mean,std));
return rand;
}
inline std::vector<int> getArrayOfGaussRandomInts(unsigned int length,double mean, double std)
{
std::vector<int>randArray;
for (unsigned int i=0;i<length;++i)
{
randArray.push_back(this->getGaussRandomInt(mean,std));
}
return randArray;
}
inline std::vector<int> getGaussRandomSys(unsigned int fractions,double mean,double std)
{
int x=this->getGaussRandomInt(mean,std);
std::vector<int>sysVectors; //Initialize to 0;
for (unsigned int i=0;i<fractions;++i)
{
sysVectors.push_back(x);
}
return sysVectors;
}
inline std::vector<int> getGaussRandomRand(unsigned int fractions,double mean,double std)
{
std::vector<int>randVectors;
for (unsigned int i=0;i<fractions;++i)
{
int x=this->getGaussRandomInt(mean,std);
//qDebug()<<x<<"Random";
randVectors.push_back(x);
}
return randVectors;
}
inline std::vector<int> addTwoIntArrays(std::vector<int> array1,std::vector<int>array2)
{
unsigned int array1Size=array1.size();
unsigned int array2Size=array2.size();
std::vector<int>summedArray;
//Check sizes are equal
if(array1Size!=array2Size)
{
qDebug()<<"Array sizes do not match!";
}
else
{
for (unsigned int i=0;i<array1Size;i++)
{
int sum=array1[i]+array2[i];
summedArray.push_back(sum);
}
}
return summedArray;
}
inline std::vector<double> addTwoDoubleArrays(std::vector<double> array1,std::vector<double>array2)
{
unsigned int array1Size=array1.size();
unsigned int array2Size=array2.size();
std::vector<double>summedArray;
//Check sizes are equal
if(array1Size!=array2Size)
{
qDebug()<<"Array sizes do not match!";
}
else
{
for (unsigned int i=0;i<array1Size;i++)
{
double sum=array1[i]+array2[i];
summedArray.push_back(sum);
}
}
return summedArray;
}
inline std::vector<double> divideDoubleArrayByInt(std::vector<double> array,int dividerIn)
{
unsigned int arraySize=array.size();
std::vector<double>dividedArray;
for (unsigned int i=0;i<arraySize;i++)
{
double divider=static_cast<double>(dividerIn);
double sum=array[i]/divider;
dividedArray.push_back(sum);
}
return dividedArray;
}
inline std::vector<int> addConstIntToIntArray(std::vector<int>input,int num)
{
unsigned int size=input.size();
for(unsigned int i=0;i<size;i++)
{
input[i]=input[i]+num;
}
return input;
}
inline double productOfVector(std::vector<double>input)
{
int size=input.size();
double result=1.0;
for (int i=0;i<size;++i)
{
result=result*input[i];
}
return result;
}
double calcMean(std::vector<double>input);
double calcStd(std::vector<double>input);
double calcSEM(std::vector<double>input);
int getRandomIntWithinLimits(int lowerLimit,int upperLimit);
inline double distanceBetweenTwoPoints(double p1[],double p2[])
{
double d12 = sqrt(((p1[0] - p2[0]) * (p1[0] - p2[0]))+
( (p1[1] - p2[1]) * (p1[1] - p2[1]))+
((p1[2] - p2[2]) * (p1[2] - p2[2])));
//qDebug()<<d12<<"dconv";
return d12;
}
inline void extendRay(double raySrc[3],double rayTarget[3],double length)
{
double dist=this->distanceBetweenTwoPoints(raySrc,rayTarget);
double xDiff=(rayTarget[0]-raySrc[0])/dist;
double yDiff=(rayTarget[1]-raySrc[1])/dist;
double zDiff=(rayTarget[2]-raySrc[2])/dist;
this->extendedRay[0]=(xDiff*length)+rayTarget[0];
this->extendedRay[1]=(yDiff*length)+rayTarget[1];
this->extendedRay[2]=(zDiff*length)+rayTarget[2];
//qDebug()<<extendedRay[0]<<extendedRay[1]<<extendedRay[2];
}
double extendedRay[3];
void pieceWiseInterpolate(std::vector<double>xPts,std::vector<double>yPts);
std::vector<int>xyzTOijk(double xyz[3],double *origin,double* spacing);
std::vector<double>extendVertex(double vertexCoords[3],double ROIorigin[3],double distance);
};
#endif // MATHUTILITY_H