MeshLib
 
Loading...
Searching...
No Matches
MRMarkedVoxelSlice.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRImGuiImage.h"
4#include <MRMesh/MRColor.h>
5#include <MRMesh/MRVector3.h>
6#include <MRMesh/MRBitSet.h>
7#include <MRMesh/MRBox.h>
9
10#ifndef MRMESH_NO_OPENVDB
11
12namespace MR
13{
14
17{
18public:
19 struct Mark
20 {
22 VoxelBitSet mask;
23 };
24
25 MRVIEWER_API MarkedVoxelSlice( const ObjectVoxels& voxels );
26
28
29 // Needed to avoid VoxelBitSet copy
30 // ensure using forceUpdate() after chaging this reference
31 VoxelBitSet& getMask( MaskType type ) { return params_.marks[type].mask; }
32 // Returns mask(VoxelBitSet of whole voxel object) of given type
33 const VoxelBitSet& getMask( MaskType type ) const { return params_.marks[type].mask; }
34 // Sets mask(VoxelBitSet of whole voxel object) of given type, updates texture
35 void setMask( const VoxelBitSet& mask, MaskType type ) { params_.marks[type].mask = mask; forceUpdate(); }
36
37 // Colors of slice marks controls, setters update texture
38 const Color& getColor( MaskType type ) const { return params_.marks[type].color; }
39 void setColor( const Color& color, MaskType type ) { params_.marks[type].color = color; forceUpdate(); }
40
41
42 // Needed to avoid VoxelBitSet copy
43 // ensure using forceUpdate() after chaging this reference
44 Mark& getMark( MaskType type ) { return params_.marks[type]; }
45 // Returns color and mask(VoxelBitSet of whole voxel object) of given type
46 const Mark& getMark( MaskType type ) const { return params_.marks[type]; }
47 // Sets color and mask(VoxelBitSet of whole voxel object) of given type, updates texture
48 void setMark( const Mark& mark, MaskType type ) { params_.marks[type] = mark; forceUpdate(); }
49
50 // Needed to avoid VoxelBitSet copy
51 // ensure using forceUpdate() after chaging this reference
52 // returns background colors and masks(VoxelBitSet of whole voxel object)
53 std::vector<Mark>& getCustomBackgroundMarks() { return params_.customBackgroundMarks; }
54 const std::vector<Mark>& getCustomBackgroundMarks() const { return params_.customBackgroundMarks; }
55 // Sets background colors and masks(VoxelBitSet of whole voxel object) of given type, updates texture
56 void setCustomBackgroundMarks( const std::vector<Mark>& backgroundMarks ) { params_.customBackgroundMarks = backgroundMarks; forceUpdate(); }
57
58 // Needed to avoid VoxelBitSet copy
59 // ensure using forceUpdate() after chaging this reference
60 // returns foreground colors and masks(VoxelBitSet of whole voxel object)
61 std::vector<Mark>& getCustomForegroundMarks() { return params_.customForegroundMarks; }
62 const std::vector<Mark>& getCustomForegroundMarks() const { return params_.customForegroundMarks; }
63 // Sets foreground colors and masks(VoxelBitSet of whole voxel object) of given type, updates texture
64 void setCustomForegroundMarks( const std::vector<Mark>& foregroundMarks ) { params_.customForegroundMarks = foregroundMarks; forceUpdate(); }
65
66
67 // Active plane (YZ, ZX or XY) controls, setters update texture
68 SlicePlane getActivePlane() const { return params_.activePlane; }
69 void setActivePlane( SlicePlane plane ) { params_.activePlane = plane; forceUpdate(); }
70
71 const Vector3i& getActiveVoxel() const { return params_.activeVoxel; }
72 void setActiveVoxel( const Vector3i& voxel ) { params_.activeVoxel = voxel; forceUpdate(); }
73
74 // Slice normalization parameters, setters update texture
75 float getMin() const { return params_.min; }
76 void setMin( float min ) { params_.min = min; forceUpdate(); }
77 float getMax() const { return params_.max; }
78 void setMax( float max ) { params_.max = max; forceUpdate(); }
79
80 // Returns current active box of slice
81 const Box3i& getActiveBox() const { return params_.activeBox; }
82 // Updates active box of slice, do not affect ObjectVoxels, updates texture
83 void setActiveBox( const Box3i& box ) { params_.activeBox = box; forceUpdate(); }
84
85 // Parameters of slice
87 {
88 // Base marks
90 std::vector<Mark> customBackgroundMarks;
91 std::vector<Mark> customForegroundMarks;
92 // Current voxel
94 // Active box, set as ObjectVoxels active box in constructor
95 Box3i activeBox;
96 // Minimum dense to show black
97 float min{0.0f};
98 // Maximum dense to show white
99 float max{0.0f};
100 // Slice plane
102 // if inactiveVoxelColor is set to some color then it will be blended with inactive voxel's color
103 std::optional<Color> inactiveVoxelColor;
104 };
105
106 // Get all parameters as one structure
107 const Parameters& getParameters() const { return params_; }
108 // Set all parameters as one structure, updates texture
109 void setParameters( const Parameters& params ) { params_ = params; forceUpdate(); }
110
111 // Set current slice with marks to texture, do not abuse this
112 MRVIEWER_API void forceUpdate();
113
114private:
115 FloatGrid grid_;
116 Vector3i dims_;
117
118 Parameters params_;
119
120};
121
122} //namespace MR
123
124#endif
Definition MRImGuiImage.h:14
ImGui visualization of a slice from voxel object and seed marks on it.
Definition MRMarkedVoxelSlice.h:17
void setActivePlane(SlicePlane plane)
Definition MRMarkedVoxelSlice.h:69
void setCustomBackgroundMarks(const std::vector< Mark > &backgroundMarks)
Definition MRMarkedVoxelSlice.h:56
const Color & getColor(MaskType type) const
Definition MRMarkedVoxelSlice.h:38
void setParameters(const Parameters &params)
Definition MRMarkedVoxelSlice.h:109
SlicePlane getActivePlane() const
Definition MRMarkedVoxelSlice.h:68
const Box3i & getActiveBox() const
Definition MRMarkedVoxelSlice.h:81
void setCustomForegroundMarks(const std::vector< Mark > &foregroundMarks)
Definition MRMarkedVoxelSlice.h:64
void setMask(const VoxelBitSet &mask, MaskType type)
Definition MRMarkedVoxelSlice.h:35
Mark & getMark(MaskType type)
Definition MRMarkedVoxelSlice.h:44
const Vector3i & getActiveVoxel() const
Definition MRMarkedVoxelSlice.h:71
std::vector< Mark > & getCustomBackgroundMarks()
Definition MRMarkedVoxelSlice.h:53
VoxelBitSet & getMask(MaskType type)
Definition MRMarkedVoxelSlice.h:31
void setActiveVoxel(const Vector3i &voxel)
Definition MRMarkedVoxelSlice.h:72
const std::vector< Mark > & getCustomForegroundMarks() const
Definition MRMarkedVoxelSlice.h:62
const VoxelBitSet & getMask(MaskType type) const
Definition MRMarkedVoxelSlice.h:33
float getMax() const
Definition MRMarkedVoxelSlice.h:77
std::vector< Mark > & getCustomForegroundMarks()
Definition MRMarkedVoxelSlice.h:61
void setMark(const Mark &mark, MaskType type)
Definition MRMarkedVoxelSlice.h:48
MRVIEWER_API void forceUpdate()
const std::vector< Mark > & getCustomBackgroundMarks() const
Definition MRMarkedVoxelSlice.h:54
const Parameters & getParameters() const
Definition MRMarkedVoxelSlice.h:107
float getMin() const
Definition MRMarkedVoxelSlice.h:75
void setMin(float min)
Definition MRMarkedVoxelSlice.h:76
void setActiveBox(const Box3i &box)
Definition MRMarkedVoxelSlice.h:83
MRVIEWER_API MarkedVoxelSlice(const ObjectVoxels &voxels)
const Mark & getMark(MaskType type) const
Definition MRMarkedVoxelSlice.h:46
void setColor(const Color &color, MaskType type)
Definition MRMarkedVoxelSlice.h:39
void setMax(float max)
Definition MRMarkedVoxelSlice.h:78
MaskType
Definition MRMarkedVoxelSlice.h:27
@ Inside
Definition MRMarkedVoxelSlice.h:27
@ Outside
Definition MRMarkedVoxelSlice.h:27
@ Count
Definition MRMarkedVoxelSlice.h:27
@ Segment
Definition MRMarkedVoxelSlice.h:27
Definition MRObjectVoxels.h:17
SlicePlane
Plane of slice in which to find path.
Definition MRVoxelPath.h:29
@ XY
= 2 cause main axis is z - [2]
Definition MRVoxelPath.h:32
Definition MRCameraOrientationPlugin.h:7
std::shared_ptr< OpenVdbFloatGrid > FloatGrid
Definition MRMesh/MRMeshFwd.h:537
Definition MRColor.h:9
static constexpr Color yellow() noexcept
Definition MRColor.h:33
static constexpr Color red() noexcept
Definition MRColor.h:30
static constexpr Color blue() noexcept
Definition MRColor.h:32
Definition MRMarkedVoxelSlice.h:20
Color color
Definition MRMarkedVoxelSlice.h:21
VoxelBitSet mask
Definition MRMarkedVoxelSlice.h:22
Definition MRMarkedVoxelSlice.h:87
SlicePlane activePlane
Definition MRMarkedVoxelSlice.h:101
std::optional< Color > inactiveVoxelColor
Definition MRMarkedVoxelSlice.h:103
std::vector< Mark > customForegroundMarks
Definition MRMarkedVoxelSlice.h:91
Vector3i activeVoxel
Definition MRMarkedVoxelSlice.h:93
Box3i activeBox
Definition MRMarkedVoxelSlice.h:95
float min
Definition MRMarkedVoxelSlice.h:97
float max
Definition MRMarkedVoxelSlice.h:99
std::array< Mark, size_t(MaskType::Count)> marks
Definition MRMarkedVoxelSlice.h:89
std::vector< Mark > customBackgroundMarks
Definition MRMarkedVoxelSlice.h:90