ITK  5.0.0
Insight Segmentation and Registration Toolkit
SphinxExamples/src/Core/Common/BoundingBoxOfAPointSet/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 itk
18 import platform
19 
20 Dimension = 3
21 CoordType = itk.ctype('float')
22 # Windows requires unsigned long long for 64-bit identifiers
23 if platform.system() == 'Windows':
24  ElementIdentifierType = itk.ctype('unsigned long long')
25 else:
26  ElementIdentifierType = itk.ctype('unsigned long')
27 
28 
29 MeshTraits = itk.DefaultStaticMeshTraits[CoordType, Dimension, Dimension]
30 PointSetType = itk.PointSet[CoordType, Dimension, MeshTraits]
31 
32 pointSet = PointSetType.New()
33 points = pointSet.GetPoints()
34 
35 # Create points
36 p0 = itk.Point[CoordType, Dimension]()
37 p1 = itk.Point[CoordType, Dimension]()
38 p2 = itk.Point[CoordType, Dimension]()
39 
40 p0[0] = 0.0
41 p0[1] = 0.0
42 p0[2] = 0.0
43 p1[0] = 0.1
44 p1[1] = 0.0
45 p1[2] = 0.0
46 p2[0] = 0.0
47 p2[1] = 0.1
48 p2[2] = 0.0
49 
50 points.InsertElement(0, p0)
51 points.InsertElement(1, p1)
52 points.InsertElement(2, p2)
53 
54 VecContType = itk.VectorContainer[ElementIdentifierType,
55  itk.Point[CoordType, Dimension]]
56 BoundingBoxType = itk.BoundingBox[ElementIdentifierType,
57  Dimension, CoordType, VecContType]
58 
59 boundingBox = BoundingBoxType.New()
60 boundingBox.SetPoints(points)
61 boundingBox.ComputeBoundingBox()
62 
63 print("bounds: " + str(boundingBox.GetBounds()))
64 print("center: " + str(boundingBox.GetCenter()))
65 print("diagonal length squared: " + str(boundingBox.GetDiagonalLength2()))