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