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 // For `std::make_shared()` in `clone()`.
23
24 std::string getClassName() const override { return "Angle"; }
25 std::string getClassNameInPlural() const override { return "Angles"; }
26
27 MRMESH_API std::shared_ptr<Object> clone() const override;
28 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
29
30 // Get the angle point in world coordinates.
31 [[nodiscard]] MRMESH_API Vector3f getWorldPoint() const;
32 // Get the angle point in local coordinates.
33 [[nodiscard]] MRMESH_API Vector3f getLocalPoint() const;
34
35 // One of the two rays representing the angle, relative to the starting point.
36 // They can have length != 1 for visualization purposes, it's probably a good idea to take the smaller of the two lengths.
37 [[nodiscard]] MRMESH_API Vector3f getWorldRay( bool second ) const;
38 // Same, but in local coordinates.
39 [[nodiscard]] MRMESH_API Vector3f getLocalRay( bool second ) const;
40
41 // Set the angle point in the local coordinates.
42 MRMESH_API virtual void setLocalPoint( const MR::Vector3f& point );
43 // Set the two rays representing the angle in the local coordinates.
44 // The lengths are preserved.
45 MRMESH_API virtual void setLocalRays( const MR::Vector3f& a, const MR::Vector3f& b );
46
47 // Whether this is a conical angle. The middle line between the rays is preserved, but the rays themselves can be rotated.
48 [[nodiscard]] MRMESH_API bool getIsConical() const;
49 MRMESH_API void setIsConical( bool value );
50
51 // 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.
52 [[nodiscard]] MRMESH_API bool getShouldVisualizeRay( bool second ) const;
53 MRMESH_API void setShouldVisualizeRay( bool second, bool enable );
54
55 // Computes the angle value, as if by `acos(dot(...))` from the two normalized `getWorldRay()`s.
56 [[nodiscard]] MRMESH_API float computeAngle() const;
57
58 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
59
60protected:
62
63 MRMESH_API void swapBase_( Object& other ) override;
64
65 MRMESH_API void serializeFields_( Json::Value& root ) const override;
66 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
67
68 MRMESH_API void setupRenderObject_() const override;
69
71
72private:
73 // Don't forget to add all the new fields to serialization.
74
75 // Whether this is a conical angle. The middle line between the rays is preserved, but the rays themselves can be rotated.
76 bool isConical_ = false;
77
78 // 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.
79 bool shouldVisualizeRay_[2]{};
80
81 // The cached value for `computeAngle()`.
82 mutable std::optional<float> cachedValue_;
83};
84
85} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:83
Definition MRAngleMeasurementObject.h:10
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
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
std::string getClassNameInPlural() const override
return human readable name of subclass in plural form
Definition MRAngleMeasurementObject.h:25
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
std::string getClassName() const override
return human readable name of subclass
Definition MRAngleMeasurementObject.h:24
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)
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:22
MRMESH_API void setupRenderObject_() const override
MRMESH_API void onWorldXfChanged_() override
Definition MRMeasurementObject.h:11
named object in the data model
Definition MRObject.h:60
Definition MRObject.h:253