Volume Cartographer 2.27.0
Volume.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <cstdint>
7#include <mutex>
8#include <optional>
9#include <utility>
10
18
19namespace volcart
20{
32// shared_from_this used in Python bindings
33// https://en.cppreference.com/w/cpp/memory/enable_shared_from_this
35 public std::enable_shared_from_this<Volume>
36{
37public:
40
42 using Pointer = std::shared_ptr<Volume>;
43
45 using SliceItem = std::pair<cv::Mat, std::optional<mmap_info>>;
46
49
52
54 static constexpr std::size_t DEFAULT_CAPACITY = 200;
55
58 Volume() = delete;
59
61 explicit Volume(filesystem::path path);
62
64 Volume(filesystem::path path, Identifier uuid, std::string name);
65
67 static auto New(const filesystem::path& path) -> Pointer;
68
70 static auto New(
71 const filesystem::path& path,
72 const Identifier& uuid,
73 const std::string& name) -> Pointer;
78 auto sliceWidth() const -> int;
80 auto sliceHeight() const -> int;
82 auto numSlices() const -> int;
84 auto voxelSize() const -> double;
86 auto min() const -> double;
88 auto max() const -> double;
93 void setSliceWidth(int w);
95 void setSliceHeight(int h);
97 void setNumberOfSlices(std::size_t numSlices);
99 void setVoxelSize(double s);
101 void setMin(double m);
103 void setMax(double m);
108 auto bounds() const -> Bounds;
110 auto isInBounds(double x, double y, double z) const -> bool;
112 auto isInBounds(const cv::Vec3d& v) const -> bool;
125 void setMemoryMapSlices(bool b);
126
134 auto getSliceData(int index) const -> cv::Mat;
135
137 auto getSliceDataCopy(int index) const -> cv::Mat;
138
147 int index, const cv::Mat& slice, bool compress = true) const;
148
150 auto getSlicePath(int index) const -> filesystem::path;
155 auto intensityAt(int x, int y, int z) const -> std::uint16_t;
156
158 auto intensityAt(const cv::Vec3d& v) const -> std::uint16_t;
159
168 auto interpolateAt(double x, double y, double z) const -> std::uint16_t;
169
171 auto interpolateAt(const cv::Vec3d& v) const -> std::uint16_t;
172
187 const cv::Vec3d& center,
188 const cv::Vec3d& xvec,
189 const cv::Vec3d& yvec,
190 int width = 64,
191 int height = 64) const -> Reslice;
196 void setCacheSlices(bool b);
197
200
202 void setCacheCapacity(std::size_t newCacheCapacity) const;
203
205 void setCacheMemoryInBytes(std::size_t nbytes) const;
206
208 auto getCacheCapacity() const -> std::size_t;
209
211 auto getCacheSize() const -> std::size_t;
212
214 void cachePurge() const;
217protected:
219 int width_{0};
221 int height_{0};
223 int slices_{0};
226
228 bool cacheSlices_{true};
230 mutable SliceCache::Pointer cache_{DefaultCache::New(DEFAULT_CAPACITY)};
232 mutable std::shared_mutex cacheMutex_;
234 // TODO: This seems excessive but I'll leave it until it can be tested
235 mutable std::vector<std::mutex> sliceMutexes_;
236
238 bool memmap_{true};
240 cv::Mat load_slice_(int index, mmap_info* mmap_info = nullptr) const;
242 cv::Mat cache_slice_(int index) const;
243};
244} // namespace volcart
Abstract Base Class for Key-Value Caches.
Definition: Cache.hpp:18
std::shared_ptr< Cache > Pointer
Definition: Cache.hpp:24
Base class for objects stored on disk with an associated metadata file.
auto path() const -> filesystem::path
Get the path to the object.
auto name() const -> std::string
Get the human-readable name for the object.
Least Recently Used Cache.
Definition: LRUCache.hpp:45
An image generated by intersecting a plane with a Volume.
Definition: Reslice.hpp:20
Volumetric image data.
Definition: Volume.hpp:36
Volume(filesystem::path path)
Load the Volume from a directory path.
auto getSlicePath(int index) const -> filesystem::path
Get the file path of a slice by index.
void cachePurge() const
Purge the slice cache.
auto bounds() const -> Bounds
Get the bounding box.
void setCacheSlices(bool b)
Enable slice caching.
auto numSlices() const -> int
Get the number of slices.
auto interpolateAt(double x, double y, double z) const -> std::uint16_t
Get the intensity value at a subvoxel position.
void setCacheMemoryInBytes(std::size_t nbytes) const
Set the maximum size of the cache in bytes.
void setCacheCapacity(std::size_t newCacheCapacity) const
Set the maximum number of cached slices.
auto getCacheSize() const -> std::size_t
Get the current number of cached slices.
void setNumberOfSlices(std::size_t numSlices)
Set the expected number of slice images.
auto sliceHeight() const -> int
Get the slice height.
int numSliceCharacters_
Definition: Volume.hpp:225
auto getSliceData(int index) const -> cv::Mat
Get a slice by index number.
bool cacheSlices_
Definition: Volume.hpp:228
SliceCache::Pointer cache_
Definition: Volume.hpp:230
std::shared_ptr< Volume > Pointer
Definition: Volume.hpp:42
void setSliceData(int index, const cv::Mat &slice, bool compress=true) const
Set a slice by index number.
auto intensityAt(int x, int y, int z) const -> std::uint16_t
Get the intensity value at a voxel position.
auto sliceWidth() const -> int
Get the slice width.
void setMemoryMapSlices(bool b)
Whether to memory map slices rather than loading into memory.
void setVoxelSize(double s)
Set the voxel size (in microns)
auto reslice(const cv::Vec3d &center, const cv::Vec3d &xvec, const cv::Vec3d &yvec, int width=64, int height=64) const -> Reslice
Create a Reslice image by intersecting the volume with a plane.
std::vector< std::mutex > sliceMutexes_
Definition: Volume.hpp:235
Volume(filesystem::path path, Identifier uuid, std::string name)
Make a new Volume at the specified path.
static constexpr std::size_t DEFAULT_CAPACITY
Definition: Volume.hpp:54
std::shared_mutex cacheMutex_
Definition: Volume.hpp:232
auto voxelSize() const -> double
Get the voxel size (in microns)
void setSliceHeight(int h)
Set the expected height of the slice images.
std::pair< cv::Mat, std::optional< mmap_info > > SliceItem
Definition: Volume.hpp:45
auto getCacheCapacity() const -> std::size_t
Get the maximum number of cached slices.
auto max() const -> double
Get the maximum intensity value in the Volume.
cv::Mat cache_slice_(int index) const
void setMin(double m)
Set the minimum value in the Volume.
cv::Mat load_slice_(int index, mmap_info *mmap_info=nullptr) const
auto isInBounds(double x, double y, double z) const -> bool
Return whether a position is within the volume bounds.
void setSliceWidth(int w)
Set the expected width of the slice images.
void setCache(SliceCache::Pointer c) const
Set the slice cache.
void setMax(double m)
Set the maximum value in the Volume.
auto getSliceDataCopy(int index) const -> cv::Mat
Get a slice by index number.
auto min() const -> double
Get the minimum intensity value in the Volume.
Volume Cartographer library
Memmap record.
Definition: MemMap.hpp:22