MeshLib Documentation
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
58template<typename To, typename From>
59To copyContour( const From & from )
60{
61 To res;
62 res.reserve( from.size() );
63 for ( const auto & p : from )
64 res.emplace_back( p );
65 return res;
66}
67
69template<typename To, typename From>
70To copyContours( const From & from )
71{
72 To res;
73 res.reserve( from.size() );
74 for ( const auto & c : from )
75 res.push_back( copyContour<typename To::value_type>( c ) );
76 return res;
77}
78
80
81// Instantiate the templates when generating bindings.
82MR_BIND_TEMPLATE( float calcOrientedArea( const Contour2<float> & contour ) )
83MR_BIND_TEMPLATE( double calcOrientedArea( const Contour2<double> & contour ) )
84MR_BIND_TEMPLATE( Vector3<float> calcOrientedArea( const Contour3<float> & contour ) )
85MR_BIND_TEMPLATE( Vector3<double> calcOrientedArea( const Contour3<double> & contour ) )
86MR_BIND_TEMPLATE( Contour2<float> copyContour( const Contour2<double> & from ) )
87MR_BIND_TEMPLATE( Contour3<float> copyContour( const Contour3<double> & from ) )
88MR_BIND_TEMPLATE( Contour2<double> copyContour( const Contour2<float> & from ) )
89MR_BIND_TEMPLATE( Contour3<double> copyContour( const Contour3<float> & from ) )
90
91} // namespace MR
To copyContours(const From &from)
copy double-contours to float-contours, or vice versa
Definition MRContour.h:70
R calcOrientedArea(const Contour2< T > &contour)
Definition MRContour.h:17
To copyContour(const From &from)
copy double-contour to float-contour, or vice versa
Definition MRContour.h:59
Definition MRCameraOrientationPlugin.h:8
Contour< Vector2< T > > Contour2
Definition MRMesh/MRMeshFwd.h:272
Contour< Vector3< T > > Contour3
Definition MRMesh/MRMeshFwd.h:273
MRMESH_CLASS Vector3
Definition MRMesh/MRMeshFwd.h:137
T area(const Vector3< T > &p, const Vector3< T > &q, const Vector3< T > &r)
computes twice the area of given triangle
Definition MRTriMath.h:160
Definition MRVector2.h:18
Definition MRMesh/MRVector3.h:19