CortidQCT  1.2.2.52
VoxelVolume.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "VolumeSize.h"
15 #include "VoxelSize.h"
16 
17 #include <cassert>
18 #include <string>
19 #include <vector>
20 
21 namespace CortidQCT {
22 
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wpadded"
25 
32 class VoxelVolume {
33 public:
35  using ValueType = float;
36 
37 private:
39  using VoxelData = std::vector<ValueType>;
40 
41 public:
44 
46  inline VoxelVolume() noexcept {}
47 
50  inline VoxelVolume(std::string const &filename) : VoxelVolume() {
51  loadFromFile(filename);
52  }
53 
55 
58 
68  VoxelVolume &loadFromFile(std::string const &filename);
69 
71 
74 
76  inline VolumeSize const &size() const noexcept { return volumeSize_; }
77 
79  inline VoxelSize const &voxelSize() const noexcept { return voxelSize_; }
80 
82  inline bool isEmpty() const noexcept { return volumeSize_.linear() == 0; }
83 
85 
107  template <class F>
108  inline auto withUnsafeDataPointer(F &&f) const
109  noexcept(noexcept(f(std::declval<VoxelData>().data()))) {
110  return f(voxelData_.data());
111  }
112 
114 
115 private:
117  VoxelData voxelData_;
118 
120  VolumeSize volumeSize_;
121 
123  VoxelSize voxelSize_;
124 };
125 #pragma clang diagnostic pop
126 
127 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
VolumeSize const & size() const noexcept
Returns the volume size.
Definition: VoxelVolume.h:76
bool isEmpty() const noexcept
Returns true iff the volume is empty.
Definition: VoxelVolume.h:82
This header contains the definition of the VoxelSize type.
VoxelSize const & voxelSize() const noexcept
Returns the voxel size.
Definition: VoxelVolume.h:79
Definition: ColorToLabelMap.h:27
constexpr std::size_t linear() const noexcept
Returns the linear size (i.e. width * height * depth)
Definition: VolumeSize.h:79
Size type for a 3D voxel.
Definition: VolumeSize.h:22
Type representing a voxel volume.
Definition: VoxelVolume.h:32
VoxelVolume() noexcept
Constructs an empty volume.
Definition: VoxelVolume.h:46
Size type for a 3D voxel.
Definition: VoxelSize.h:22
VoxelVolume(std::string const &filename)
Definition: VoxelVolume.h:50
auto withUnsafeDataPointer(F &&f) const noexcept(noexcept(f(std::declval< VoxelData >().data())))
Calls the given functional with an unsafe pointer to the raw voxel storage.
Definition: VoxelVolume.h:108
float ValueType
Voxel value type.
Definition: VoxelVolume.h:35
This header contains the definition of the VolumeSize type.
VoxelVolume & loadFromFile(std::string const &filename)
Loads the volume data from file using format auto detection.
Definition: VoxelVolume.cpp:25