| 24 | using namespace mitk; |
| 25 | |
| 26 | void InitBaseGeometry(py::module_& m) |
| 27 | { |
| 28 | py::class_<BaseGeometry, BaseGeometry::Pointer>(m, "BaseGeometry", |
| 29 | R"(Spatial geometry of a 3D object. |
| 30 | |
| 31 | A ``BaseGeometry`` ties the discrete index space (voxel indices) of an |
| 32 | image or data object to a continuous world coordinate system. It carries: |
| 33 | |
| 34 | - An **origin**: world coordinates of the index ``(0, 0, 0)``. |
| 35 | - A **spacing**: world distance between adjacent indices along each axis. |
| 36 | - A **direction cosine matrix**: orientation of the index axes in world |
| 37 | space. |
| 38 | - **Bounds**: the index-space extent of the data. |
| 39 | |
| 40 | ``BaseGeometry`` is abstract. The concrete subclasses bound here are |
| 41 | :py:class:`Geometry3D`, :py:class:`PlaneGeometry`, and |
| 42 | :py:class:`SlicedGeometry3D`. |
| 43 | )") |
| 44 | .def_property("image_geometry", &BaseGeometry::GetImageGeometry, &BaseGeometry::SetImageGeometry, |
| 45 | R"(Whether this geometry is interpreted as an image geometry. |
| 46 | |
| 47 | When True, world coordinates address voxel centers (corner-based addressing |
| 48 | shifted by half a voxel); when False, world coordinates address voxel |
| 49 | corners. |
| 50 | )") |
| 51 | .def_property("origin", &BaseGeometry::GetOrigin, &BaseGeometry::SetOrigin, |
| 52 | "World coordinates of the index ``(0, 0, 0)`` as a :py:class:`Point3D`.") |
| 53 | .def_property("spacing", &BaseGeometry::GetSpacing, &BaseGeometry::SetSpacing, |
| 54 | "Voxel spacing in world units as a :py:class:`Vector3D` ``(sx, sy, sz)``.") |
| 55 | .def("enforce_spacing", |
| 56 | [](BaseGeometry& g, const Vector3D& s) { |
| 57 | g.SetSpacing(s, true); |
| 58 | }, |
| 59 | py::arg("spacing"), |
| 60 | R"(Set spacing and rescale the index-to-world transform accordingly. |
| 61 | |
| 62 | Equivalent to ``SetSpacing(spacing, enforceSetSpacing=True)``: rather than |
| 63 | storing the spacing as an independent value, the transform is rebuilt so |
| 64 | that the requested spacing is preserved exactly when the matrix is |
| 65 | re-decomposed. |
| 66 | |
| 67 | Args: |
| 68 | spacing: New spacing as a :py:class:`Vector3D`. |
| 69 | )") |
| 70 | .def_property("frame_of_reference_id", &BaseGeometry::GetFrameOfReferenceID, &BaseGeometry::SetFrameOfReferenceID, |
| 71 | "DICOM Frame of Reference ID used to group geometries that share a coordinate system.") |
| 72 | .def_property("bounds", |
| 73 | [](const BaseGeometry& g) { |
| 74 | const auto b = g.GetBounds(); |
| 75 | return std::vector<ScalarType>(b.begin(), b.end()); |
| 76 | }, |
| 77 | [](BaseGeometry& g, const std::vector<ScalarType>& v) { |
| 78 | if (v.size() != 6) |
| 79 | mitkThrow() << "Bounds must be of length 6"; |
| 80 | |
| 81 | BaseGeometry::BoundsArrayType b; |
| 82 | std::copy(v.begin(), v.end(), b.begin()); |
| 83 |
no test coverage detected