24 constexpr static const
char* TypeName() noexcept {
return "ObjectVoxels"; }
25 virtual const char*
typeName()
const override {
return TypeName(); }
30 const std::shared_ptr<Mesh>&
surface()
const {
return mesh_; }
33 const VdbVolume&
vdbVolume()
const {
return vdbVolume_; };
39 [[nodiscard]]
virtual bool hasModel()
const override {
return bool( vdbVolume_.data ); }
43 {
return vdbVolume_.dims; }
49 {
return histogram_; }
52 {
return vdbVolume_.voxelSize; }
55 virtual std::string
getClassName()
const override {
return "Voxels"; }
119 void selectVoxels(
const VoxelBitSet& selectedVoxels ) { selectedVoxels_ = selectedVoxels; }
159 } shadingType{ ShadingType::None };
166 } lutType{ LutType::Rainbow };
179 } alphaType{ AlphaType::Constant };
180 uint8_t alphaLimit{ 10 };
221 int maxSurfaceVertices_{ 5'000'000 };
222 VdbVolume vdbVolume_;
223 float isoValue_{0.0f};
224 bool dualMarchingCubes_{
true};
226 Histogram histogram_;
227 mutable std::optional<Box3i> activeBounds_;
228 mutable std::optional<size_t> activeVoxels_;
230 const char * serializeFormat_ =
".raw";
233 VolumeIndexer indexer_ = VolumeIndexer( vdbVolume_.dims );
234 Vector3f reverseVoxelSize_;
236 void updateHistogram_(
float min,
float max, ProgressCallback cb = {} );
240 void setDefaultColors_();
243 void setDefaultSceneProperties_();
250 bool volumeRendering_{
false };
#define MRVOXELS_API
Definition MRVoxelsFwd.h:13
#define MRVOXELS_CLASS
Definition MRVoxelsFwd.h:14
Definition MRHistogram.h:10
Definition MRObjectMeshHolder.h:30
Definition MRObjectVoxels.h:17
virtual MRVOXELS_API Expected< std::future< Expected< void > > > serializeModel_(const std::filesystem::path &path) const override
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:42
VdbVolume & varVdbVolume()
Definition MRObjectVoxels.h:34
std::unique_ptr< SimpleVolume > getVolumeRenderingData() const
Definition MRObjectVoxels.h:146
const Vector3f & voxelSize() const
Definition MRObjectVoxels.h:51
MRVOXELS_API std::shared_ptr< Mesh > updateIsoSurface(std::shared_ptr< Mesh > mesh)
const VoxelBitSet & getVolumeRenderActiveVoxels() const
get active (visible) voxels
Definition MRObjectVoxels.h:122
MRVOXELS_API Vector3i getCoordinateByVoxelId(VoxelId id) const
const char * serializeFormat() const
returns file extension used to serialize the voxels
Definition MRObjectVoxels.h:208
bool isVolumeRenderingEnabled() const
Definition MRObjectVoxels.h:140
const VolumeRenderingParams & getVolumeRenderingParams() const
Definition MRObjectVoxels.h:183
virtual MRVOXELS_API std::shared_ptr< Object > clone() const override
const VoxelBitSet & getSelectedVoxels() const
Definition MRObjectVoxels.h:118
bool getDualMarchingCubes() const
returns true if the iso-surface is built using Dual Marching Cubes algorithm or false if using Standa...
Definition MRObjectVoxels.h:100
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:45
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:30
MRVOXELS_API Histogram updateHistogram(Histogram histogram)
IsoSurfaceChangedSignal isoSurfaceChangedSignal
Definition MRObjectVoxels.h:215
virtual MRVOXELS_API void setDirtyFlags(uint32_t mask, bool invalidateCaches=true) override
const VdbVolume & vdbVolume() const
Return VdbVolume.
Definition MRObjectVoxels.h:33
void selectVoxels(const VoxelBitSet &selectedVoxels)
Definition MRObjectVoxels.h:119
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:37
VoxelBitSet volumeRenderActiveVoxels_
Definition MRObjectVoxels.h:247
MRVOXELS_API void construct(const FloatGrid &grid, const Vector3f &voxelSize, const std::optional< Vector2f > &minmax={})
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,...
virtual std::string getClassName() const override
return human readable name of subclass
Definition MRObjectVoxels.h:55
const VolumeIndexer & getVolumeIndexer() const
Returns indexer with more options.
Definition MRObjectVoxels.h:134
MRVOXELS_API void setVolumeRenderActiveVoxels(const VoxelBitSet &activeVoxels)
set active (visible) voxels (using only in Volume Rendering mode)
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 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:191
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:202
virtual MRVOXELS_API void swapBase_(Object &other) override
swaps this object with other
VoxelBitSet selectedVoxels_
Definition MRObjectVoxels.h:246
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:105
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:48
MRVOXELS_API Histogram recalculateHistogram(std::optional< Vector2f > minmax, ProgressCallback cb={}) const
Calculates and returns new histogram.
MRVOXELS_API void setSerializeFormat(const char *newFormat)
sets file extension used to serialize the voxels: must be not null and must start from '....
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:39
MRVOXELS_API void construct(const SimpleVolumeMinMax &simpleVolumeMinMax, ProgressCallback cb={}, bool normalPlusGrad=false)
named object in the data model
Definition MRObject.h:60
Definition MRVolumeIndexer.h:65
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:576
@ None
special value not to limit path in one slice
Definition MRVoxelPath.h:33
Definition MRCameraOrientationPlugin.h:8
std::shared_ptr< OpenVdbFloatGrid > FloatGrid
Definition MRVoxelsFwd.h:25
FilterType
Definition MRMesh/MRMeshFwd.h:579
tl::expected< T, E > Expected
Definition MRExpected.h:58
std::function< Vector3f(const Vector3f &, const Vector3f &, float, float, float)> VoxelPointPositioner
Definition MRMarchingCubes.h:16
Definition MRObjectVoxels.h:150
ShadingType
Definition MRObjectVoxels.h:155
bool operator==(const VolumeRenderingParams &) const =default
LutType
Definition MRObjectVoxels.h:162
AlphaType
Definition MRObjectVoxels.h:175
Definition MRObject.h:246
Definition MRUniquePtr.h:12