| 19 | namespace mitk |
| 20 | { |
| 21 | PixelType MakePixelType(const py::object& dtype, size_t components) |
| 22 | { |
| 23 | auto dt = py::dtype::from_args(dtype); |
| 24 | |
| 25 | // numpy bool maps to MITK's conventional unsigned char representation. |
| 26 | // Check this before the generic char/uchar branches because numpy bool |
| 27 | // is a distinct dtype with its own kind ('b'). |
| 28 | if (dt.kind() == 'b') return MakePixelType<unsigned char, unsigned char>(components); |
| 29 | |
| 30 | if (dt.is(py::dtype::of<unsigned char>())) return MakePixelType<unsigned char, unsigned char>(components); |
| 31 | if (dt.is(py::dtype::of<char>())) return MakePixelType<char, char>(components); |
| 32 | if (dt.is(py::dtype::of<unsigned short>())) return MakePixelType<unsigned short, unsigned short>(components); |
| 33 | if (dt.is(py::dtype::of<short>())) return MakePixelType<short, short>(components); |
| 34 | if (dt.is(py::dtype::of<unsigned int>())) return MakePixelType<unsigned int, unsigned int>(components); |
| 35 | if (dt.is(py::dtype::of<int>())) return MakePixelType<int, int>(components); |
| 36 | if (dt.is(py::dtype::of<float>())) return MakePixelType<float, float>(components); |
| 37 | if (dt.is(py::dtype::of<double>())) return MakePixelType<double, double>(components); |
| 38 | |
| 39 | mitkThrow() << "Unsupported numpy dtype: " << std::string(py::str(dt)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void InitPixelType(py::module_& m) |
no outgoing calls
no test coverage detected