| 158 | } |
| 159 | |
| 160 | py::array AsNumpyDirect(Image& img, bool writeable, mitk::TimeStepType time_step) |
| 161 | { |
| 162 | void* data = img.GetData(static_cast<int>(time_step)); |
| 163 | |
| 164 | if (data == nullptr) |
| 165 | mitkThrow() << "Could not access image data at time step " << time_step; |
| 166 | |
| 167 | // Pin the Image::Pointer in the capsule so the buffer outlives the |
| 168 | // numpy array regardless of who else holds a reference to the image. |
| 169 | auto* pin = new Image::Pointer(&img); |
| 170 | auto capsule = py::capsule(pin, "mitk.ImagePin", &DeleteImagePinCapsule); |
| 171 | |
| 172 | return BuildNumpyArray(img, data, writeable, std::move(capsule)); |
| 173 | } |
| 174 | |
| 175 | py::array AsNumpyAccessor(Image& img, bool writeable) |
| 176 | { |
no test coverage detected