MeshLib C++ Docs
Loading...
Searching...
No Matches
MRFeatureHelpers.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRFeatureObject.h"
5
6#if MR_COMPILING_C_BINDINGS
8#endif
9
10#include <unordered_map>
11#include <unordered_set>
12
13namespace MR
14{
17
18
22{
23 Point,
24 Line,
25 Plane,
26 Circle,
27 Sphere,
29 Cone,
30 _count,
31};
32
34template <FeaturesObjectKind X> struct ObjKindTraits
35{
36};
38{
40 static constexpr std::string_view name = "Point";
41};
43{
45 static constexpr std::string_view name = "Line";
46};
48{
50 static constexpr std::string_view name = "Plane";
51};
53{
55 static constexpr std::string_view name = "Circle";
56};
58{
60 static constexpr std::string_view name = "Sphere";
61};
63{
65 static constexpr std::string_view name = "Cylinder";
66};
68{
70 static constexpr std::string_view name = "Cone";
71};
72
74template <typename F>
75bool forEachObjectKind( F&& func )
76{
77 return[&]<int ...I>( std::integer_sequence<int, I...> )
78 {
79 return ( func( std::integral_constant<FeaturesObjectKind, FeaturesObjectKind( I )>{} ) || ... );
80 }( std::make_integer_sequence<int, int( FeaturesObjectKind::_count )>{} );
81}
82
84template <typename ...P>
85[[nodiscard]] std::shared_ptr<VisualObject> makeObjectFromEnum( FeaturesObjectKind kind, P&&... params )
86{
87 std::shared_ptr<VisualObject> ret;
88 [[maybe_unused]] bool ok = forEachObjectKind( [&] ( auto thisKind )
89 {
90 if ( thisKind.value == kind )
91 {
92 ret = std::make_shared<typename ObjKindTraits<thisKind.value>::type>( std::forward<P>( params )... );
93 return true;
94 }
95 return false;
96 } );
97 assert( ok && "This object type isn't added to `ObjKindTraits`." );
98 return ret;
99}
100
102template <typename ...P>
103[[nodiscard]] std::shared_ptr<VisualObject> makeObjectFromClassName( std::string className, P&&... params )
104{
105 std::shared_ptr<VisualObject> ret;
106 [[maybe_unused]] bool ok = forEachObjectKind( [&] ( auto thisKind )
107 {
108 if ( ObjKindTraits<thisKind.value>::name == className )
109 {
110 ret = std::make_shared<typename ObjKindTraits<thisKind.value>::type>( std::forward<P>( params )... );
111 return true;
112 }
113 return false;
114 } );
115 assert( ok && "This object type isn't added to `ObjKindTraits`." );
116 return ret;
117}
118
119template <typename T>
120concept HasGetNormalMethod = requires( T t )
121{
122 {
123 t.getNormal()
124 } -> std::convertible_to<Vector3f>;
125};
126
127template <typename T>
128concept HasGetDirectionMethod = requires( T t )
129{
130 {
131 t.getDirection()
132 } -> std::convertible_to<Vector3f>;
133};
134
136MRMESH_API std::optional<Vector3f> getFeatureNormal( FeatureObject* feature );
137
139MRMESH_API std::optional<Vector3f> getFeatureDirection( FeatureObject* feature );
140
142MRMESH_API std::unordered_set<std::string> getFeaturesTypeWithNormals();
143
145MRMESH_API std::unordered_set<std::string> getFeaturesTypeWithDirections();
146
147}
Definition MRCircleObject.h:17
Definition MRConeObject.h:22
Definition MRCylinderObject.h:21
An interface class which allows feature objects to share setters and getters on their main properties...
Definition MRFeatureObject.h:96
Definition MRLineObject.h:16
Definition MRPlaneObject.h:15
Definition MRPointObject.h:17
Definition MRSphereObject.h:18
Definition MRFeatureHelpers.h:128
Definition MRFeatureHelpers.h:120
MRMESH_API std::optional< Vector3f > getFeatureDirection(FeatureObject *feature)
Using forEachObjectKind the template collects a list of features for which the method ....
FeaturesObjectKind
Definition MRFeatureHelpers.h:22
MRMESH_API std::optional< Vector3f > getFeatureNormal(FeatureObject *feature)
Using forEachObjectKind the template collects a list of features for which the method ....
MRMESH_API std::unordered_set< std::string > getFeaturesTypeWithDirections()
Try to getDirection from specific feature using forEachObjectKind template. Returns nullopt is ....
bool forEachObjectKind(F &&func)
Calls func, which is ( auto kind ) -> bool, for each known object kind. If it returns true,...
Definition MRFeatureHelpers.h:75
MRMESH_API std::unordered_set< std::string > getFeaturesTypeWithNormals()
Try to getNormal from specific feature using forEachObjectKind template. Returns nullopt is ....
std::shared_ptr< VisualObject > makeObjectFromEnum(FeaturesObjectKind kind, P &&... params)
Allocates an object of type kind, passing params... to its constructor.
Definition MRFeatureHelpers.h:85
std::shared_ptr< VisualObject > makeObjectFromClassName(std::string className, P &&... params)
Allocates an object of type kind, passing params... to its constructor.
Definition MRFeatureHelpers.h:103
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRLine.h:16
Various information about different types of objects.
Definition MRFeatureHelpers.h:35
Definition MRSphere.h:14