ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Common/AddOffsetToIndex/Code.py
1 #!/usr/bin/env python
2 
3 # Copyright NumFOCUS
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # https://www.apache.org/licenses/LICENSE-2.0.txt
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import sys
18 import itk
19 
20 from distutils.version import StrictVersion as VS
21 
22 if VS(itk.Version.GetITKVersion()) < VS("4.9.0"):
23  print("ITK 4.9.0 is required.")
24  sys.exit(1)
25 
26 Dimension = 2
27 
28 index = itk.Index[Dimension]()
29 index.Fill(5)
30 
31 offset = itk.Offset[Dimension]()
32 offset.Fill(1)
33 
34 newIndex = index + offset
35 
36 print("index: " + str([int(index[0]), int(index[1])]))
37 print("offset: " + str([int(offset[0]), int(offset[1])]))
38 print("index + offset: " + str([int(newIndex[0]), int(newIndex[1])]))
39 print("")
40 
41 offset[0] = -1
42 newIndex = index + offset
43 
44 print("index: " + str([int(index[0]), int(index[1])]))
45 print("offset: " + str([int(offset[0]), int(offset[1])]))
46 print("index + offset: " + str([int(newIndex[0]), int(newIndex[1])]))
47 print("")
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::Version::GetITKVersion
static const char * GetITKVersion()
itk::Offset
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:66