MeshLib C++ Docs
Loading...
Searching...
No Matches
MRObjectPointsHolder.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPch/MRBindingMacros.h"
4#include "MRVisualObject.h"
5#include "MRXfBasedCache.h"
6#include "MRPointCloudPart.h"
7
8namespace MR
9{
12
13
14enum class MRMESH_CLASS PointsVisualizePropertyType
15{
17 _count [[maybe_unused]],
18};
19template <> struct IsVisualizeMaskEnum<PointsVisualizePropertyType> : std::true_type {};
20
23class MRMESH_CLASS ObjectPointsHolder : public VisualObject
24{
25public:
26 MRMESH_API ObjectPointsHolder();
27
28 ObjectPointsHolder( ObjectPointsHolder&& ) noexcept = default;
29 ObjectPointsHolder& operator = ( ObjectPointsHolder&& ) noexcept = default;
30
31 constexpr static const char* StaticTypeName() noexcept { return "PointsHolder"; }
32 virtual const char* typeName() const override { return StaticTypeName(); }
33
34 MRMESH_API virtual void applyScale( float scaleFactor ) override;
35
36 MRMESH_API virtual bool hasVisualRepresentation() const override;
37
38 [[nodiscard]] virtual bool hasModel() const override { return bool( points_ ); }
39
40 const std::shared_ptr<const PointCloud>& pointCloud() const
41 { return reinterpret_cast< const std::shared_ptr<const PointCloud>& >( points_ ); }
42
44 [[nodiscard]] PointCloudPart pointCloudPart() const { return selectedPoints_.any() ? PointCloudPart{ *points_, &selectedPoints_ } : PointCloudPart{ *points_ }; }
45
46 MRMESH_API virtual std::shared_ptr<Object> clone() const override;
47 MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
48
49 MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
50
52 const VertBitSet& getSelectedPoints() const { return selectedPoints_; }
53
55 void selectPoints( VertBitSet newSelection ) { updateSelectedPoints( newSelection ); }
56
58 MRMESH_API virtual void updateSelectedPoints( VertBitSet& selection );
59
61 MRMESH_API const VertBitSet& getSelectedPointsOrAll() const;
62
65 {
66 return selectedVerticesColor_.get( id );
67 }
69 MRMESH_API virtual void setSelectedVerticesColor( const Color& color, ViewportId id = {} );
70
73
75 MRMESH_API void copyAllSolidColors( const ObjectPointsHolder& other );
76
77 [[nodiscard]] MRMESH_API bool supportsVisualizeProperty( AnyVisualizeMaskEnum type ) const override;
78
80 const VertColors& getVertsColorMap() const { return vertsColorMap_; }
81
83 virtual void setVertsColorMap( VertColors vertsColorMap ) { vertsColorMap_ = std::move( vertsColorMap ); setDirtyFlags( DIRTY_VERTS_COLORMAP ); }
84
86 virtual void updateVertsColorMap( VertColors& vertsColorMap ) { std::swap( vertsColorMap_, vertsColorMap ); setDirtyFlags( DIRTY_VERTS_COLORMAP ); }
87
89 MRMESH_API virtual void copyColors( const ObjectPointsHolder & src, const VertMap & thisToSrc, const FaceMap& thisToSrcFaces = {} );
90
94 MRMESH_API const ViewportMask& getVisualizePropertyMask( AnyVisualizeMaskEnum type ) const override;
95
97 MRMESH_API virtual void setPointSize( float size );
99 virtual float getPointSize() const { return pointSize_; }
100
104
107 MRMESH_API virtual Box3f getWorldBox( ViewportId = {} ) const override;
109 MRMESH_API size_t numValidPoints() const;
111 MRMESH_API size_t numSelectedPoints() const;
112
114 [[nodiscard]] MRMESH_API virtual size_t heapBytes() const override;
115
122 int getRenderDiscretization() const { return renderDiscretization_; }
123
125 MRMESH_API size_t numRenderingValidPoints() const;
126
128 static constexpr int MaxRenderingPointsDefault = 1'000'000;
130 static constexpr int MaxRenderingPointsUnlimited = std::numeric_limits<int>::max();
131
134 MRMESH_API int getMaxRenderingPoints() const { return maxRenderingPoints_; }
135
138 MRMESH_API void setMaxRenderingPoints( int val );
139
141 [[nodiscard]] const char * serializeFormat() const { return serializeFormat_; }
142 [[deprecated]] MR_BIND_IGNORE const char * savePointsFormat() const { return serializeFormat(); }
143
146 MRMESH_API void setSerializeFormat( const char * newFormat );
147 [[deprecated]] MR_BIND_IGNORE void setSavePointsFormat( const char * newFormat ) { setSerializeFormat( newFormat ); }
148
150 MRMESH_API void resetFrontColor() override;
152 MRMESH_API void resetColors() override;
153
157
160
162 using ChangedSignal = Signal<void( uint32_t mask )>;
165
166protected:
167 VertBitSet selectedPoints_;
168 mutable std::optional<size_t> numValidPoints_;
169 mutable std::optional<size_t> numSelectedPoints_;
171 ViewportMask showSelectedVertices_ = ViewportMask::all();
172 VertColors vertsColorMap_;
173
176 MRMESH_API virtual void swapSignals_( Object& other ) override;
177
178 std::shared_ptr<PointCloud> points_;
180
182 float pointSize_{ 5.0f };
183
184 ObjectPointsHolder( const ObjectPointsHolder& other ) = default;
185
187 MRMESH_API virtual void swapBase_( Object& other ) override;
188
189 MRMESH_API virtual Box3f computeBoundingBox_() const override;
190
191 MRMESH_API virtual Expected<std::future<Expected<void>>> serializeModel_( const std::filesystem::path& path ) const override;
192
193 MRMESH_API virtual Expected<void> deserializeModel_( const std::filesystem::path& path, ProgressCallback progressCb = {} ) override;
194
195 MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
196
197 MRMESH_API virtual void deserializeFields_( const Json::Value& root ) override;
198
199 MRMESH_API virtual void setupRenderObject_() const override;
200
202 MRMESH_API void setAllVisualizeProperties_( const AllVisualizeProperties& properties, std::size_t& pos ) override;
203
204 int maxRenderingPoints_ = MaxRenderingPointsDefault;
205
206private:
207
209 void setDefaultColors_();
210
212 void setDefaultSceneProperties_();
213
215 void updateRenderDiscretization_();
216
217 int renderDiscretization_ = 1;
218
219 const char * serializeFormat_ = nullptr;
220};
221
224[[nodiscard]] MRMESH_API const std::string & defaultSerializePointsFormat();
225
230MRMESH_API void setDefaultSerializePointsFormat( std::string newFormat );
231
232}
Definition MRVisualObject.h:54
Definition MRObjectPointsHolder.h:24
named object in the data model
Definition MRObject.h:62
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:116
ViewportProperty< Color > selectedVerticesColor_
Definition MRObjectPointsHolder.h:170
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...
MR_BIND_IGNORE const char * savePointsFormat() const
Definition MRObjectPointsHolder.h:142
MRMESH_API const ViewportProperty< Color > & getSelectedVerticesColorsForAllViewports() const
MRMESH_API int getMaxRenderingPoints() const
Definition MRObjectPointsHolder.h:134
MRMESH_API ObjectPointsHolder()
ObjectPointsHolder(ProtectedStruct, const ObjectPointsHolder &obj)
Definition MRObjectPointsHolder.h:102
const std::shared_ptr< const PointCloud > & pointCloud() const
Definition MRObjectPointsHolder.h:40
std::optional< size_t > numValidPoints_
Definition MRObjectPointsHolder.h:168
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 void copyColors(const ObjectPointsHolder &src, const VertMap &thisToSrc, const FaceMap &thisToSrcFaces={})
copies point colors from given source object
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
virtual void updateVertsColorMap(VertColors &vertsColorMap)
swaps per-point colors of the object with given argument
Definition MRObjectPointsHolder.h:86
virtual MRMESH_API void setupRenderObject_() const override
ObjectPointsHolder(ObjectPointsHolder &&) noexcept=default
MR_BIND_IGNORE void setSavePointsFormat(const char *newFormat)
Definition MRObjectPointsHolder.h:147
ChangedSignal pointsChangedSignal
Definition MRObjectPointsHolder.h:163
VertColors vertsColorMap_
Definition MRObjectPointsHolder.h:172
virtual bool hasModel() const override
Definition MRObjectPointsHolder.h:38
const Color & getSelectedVerticesColor(ViewportId id={}) const
returns colors of selected vertices
Definition MRObjectPointsHolder.h:64
MRMESH_API size_t numSelectedPoints() const
returns cached information about the number of selected points
virtual const char * typeName() const override
Definition MRObjectPointsHolder.h:32
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:156
virtual MRMESH_API void deserializeFields_(const Json::Value &root) override
VertBitSet selectedPoints_
Definition MRObjectPointsHolder.h:167
int getRenderDiscretization() const
Definition MRObjectPointsHolder.h:122
virtual MRMESH_API Expected< std::future< Expected< void > > > serializeModel_(const std::filesystem::path &path) const override
MRMESH_API void setMaxRenderingPoints(int val)
tl::expected< T, E > Expected
Definition MRExpected.h:31
virtual MRMESH_API Box3f computeBoundingBox_() const override
Signal< void()> renderDiscretizationChangedSignal
signal about render discretization changing, triggered in setRenderDiscretization
Definition MRObjectPointsHolder.h:159
MRMESH_API const ViewportMask & getVisualizePropertyMask(AnyVisualizeMaskEnum type) const override
returns mask of viewports where given property is set
MRMESH_API void setSerializeFormat(const char *newFormat)
virtual MRMESH_API std::shared_ptr< Object > clone() const override
MRMESH_API void copyAllSolidColors(const ObjectPointsHolder &other)
set all object solid colors (front/back/etc.) from other object for all viewports
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:179
ChangedSignal normalsChangedSignal
Definition MRObjectPointsHolder.h:164
MRMESH_API AllVisualizeProperties getAllVisualizeProperties() const override
get all visualize properties masks
PointCloudPart pointCloudPart() const
reinterpret_cast to avoid making a copy of shared_ptr
Definition MRObjectPointsHolder.h:44
virtual MRMESH_API void setSelectedVerticesColor(const Color &color, ViewportId id={})
sets colors of selected vertices
const char * serializeFormat() const
returns overriden file extension used to serialize point cloud inside this object,...
Definition MRObjectPointsHolder.h:141
virtual float getPointSize() const
returns size of points on screen in pixels
Definition MRObjectPointsHolder.h:99
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:55
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)
MRMESH_API void setDefaultSerializePointsFormat(std::string newFormat)
std::shared_ptr< PointCloud > points_
Definition MRObjectPointsHolder.h:178
virtual MRMESH_API Box3f getWorldBox(ViewportId={}) const override
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:13
virtual void setVertsColorMap(VertColors vertsColorMap)
sets per-point colors of the object
Definition MRObjectPointsHolder.h:83
SelectedVertices
Definition MRObjectPointsHolder.h:16
const VertBitSet & getSelectedPoints() const
gets current selected points
Definition MRObjectPointsHolder.h:52
MRMESH_API void resetFrontColor() override
reset basic object colors to their default values from the current theme
virtual MRMESH_API void serializeFields_(Json::Value &root) const override
const VertColors & getVertsColorMap() const
returns per-point colors of the object
Definition MRObjectPointsHolder.h:80
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:169
MRMESH_API void resetColors() override
reset all object colors to their default values from the current theme
MRMESH_API const std::string & defaultSerializePointsFormat()
std::vector< ViewportMask > AllVisualizeProperties
Definition MRVisualObject.h:72
@ DIRTY_VERTS_COLORMAP
Definition MRVisualObject.h:86
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRColor.h:12
Definition MRVisualObject.h:32
Definition MRObject.h:284
represents full point cloud (if region is nullptr) or some portion of point cloud (if region pointer ...
Definition MRPointCloudPart.h:13