MeshLib Documentation
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
17{
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
91
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
107 float offset, bool withSign = false );
108
111 float offset, bool withSign = false );
112
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 {
124 return { Matrix3f::fromColumns( pixelSize.x * Vector3f::plusX(), pixelSize.y * Vector3f::plusY(), Vector3f::plusZ() ), { orgPoint.x, orgPoint.y, 0.F } };
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
136{
139
142
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 {
168 return { Matrix3f::fromColumns( pixelXVec, pixelYVec, direction ), orgPoint };
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
188
189} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
auto depth(const Box< V > &box)
returns size along z axis
Definition MRMesh/MRBox.h:261
Definition MRCameraOrientationPlugin.h:8
ImVec2 size(const ViewportRectangle &rect)
Definition MRViewport.h:32
Contours2< float > Contours2f
Definition MRMesh/MRMeshFwd.h:283
Structure with parameters to generate DistanceMap by Contours.
Definition MRDistanceMapParams.h:94
MRMESH_API ContourToDistanceMapParams(const Vector2i &resolution, const Vector2f &oriPoint, const Vector2f &areaSize, bool withSign=false)
Ctor, calculating pixelSize by areaSize & dmapSize.
MRMESH_API ContourToDistanceMapParams(float pixelSize, const Contours2f &contours, float offset, bool withSign=false)
Ctor, calculating resolution & oriPoint by contours box + offset.
AffineXf3f xf() const
Definition MRDistanceMapParams.h:126
Vector2i resolution
distance map size
Definition MRDistanceMapParams.h:129
Vector2f orgPoint
coordinates of origin area corner
Definition MRDistanceMapParams.h:130
ContourToDistanceMapParams()=default
Default ctor, make sure to fill all fields manually.
MRMESH_API ContourToDistanceMapParams(const Vector2i &resolution, const Box2f &box, bool withSign=false)
Ctor, calculating pixelSize & oriPoint by box parameters.
Vector2f toWorld(Vector2f point) const
Definition MRDistanceMapParams.h:116
MRMESH_API ContourToDistanceMapParams(const DistanceMapToWorld &toWorld)
MRMESH_API ContourToDistanceMapParams(const Vector2i &resolution, const Contours2f &contours, float offset, bool withSign=false)
Ctor, calculating pixelSize & oriPoint by contours box + offset.
Vector2f pixelSize
pixel size
Definition MRDistanceMapParams.h:128
bool withSign
allows calculate negative values of distance (inside closed and correctly oriented (CW) contours)
Definition MRDistanceMapParams.h:131
This structure store data to transform distance map to world coordinates.
Definition MRDistanceMapParams.h:136
AffineXf3f xf() const
Definition MRDistanceMapParams.h:170
DistanceMapToWorld()=default
Default ctor init all fields with zeros, make sure to fill them manually.
Vector3f orgPoint
world coordinates of distance map origin corner
Definition MRDistanceMapParams.h:173
MRMESH_API DistanceMapToWorld(const ContourToDistanceMapParams &params)
Init fields by ContourToDistanceMapParams struct.
DistanceMapToWorld(const AffineXf3f &xf)
Converts from AffineXf3f.
Definition MRDistanceMapParams.h:147
Vector3f pixelXVec
Definition MRDistanceMapParams.h:177
Vector3f direction
Definition MRDistanceMapParams.h:184
Vector3f toWorld(float x, float y, float depth) const
Definition MRDistanceMapParams.h:160
Vector3f pixelYVec
Definition MRDistanceMapParams.h:181
MRMESH_API DistanceMapToWorld(const MeshToDistanceMapParams &params)
Init fields by MeshToDistanceMapParams struct.
Definition MRDistanceMapParams.h:17
float minValue
Using of this parameter depends on useDistanceLimits.
Definition MRDistanceMapParams.h:80
MRMESH_API MeshToDistanceMapParams(const Matrix3f &rotation, const Vector3f &origin, const Vector2i &resolution, const Vector2f &size)
MRMESH_API MeshToDistanceMapParams(const Matrix3f &rotation, const Vector3f &origin, const Vector2f &pixelSize, const Vector2i &resolution)
float maxValue
Using of this parameter depends on useDistanceLimits.
Definition MRDistanceMapParams.h:81
Vector3f direction
direction of intersection ray
Definition MRDistanceMapParams.h:67
Vector3f yRange
Cartesian range vector between distance map borders in Y direction.
Definition MRDistanceMapParams.h:66
void setDistanceLimits(float min, float max)
Definition MRDistanceMapParams.h:72
Vector2i resolution
resolution of distance map
Definition MRDistanceMapParams.h:83
MRMESH_API MeshToDistanceMapParams(const AffineXf3f &xf, const Vector2f &pixelSize, const Vector2i &resolution)
MRMESH_API MeshToDistanceMapParams(const Matrix3f &rotation, const Vector2i &resolution, const MeshPart &mp, bool usePreciseBoundingBox=false)
bool allowNegativeValues
allows to find intersections in backward to direction vector with negative values
Definition MRDistanceMapParams.h:79
Vector3f orgPoint
location of (0,0) pixel with value 0.f
Definition MRDistanceMapParams.h:68
Vector3f xRange
Cartesian range vector between distance map borders in X direction.
Definition MRDistanceMapParams.h:65
MRMESH_API MeshToDistanceMapParams(const Vector3f &direction, const Vector2i &resolution, const MeshPart &mp, bool usePreciseBoundingBox=false)
bool useDistanceLimits
out of limits intersections will be set to non-valid
Definition MRDistanceMapParams.h:78
MeshToDistanceMapParams()=default
default constructor. Manual params initialization is required:
AffineXf3f xf() const
Definition MRDistanceMapParams.h:63
MRMESH_API MeshToDistanceMapParams(const Vector3f &direction, const Vector2f &pixelSize, const MeshPart &mp, bool usePreciseBoundingBox=false)
MRMESH_API MeshToDistanceMapParams(const AffineXf3f &xf, const Vector2i &resolution, const Vector2f &size)