ITK  5.0.0
Insight Segmentation and Registration Toolkit
SphinxExamples/src/Core/Common/AddOffsetToIndex/Code.py
1 #!/usr/bin/env python
2 
3 # Copyright Insight Software Consortium
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 # http://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 if VS(itk.Version.GetITKVersion()) < VS("4.9.0"):
22  print("ITK 4.9.0 is required.")
23  sys.exit(1)
24 
25 Dimension = 2
26 
27 index = itk.Index[Dimension]()
28 index.Fill(5)
29 
30 offset = itk.Offset[Dimension]()
31 offset.Fill(1)
32 
33 newIndex = index + offset
34 
35 print("index: " + str([int(index[0]), int(index[1])]))
36 print("offset: " + str([int(offset[0]), int(offset[1])]))
37 print("index + offset: " + str([int(newIndex[0]), int(newIndex[1])]))
38 print("")
39 
40 offset[0] = -1
41 newIndex = index + offset
42 
43 print("index: " + str([int(index[0]), int(index[1])]))
44 print("offset: " + str([int(offset[0]), int(offset[1])]))
45 print("index + offset: " + str([int(newIndex[0]), int(newIndex[1])]))
46 print("")