24 constexpr static const
char* TypeName() noexcept {
return "ObjectVoxels"; }
25 virtual const char*
typeName()
const override {
return TypeName(); }
27 constexpr static const char*
ClassName() noexcept {
return "Voxel Volume"; }
28 virtual std::string
className()
const override {
return ClassName(); }
36 const std::shared_ptr<Mesh>&
surface()
const {
return data_.mesh; }
39 const VdbVolume&
vdbVolume()
const {
return vdbVolume_; };
45 [[nodiscard]]
virtual bool hasModel()
const override {
return bool( vdbVolume_.data ); }
49 {
return vdbVolume_.dims; }
55 {
return histogram_; }
58 {
return vdbVolume_.voxelSize; }
124 void selectVoxels(
const VoxelBitSet& selectedVoxels ) { selectedVoxels_ = selectedVoxels; }
164 } shadingType{ ShadingType::None };
171 } lutType{ LutType::Rainbow };
180 float samplingStep{ -1.0f };
187 } alphaType{ AlphaType::Constant };
188 uint8_t alphaLimit{ 10 };
237 int maxSurfaceVertices_{ 5'000'000 };
238 VdbVolume vdbVolume_;
239 float isoValue_{0.0f};
240 bool dualMarchingCubes_{
true};
242 Histogram histogram_;
243 mutable std::optional<Box3i> activeBounds_;
244 mutable std::optional<size_t> activeVoxels_;
246 const char * serializeFormat_ =
nullptr;
249 VolumeIndexer indexer_ = VolumeIndexer( vdbVolume_.dims );
250 Vector3f reverseVoxelSize_;
252 void updateHistogram_(
float min,
float max, ProgressCallback cb = {} );
256 void setDefaultColors_();
259 void setDefaultSceneProperties_();
266 bool volumeRendering_{
false };
#define MRVOXELS_API
Definition MRVoxels/MRVoxelsFwd.h:13
#define MRVOXELS_CLASS
Definition MRVoxels/MRVoxelsFwd.h:14
wrapper class that helps mrbind to avoid excess MRVDBFloatGrid.h includes
Definition MRVoxels/MRFloatGrid.h:21
Definition MRHistogram.h:10
Definition MRObjectMeshHolder.h:32
Definition MRObjectVoxels.h:17
virtual MRVOXELS_API Expected< std::future< Expected< void > > > serializeModel_(const std::filesystem::path &path) const override
virtual std::string classNameInPlural() const override
Definition MRObjectVoxels.h:31
virtual MRVOXELS_API void setDualMarchingCubes(bool on, bool updateSurface=true, ProgressCallback cb={})
MRVOXELS_API Expected< std::shared_ptr< Mesh > > recalculateIsoSurface(float iso, ProgressCallback cb={}) const
Calculates and return new mesh or error message.
const Vector3i & dimensions() const
Returns dimensions of voxel objects.
Definition MRObjectVoxels.h:48
VdbVolume & varVdbVolume()
Definition MRObjectVoxels.h:40
std::unique_ptr< SimpleVolume > getVolumeRenderingData() const
Definition MRObjectVoxels.h:151
const Vector3f & voxelSize() const
Definition MRObjectVoxels.h:57
MRVOXELS_API std::shared_ptr< Mesh > updateIsoSurface(std::shared_ptr< Mesh > mesh)
const VoxelBitSet & getVolumeRenderActiveVoxels() const
get active (visible) voxels
Definition MRObjectVoxels.h:127
MRVOXELS_API Vector3i getCoordinateByVoxelId(VoxelId id) const
const char * serializeFormat() const
returns overriden file extension used to serialize voxels inside this object, nullptr means defaultSe...
Definition MRObjectVoxels.h:216
bool isVolumeRenderingEnabled() const
Definition MRObjectVoxels.h:145
const VolumeRenderingParams & getVolumeRenderingParams() const
Definition MRObjectVoxels.h:191
virtual MRVOXELS_API std::shared_ptr< Object > clone() const override
const VoxelBitSet & getSelectedVoxels() const
Definition MRObjectVoxels.h:123
bool getDualMarchingCubes() const
returns true if the iso-surface is built using Dual Marching Cubes algorithm or false if using Standa...
Definition MRObjectVoxels.h:105
virtual MRVOXELS_API void invalidateActiveBoundsCaches()
Call this function in main thread post processing if you call setActiveBounds from progress bar threa...
float getIsoValue() const
Returns current iso value.
Definition MRObjectVoxels.h:51
MRVOXELS_API void deserializeFields_(const Json::Value &root) override
const std::shared_ptr< Mesh > & surface() const
Returns iso surface, empty if iso value is not set.
Definition MRObjectVoxels.h:36
MRVOXELS_API Histogram updateHistogram(Histogram histogram)
IsoSurfaceChangedSignal isoSurfaceChangedSignal
Definition MRObjectVoxels.h:227
virtual MRVOXELS_API void setDirtyFlags(uint32_t mask, bool invalidateCaches=true) override
const VdbVolume & vdbVolume() const
Return VdbVolume.
Definition MRObjectVoxels.h:39
void selectVoxels(const VoxelBitSet &selectedVoxels)
Definition MRObjectVoxels.h:124
MRVOXELS_API Expected< std::shared_ptr< Mesh > > recalculateIsoSurface(const VdbVolume &volume, float iso, ProgressCallback cb={}) const
Same as above, but takes external volume.
const FloatGrid & grid() const
Returns Float grid which contains voxels data, see more on openvdb::FloatGrid.
Definition MRObjectVoxels.h:43
VoxelBitSet volumeRenderActiveVoxels_
Definition MRObjectVoxels.h:263
MRVOXELS_API void construct(const FloatGrid &grid, const Vector3f &voxelSize, const std::optional< Vector2f > &minmax={})
static constexpr const char * ClassName() noexcept
Definition MRObjectVoxels.h:27
MRVOXELS_API void setVolumeRenderingParams(const VolumeRenderingParams ¶ms)
MRVOXELS_API VoxelId getVoxelIdByCoordinate(const Vector3i &coord) const
MRVOXELS_API void construct(const VdbVolume &vdbVolume)
Clears all internal data and then creates grid and calculates histogram (surface is not built,...
const VolumeIndexer & getVolumeIndexer() const
Returns indexer with more options.
Definition MRObjectVoxels.h:139
MRVOXELS_API void setVolumeRenderActiveVoxels(const VoxelBitSet &activeVoxels)
set active (visible) voxels (using only in Volume Rendering mode)
static constexpr const char * ClassNameInPlural() noexcept
Definition MRObjectVoxels.h:30
MRVOXELS_API void updateHistogramAndSurface(ProgressCallback cb={})
MRVOXELS_API ObjectVoxels()
MRVOXELS_API void enableVolumeRendering(bool on)
virtual MRVOXELS_API void serializeFields_(Json::Value &root) const override
MRVOXELS_API void resetFrontColor() override
reset basic object colors to their default values from the current theme
MRVOXELS_API void construct(const SimpleVolume &simpleVolume, const std::optional< Vector2f > &minmax={}, ProgressCallback cb={}, bool normalPlusGrad=false)
MRVOXELS_API VdbVolume updateVdbVolume(VdbVolume vdbVolume)
virtual MRVOXELS_API Expected< bool > setIsoValue(float iso, ProgressCallback cb={}, bool updateSurface=true)
int getMaxSurfaceVertices() const
gets top limit on the number of vertices in the iso-surface
Definition MRObjectVoxels.h:199
virtual std::string className() const override
Definition MRObjectVoxels.h:28
MRVOXELS_API bool prepareDataForVolumeRendering(ProgressCallback cb={}) const
virtual MRVOXELS_API void setActiveBounds(const Box3i &activeBox, ProgressCallback cb={}, bool updateSurface=true)
MRVOXELS_API const Box3i & getActiveBounds() const
ObjectVoxels(ProtectedStruct, const ObjectVoxels &obj)
Definition MRObjectVoxels.h:210
virtual MRVOXELS_API void swapBase_(Object &other) override
swaps this object with other
VoxelBitSet selectedVoxels_
Definition MRObjectVoxels.h:262
MRVOXELS_API void setMaxSurfaceVertices(int maxVerts)
sets top limit on the number of vertices in the iso-surface
virtual MRVOXELS_API void swapSignals_(Object &other) override
virtual const char * typeName() const override
Definition MRObjectVoxels.h:25
MRVOXELS_API size_t activeVoxels() const
returns cached information about the number of active voxels
virtual MRVOXELS_API size_t heapBytes() const override
returns the amount of memory this object occupies on heap
virtual MRVOXELS_API bool hasVisualRepresentation() const override
mesh object can be seen if the mesh has at least one edge
virtual MRVOXELS_API std::vector< std::string > getInfoLines() const override
return several info lines that can better describe the object in the UI
virtual void setVoxelPointPositioner(VoxelPointPositioner positioner)
set voxel point positioner for Marching Cubes (only for Standard Marching Cubes)
Definition MRObjectVoxels.h:110
MRVOXELS_API VoxelId getVoxelIdByPoint(const Vector3f &point) const
ObjectVoxels(const ObjectVoxels &other)=default
MRVOXELS_API Expected< void > deserializeModel_(const std::filesystem::path &path, ProgressCallback progressCb={}) override
Reads model from file.
const Histogram & histogram() const
Returns histogram.
Definition MRObjectVoxels.h:54
MRVOXELS_API Histogram recalculateHistogram(std::optional< Vector2f > minmax, ProgressCallback cb={}) const
Calculates and returns new histogram.
MRVOXELS_API void setSerializeFormat(const char *newFormat)
VoxelsChangedSignal voxelsChangedSignal
Definition MRObjectVoxels.h:231
virtual MRVOXELS_API std::shared_ptr< Object > shallowClone() const override
virtual MRVOXELS_API void applyScale(float scaleFactor) override
scale object size (all point positions)
virtual bool hasModel() const override
Definition MRObjectVoxels.h:45
MRVOXELS_API void construct(const SimpleVolumeMinMax &simpleVolumeMinMax, ProgressCallback cb={}, bool normalPlusGrad=false)
named object in the data model
Definition MRObject.h:62
Definition MRVolumeIndexer.h:65
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:729
@ None
special value not to limit path in one slice
Definition MRVoxelPath.h:33
Definition MRCameraOrientationPlugin.h:8
FilterType
Definition MRMesh/MRMeshFwd.h:732
tl::expected< T, E > Expected
Definition MRExpected.h:25
MRVOXELS_API const std::string & defaultSerializeVoxelsFormat()
MRVOXELS_API void setDefaultSerializeVoxelsFormat(std::string newFormat)
std::function< Vector3f(const Vector3f &, const Vector3f &, float, float, float)> VoxelPointPositioner
Definition MRMarchingCubes.h:16
Definition MRMesh/MRColor.h:9
Definition MRObjectVoxels.h:155
ShadingType
Definition MRObjectVoxels.h:160
bool operator==(const VolumeRenderingParams &) const =default
LutType
Definition MRObjectVoxels.h:167
AlphaType
Definition MRObjectVoxels.h:183
Definition MRObject.h:279
Definition MRUniquePtr.h:12