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