MeshLib C++ Docs
Loading...
Searching...
No Matches
MRRadiusMeasurementObject.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace MR
6{
7
8// Represents a radius measurement.
10{
11 // The xf encodes the radius: the origin is the center point, and (1,0,0) is the end point.
12 // For non-spherical radiuses, (0,0,1) is the circle normal.
13public:
15
17 RadiusMeasurementObject& operator=( RadiusMeasurementObject&& ) noexcept = default;
18
19 constexpr static const char* TypeName() noexcept { return "RadiusMeasurementObject"; }
20 const char* typeName() const override { return TypeName(); }
21
22 // For `std::make_shared()` in `clone()`.
24
25 std::string getClassName() const override { return "Radius"; }
26 std::string getClassNameInPlural() const override { return "Radii"; }
27
28 MRMESH_API std::shared_ptr<Object> clone() const override;
29 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
30
31 // Get the center in world coordinates.
32 [[nodiscard]] MRMESH_API Vector3f getWorldCenter() const;
33 // Get the center in local coordinates.
34 [[nodiscard]] MRMESH_API Vector3f getLocalCenter() const;
35
36 // The length of this vector is the radius, and the direction is the preferred line drawing direction.
37 [[nodiscard]] MRMESH_API Vector3f getWorldRadiusAsVector() const;
38 [[nodiscard]] MRMESH_API Vector3f getLocalRadiusAsVector() const;
39
40 // The preferred radius normal, for non-spherical radiuses.
41 [[nodiscard]] MRMESH_API Vector3f getWorldNormal() const;
42 [[nodiscard]] MRMESH_API Vector3f getLocalNormal() const;
43
44 MRMESH_API virtual void setLocalCenter( const MR::Vector3f& center );
45 // Sets the local radius vector (the length of which is the radius value),
46 // and also the radius normal (which is ignored for spherical radiuses).
47 // The normal is automatically normalized and made perpendicular to the `radiusVec`.
48 MRMESH_API virtual void setLocalRadiusAsVector( const MR::Vector3f& radiusVec, const Vector3f& normal );
49 // Same, but without a preferred normal.
50 void setLocalRadiusAsVector( const MR::Vector3f& radiusVec ) { setLocalRadiusAsVector( radiusVec, radiusVec.furthestBasisVector() ); }
51
52 // Whether we should draw this as a diameter instead of a radius.
53 [[nodiscard]] bool getDrawAsDiameter() const { return drawAsDiameter_; }
54 MRMESH_API virtual void setDrawAsDiameter( bool value );
55
56 // Whether this is a sphere radius, as opposed to circle/cylinder radius.
57 [[nodiscard]] bool getIsSpherical() const { return isSpherical_; }
58 virtual void setIsSpherical( bool value ) { isSpherical_ = value; }
59
60 // The visual leader line length multiplier, relative to the radius.
61 // You're recommended to set a min absolute value for the resulting length when rendering.
62 [[nodiscard]] float getVisualLengthMultiplier() const { return visualLengthMultiplier_; }
63 virtual void setVisualLengthMultiplier( float value ) { visualLengthMultiplier_ = value; }
64
65 // Computes the radius/diameter value, as if by `getLocalRadiusAsVector()`, possibly multiplied by two if `getDrawAsDiameter()`.
66 [[nodiscard]] MRMESH_API float computeRadiusOrDiameter() const;
67
68 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
69
70protected:
72
73 MRMESH_API void swapBase_( Object& other ) override;
74
75 MRMESH_API void serializeFields_( Json::Value& root ) const override;
76 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
77
78 MRMESH_API void setupRenderObject_() const override;
79
81
82private:
83 // Don't forget to add all the new fields to serialization.
84
85 // Whether we should draw this object as a diameter instead of a radius.
86 bool drawAsDiameter_ = false;
87 // Whether this is a sphere radius, as opposed to circle/cylinder radius.
88 bool isSpherical_ = false;
89
90 // The visual leader line length multiplier, relative to the radius.
91 // You're recommended to set a min absolute value for the resulting length when rendering.
92 float visualLengthMultiplier_ = 2 / 3.f;
93
94 // The cached value for `computeRadiusOrDiameter()`.
95 mutable std::optional<float> cachedValue_;
96};
97
98} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:79
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:83
Definition MRMeasurementObject.h:11
named object in the data model
Definition MRObject.h:60
Definition MRRadiusMeasurementObject.h:10
MRMESH_API std::shared_ptr< Object > shallowClone() const override
MRMESH_API Vector3f getWorldNormal() const
virtual void setVisualLengthMultiplier(float value)
Definition MRRadiusMeasurementObject.h:63
MRMESH_API void swapBase_(Object &other) override
swaps this object with other
MRMESH_API Vector3f getWorldCenter() const
virtual MRMESH_API void setDrawAsDiameter(bool value)
virtual MRMESH_API void setLocalRadiusAsVector(const MR::Vector3f &radiusVec, const Vector3f &normal)
RadiusMeasurementObject(RadiusMeasurementObject &&) noexcept=default
std::string getClassName() const override
return human readable name of subclass
Definition MRRadiusMeasurementObject.h:25
MRMESH_API Vector3f getLocalCenter() const
RadiusMeasurementObject(ProtectedStruct, const RadiusMeasurementObject &obj)
Definition MRRadiusMeasurementObject.h:23
MRMESH_API void setupRenderObject_() const override
MRMESH_API Vector3f getLocalNormal() const
virtual void setIsSpherical(bool value)
Definition MRRadiusMeasurementObject.h:58
void setLocalRadiusAsVector(const MR::Vector3f &radiusVec)
Definition MRRadiusMeasurementObject.h:50
virtual MRMESH_API void setLocalCenter(const MR::Vector3f &center)
float getVisualLengthMultiplier() const
Definition MRRadiusMeasurementObject.h:62
bool getIsSpherical() const
Definition MRRadiusMeasurementObject.h:57
MRMESH_API std::vector< std::string > getInfoLines() const override
return several info lines that can better describe the object in the UI
bool getDrawAsDiameter() const
Definition MRRadiusMeasurementObject.h:53
MRMESH_API Vector3f getWorldRadiusAsVector() const
MRMESH_API Vector3f getLocalRadiusAsVector() const
MRMESH_API float computeRadiusOrDiameter() const
MRMESH_API std::shared_ptr< Object > clone() const override
MRMESH_API void deserializeFields_(const Json::Value &root) override
const char * typeName() const override
Definition MRRadiusMeasurementObject.h:20
std::string getClassNameInPlural() const override
return human readable name of subclass in plural form
Definition MRRadiusMeasurementObject.h:26
MRMESH_API void serializeFields_(Json::Value &root) const override
RadiusMeasurementObject(const RadiusMeasurementObject &other)=default
RadiusMeasurementObject()
Definition MRRadiusMeasurementObject.h:14
MRMESH_API void onWorldXfChanged_() override
Definition MRObject.h:253