MeshLib C++ Docs
Loading...
Searching...
No Matches
MRClosestWeightedPoint.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRMeshTriPoint.h"
5#include "MRPch/MRBindingMacros.h"
6#include <cfloat>
7
8namespace MR
9{
10
11struct PointAndDistance
12{
14 VertId vId;
15
17 float dist = 0;
18
20 [[nodiscard]] bool valid() const { return vId.valid(); }
21 [[nodiscard]] explicit operator bool() const { return vId.valid(); }
22};
23
24struct MeshPointAndDistance
25{
27 Vector3f loc;
28
30 MeshTriPoint mtp;
31
33 float eucledeanDist = 0;
34
36 float w = 0;
37
42 bool bidirectionalOrOutside = true;
43
45 [[nodiscard]] float bidirDist() const
46 {
47 return eucledeanDist - w;
48 }
49
53 [[nodiscard]] float dist() const
54 {
56 }
57
59 auto operator <=> ( const MeshPointAndDistance& other ) const
60 {
61 if ( bidirectionalOrOutside && other.bidirectionalOrOutside )
62 return eucledeanDist - w <=> other.eucledeanDist - other.w;
63 if ( bidirectionalOrOutside != other.bidirectionalOrOutside )
64 return eucledeanDist <=> other.eucledeanDist;
65 return eucledeanDist + ( bidirectionalOrOutside ? -w : w ) <=>
66 other.eucledeanDist + ( other.bidirectionalOrOutside ? -other.w : other.w );
67 }
68
70 [[nodiscard]] bool valid() const { return mtp.valid(); }
71 [[nodiscard]] explicit operator bool() const { return mtp.valid(); }
72};
73
74struct DistanceFromWeightedPointsParams
75{
77 VertMetric pointWeight;
78
81 float minWeight = 0;
82
85 float maxWeight = 0;
86
89 float maxWeightGrad = FLT_MAX;
90
95 bool bidirectionalMode = true;
96
97 // To allow passing Python lambdas into `pointWeight`.
98 MR_BIND_PREFER_UNLOCK_GIL_WHEN_USED_AS_PARAM
99};
100
101struct DistanceFromWeightedPointsComputeParams : DistanceFromWeightedPointsParams
102{
105 float minBidirDist = -FLT_MAX; // default 0 here does not work for negative distances
106
108 float maxBidirDist = FLT_MAX;
109};
110
115 const AABBTreePoints& tree, const DistanceFromWeightedPointsComputeParams& params );
116
121 const Mesh& mesh, const DistanceFromWeightedPointsComputeParams& params );
122
123} //namespace MR
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRAABBTreePoints.h:16
Definition MRClosestWeightedPoint.h:102
new unsafe ref bool bidirectionalMode
new unsafe ref float maxWeightGrad
new unsafe MR.Std.Function_FloatFuncFromMRVertId pointWeight
Definition MRClosestWeightedPoint.h:25
new unsafe ref bool bidirectionalOrOutside
new unsafe ref float w
new unsafe ref float eucledeanDist
new unsafe ref MR.Vector3f loc
new unsafe MR.MeshTriPoint mtp
Definition MRMesh/MRMesh.h:23
Definition MRClosestWeightedPoint.h:12
new unsafe ref MR.VertId vId
new unsafe ref float dist
Definition MRCameraOrientationPlugin.h:8
MRMESH_API PointAndDistance findClosestWeightedPoint(const Vector3f &loc, const AABBTreePoints &tree, const DistanceFromWeightedPointsComputeParams &params)
MRMESH_API MeshPointAndDistance findClosestWeightedMeshPoint(const Vector3f &loc, const Mesh &mesh, const DistanceFromWeightedPointsComputeParams &params)