MeshLib C++ Docs
Loading...
Searching...
No Matches
MRDistanceMapParams.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMatrix.h"
4#include "MRBitSet.h"
5#include "MRAffineXf3.h"
6#include "MRVector2.h"
7#include "MRBox.h"
8#include "MRMeshPart.h"
9
10namespace MR
11{
12
15
16struct MeshToDistanceMapParams
17{
19 MeshToDistanceMapParams() = default;
20
27 MRMESH_API MeshToDistanceMapParams( const Vector3f& direction, const Vector2i& resolution, const MeshPart& mp, bool usePreciseBoundingBox = false );
28 MRMESH_API MeshToDistanceMapParams( const Vector3f& direction, const Vector2f& pixelSize, const MeshPart& mp, bool usePreciseBoundingBox = false );
29
35 MRMESH_API MeshToDistanceMapParams( const Matrix3f& rotation, const Vector3f& origin, const Vector2i& resolution, const Vector2f& size );
36 MRMESH_API MeshToDistanceMapParams( const Matrix3f& rotation, const Vector3f& origin, const Vector2f& pixelSize, const Vector2i& resolution );
37
45 MRMESH_API MeshToDistanceMapParams( const Matrix3f& rotation, const Vector2i& resolution, const MeshPart& mp, bool usePreciseBoundingBox = false );
46
55 MRMESH_API MeshToDistanceMapParams( const AffineXf3f& xf, const Vector2i& resolution, const Vector2f& size );
56 MRMESH_API MeshToDistanceMapParams( const AffineXf3f& xf, const Vector2f& pixelSize, const Vector2i& resolution );
57
59 operator AffineXf3f() const
60 {
61 return { Matrix3f::fromColumns( xRange / float( resolution.x ), yRange / float( resolution.y ), direction ), orgPoint };
62 }
63 AffineXf3f xf() const { return operator AffineXf3f(); }
64
65 Vector3f xRange = Vector3f( 1.f, 0.f, 0.f );
66 Vector3f yRange = Vector3f( 0.f, 1.f, 0.f );
67 Vector3f direction = Vector3f( 0.f, 0.f, 1.f );
68 Vector3f orgPoint = Vector3f( 0.f, 0.f, 0.f );
69
72 void setDistanceLimits( float min, float max )
73 {
74 useDistanceLimits = true;
75 minValue = min;
76 maxValue = max;
77 }
78 bool useDistanceLimits = false;
79 bool allowNegativeValues = false;
80 float minValue = 0.f;
81 float maxValue = 0.f;
82
83 Vector2i resolution;
84
85private:
86 std::pair<Vector3f,Vector2f> orgSizeFromMeshPart_( const Matrix3f& rotation, const MeshPart& mp, bool presiceBox ) const;
87 void initFromSize_( const AffineXf3f& worldOrientation, const Vector2i& resolution, const Vector2f& size );
88};
89
90struct DistanceMapToWorld;
91
93struct ContourToDistanceMapParams
94{
97
99 MRMESH_API ContourToDistanceMapParams( const Vector2i& resolution, const Vector2f& oriPoint,
100 const Vector2f& areaSize, bool withSign = false );
101
103 MRMESH_API ContourToDistanceMapParams( const Vector2i& resolution, const Box2f& box, bool withSign = false );
104
106 MRMESH_API ContourToDistanceMapParams( const Vector2i& resolution, const Contours2f& contours,
107 float offset, bool withSign = false );
108
110 MRMESH_API ContourToDistanceMapParams( float pixelSize, const Contours2f& contours,
111 float offset, bool withSign = false );
112
113 MRMESH_API explicit ContourToDistanceMapParams( const DistanceMapToWorld& toWorld );
116 Vector2f toWorld( Vector2f point ) const
117 {
118 return orgPoint + Vector2f{ pixelSize.x * point.x, pixelSize.y * point.y };
119 }
120
122 operator AffineXf3f() const
123 {
125 }
126 AffineXf3f xf() const { return operator AffineXf3f(); }
127
128 Vector2f pixelSize{ 1.F, 1.F };
129 Vector2i resolution{ 1, 1 };
130 Vector2f orgPoint{ 0.F, 0.F };
131 bool withSign{ false };
132};
133
135struct DistanceMapToWorld
136{
138 DistanceMapToWorld() = default;
139
141 MRMESH_API DistanceMapToWorld( const MeshToDistanceMapParams& params );
142
144 MRMESH_API DistanceMapToWorld( const ContourToDistanceMapParams& params );
145
147 DistanceMapToWorld( const AffineXf3f & xf )
148 : orgPoint( xf.b )
149 , pixelXVec( xf.A.col( 0 ) )
150 , pixelYVec( xf.A.col( 1 ) )
151 , direction( xf.A.col( 2 ) )
152 {
153 }
154
155
160 Vector3f toWorld( float x, float y, float depth ) const
161 {
162 return orgPoint + x * pixelXVec + y * pixelYVec + depth * direction;
163 }
164
166 operator AffineXf3f() const
167 {
169 }
170 AffineXf3f xf() const { return operator AffineXf3f(); }
171
173 Vector3f orgPoint;
177 Vector3f pixelXVec{ Vector3f::plusX() };
181 Vector3f pixelYVec{ Vector3f::plusY() };
184 Vector3f direction{ Vector3f::plusZ() };
185};
186
188struct DistanceMapLoadSettings
189{
191 DistanceMapToWorld* distanceMapToWorld = nullptr;
193 ProgressCallback progress;
194};
195
197struct DistanceMapSaveSettings
198{
200 const AffineXf3f* xf = nullptr;
202 ProgressCallback progress;
203};
204
206
207} // namespace MR
#define MRMESH_API
Definition MRMeshFwd.h:80
new unsafe ref MR.Vector2f orgPoint
new unsafe ref MR.Vector2i resolution
new unsafe ref MR.Vector2f pixelSize
new unsafe MR.Std.Function_BoolFuncFromFloat progress
new unsafe MR.? DistanceMapToWorld distanceMapToWorld
new unsafe MR.? ConstBox_AffineXf3f xf
new unsafe MR.Std.Function_BoolFuncFromFloat progress
new unsafe ref MR.Vector3f direction
new unsafe ref MR.Vector3f pixelXVec
new unsafe ref MR.Vector3f pixelYVec
new unsafe ref MR.Vector3f orgPoint
new unsafe ref MR.Vector3f direction
new unsafe ref MR.Vector3f yRange
new unsafe ref bool allowNegativeValues
new unsafe ref MR.Vector3f orgPoint
new unsafe ref MR.Vector3f xRange
new unsafe ref float minValue
new unsafe ref bool useDistanceLimits
new unsafe ref float maxValue
unsafe void setDistanceLimits(float min, float max)
auto depth(const Box< V > &box)
returns size along z axis
Definition MRMesh/MRBox.h:368
constexpr auto max(A a, B b)
Definition MRImGuiVectorOperators.h:143
constexpr auto min(A a, B b)
Definition MRImGuiVectorOperators.h:141
MRVIEWER_API void point(Element elem, const Params &params, ImVec2 point)
Definition MRCameraOrientationPlugin.h:8
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:29
static unsafe MR.Matrix3f fromColumns(in MR.Vector3f x, in MR.Vector3f y, in MR.Vector3f z)
static MR.Vector3f plusX()
static MR.Vector3f plusY()
static MR.Vector3f plusZ()