-
Notifications
You must be signed in to change notification settings - Fork 7
/
itkMABMISBasicOperationFilter.hxx
132 lines (115 loc) · 2.81 KB
/
itkMABMISBasicOperationFilter.hxx
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
#ifndef __itkMABMISBasicOperationFilter_hxx
#define __itkMABMISBasicOperationFilter_hxx
#include "itkMABMISBasicOperationFilter.h"
namespace itk
{
namespace Statistics
{
template <class TInputImage, class TOutputImage>
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::MABMISBasicOperationFilter()
{
}
template <class TInputImage, class TOutputImage>
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::~MABMISBasicOperationFilter()
{
}
template <class TInputImage, class TOutputImage>
void
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::PrintSelf(std::ostream& os, Indent indent) const
{
Superclass::PrintSelf( os, indent );
}
template <class TInputImage, class TOutputImage>
void
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::RemoveFile(std::string filename)
{
if( itksys::SystemTools::FileExists(filename.c_str(), true) )
{
#if defined(_WIN32) && !defined(__CYGWIN__)
std::ostringstream oss(std::ostringstream::out);
oss << "del /F " << filename << std::endl;
// std::cerr << oss.str().c_str();
system(oss.str().c_str() );
#else
std::ostringstream oss(std::ostringstream::out);
oss << "rm -f " << filename << std::endl;
// std::cerr << oss.str().c_str();
system(oss.str().c_str() );
#endif
}
return;
}
// bubble sort on double array
template <class TInputImage, class TOutputImage>
void
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::bubbleSort(double* arr, int* index, int n)
{
bool swapped = true;
int j = 0;
double tmp;
int index_tmp;
while( swapped )
{
swapped = false;
++j;
for( int i = 0; i < n - j; ++i )
{
if( arr[i] > arr[i + 1] )
{
tmp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = tmp;
index_tmp = index[i];
index[i] = index[i + 1];
index[i + 1] = index_tmp;
swapped = true;
}
}
}
}
template <class TInputImage, class TOutputImage>
void
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::myitoa(int num, std::string& str, int digit)
{
str = "";
if( num < 10 )
{
str.append("00");
}
else if( num < 100 )
{
str.append("0");
}
std::stringstream st;
st << num;
str.append(st.str() );
return;
}
template <class TInputImage, class TOutputImage>
void
MABMISBasicOperationFilter<TInputImage, TOutputImage>
::SaveMatrix2File(vnl_matrix<double> matrix, int iSize, int jSize, std::string martixFileName)
{
std::ofstream outfile;
outfile.open(martixFileName.c_str() );
for( int i = 0; i < iSize; ++i )
{
for( int j = 0; j < jSize; ++j )
{
outfile << ' ';
outfile << std::right << std::fixed << std::setw(8) << std::setprecision(2) << matrix[i][j];
}
outfile << std::endl;
}
outfile.close();
return;
}
} // namespace Statistics
} // namespace itk
#endif