ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Common/BoundingBoxOfAPointSet/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 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 PointSetType = itk.PointSet[CoordType, Dimension]
30 
31 pointSet = PointSetType.New()
32 points = pointSet.GetPoints()
33 
34 # Create points
35 p0 = itk.Point[CoordType, Dimension]()
36 p1 = itk.Point[CoordType, Dimension]()
37 p2 = itk.Point[CoordType, Dimension]()
38 
39 p0[0] = 0.0
40 p0[1] = 0.0
41 p0[2] = 0.0
42 p1[0] = 0.1
43 p1[1] = 0.0
44 p1[2] = 0.0
45 p2[0] = 0.0
46 p2[1] = 0.1
47 p2[2] = 0.0
48 
49 points.InsertElement(0, p0)
50 points.InsertElement(1, p1)
51 points.InsertElement(2, p2)
52 
53 VecContType = itk.VectorContainer[
54  ElementIdentifierType, itk.Point[CoordType, Dimension]
55 ]
56 BoundingBoxType = itk.BoundingBox[
57  ElementIdentifierType, Dimension, CoordType, VecContType
58 ]
59 
60 boundingBox = BoundingBoxType.New()
61 boundingBox.SetPoints(points)
62 boundingBox.ComputeBoundingBox()
63 
64 print("bounds: " + str(boundingBox.GetBounds()))
65 print("center: " + str(boundingBox.GetCenter()))
66 print("diagonal length squared: " + str(boundingBox.GetDiagonalLength2()))
itk::detail::VectorContainer
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
Definition: itkVectorContainer.h:51
itk::PointSet
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition: itkPointSet.h:81
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::BoundingBox
Represent and compute information about bounding boxes.
Definition: itkBoundingBox.h:70