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.
10class MRMESH_CLASS DistanceMeasurementObject : public MeasurementObject, public ObjectComparableWithReference
11{
12 // The xf encodes the distance: the origin is one point, and (1,0,0) is another.
13public:
14 DistanceMeasurementObject() {}
15
16 DistanceMeasurementObject( DistanceMeasurementObject&& ) noexcept = default;
17 DistanceMeasurementObject& operator=( DistanceMeasurementObject&& ) noexcept = default;
18
19 constexpr static const char* StaticTypeName() noexcept { return "DistanceMeasurementObject"; }
20 const char* typeName() const override { return StaticTypeName(); }
21
22 constexpr static const char* StaticClassName() noexcept { return "Distance"; }
23 virtual std::string className() const override { return StaticClassName(); }
24
25 constexpr static const char* StaticClassNameInPlural() noexcept { return "Distances"; }
26 virtual std::string classNameInPlural() const override { return StaticClassNameInPlural(); }
27
28 // For `std::make_shared()` in `clone()`.
29 DistanceMeasurementObject( ProtectedStruct, const DistanceMeasurementObject& obj ) : DistanceMeasurementObject( obj ) {}
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.
64 [[nodiscard]] MRMESH_API DistanceMode getDistanceMode() const;
65 MRMESH_API virtual void setDistanceMode( DistanceMode mode );
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:
84 DistanceMeasurementObject( const DistanceMeasurementObject& other ) = default;
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
93 MRMESH_API void onWorldXfChanged_() override;
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 MRMeshFwd.h:80
#define MRMESH_CLASS
Definition MRMeshFwd.h:87
Definition MRCameraOrientationPlugin.h:8