MeshLib C++ Docs
Loading...
Searching...
No Matches
MRDistanceMeasurementObject.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace MR
7{
8
9// Represents a distance measurement.
11{
12 // The xf encodes the distance: the origin is one point, and (1,0,0) is another.
13public:
15
17 DistanceMeasurementObject& operator=( DistanceMeasurementObject&& ) noexcept = default;
18
19 constexpr static const char* TypeName() noexcept { return "DistanceMeasurementObject"; }
20 const char* typeName() const override { return TypeName(); }
21
22 constexpr static const char* ClassName() noexcept { return "Distance"; }
23 virtual std::string className() const override { return ClassName(); }
24
25 constexpr static const char* ClassNameInPlural() noexcept { return "Distances"; }
26 virtual std::string classNameInPlural() const override { return ClassNameInPlural(); }
27
28 // For `std::make_shared()` in `clone()`.
30
31 MRMESH_API std::shared_ptr<Object> clone() const override;
32 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
33
34 // Get the starting point in world coordinates.
35 [[nodiscard]] MRMESH_API Vector3f getWorldPoint() const;
36 // Get the starting point in local coordinates.
37 [[nodiscard]] MRMESH_API Vector3f getLocalPoint() const;
38
39 // The delta from the starting point to the other point.
40 [[nodiscard]] MRMESH_API Vector3f getWorldDelta() const;
41 [[nodiscard]] MRMESH_API Vector3f getLocalDelta() const;
42
43 // Set the start point in the local coordinates.
44 MRMESH_API virtual void setLocalPoint( const MR::Vector3f& point );
45 // Set the delta vector in the local coordinates.
46 MRMESH_API virtual void setLocalDelta( const MR::Vector3f& delta );
47
48 // Whether the distance should be displayed as a negative one.
49 [[nodiscard]] MRMESH_API bool isNegative() const;
50 MRMESH_API virtual void setIsNegative( bool value );
51
52 enum class DistanceMode
53 {
54 euclidean, // Euclidean distance.
55 euclideanWithSignedDeltasPerAxis, // Euclidean distance, but also display per-axis deltas with signs.
56 euclideanWithAbsoluteDeltasPerAxis, // Euclidean distance, but also display per-axis deltas without signs.
57 // Absolute distance in one axis.
58 // This can still be made negative by `setIsNegative(true)`. The point is that the real sign is ignored.
59 xAbsolute,
60 yAbsolute,
61 zAbsolute,
62 };
63 // Whether we should draw the individual X/Y/Z deltas in addition to the distance itself.
66
67 // Computes the distance value. This is affected by `getDistanceMode()`.
68 // In `euclidean`, this is `getWorldDelta().length() * (isNegative() ? -1 : 1)`.
69 [[nodiscard]] MRMESH_API float computeDistance() const;
70
71 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
72
73 // Implement `ObjectComparableWithReference`:
74 [[nodiscard]] MRMESH_API std::size_t numComparableProperties() const override;
75 [[nodiscard]] MRMESH_API std::string_view getComparablePropertyName( std::size_t i ) const override;
76 [[nodiscard]] MRMESH_API std::optional<ComparableProperty> computeComparableProperty( std::size_t i ) const override;
77 [[nodiscard]] MRMESH_API std::optional<ComparisonTolerance> getComparisonTolerence( std::size_t i ) const override;
78 MRMESH_API void setComparisonTolerance( std::size_t i, std::optional<ComparisonTolerance> newTolerance ) override;
79 MRMESH_API std::string_view getComparisonReferenceValueName( std::size_t i ) const override;
80 [[nodiscard]] MRMESH_API ComparisonReferenceValue getComparisonReferenceValue( std::size_t i ) const override;
81 MRMESH_API void setComparisonReferenceValue( std::size_t i, std::optional<ComparisonReferenceValue::Var> value ) override;
82
83protected:
85
86 MRMESH_API void swapBase_( Object& other ) override;
87
88 MRMESH_API void serializeFields_( Json::Value& root ) const override;
89 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
90
91 MRMESH_API void setupRenderObject_() const override;
92
94
95private:
96 // Don't forget to add all the new fields to serialization.
97
98 // Whether the distance should be displayed as a negative one.
99 bool isNegative_ = false;
100
101 // Whether we should draw the individual X/Y/Z deltas in addition to the distance itself.
102 DistanceMode perCoordDeltas_ = DistanceMode::euclidean;
103
104 // The cached value for `computeDistance()`.
105 mutable std::optional<float> cachedValue_;
106
107 std::optional<ComparisonTolerance> tolerance_;
108
109 std::optional<float> referenceValue_;
110};
111
112} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:84
Definition MRDistanceMeasurementObject.h:11
virtual MRMESH_API void setLocalDelta(const MR::Vector3f &delta)
MRMESH_API Vector3f getLocalPoint() const
static constexpr const char * ClassName() noexcept
Definition MRDistanceMeasurementObject.h:22
MRMESH_API void setComparisonTolerance(std::size_t i, std::optional< ComparisonTolerance > newTolerance) override
virtual MRMESH_API void setLocalPoint(const MR::Vector3f &point)
DistanceMeasurementObject(const DistanceMeasurementObject &other)=default
virtual std::string classNameInPlural() const override
Definition MRDistanceMeasurementObject.h:26
MRMESH_API void deserializeFields_(const Json::Value &root) override
MRMESH_API std::string_view getComparisonReferenceValueName(std::size_t i) const override
MRMESH_API float computeDistance() const
DistanceMeasurementObject()
Definition MRDistanceMeasurementObject.h:14
MRMESH_API Vector3f getLocalDelta() const
MRMESH_API void serializeFields_(Json::Value &root) const override
virtual MRMESH_API void setDistanceMode(DistanceMode mode)
MRMESH_API std::optional< ComparisonTolerance > getComparisonTolerence(std::size_t i) const override
const char * typeName() const override
Definition MRDistanceMeasurementObject.h:20
MRMESH_API std::size_t numComparableProperties() const override
MRMESH_API void setupRenderObject_() const override
MRMESH_API Vector3f getWorldPoint() const
DistanceMeasurementObject(DistanceMeasurementObject &&) noexcept=default
MRMESH_API std::shared_ptr< Object > shallowClone() const override
DistanceMeasurementObject(ProtectedStruct, const DistanceMeasurementObject &obj)
Definition MRDistanceMeasurementObject.h:29
MRMESH_API ComparisonReferenceValue getComparisonReferenceValue(std::size_t i) const override
virtual MRMESH_API void setIsNegative(bool value)
MRMESH_API std::string_view getComparablePropertyName(std::size_t i) const override
MRMESH_API Vector3f getWorldDelta() const
MRMESH_API void onWorldXfChanged_() override
MRMESH_API bool isNegative() const
static constexpr const char * ClassNameInPlural() noexcept
Definition MRDistanceMeasurementObject.h:25
MRMESH_API std::optional< ComparableProperty > computeComparableProperty(std::size_t i) const override
MRMESH_API std::shared_ptr< Object > clone() const override
DistanceMode
Definition MRDistanceMeasurementObject.h:53
virtual std::string className() const override
Definition MRDistanceMeasurementObject.h:23
MRMESH_API DistanceMode getDistanceMode() const
MRMESH_API void swapBase_(Object &other) override
swaps this object with other
MRMESH_API void setComparisonReferenceValue(std::size_t i, std::optional< ComparisonReferenceValue::Var > value) override
MRMESH_API std::vector< std::string > getInfoLines() const override
return several info lines that can better describe the object in the UI
Definition MRMeasurementObject.h:11
Definition MRObjectComparableWithReference.h:14
named object in the data model
Definition MRObject.h:62
Definition MRCameraOrientationPlugin.h:8
Definition MRObjectComparableWithReference.h:87
Definition MRObject.h:279