-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
115 lines (97 loc) · 4.09 KB
/
main.cpp
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
//**********************************************************
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
//**********************************************************
//
//
#include <iostream>
#include <itkImage.h>
#include <itkImageRegionIteratorWithIndex.h>
#include <itkImageFileWriter.h>
#include "itkSphericalToCartesianTransform.h"
#include "itkMyResampleImageFilter.h"
#include "itkCartesianToSphericalTransform.h"
void forwardPointTest(){
using SphericalToCartTransformType = itk::SphericalToCartesianTransform<double>;
SphericalToCartTransformType::Pointer c2SphericalTx = SphericalToCartTransformType::New();
c2SphericalTx->SetRadius(2);
SphericalToCartTransformType::InputPointType point;
double theta = 45, phi = 45;
point[0] = theta*(3.14/180);
point[1] = phi*(3.14/180);
c2SphericalTx->TransformPoint(point);
std::cout << point << " -> " << c2SphericalTx->TransformPoint(point) << "\n";
}
int forwardImageMappingTest(){
using InputImageType = itk::Image<float, 2>;
InputImageType::Pointer spherical = InputImageType::New();
double thetaStep = 0.5, phiStep = 0.5;
InputImageType::SizeType size;
size[0] = 360/thetaStep;
size[1] = 180/phiStep;
InputImageType::PointType origin;
origin.Fill(0.0);
InputImageType::SpacingType spacing;
spacing[0] = (3.14159/180)*thetaStep;
spacing[1] = (3.14159/180)*phiStep;
spherical->SetOrigin(origin);
spherical->SetSpacing(spacing);
spherical->SetRegions(size);//sphericalRegion);
spherical->Allocate();
itk::ImageRegionIteratorWithIndex<InputImageType> iter(spherical, spherical->GetLargestPossibleRegion());
InputImageType::PointType physicalPoint;
iter.GoToBegin();
while (!iter.IsAtEnd()){
spherical->TransformIndexToPhysicalPoint(iter.GetIndex(), physicalPoint);
double value = std::sin(3*physicalPoint[0]) + 1; //sin(theta)
iter.Set(value);
++iter;
}
using SphericalWriterType = itk::ImageFileWriter<InputImageType>;
SphericalWriterType::Pointer sphericalWriter = SphericalWriterType::New();
sphericalWriter->SetInput(spherical);
sphericalWriter->SetFileName("spherical.tif");
sphericalWriter->Update();
using CartToSphericalTransformType = itk::CartesianToSphericalTransform<double>;
CartToSphericalTransformType::Pointer sphericalToCartTx = CartToSphericalTransformType::New();
sphericalToCartTx->SetRadius(2.0);
using OutputImageType = itk::Image<float, 3 >;
using ResampleFilterType = itk::MyResampleImageFilter<InputImageType, OutputImageType>;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
ResampleFilterType::SizeType outputSize;
outputSize.Fill(100);
ResampleFilterType::OutputPointType outputOrigin;
outputOrigin.Fill(-5.0);
OutputImageType::IndexType outputStartIndex;
outputStartIndex.Fill(0);
OutputImageType::SpacingType outputSpacing;
outputSpacing.Fill(0.1);
resampler->SetDefaultPixelValue(-0.1);
resampler->SetInput(spherical);
resampler->SetTransform(sphericalToCartTx);
resampler->SetOutputSpacing(outputSpacing);
resampler->SetOutputOrigin(outputOrigin);
resampler->SetOutputStartIndex(outputStartIndex);
resampler->SetSize(outputSize);
using CartesianWriterType = itk::ImageFileWriter<OutputImageType >;
CartesianWriterType::Pointer cartesianWriter = CartesianWriterType::New();
cartesianWriter->SetInput(resampler->GetOutput());
cartesianWriter->SetFileName("cartesian.tif");
cartesianWriter->Update();
return 0;
}
int main() {
forwardPointTest();
forwardImageMappingTest();
return 0;
}