MeshLib Documentation
Loading...
Searching...
No Matches
MRRenderFeatureObjects.h
Go to the documentation of this file.
1#pragma once
2
15
17{
18
19namespace detail
20{
21 // See `WrappedModelSubobject` below. This class holds optional components for it that depend on the template parameter.
22 template <bool IsPrimary, typename BaseObjectType>
23 class WrappedModelSubobjectPart : public BaseObjectType {};
24
25 template <bool IsPrimary>
26 class WrappedModelSubobjectPart<IsPrimary, ObjectPoints> : public ObjectPoints, public virtual RenderWrapObject::BasicWrapperTarget<FeatureObject>
27 {
28 public:
29 float getPointSize() const override
30 {
31 const_cast<WrappedModelSubobjectPart &>( *this ).setPointSize( IsPrimary ? target_->getPointSize() : target_->getSubfeaturePointSize() );
33 }
34
36 {
37 if ( !IsPrimary )
38 const_cast<WrappedModelSubobjectPart &>( *this ).setGlobalAlpha( (std::uint8_t)std::clamp( int( target_->getGlobalAlpha() * target_->getSubfeatureAlphaPoints() ), 0, 255 ) );
40 }
41 };
42
43 template <bool IsPrimary>
44 class WrappedModelSubobjectPart<IsPrimary, ObjectLines> : public ObjectLines, public virtual RenderWrapObject::BasicWrapperTarget<FeatureObject>
45 {
46 public:
47 float getLineWidth() const override
48 {
49 const_cast<WrappedModelSubobjectPart &>( *this ).setLineWidth( IsPrimary ? target_->getLineWidth() : target_->getSubfeatureLineWidth() );
51 }
52
54 {
55 if ( !IsPrimary )
56 const_cast<WrappedModelSubobjectPart &>( *this ).setGlobalAlpha( (std::uint8_t)std::clamp( int( target_->getGlobalAlpha() * target_->getSubfeatureAlphaLines() ), 0, 255 ) );
58 }
59 };
60
61 template <bool IsPrimary>
62 class WrappedModelSubobjectPart<IsPrimary, ObjectMesh> : public ObjectMesh, public virtual RenderWrapObject::BasicWrapperTarget<FeatureObject>
63 {
64 public:
66 {
67 if ( !IsPrimary )
68 const_cast<WrappedModelSubobjectPart &>( *this ).setGlobalAlpha( (std::uint8_t)std::clamp( int( target_->getGlobalAlpha() * target_->getSubfeatureAlphaMesh() ), 0, 255 ) );
70 }
71 };
72}
73
74// Wraps a datamodel object to override some of its visual properties.
75// This is used for stub datamodel objects that we store inside of renderobjects to provide them with models (aka visualization data: meshes, etc).
76// The base template handles `IsPrimary == true`. We have a specialization below for `false`.
77template <bool IsPrimary, typename BaseObjectType>
78class WrappedModelSubobject : public detail::WrappedModelSubobjectPart<IsPrimary, BaseObjectType>, public virtual RenderWrapObject::BasicWrapperTarget<FeatureObject>
79{
80public:
81 bool isSelected() const override
82 {
83 return target_->isSelected();
84 }
85
86 const ViewportProperty<Color>& getFrontColorsForAllViewports( bool selected = true ) const override
87 {
88 return target_->getFrontColorsForAllViewports( selected );
89 }
90
92 {
93 return target_->getBackColorsForAllViewports();
94 }
95
97 {
98 if ( IsPrimary )
99 const_cast<WrappedModelSubobject &>( *this ).setGlobalAlpha( (std::uint8_t)std::clamp( int( target_->getGlobalAlpha() * target_->getMainFeatureAlpha() ), 0, 255 ) );
101 }
102};
103
104template <typename BaseObjectType>
105class WrappedModelSubobject<false, BaseObjectType> : public detail::WrappedModelSubobjectPart<false, BaseObjectType>, public virtual RenderWrapObject::BasicWrapperTarget<FeatureObject>
106{
107public:
108 bool isSelected() const override
109 {
110 return target_->isSelected();
111 }
112
114 {
115 if ( auto p = this->parent() )
116 {
117 if ( auto f = dynamic_cast<const FeatureObject*>( p ) )
118 const_cast<WrappedModelSubobject &>( *this ).setVisibilityMask( f->getVisualizePropertyMask( FeatureVisualizePropertyType::Subfeatures ) );
119 }
120
121 return this->visibilityMask_;
122 }
123
124 const ViewportProperty<Color>& getFrontColorsForAllViewports( bool selected = true ) const override
125 {
126 return dynamic_cast<const FeatureObject&>( *target_ ).getDecorationsColorForAllViewports( selected );
127 }
128};
129
130// A common base class for sub-renderobjects that are combined into the proper features.
131// `ObjectType` is the underlying datamodel object that stores the mesh, e.g. `ObjectMesh`.
132// `RenderObjectType` is the underlying render object, e.g. `RenderMeshObject`.
133// If `IsPrimary` is true, the visual properties are copied from the target datamodel object.
134template <bool IsPrimary, typename ObjectType, typename RenderObjectType>
135class RenderFeatureComponent : public RenderWrapObject::Wrapper<WrappedModelSubobject<IsPrimary, ObjectType>, RenderObjectType>
136{
138public:
139 using Base::Base;
140
141 bool shouldRender( ViewportId viewportId ) const
142 {
143 // Skip rendering the secondary components (aka subfeatures) if they are disabled.
144 if constexpr ( !IsPrimary )
145 {
146 if ( !this->subobject.target_->getVisualizeProperty( FeatureVisualizePropertyType::Subfeatures, viewportId ) )
147 return false;
148 }
149 return true;
150 }
151
152 bool render( const ModelRenderParams& params ) override
153 {
154 if ( !shouldRender( params.viewportId ) )
155 return false;
156 return Base::render( params );
157 }
158
159 void renderPicker( const ModelBaseRenderParams& params, unsigned geomId ) override
160 {
161 if ( !shouldRender( params.viewportId ) )
162 return;
163 return Base::renderPicker( params, geomId );
164 }
165};
166
167// This renderobject draws custom points.
168// If `IsPrimary` is true, the visual properties are copied from the target datamodel object.
169template <bool IsPrimary>
170class RenderFeaturePointsComponent : public RenderFeatureComponent<IsPrimary, ObjectPoints, RenderPointsObject>
171{
173public:
174 using Base::Base;
175 auto& getPoints() { return Base::subobject; }
176};
177
178// This renderobject draws custom lines.
179// If `IsPrimary` is true, the visual properties are copied from the target datamodel object.
180template <bool IsPrimary>
181class RenderFeatureLinesComponent : public RenderFeatureComponent<IsPrimary, ObjectLines, RenderLinesObject>
182{
184public:
185 using Base::Base;
186 auto& getLines() { return Base::subobject; }
187};
188
189// This renderobject draws a custom mesh.
190// If `IsPrimary` is true, the visual properties are copied from the target datamodel object.
191template <bool IsPrimary>
192class RenderFeatureMeshComponent : public RenderFeatureComponent<IsPrimary, ObjectMesh, RenderMeshObject>
193{
195public:
196 using Base::Base;
197 auto& getMesh() { return Base::subobject; }
198};
199
200
201// This renderobject draws a plane normal for the target object.
203{
204public:
205 MRVIEWER_API RenderPlaneNormalComponent( const VisualObject& object );
206
207 MRVIEWER_API bool render( const ModelRenderParams& params ) override;
208 MRVIEWER_API void renderPicker( const ModelBaseRenderParams& params, unsigned geomId ) override;
209};
210
211class RenderPointFeatureObject : public RenderObjectCombinator<RenderDefaultUiObject, RenderFeaturePointsComponent<true>, RenderResetDirtyComponent>
212{
213public:
214 MRVIEWER_API RenderPointFeatureObject( const VisualObject& object );
215
216 MRVIEWER_API std::string getObjectNameString( const VisualObject& object, ViewportId viewportId ) const override;
217};
218
219class RenderLineFeatureObject : public RenderObjectCombinator<RenderDefaultUiObject, RenderFeatureLinesComponent<true>, RenderResetDirtyComponent>
220{
221public:
222 MRVIEWER_API RenderLineFeatureObject( const VisualObject& object );
223
224 MRVIEWER_API std::string getObjectNameString( const VisualObject& object, ViewportId viewportId ) const override;
225};
226
227class RenderCircleFeatureObject : public RenderObjectCombinator<RenderDefaultUiObject, RenderFeatureLinesComponent<true>, RenderFeaturePointsComponent<false>, RenderResetDirtyComponent>
228{
229 const VisualObject* object_ = nullptr;
231public:
232 MRVIEWER_API RenderCircleFeatureObject( const VisualObject& object );
233 MRVIEWER_API void renderUi( const UiRenderParams& params ) override;
234};
235
237 : public RenderObjectCombinator<
238 RenderDefaultUiObject,
239 // Main mesh.
240 RenderFeatureMeshComponent<true>,
241 // Subfeatures.
242 RenderFeatureLinesComponent<false>, RenderFeaturePointsComponent<false>,
243 // Normal mesh.
244 RenderPlaneNormalComponent,
245 RenderResetDirtyComponent
246 >
247{
248public:
249 MRVIEWER_API RenderPlaneFeatureObject( const VisualObject& object );
250
251 MRVIEWER_API std::string getObjectNameString( const VisualObject& object, ViewportId viewportId ) const override;
252};
253
254class RenderSphereFeatureObject : public RenderObjectCombinator<RenderDefaultUiObject, RenderFeatureMeshComponent<true>, RenderFeaturePointsComponent<false>, RenderResetDirtyComponent>
255{
256 const VisualObject* object_ = nullptr;
258public:
259 MRVIEWER_API RenderSphereFeatureObject( const VisualObject& object );
260 MRVIEWER_API void renderUi( const UiRenderParams& params ) override;
261};
262
263class RenderCylinderFeatureObject : public RenderObjectCombinator<RenderDefaultUiObject, RenderFeatureMeshComponent<true>, RenderFeatureLinesComponent<false>, RenderFeaturePointsComponent<false>, RenderResetDirtyComponent>
264{
265 const VisualObject* object_ = nullptr;
268public:
269 MRVIEWER_API RenderCylinderFeatureObject( const VisualObject& object );
270 MRVIEWER_API void renderUi( const UiRenderParams& params ) override;
271};
272
273class RenderConeFeatureObject : public RenderObjectCombinator<RenderDefaultUiObject, RenderFeatureMeshComponent<true>, RenderFeatureLinesComponent<false>, RenderFeaturePointsComponent<false>, RenderResetDirtyComponent>
274{
275 const VisualObject* object_ = nullptr;
279public:
280 MRVIEWER_API RenderConeFeatureObject( const VisualObject& object );
281 MRVIEWER_API void renderUi( const UiRenderParams& params ) override;
282};
283
284}
An interface class which allows feature objects to share setters and getters on their main properties...
Definition MRFeatureObject.h:93
virtual MRMESH_API const ViewportProperty< Color > & getDecorationsColorForAllViewports(bool selected) const
virtual float getLineWidth() const
Definition MRObjectLinesHolder.h:43
Definition MRObjectLines.h:11
Definition MRObjectMesh.h:11
virtual float getPointSize() const
returns size of points on screen in pixels
Definition MRObjectPointsHolder.h:75
Definition MRObjectPoints.h:11
Definition MRRenderDimensions.h:69
Definition MRRenderDimensions.h:97
Definition MRRenderDimensions.h:40
Definition MRRenderFeatureObjects.h:228
MRVIEWER_API void renderUi(const UiRenderParams &params) override
MRVIEWER_API RenderCircleFeatureObject(const VisualObject &object)
Definition MRRenderFeatureObjects.h:274
MRVIEWER_API void renderUi(const UiRenderParams &params) override
MRVIEWER_API RenderConeFeatureObject(const VisualObject &object)
Definition MRRenderFeatureObjects.h:264
MRVIEWER_API void renderUi(const UiRenderParams &params) override
MRVIEWER_API RenderCylinderFeatureObject(const VisualObject &object)
Definition MRRenderFeatureObjects.h:136
void renderPicker(const ModelBaseRenderParams &params, unsigned geomId) override
Definition MRRenderFeatureObjects.h:159
bool render(const ModelRenderParams &params) override
Definition MRRenderFeatureObjects.h:152
bool shouldRender(ViewportId viewportId) const
Definition MRRenderFeatureObjects.h:141
Definition MRRenderFeatureObjects.h:182
auto & getLines()
Definition MRRenderFeatureObjects.h:186
Definition MRRenderFeatureObjects.h:193
auto & getMesh()
Definition MRRenderFeatureObjects.h:197
Definition MRRenderFeatureObjects.h:171
auto & getPoints()
Definition MRRenderFeatureObjects.h:175
Definition MRRenderFeatureObjects.h:220
MRVIEWER_API RenderLineFeatureObject(const VisualObject &object)
MRVIEWER_API std::string getObjectNameString(const VisualObject &object, ViewportId viewportId) const override
Definition MRRenderFeatureObjects.h:247
MRVIEWER_API std::string getObjectNameString(const VisualObject &object, ViewportId viewportId) const override
MRVIEWER_API RenderPlaneFeatureObject(const VisualObject &object)
Definition MRRenderFeatureObjects.h:203
MRVIEWER_API RenderPlaneNormalComponent(const VisualObject &object)
MRVIEWER_API bool render(const ModelRenderParams &params) override
MRVIEWER_API void renderPicker(const ModelBaseRenderParams &params, unsigned geomId) override
Definition MRRenderFeatureObjects.h:212
MRVIEWER_API RenderPointFeatureObject(const VisualObject &object)
MRVIEWER_API std::string getObjectNameString(const VisualObject &object, ViewportId viewportId) const override
Definition MRRenderFeatureObjects.h:255
MRVIEWER_API void renderUi(const UiRenderParams &params) override
MRVIEWER_API RenderSphereFeatureObject(const VisualObject &object)
bool isSelected() const override
Definition MRRenderFeatureObjects.h:108
const ViewportProperty< Color > & getFrontColorsForAllViewports(bool selected=true) const override
Definition MRRenderFeatureObjects.h:124
ViewportMask visibilityMask() const override
Definition MRRenderFeatureObjects.h:113
Definition MRRenderFeatureObjects.h:79
const ViewportProperty< uint8_t > & getGlobalAlphaForAllViewports() const override
Definition MRRenderFeatureObjects.h:96
const ViewportProperty< Color > & getBackColorsForAllViewports() const override
Definition MRRenderFeatureObjects.h:91
const ViewportProperty< Color > & getFrontColorsForAllViewports(bool selected=true) const override
Definition MRRenderFeatureObjects.h:86
bool isSelected() const override
Definition MRRenderFeatureObjects.h:81
const ViewportProperty< uint8_t > & getGlobalAlphaForAllViewports() const override
returns global transparency alpha of object in all viewports
Definition MRRenderFeatureObjects.h:53
float getLineWidth() const override
Definition MRRenderFeatureObjects.h:47
const ViewportProperty< uint8_t > & getGlobalAlphaForAllViewports() const override
returns global transparency alpha of object in all viewports
Definition MRRenderFeatureObjects.h:65
const ViewportProperty< uint8_t > & getGlobalAlphaForAllViewports() const override
returns global transparency alpha of object in all viewports
Definition MRRenderFeatureObjects.h:35
float getPointSize() const override
returns size of points on screen in pixels
Definition MRRenderFeatureObjects.h:29
Definition MRRenderFeatureObjects.h:23
Definition MRIRenderObject.h:170
Definition MRRenderWrapObject.h:28
const ObjectType * target_
Definition MRRenderWrapObject.h:32
Definition MRRenderWrapObject.h:39
Definition MRViewportId.h:16
stores mask of viewport unique identifiers
Definition MRViewportId.h:38
Definition MRViewportProperty.h:17
Visual Object.
Definition MRVisualObject.h:131
virtual MRMESH_API const ViewportProperty< uint8_t > & getGlobalAlphaForAllViewports() const
returns global transparency alpha of object in all viewports
Definition MRRenderFeatureObjects.h:17
ViewportId viewportId
Definition MRIRenderObject.h:36
Definition MRIRenderObject.h:43
Mesh rendering parameters for primary rendering (as opposed to the picker).
Definition MRIRenderObject.h:51
ObjectType subobject
Definition MRRenderWrapObject.h:15
Definition MRIRenderObject.h:107