MeshLib C++ Docs
Loading...
Searching...
No Matches
MRContour.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRPch/MRBindingMacros.h"
4#include "MRMeshFwd.h"
5#include "MRVector3.h"
6
7namespace MR
8{
9
13
16template<typename T, typename R = T>
17R calcOrientedArea( const Contour2<T> & contour )
18{
19 if ( contour.size() < 3 )
20 return 0;
21
22 R area = 0;
23 Vector2<R> p0{ contour[0] };
24
25 for ( int i = 2; i < contour.size(); ++i )
26 {
27 Vector2<R> p1{ contour[i - 1] };
28 Vector2<R> p2{ contour[i] };
29 area += cross( p2 - p0, p1 - p0 );
30 }
31
32 return R(0.5) * area;
33}
34
38template<typename T, typename R = T>
40{
41 if ( contour.size() < 3 )
42 return {};
43
45 Vector3<R> p0{ contour[0] };
46
47 for ( int i = 2; i < contour.size(); ++i )
48 {
49 Vector3<R> p1{ contour[i - 1] };
50 Vector3<R> p2{ contour[i] };
51 area += cross( p1 - p0, p2 - p0 );
52 }
53
54 return R(0.5) * area;
55}
56
59template<typename V, typename R = typename V::ValueType>
60R calcLength( const Contour<V>& contour )
61{
62 R l = R( 0 );
63 for ( int i = 1; i < contour.size(); ++i )
64 l += R( ( contour[i] - contour[i - 1] ).length() );
65 return l;
66}
67
71template<typename To, typename From>
72MR_BIND_IGNORE To convertContour( const From & from )
73{
74 To res;
75 res.reserve( from.size() );
76 for ( const auto & p : from )
77 res.emplace_back( p );
78 return res;
79}
80
84template<typename To, typename From>
85MR_BIND_IGNORE To convertContours( const From & from )
86{
87 To res;
88 res.reserve( from.size() );
89 for ( const auto & c : from )
90 res.push_back( convertContour<typename To::value_type>( c ) );
91 return res;
92}
93
95
96// Instantiate the templates when generating bindings.
97MR_BIND_TEMPLATE( float calcOrientedArea( const Contour2<float> & contour ) )
98MR_BIND_TEMPLATE( double calcOrientedArea( const Contour2<double> & contour ) )
99MR_BIND_TEMPLATE( float calcLength( const Contour2<float>& contour ) )
100MR_BIND_TEMPLATE( double calcLength( const Contour2<double>& contour ) )
101MR_BIND_TEMPLATE( float calcLength( const Contour3<float>& contour ) )
102MR_BIND_TEMPLATE( double calcLength( const Contour3<double>& contour ) )
103MR_BIND_TEMPLATE( Vector3<float> calcOrientedArea( const Contour3<float> & contour ) )
104MR_BIND_TEMPLATE( Vector3<double> calcOrientedArea( const Contour3<double> & contour ) )
105
106
107template <typename From> [[nodiscard]] Contour2f convertContourTo2f( const From &from ) { return convertContour<Contour2f>( from ); }
108template <typename From> [[nodiscard]] Contour3f convertContourTo3f( const From &from ) { return convertContour<Contour3f>( from ); }
109template <typename From> [[nodiscard]] Contour2d convertContourTo2d( const From &from ) { return convertContour<Contour2d>( from ); }
110template <typename From> [[nodiscard]] Contour3d convertContourTo3d( const From &from ) { return convertContour<Contour3d>( from ); }
111
112template <typename From> [[nodiscard]] Contours2f convertContoursTo2f( const From &from ) { return convertContours<Contours2f>( from ); }
113template <typename From> [[nodiscard]] Contours3f convertContoursTo3f( const From &from ) { return convertContours<Contours3f>( from ); }
114template <typename From> [[nodiscard]] Contours2d convertContoursTo2d( const From &from ) { return convertContours<Contours2d>( from ); }
115template <typename From> [[nodiscard]] Contours3d convertContoursTo3d( const From &from ) { return convertContours<Contours3d>( from ); }
116
117MR_BIND_TEMPLATE( Contour2f convertContourTo2f( const Contour2f & from ) )
118MR_BIND_TEMPLATE( Contour2f convertContourTo2f( const Contour2d & from ) )
119MR_BIND_TEMPLATE( Contour2f convertContourTo2f( const Contour3f & from ) )
120MR_BIND_TEMPLATE( Contour2f convertContourTo2f( const Contour3d & from ) )
121MR_BIND_TEMPLATE( Contour2d convertContourTo2d( const Contour2f & from ) )
122MR_BIND_TEMPLATE( Contour2d convertContourTo2d( const Contour2d & from ) )
123MR_BIND_TEMPLATE( Contour2d convertContourTo2d( const Contour3f & from ) )
124MR_BIND_TEMPLATE( Contour2d convertContourTo2d( const Contour3d & from ) )
125MR_BIND_TEMPLATE( Contour3f convertContourTo3f( const Contour2f & from ) )
126MR_BIND_TEMPLATE( Contour3f convertContourTo3f( const Contour2d & from ) )
127MR_BIND_TEMPLATE( Contour3f convertContourTo3f( const Contour3f & from ) )
128MR_BIND_TEMPLATE( Contour3f convertContourTo3f( const Contour3d & from ) )
129MR_BIND_TEMPLATE( Contour3d convertContourTo3d( const Contour2f & from ) )
130MR_BIND_TEMPLATE( Contour3d convertContourTo3d( const Contour2d & from ) )
131MR_BIND_TEMPLATE( Contour3d convertContourTo3d( const Contour3f & from ) )
132MR_BIND_TEMPLATE( Contour3d convertContourTo3d( const Contour3d & from ) )
133
134MR_BIND_TEMPLATE( Contours2f convertContoursTo2f( const Contours2f & from ) )
135MR_BIND_TEMPLATE( Contours2f convertContoursTo2f( const Contours2d & from ) )
136MR_BIND_TEMPLATE( Contours2f convertContoursTo2f( const Contours3f & from ) )
137MR_BIND_TEMPLATE( Contours2f convertContoursTo2f( const Contours3d & from ) )
138MR_BIND_TEMPLATE( Contours2d convertContoursTo2d( const Contours2f & from ) )
139MR_BIND_TEMPLATE( Contours2d convertContoursTo2d( const Contours2d & from ) )
140MR_BIND_TEMPLATE( Contours2d convertContoursTo2d( const Contours3f & from ) )
141MR_BIND_TEMPLATE( Contours2d convertContoursTo2d( const Contours3d & from ) )
142MR_BIND_TEMPLATE( Contours3f convertContoursTo3f( const Contours2f & from ) )
143MR_BIND_TEMPLATE( Contours3f convertContoursTo3f( const Contours2d & from ) )
144MR_BIND_TEMPLATE( Contours3f convertContoursTo3f( const Contours3f & from ) )
145MR_BIND_TEMPLATE( Contours3f convertContoursTo3f( const Contours3d & from ) )
146MR_BIND_TEMPLATE( Contours3d convertContoursTo3d( const Contours2f & from ) )
147MR_BIND_TEMPLATE( Contours3d convertContoursTo3d( const Contours2d & from ) )
148MR_BIND_TEMPLATE( Contours3d convertContoursTo3d( const Contours3f & from ) )
149MR_BIND_TEMPLATE( Contours3d convertContoursTo3d( const Contours3d & from ) )
150
151} // namespace MR
length
Definition MRObjectDimensionsEnum.h:14
Contour
Definition MRObjectLabel.h:16
R calcLength(const Contour< V > &contour)
Definition MRContour.h:60
MR_BIND_IGNORE To convertContour(const From &from)
Definition MRContour.h:72
MR_BIND_IGNORE To convertContours(const From &from)
Definition MRContour.h:85
R calcOrientedArea(const Contour2< T > &contour)
Definition MRContour.h:17
Definition MRCameraOrientationPlugin.h:8
float area(const MeshTopology &topology, const VertCoords &points, FaceId f)
returns the area of given face
Definition MRMeshMath.h:166
Contour3< double > Contour3d
Definition MRMesh/MRMeshFwd.h:316
Contour2f convertContourTo2f(const From &from)
Definition MRContour.h:107
Contour2< double > Contour2d
Definition MRMesh/MRMeshFwd.h:314
Contours2d convertContoursTo2d(const From &from)
Definition MRContour.h:114
Contour2< float > Contour2f
Definition MRMesh/MRMeshFwd.h:315
Contours2< double > Contours2d
Definition MRMesh/MRMeshFwd.h:322
Contours2f convertContoursTo2f(const From &from)
Definition MRContour.h:112
Contours2< float > Contours2f
Definition MRMesh/MRMeshFwd.h:323
Contour< Vector2< T > > Contour2
Definition MRMesh/MRMeshFwd.h:312
Contour< Vector3< T > > Contour3
Definition MRMesh/MRMeshFwd.h:313
Contours3f convertContoursTo3f(const From &from)
Definition MRContour.h:113
Contour3f convertContourTo3f(const From &from)
Definition MRContour.h:108
Contour2d convertContourTo2d(const From &from)
Definition MRContour.h:109
MRMESH_CLASS Vector3
Definition MRMesh/MRMeshFwd.h:177
Contours3< float > Contours3f
Definition MRMesh/MRMeshFwd.h:325
Contour3d convertContourTo3d(const From &from)
Definition MRContour.h:110
Contour3< float > Contour3f
Definition MRMesh/MRMeshFwd.h:317
Contours3d convertContoursTo3d(const From &from)
Definition MRContour.h:115
Contours3< double > Contours3d
Definition MRMesh/MRMeshFwd.h:324
Definition MRVector2.h:25
Definition MRMesh/MRVector3.h:26