MeshLib
 
Loading...
Searching...
No Matches
MROffsetContours.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#include "MRConstants.h"
4#include "MRExpected.h"
5#include <functional>
6#include <string>
7
8namespace MR
9{
10
12{
13 // -1 means unknown index
14 int contourId{ -1 };
15 // -1 means unknown index
16 int vertId{ -1 };
17 bool valid() const { return contourId >= 0 && vertId >= 0; }
18};
19
21{
22 // Should be always valid
23 // index of lower corresponding origin point on input contour
25 // index of lower corresponding destination point on input contour
27 // index of upper corresponding origin point on input contour
29 // index of upper corresponding destination point on input contour
31
32 // ratio of intersection point on lOrg->lDest segment
33 // 0.0 -> lOrg
34 // 1.0 -> lDest
35 float lRatio{ 0.0f };
36 // ratio of intersection point on uOrg->uDest segment
37 // 0.0 -> uOrg
38 // 1.0 -> uDest
39 float uRatio{ 0.0f };
40
41 bool valid() const { return lOrg.valid(); }
42 bool isIntersection() const { return lDest.valid(); }
43};
44using OffsetContoursVertMap = std::vector<OffsetContoursOrigins>;
45using OffsetContoursVertMaps = std::vector<OffsetContoursVertMap>;
46
48{
50 enum class Type
51 {
52 Offset,
53 Shell
54 } type{ Type::Offset };
55
57 enum class EndType
58 {
59 Round,
60 Cut
61 } endType{ EndType::Round };
62
64 enum class CornerType
65 {
66 Round,
67 Sharp
68 } cornerType{ CornerType::Round };
69
71 float minAnglePrecision = PI_F / 9.0f; // 20 deg
73 float maxSharpAngle = PI_F * 2.0f / 3.0f; // 120 deg
74
77};
78
80[[nodiscard]] MRMESH_API Expected<Contours2f> offsetContours( const Contours2f& contours, float offset,
81 const OffsetContoursParams& params = {} );
82
83
84using ContoursVariableOffset = std::function<float( int, int )>;
87 ContoursVariableOffset offset, const OffsetContoursParams& params = {} );
88
91{
94 using OriginZCallback = std::function<float( const Contours2f& offsetCont, const OffsetContourIndex& offsetIndex, const OffsetContoursOrigins& origingContourMapoing)>;
98};
99
101[[nodiscard]] MRMESH_API Expected<Contours3f> offsetContours( const Contours3f& contours, float offset,
102 const OffsetContoursParams& params = {}, const OffsetContoursRestoreZParams& zParmas = {} );
103
106 ContoursVariableOffset offset, const OffsetContoursParams& params = {}, const OffsetContoursRestoreZParams& zParmas = {} );
107
108}
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRCameraOrientationPlugin.h:7
std::function< float(int, int)> ContoursVariableOffset
Definition MROffsetContours.h:84
std::vector< OffsetContoursVertMap > OffsetContoursVertMaps
Definition MROffsetContours.h:45
tl::expected< T, E > Expected
Definition MRExpected.h:49
Contours2< float > Contours2f
Definition MRMesh/MRMeshFwd.h:282
std::vector< OffsetContoursOrigins > OffsetContoursVertMap
Definition MROffsetContours.h:44
Contours3< float > Contours3f
Definition MRMesh/MRMeshFwd.h:284
MRMESH_API Expected< Contours2f > offsetContours(const Contours2f &contours, float offset, const OffsetContoursParams &params={})
offsets 2d contours in plane
Definition MROffsetContours.h:12
int vertId
Definition MROffsetContours.h:16
bool valid() const
Definition MROffsetContours.h:17
int contourId
Definition MROffsetContours.h:14
Definition MROffsetContours.h:21
float lRatio
Definition MROffsetContours.h:35
OffsetContourIndex uDest
Definition MROffsetContours.h:30
OffsetContourIndex uOrg
Definition MROffsetContours.h:28
bool valid() const
Definition MROffsetContours.h:41
OffsetContourIndex lDest
Definition MROffsetContours.h:26
float uRatio
Definition MROffsetContours.h:39
bool isIntersection() const
Definition MROffsetContours.h:42
OffsetContourIndex lOrg
Definition MROffsetContours.h:24
Definition MROffsetContours.h:48
EndType
type of offsetting on ends of non-closed contours
Definition MROffsetContours.h:58
@ Round
creates round ends (use minAnglePrecision)
@ Cut
creates sharp end (same as Round with minAnglePrecision < 180 deg)
float minAnglePrecision
precision of round corners and ends
Definition MROffsetContours.h:71
float maxSharpAngle
limit for sharp corners connection
Definition MROffsetContours.h:73
CornerType
type of positive offset curve in corners
Definition MROffsetContours.h:65
@ Sharp
creates sharp connected corner (use maxSharpAngle as limit)
@ Round
creates round corners (use minAnglePrecision)
OffsetContoursVertMaps * indicesMap
optional output that maps result contour ids to input contour ids
Definition MROffsetContours.h:76
enum MR::OffsetContoursParams::Type Offset
enum MR::OffsetContoursParams::EndType Round
Type
type of offset
Definition MROffsetContours.h:51
@ Offset
One-side signed offset, requires closed contours.
Parameters of restoring Z coordinate of XY offset 3d contours.
Definition MROffsetContours.h:91
std::function< float(const Contours2f &offsetCont, const OffsetContourIndex &offsetIndex, const OffsetContoursOrigins &origingContourMapoing)> OriginZCallback
Definition MROffsetContours.h:94
OriginZCallback zCallback
Definition MROffsetContours.h:95
int relaxIterations
if > 0 z coordinate will be relaxed this many iterations
Definition MROffsetContours.h:97