MeshLib Documentation
Loading...
Searching...
No Matches
MRObjectPointsHolder.h
Go to the documentation of this file.
1#pragma once
2#include "MRVisualObject.h"
3#include "MRXfBasedCache.h"
4
5namespace MR
6{
7
8enum class MRMESH_CLASS PointsVisualizePropertyType
9{
11 _count [[maybe_unused]],
12};
13template <> struct IsVisualizeMaskEnum<PointsVisualizePropertyType> : std::true_type {};
14
18{
19public:
21
22 ObjectPointsHolder( ObjectPointsHolder&& ) noexcept = default;
23 ObjectPointsHolder& operator = ( ObjectPointsHolder&& ) noexcept = default;
24
25 constexpr static const char* TypeName() noexcept { return "PointsHolder"; }
26 virtual const char* typeName() const override { return TypeName(); }
27
28 MRMESH_API virtual void applyScale( float scaleFactor ) override;
29
30 MRMESH_API virtual bool hasVisualRepresentation() const override;
31
32 [[nodiscard]] virtual bool hasModel() const override { return bool( points_ ); }
33
34 const std::shared_ptr<const PointCloud>& pointCloud() const
35 { return reinterpret_cast< const std::shared_ptr<const PointCloud>& >( points_ ); } // reinterpret_cast to avoid making a copy of shared_ptr
36
37 MRMESH_API virtual std::shared_ptr<Object> clone() const override;
38 MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
39
40 MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
41
43 const VertBitSet& getSelectedPoints() const { return selectedPoints_; }
44
46 void selectPoints( VertBitSet newSelection ) { updateSelectedPoints( newSelection ); }
47
49 MRMESH_API virtual void updateSelectedPoints( VertBitSet& selection );
50
52 MRMESH_API const VertBitSet& getSelectedPointsOrAll() const;
53
56 {
57 return selectedVerticesColor_.get( id );
58 }
60 MRMESH_API virtual void setSelectedVerticesColor( const Color& color, ViewportId id = {} );
61
64
65 [[nodiscard]] MRMESH_API bool supportsVisualizeProperty( AnyVisualizeMaskEnum type ) const override;
66
71
73 MRMESH_API virtual void setPointSize( float size );
75 virtual float getPointSize() const { return pointSize_; }
76
80
83 MRMESH_API virtual Box3f getWorldBox( ViewportId = {} ) const override;
85 MRMESH_API size_t numValidPoints() const;
88
90 [[nodiscard]] MRMESH_API virtual size_t heapBytes() const override;
91
98 int getRenderDiscretization() const { return renderDiscretization_; }
99
102
104 static constexpr int MaxRenderingPointsDefault = 1'000'000;
106 static constexpr int MaxRenderingPointsUnlimited = std::numeric_limits<int>::max();
107
110 MRMESH_API int getMaxRenderingPoints() const { return maxRenderingPoints_; }
111
115
117 [[nodiscard]] const char * savePointsFormat() const { return savePointsFormat_; }
118
120 MRMESH_API void setSavePointsFormat( const char * newFormat );
121
125
128
129protected:
130 VertBitSet selectedPoints_;
131 mutable std::optional<size_t> numValidPoints_;
132 mutable std::optional<size_t> numSelectedPoints_;
134 ViewportMask showSelectedVertices_ = ViewportMask::all();
135
138 MRMESH_API virtual void swapSignals_( Object& other ) override;
139
140 std::shared_ptr<PointCloud> points_;
142
144 float pointSize_{ 5.0f };
145
146 ObjectPointsHolder( const ObjectPointsHolder& other ) = default;
147
149 MRMESH_API virtual void swapBase_( Object& other ) override;
150
151 MRMESH_API virtual Box3f computeBoundingBox_() const override;
152
153 MRMESH_API virtual Expected<std::future<Expected<void>>> serializeModel_( const std::filesystem::path& path ) const override;
154
155 MRMESH_API virtual Expected<void> deserializeModel_( const std::filesystem::path& path, ProgressCallback progressCb = {} ) override;
156
157 MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
158
159 MRMESH_API virtual void deserializeFields_( const Json::Value& root ) override;
160
161 MRMESH_API virtual void setupRenderObject_() const override;
162
164 MRMESH_API void setAllVisualizeProperties_( const AllVisualizeProperties& properties, std::size_t& pos ) override;
165
166 int maxRenderingPoints_ = MaxRenderingPointsDefault;
167
168private:
169
171 void setDefaultColors_();
172
174 void setDefaultSceneProperties_();
175
176 // update renderDiscretization_ as numValidPoints_ / maxRenderingPoints_ (rounded up)
177 void updateRenderDiscretization_();
178
179 int renderDiscretization_ = 1; // auxiliary parameter to avoid recalculation in every frame
180
181 // falls back to the PLY format if no CTM format support is available
182 // NOTE: CTM format support is available in the MRIOExtras library; make sure to load it if you prefer CTM
183 const char * savePointsFormat_ = ".ctm";
184};
185
186}
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:50
SelectedVertices
Definition MRObjectPointsHolder.h:10
Definition MRVisualObject.h:67
Definition MRObjectPointsHolder.h:18
ViewportProperty< Color > selectedVerticesColor_
Definition MRObjectPointsHolder.h:133
MRMESH_API bool supportsVisualizeProperty(AnyVisualizeMaskEnum type) const override
Returns true if this class supports the property type. Otherwise passing it to the functions below is...
MRMESH_API const ViewportProperty< Color > & getSelectedVerticesColorsForAllViewports() const
MRMESH_API int getMaxRenderingPoints() const
Definition MRObjectPointsHolder.h:110
MRMESH_API ObjectPointsHolder()
ObjectPointsHolder(ProtectedStruct, const ObjectPointsHolder &obj)
Definition MRObjectPointsHolder.h:78
const std::shared_ptr< const PointCloud > & pointCloud() const
Definition MRObjectPointsHolder.h:34
std::optional< size_t > numValidPoints_
Definition MRObjectPointsHolder.h:131
virtual MRMESH_API void swapSignals_(Object &other) override
MRMESH_API size_t numRenderingValidPoints() const
returns count of valid points that will be rendered
virtual MRMESH_API size_t heapBytes() const override
returns the amount of memory this object occupies on heap
virtual MRMESH_API void setDirtyFlags(uint32_t mask, bool invalidateCaches=true) override
const char * savePointsFormat() const
returns file extension used to serialize the points
Definition MRObjectPointsHolder.h:117
virtual MRMESH_API void setupRenderObject_() const override
ObjectPointsHolder(ObjectPointsHolder &&) noexcept=default
MRMESH_API void setSavePointsFormat(const char *newFormat)
sets file extension used to serialize the points: must be not null and must start from '....
virtual bool hasModel() const override
Definition MRObjectPointsHolder.h:32
const Color & getSelectedVerticesColor(ViewportId id={}) const
returns colors of selected vertices
Definition MRObjectPointsHolder.h:55
MRMESH_API size_t numSelectedPoints() const
returns cached information about the number of selected points
virtual const char * typeName() const override
Definition MRObjectPointsHolder.h:26
MRMESH_API void setAllVisualizeProperties_(const AllVisualizeProperties &properties, std::size_t &pos) override
set all visualize properties masks
MRMESH_API const VertBitSet & getSelectedPointsOrAll() const
returns selected points if any, otherwise returns all valid points
SelectionChangedSignal pointsSelectionChangedSignal
Definition MRObjectPointsHolder.h:124
virtual MRMESH_API void deserializeFields_(const Json::Value &root) override
VertBitSet selectedPoints_
Definition MRObjectPointsHolder.h:130
int getRenderDiscretization() const
Definition MRObjectPointsHolder.h:98
virtual MRMESH_API Expected< std::future< Expected< void > > > serializeModel_(const std::filesystem::path &path) const override
MRMESH_API void setMaxRenderingPoints(int val)
virtual MRMESH_API Box3f computeBoundingBox_() const override
Signal< void()> renderDiscretizationChangedSignal
signal about render discretization changing, triggered in setRenderDiscretization
Definition MRObjectPointsHolder.h:127
MRMESH_API const ViewportMask & getVisualizePropertyMask(AnyVisualizeMaskEnum type) const override
returns mask of viewports where given property is set
virtual MRMESH_API std::shared_ptr< Object > clone() const override
ObjectPointsHolder(const ObjectPointsHolder &other)=default
virtual MRMESH_API void updateSelectedPoints(VertBitSet &selection)
swaps current selected points with the argument
ViewportProperty< XfBasedCache< Box3f > > worldBox_
Definition MRObjectPointsHolder.h:141
MRMESH_API AllVisualizeProperties getAllVisualizeProperties() const override
get all visualize properties masks
virtual MRMESH_API void setSelectedVerticesColor(const Color &color, ViewportId id={})
sets colors of selected vertices
virtual float getPointSize() const
returns size of points on screen in pixels
Definition MRObjectPointsHolder.h:75
virtual MRMESH_API Expected< void > deserializeModel_(const std::filesystem::path &path, ProgressCallback progressCb={}) override
Reads model from file.
virtual MRMESH_API void setPointSize(float size)
sets size of points on screen in pixels
virtual MRMESH_API bool hasVisualRepresentation() const override
does the object have any visual representation (visible points, triangles, edges, etc....
virtual MRMESH_API std::shared_ptr< Object > shallowClone() const override
void selectPoints(VertBitSet newSelection)
sets current selected points
Definition MRObjectPointsHolder.h:46
MRMESH_API size_t numValidPoints() const
returns cached information about the number of valid points
virtual MRMESH_API void applyScale(float scaleFactor) override
scale object size (all point positions)
std::shared_ptr< PointCloud > points_
Definition MRObjectPointsHolder.h:140
virtual MRMESH_API Box3f getWorldBox(ViewportId={}) const override
const VertBitSet & getSelectedPoints() const
gets current selected points
Definition MRObjectPointsHolder.h:43
virtual MRMESH_API void serializeFields_(Json::Value &root) const override
virtual MRMESH_API void swapBase_(Object &other) override
swaps this object with other
virtual MRMESH_API void setSelectedVerticesColorsForAllViewports(ViewportProperty< Color > val)
std::optional< size_t > numSelectedPoints_
Definition MRObjectPointsHolder.h:132
named object in the data model
Definition MRObject.h:60
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:131
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:576
std::vector< ViewportMask > AllVisualizeProperties
Definition MRVisualObject.h:85
Definition MRCameraOrientationPlugin.h:8
tl::expected< T, E > Expected
Definition MRExpected.h:58
Definition MRColor.h:9
Definition MRVisualObject.h:45
Definition MRObject.h:246