MeshLib C++ Docs
Loading...
Searching...
No Matches
MRObjectComparableWithReference.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMesh/MRMeshFwd.h"
4#include "MRMesh/MRVector3.h"
5
6#include <optional>
7#include <variant>
8
9namespace MR
10{
11
12// A base class for a data-model object that is a feature/measurement that can be compared between two models.
14{
15 public:
16 virtual ~ObjectComparableWithReference() = default;
17
18 // We have no member variables, so lack of the implicit copy operations wouldn't matter, but MSVC warns on this, so we have to be explicit.
24
25
26 // Comparing properties:
27
28 // When comparing this object with a reference, how many different properties can we output?
29 [[nodiscard]] virtual std::size_t numComparableProperties() const = 0;
30
31 // `i` goes up to `numComparableProperties()`, exclusive.
32 [[nodiscard]] virtual std::string_view getComparablePropertyName( std::size_t i ) const = 0;
33
35 {
36 float value = 0;
37
38 // This can be null if the reference value isn't set, or something else is wrong.
39 // This can match whatever is set via `get/setComparisonReferenceValue()`, but not necessarily.
40 // E.g. for point coordinates, those functions act on the reference coordinates (three optional floats), but this number is always zero,
41 // and the `value` is the distance to those coordinates.
42 std::optional<float> referenceValue = 0.f;
43 };
44
45 // Compute a value of a property.
46 // Compare `value` and `referenceValue` using the tolerance.
47 // This can return null if the value is impossible to compute, e.g. for some types if the reference isn't set (e.g. if
48 // we're computing the distance to a reference point).
49 // `i` goes up to `numComparableProperties()`, exclusive.
50 [[nodiscard]] virtual std::optional<ComparableProperty> computeComparableProperty( std::size_t i ) const = 0;
51
52
53 // Tolerances:
54
56 {
57 // How much larger can this value be compared to the reference?
58 float positive = 0;
59 // How much smaller can this value be compared to the reference?
60 // This number should normally be zero or negative.
61 float negative = 0;
62 };
63
64 // Returns the tolerance for a specific comparable property. Returns null if not set.
65 // `i` goes up to `numComparableProperties()`, exclusive.
66 [[nodiscard]] virtual std::optional<ComparisonTolerance> getComparisonTolerence( std::size_t i ) const = 0;
67
68 // Sets the tolerance for a specific comparable property.
69 // `i` goes up to `numComparableProperties()`, exclusive.
70 virtual void setComparisonTolerance( std::size_t i, std::optional<ComparisonTolerance> newTolerance ) = 0;
71
72 // If true, indicates that the getter will always return zero negative tolerance, and the setter will ignore the negative tolerance.
73 // `i` goes up to `numComparableProperties()`, exclusive.
74 [[nodiscard]] virtual bool comparisonToleranceIsAlwaysOnlyPositive( std::size_t i ) const { (void)i; return false; }
75
76
77 // Reference values:
78
79 // The number and types of reference values can be entirely different compared to `numComparableProperties()`.
80 [[nodiscard]] virtual std::size_t numComparisonReferenceValues() const { return numComparableProperties(); }
81
82 // `i` goes up to `numComparisonReferenceValues()`, exclusive.
83 [[nodiscard]] virtual std::string_view getComparisonReferenceValueName( std::size_t i ) const = 0;
84
85 // This can't be `std::optional<Var>`, because we still need the variant to know the correct type.
87 {
88 using Var = std::variant<float, Vector3f>;
89
90 bool isSet = false;
91
92 // If `isSet == false`, this will hold zeroes, or some other default values.
94 };
95
96 // Returns the internal reference value.
97 // If the value wasn't set yet (as indicated by `isSet == false`), you can still use the returned variant to get the expected type.
98 // `i` goes up to `numComparisonReferenceValues()`, exclusive.
99 [[nodiscard]] virtual ComparisonReferenceValue getComparisonReferenceValue( std::size_t i ) const = 0;
100 // Sets the internal reference value. Makes `hasComparisonReferenceValue()` return true.
101 // If you pass nullopt, removes this reference value.
102 // Only a certain variant type is legal to pass, depending on the derived class and the index. Use `getComparisonReferenceValue()` to determine that type.
103 // `i` goes up to `numComparisonReferenceValues()`, exclusive.
104 virtual void setComparisonReferenceValue( std::size_t i, std::optional<ComparisonReferenceValue::Var> value ) = 0;
105 void setComparisonReferenceVal( std::size_t i, const ComparisonReferenceValue& value )
106 {
107 if ( value.isSet )
108 setComparisonReferenceValue( i, value.var );
109 else
110 setComparisonReferenceValue( i, std::nullopt );
111 }
112};
113
114}
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:84
Definition MRObjectComparableWithReference.h:14
void setComparisonReferenceVal(std::size_t i, const ComparisonReferenceValue &value)
Definition MRObjectComparableWithReference.h:105
virtual ComparisonReferenceValue getComparisonReferenceValue(std::size_t i) const =0
virtual std::optional< ComparableProperty > computeComparableProperty(std::size_t i) const =0
ObjectComparableWithReference & operator=(ObjectComparableWithReference &&)=default
virtual std::size_t numComparableProperties() const =0
virtual void setComparisonTolerance(std::size_t i, std::optional< ComparisonTolerance > newTolerance)=0
virtual std::size_t numComparisonReferenceValues() const
Definition MRObjectComparableWithReference.h:80
virtual ~ObjectComparableWithReference()=default
ObjectComparableWithReference(ObjectComparableWithReference &&)=default
virtual bool comparisonToleranceIsAlwaysOnlyPositive(std::size_t i) const
Definition MRObjectComparableWithReference.h:74
virtual std::string_view getComparisonReferenceValueName(std::size_t i) const =0
virtual void setComparisonReferenceValue(std::size_t i, std::optional< ComparisonReferenceValue::Var > value)=0
ObjectComparableWithReference & operator=(const ObjectComparableWithReference &)=default
virtual std::string_view getComparablePropertyName(std::size_t i) const =0
virtual std::optional< ComparisonTolerance > getComparisonTolerence(std::size_t i) const =0
ObjectComparableWithReference(const ObjectComparableWithReference &)=default
Definition MRCameraOrientationPlugin.h:8
Definition MRObjectComparableWithReference.h:35
Definition MRObjectComparableWithReference.h:87
bool isSet
Definition MRObjectComparableWithReference.h:90
std::variant< float, Vector3f > Var
Definition MRObjectComparableWithReference.h:88
Var var
Definition MRObjectComparableWithReference.h:93
Definition MRObjectComparableWithReference.h:56