MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAngleMeasurementObject.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace MR
6{
7
8// Represents an angle measurement.
10{
11 // The xf encodes the two rays: the origin is the angle point, (1,0,0) is the first ray, (0,1,0) is the second ray.
12public:
14
16 AngleMeasurementObject& operator=( AngleMeasurementObject&& ) noexcept = default;
17
18 constexpr static const char* TypeName() noexcept { return "AngleMeasurementObject"; }
19 const char* typeName() const override { return TypeName(); }
20
21 constexpr static const char* ClassName() noexcept { return "Angle"; }
22 virtual std::string className() const override { return ClassName(); }
23
24 constexpr static const char* ClassNameInPlural() noexcept { return "Angles"; }
25 virtual std::string classNameInPlural() const override { return ClassNameInPlural(); }
26
27 // For `std::make_shared()` in `clone()`.
29
30 MRMESH_API std::shared_ptr<Object> clone() const override;
31 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
32
33 // Get the angle point in world coordinates.
34 [[nodiscard]] MRMESH_API Vector3f getWorldPoint() const;
35 // Get the angle point in local coordinates.
36 [[nodiscard]] MRMESH_API Vector3f getLocalPoint() const;
37
38 // One of the two rays representing the angle, relative to the starting point.
39 // They can have length != 1 for visualization purposes, it's probably a good idea to take the smaller of the two lengths.
40 [[nodiscard]] MRMESH_API Vector3f getWorldRay( bool second ) const;
41 // Same, but in local coordinates.
42 [[nodiscard]] MRMESH_API Vector3f getLocalRay( bool second ) const;
43
44 // Set the angle point in the local coordinates.
45 MRMESH_API virtual void setLocalPoint( const MR::Vector3f& point );
46 // Set the two rays representing the angle in the local coordinates.
47 // The lengths are preserved.
48 MRMESH_API virtual void setLocalRays( const MR::Vector3f& a, const MR::Vector3f& b );
49
50 // Whether this is a conical angle. The middle line between the rays is preserved, but the rays themselves can be rotated.
51 [[nodiscard]] MRMESH_API bool getIsConical() const;
52 MRMESH_API void setIsConical( bool value );
53
54 // Whether we should draw a ray from the center point to better visualize the angle. Enable this if there isn't already a line object there.
55 [[nodiscard]] MRMESH_API bool getShouldVisualizeRay( bool second ) const;
56 MRMESH_API void setShouldVisualizeRay( bool second, bool enable );
57
58 // Computes the angle value, as if by `acos(dot(...))` from the two normalized `getWorldRay()`s.
59 [[nodiscard]] MRMESH_API float computeAngle() const;
60
61 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
62
63protected:
65
66 MRMESH_API void swapBase_( Object& other ) override;
67
68 MRMESH_API void serializeFields_( Json::Value& root ) const override;
69 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
70
71 MRMESH_API void setupRenderObject_() const override;
72
74
75private:
76 // Don't forget to add all the new fields to serialization.
77
78 // Whether this is a conical angle. The middle line between the rays is preserved, but the rays themselves can be rotated.
79 bool isConical_ = false;
80
81 // Whether we should draw a ray from the center point to better visualize the angle. Enable this if there isn't already a line object there.
82 bool shouldVisualizeRay_[2]{};
83
84 // The cached value for `computeAngle()`.
85 mutable std::optional<float> cachedValue_;
86};
87
88} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:80
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:84
Definition MRAngleMeasurementObject.h:10
static constexpr const char * ClassNameInPlural() noexcept
Definition MRAngleMeasurementObject.h:24
MRMESH_API Vector3f getWorldPoint() const
MRMESH_API std::shared_ptr< Object > clone() const override
MRMESH_API void swapBase_(Object &other) override
swaps this object with other
virtual std::string className() const override
Definition MRAngleMeasurementObject.h:22
MRMESH_API bool getShouldVisualizeRay(bool second) const
MRMESH_API void serializeFields_(Json::Value &root) const override
MRMESH_API void setIsConical(bool value)
AngleMeasurementObject(const AngleMeasurementObject &other)=default
MRMESH_API void deserializeFields_(const Json::Value &root) override
MRMESH_API bool getIsConical() const
virtual MRMESH_API void setLocalRays(const MR::Vector3f &a, const MR::Vector3f &b)
MRMESH_API Vector3f getWorldRay(bool second) const
AngleMeasurementObject(AngleMeasurementObject &&) noexcept=default
MRMESH_API std::vector< std::string > getInfoLines() const override
return several info lines that can better describe the object in the UI
MRMESH_API std::shared_ptr< Object > shallowClone() const override
AngleMeasurementObject()
Definition MRAngleMeasurementObject.h:13
MRMESH_API float computeAngle() const
const char * typeName() const override
Definition MRAngleMeasurementObject.h:19
MRMESH_API void setShouldVisualizeRay(bool second, bool enable)
virtual std::string classNameInPlural() const override
Definition MRAngleMeasurementObject.h:25
MRMESH_API Vector3f getLocalPoint() const
virtual MRMESH_API void setLocalPoint(const MR::Vector3f &point)
MRMESH_API Vector3f getLocalRay(bool second) const
AngleMeasurementObject(ProtectedStruct, const AngleMeasurementObject &obj)
Definition MRAngleMeasurementObject.h:28
MRMESH_API void setupRenderObject_() const override
MRMESH_API void onWorldXfChanged_() override
static constexpr const char * ClassName() noexcept
Definition MRAngleMeasurementObject.h:21
Definition MRMeasurementObject.h:11
named object in the data model
Definition MRObject.h:62
Definition MRCameraOrientationPlugin.h:8
Definition MRObject.h:279