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 "MRBitSet.h"
5#include "MRVisualObject.h"
6#include "MRXfBasedCache.h"
7#include "MRPointCloudPart.h"
8#include "MRHeapBytes.h"
9
10namespace MR
11{
14
15
16enum class MRMESH_CLASS PointsVisualizePropertyType
17{
19 _count [[maybe_unused]],
20};
21template <> struct IsVisualizeMaskEnum<PointsVisualizePropertyType> : std::true_type {};
22
26{
27public:
29
30 ObjectPointsHolder( ObjectPointsHolder&& ) noexcept = default;
31 ObjectPointsHolder& operator = ( ObjectPointsHolder&& ) noexcept = default;
32
33 constexpr static const char* StaticTypeName() noexcept { return "PointsHolder"; }
34 virtual const char* typeName() const override { return StaticTypeName(); }
35
36 MRMESH_API virtual void applyScale( float scaleFactor ) override;
37
38 MRMESH_API virtual bool hasVisualRepresentation() const override;
39
40 [[nodiscard]] virtual bool hasModel() const override { return bool( points_ ); }
41
43 [[nodiscard]] PointCloud* varPointCloudPtr() { return points_.get(); }
44
46 [[nodiscard]] const PointCloud* pointCloudPtr() const { return points_.get(); }
47
48 #ifdef __GNUC__
49 #pragma GCC diagnostic push
50 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
51 #endif
53 [[deprecated( "use pointCloudPtr() instead" )]]
54 const std::shared_ptr<const PointCloud>& pointCloud() const
55 { return reinterpret_cast< const std::shared_ptr<const PointCloud>& >( points_ ); }
56 #ifdef __GNUC__
57 #pragma GCC diagnostic pop
58 #endif
59
62
63 MRMESH_API virtual std::shared_ptr<Object> clone() const override;
64 MRMESH_API virtual std::shared_ptr<Object> shallowClone() const override;
65
66 MRMESH_API virtual void setDirtyFlags( uint32_t mask, bool invalidateCaches = true ) override;
67
69 const VertBitSet& getSelectedPoints() const { return selectedPoints_; }
70
72 void selectPoints( VertBitSet newSelection ) { updateSelectedPoints( newSelection ); }
73
75 MRMESH_API virtual void updateSelectedPoints( VertBitSet& selection );
76
78 MRMESH_API const VertBitSet& getSelectedPointsOrAll() const;
79
82 {
83 return selectedVerticesColor_.get( id );
84 }
85
86 MRMESH_API virtual void setSelectedVerticesColor( const Color& color, ViewportId id = {} );
87
90
93
94 [[nodiscard]] MRMESH_API bool supportsVisualizeProperty( AnyVisualizeMaskEnum type ) const override;
95
97 const VertColors& getVertsColorMap() const { return vertsColorMap_; }
98
100 virtual void setVertsColorMap( VertColors vertsColorMap ) { vertsColorMap_ = std::move( vertsColorMap ); setDirtyFlags( DIRTY_VERTS_COLORMAP ); }
101
103 virtual void updateVertsColorMap( VertColors& vertsColorMap ) { std::swap( vertsColorMap_, vertsColorMap ); setDirtyFlags( DIRTY_VERTS_COLORMAP ); }
104
106 MRMESH_API virtual void copyColors( const ObjectPointsHolder & src, const VertMap & thisToSrc, const FaceMap& thisToSrcFaces = {} );
107
112
114 MRMESH_API virtual void setPointSize( float size );
116 virtual float getPointSize() const { return pointSize_; }
117
121
124 MRMESH_API virtual Box3f getWorldBox( ViewportId = {} ) const override;
129
131 [[nodiscard]] MRMESH_API virtual size_t heapBytes() const override;
132
139 int getRenderDiscretization() const { return renderDiscretization_; }
140
143
145 static constexpr int MaxRenderingPointsDefault = 1'000'000;
147 static constexpr int MaxRenderingPointsUnlimited = std::numeric_limits<int>::max();
148
152
156
158 [[nodiscard]] const char * serializeFormat() const { return serializeFormat_; }
159 [[deprecated]] MR_BIND_IGNORE const char * savePointsFormat() const { return serializeFormat(); }
160
163 MRMESH_API void setSerializeFormat( const char * newFormat );
164 [[deprecated]] MR_BIND_IGNORE void setSavePointsFormat( const char * newFormat ) { setSerializeFormat( newFormat ); }
165
169 MRMESH_API void resetColors() override;
170
174
177
179 using ChangedSignal = Signal<void( uint32_t mask )>;
182
183protected:
184 VertBitSet selectedPoints_;
185 mutable std::optional<size_t> numValidPoints_;
186 mutable std::optional<size_t> numSelectedPoints_;
189 VertColors vertsColorMap_;
190
193 MRMESH_API virtual void swapSignals_( Object& other ) override;
194
195 std::shared_ptr<PointCloud> points_;
197
199 float pointSize_{ 5.0f };
200
202
204 MRMESH_API virtual void swapBase_( Object& other ) override;
205
206 MRMESH_API virtual Box3f computeBoundingBox_() const override;
207
208 MRMESH_API virtual Expected<std::future<Expected<void>>> serializeModel_( const std::filesystem::path& path ) const override;
209
210 MRMESH_API virtual Expected<void> deserializeModel_( const std::filesystem::path& path, ProgressCallback progressCb = {} ) override;
211
212 MRMESH_API virtual void serializeFields_( Json::Value& root ) const override;
213
214 MRMESH_API virtual void deserializeFields_( const Json::Value& root ) override;
215
216 MRMESH_API virtual void setupRenderObject_() const override;
217
219 MRMESH_API void setAllVisualizeProperties_( const AllVisualizeProperties& properties, std::size_t& pos ) override;
220
222
223private:
224
226 void setDefaultColors_();
227
229 void setDefaultSceneProperties_();
230
232 void updateRenderDiscretization_();
233
234 int renderDiscretization_ = 1;
235
236 const char * serializeFormat_ = nullptr;
237};
238
241[[nodiscard]] MRMESH_API const std::string & defaultSerializePointsFormat();
242
247MRMESH_API void setDefaultSerializePointsFormat( std::string newFormat );
248
249}
#define MRMESH_API
Definition MRMeshFwd.h:85
#define MRMESH_CLASS
Definition MRMeshFwd.h:92
Definition MRVisualObject.h:54
named object in the data model
Definition MRObject.h:61
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:42
static ViewportMask all()
mask meaning all or any viewports
Definition MRViewportId.h:49
Definition MRViewportProperty.h:17
std::function< bool(float)> ProgressCallback
Definition MRMeshFwd.h:759
void setMaxRenderingPoints(int val)
ViewportProperty< Color > selectedVerticesColor_
Definition MRObjectPointsHolder.h:187
void setAllVisualizeProperties_(const AllVisualizeProperties &properties, std::size_t &pos) override
set all visualize properties masks
virtual Box3f getWorldBox(ViewportId={}) const override
virtual void setSelectedVerticesColorsForAllViewports(ViewportProperty< Color > val)
const VertBitSet & getSelectedPointsOrAll() const
returns selected points if any, otherwise returns all valid points
MR_BIND_IGNORE const char * savePointsFormat() const
Definition MRObjectPointsHolder.h:159
ObjectPointsHolder(ProtectedStruct, const ObjectPointsHolder &obj)
Definition MRObjectPointsHolder.h:119
int maxRenderingPoints_
Definition MRObjectPointsHolder.h:221
virtual Expected< std::future< Expected< void > > > serializeModel_(const std::filesystem::path &path) const override
const std::shared_ptr< const PointCloud > & pointCloud() const
Definition MRObjectPointsHolder.h:54
std::optional< size_t > numValidPoints_
Definition MRObjectPointsHolder.h:185
virtual void serializeFields_(Json::Value &root) const override
void resetColors() override
reset all object colors to their default values from the current theme
virtual std::shared_ptr< Object > shallowClone() const override
virtual void updateVertsColorMap(VertColors &vertsColorMap)
swaps per-point colors of the object with given argument
Definition MRObjectPointsHolder.h:103
const std::string & defaultSerializePointsFormat()
virtual void setPointSize(float size)
sets size of points on screen in pixels
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
size_t numValidPoints() const
returns cached information about the number of valid points
ObjectPointsHolder(ObjectPointsHolder &&) noexcept=default
MR_BIND_IGNORE void setSavePointsFormat(const char *newFormat)
Definition MRObjectPointsHolder.h:164
ChangedSignal pointsChangedSignal
Definition MRObjectPointsHolder.h:180
VertColors vertsColorMap_
Definition MRObjectPointsHolder.h:189
virtual bool hasModel() const override
Definition MRObjectPointsHolder.h:40
Signal< void()> SelectionChangedSignal
signal about points selection changing, triggered in selectPoints
Definition MRObjectPointsHolder.h:172
ViewportMask showSelectedVertices_
Definition MRObjectPointsHolder.h:188
const Color & getSelectedVerticesColor(ViewportId id={}) const
returns colors of selected vertices
Definition MRObjectPointsHolder.h:81
static constexpr const char * StaticTypeName() noexcept
Definition MRObjectPointsHolder.h:33
virtual const char * typeName() const override
Definition MRObjectPointsHolder.h:34
Signal< void(uint32_t mask)> ChangedSignal
signal about points or normals changing, triggered in setDirtyFlag
Definition MRObjectPointsHolder.h:179
SelectionChangedSignal pointsSelectionChangedSignal
Definition MRObjectPointsHolder.h:173
virtual void updateSelectedPoints(VertBitSet &selection)
swaps current selected points with the argument
VertBitSet selectedPoints_
Definition MRObjectPointsHolder.h:184
static constexpr int MaxRenderingPointsUnlimited
recommended value for maximum rendered points number to disable discretization
Definition MRObjectPointsHolder.h:147
int getRenderDiscretization() const
Definition MRObjectPointsHolder.h:139
_count
If true, show additional details on the name tag, such as point coordinates. Not all features use thi...
Definition MRFeatureObject.h:90
tl::expected< T, E > Expected
Definition MRExpected.h:31
virtual Box3f computeBoundingBox_() const override
Signal< void()> renderDiscretizationChangedSignal
signal about render discretization changing, triggered in setRenderDiscretization
Definition MRObjectPointsHolder.h:176
virtual void setupRenderObject_() const override
virtual void setDirtyFlags(uint32_t mask, bool invalidateCaches=true) override
int getMaxRenderingPoints() const
Definition MRObjectPointsHolder.h:151
const ViewportMask & getVisualizePropertyMask(AnyVisualizeMaskEnum type) const override
returns mask of viewports where given property is set
void setDefaultSerializePointsFormat(std::string newFormat)
ObjectPointsHolder(const ObjectPointsHolder &other)=default
virtual void copyColors(const ObjectPointsHolder &src, const VertMap &thisToSrc, const FaceMap &thisToSrcFaces={})
copies point colors from given source object
virtual bool hasVisualRepresentation() const override
does the object have any visual representation (visible points, triangles, edges, etc....
size_t numSelectedPoints() const
returns cached information about the number of selected points
ViewportProperty< XfBasedCache< Box3f > > worldBox_
Definition MRObjectPointsHolder.h:196
ChangedSignal normalsChangedSignal
Definition MRObjectPointsHolder.h:181
size_t numRenderingValidPoints() const
returns count of valid points that will be rendered
PointCloudPart pointCloudPart() const
reinterpret_cast to avoid making a copy of shared_ptr
Definition MRObjectPointsHolder.h:61
bool supportsVisualizeProperty(AnyVisualizeMaskEnum type) const override
Returns true if this class supports the property type. Otherwise passing it to the functions below is...
const char * serializeFormat() const
returns overriden file extension used to serialize point cloud inside this object,...
Definition MRObjectPointsHolder.h:158
PointCloud * varPointCloudPtr()
returns the point cloud of this object for modification, or nullptr if it is not set
Definition MRObjectPointsHolder.h:43
virtual float getPointSize() const
returns size of points on screen in pixels
Definition MRObjectPointsHolder.h:116
virtual std::shared_ptr< Object > clone() const override
static constexpr int MaxRenderingPointsDefault
default value for maximum rendered points number
Definition MRObjectPointsHolder.h:145
virtual Expected< void > deserializeModel_(const std::filesystem::path &path, ProgressCallback progressCb={}) override
Reads model from file.
virtual void deserializeFields_(const Json::Value &root) override
void selectPoints(VertBitSet newSelection)
sets current selected points
Definition MRObjectPointsHolder.h:72
AllVisualizeProperties getAllVisualizeProperties() const override
get all visualize properties masks
virtual void swapBase_(Object &other) override
swaps this object with other
std::shared_ptr< PointCloud > points_
Definition MRObjectPointsHolder.h:195
void resetFrontColor() override
reset basic object colors to their default values from the current theme
const PointCloud * pointCloudPtr() const
returns the point cloud of this object, or nullptr if it is not set
Definition MRObjectPointsHolder.h:46
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:100
SelectedVertices
Definition MRObjectPointsHolder.h:18
virtual void applyScale(float scaleFactor) override
scale object size (all point positions)
virtual void swapSignals_(Object &other) override
virtual size_t heapBytes() const override
returns the amount of memory this object occupies on heap
const VertBitSet & getSelectedPoints() const
gets current selected points
Definition MRObjectPointsHolder.h:69
virtual void setSelectedVerticesColor(const Color &color, ViewportId id={})
sets colors of selected vertices
const VertColors & getVertsColorMap() const
returns per-point colors of the object
Definition MRObjectPointsHolder.h:97
void setSerializeFormat(const char *newFormat)
const ViewportProperty< Color > & getSelectedVerticesColorsForAllViewports() const
void copyAllSolidColors(const ObjectPointsHolder &other)
set all object solid colors (front/back/etc.) from other object for all viewports
std::optional< size_t > numSelectedPoints_
Definition MRObjectPointsHolder.h:186
float pointSize_
size of point in pixels
Definition MRObjectPointsHolder.h:199
@ other
Angle, normally float. Measure in radians.
Definition MRFeatureObject.h:27
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:289
represents full point cloud (if region is nullptr) or some portion of point cloud (if region pointer ...
Definition MRPointCloudPart.h:13
Definition MRPointCloud.h:17
Definition MRSignal.h:28