MeshLib Documentation
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
27 MRMESH_API std::shared_ptr<Object> clone() const override;
28 MRMESH_API std::shared_ptr<Object> shallowClone() const override;
29
30 // Get the center in world coordinates.
31 [[nodiscard]] MRMESH_API Vector3f getWorldCenter() const;
32 // Get the center in local coordinates.
33 [[nodiscard]] MRMESH_API Vector3f getLocalCenter() const;
34
35 // The length of this vector is the radius, and the direction is the preferred line drawing direction.
36 [[nodiscard]] MRMESH_API Vector3f getWorldRadiusAsVector() const;
37 [[nodiscard]] MRMESH_API Vector3f getLocalRadiusAsVector() const;
38
39 // The preferred radius normal, for non-spherical radiuses.
40 [[nodiscard]] MRMESH_API Vector3f getWorldNormal() const;
41 [[nodiscard]] MRMESH_API Vector3f getLocalNormal() const;
42
43 MRMESH_API virtual void setLocalCenter( const MR::Vector3f& center );
44 // Sets the local radius vector (the length of which is the radius value),
45 // and also the radius normal (which is ignored for spherical radiuses).
46 // The normal is automatically normalized and made perpendicular to the `radiusVec`.
47 MRMESH_API virtual void setLocalRadiusAsVector( const MR::Vector3f& radiusVec, const Vector3f& normal );
48 // Same, but without a preferred normal.
49 void setLocalRadiusAsVector( const MR::Vector3f& radiusVec ) { setLocalRadiusAsVector( radiusVec, radiusVec.furthestBasisVector() ); }
50
51 // Whether we should draw this as a diameter instead of a radius.
52 [[nodiscard]] bool getDrawAsDiameter() const { return drawAsDiameter_; }
53 MRMESH_API virtual void setDrawAsDiameter( bool value );
54
55 // Whether this is a sphere radius, as opposed to circle/cylinder radius.
56 [[nodiscard]] bool getIsSpherical() const { return isSpherical_; }
57 virtual void setIsSpherical( bool value ) { isSpherical_ = value; }
58
59 // The visual leader line length multiplier, relative to the radius.
60 // You're recommended to set a min absolute value for the resulting length when rendering.
61 [[nodiscard]] float getVisualLengthMultiplier() const { return visualLengthMultiplier_; }
62 virtual void setVisualLengthMultiplier( float value ) { visualLengthMultiplier_ = value; }
63
64 // Computes the radius/diameter value, as if by `getLocalRadiusAsVector()`, possibly multiplied by two if `getDrawAsDiameter()`.
65 [[nodiscard]] MRMESH_API float computeRadiusOrDiameter() const;
66
67 [[nodiscard]] MRMESH_API std::vector<std::string> getInfoLines() const override;
68
69protected:
71
72 MRMESH_API void swapBase_( Object& other ) override;
73
74 MRMESH_API void serializeFields_( Json::Value& root ) const override;
75 MRMESH_API void deserializeFields_( const Json::Value& root ) override;
76
77 MRMESH_API void setupRenderObject_() const override;
78
80
81private:
82 // Don't forget to add all the new fields to serialization.
83
84 // Whether we should draw this object as a diameter instead of a radius.
85 bool drawAsDiameter_ = false;
86 // Whether this is a sphere radius, as opposed to circle/cylinder radius.
87 bool isSpherical_ = false;
88
89 // The visual leader line length multiplier, relative to the radius.
90 // You're recommended to set a min absolute value for the resulting length when rendering.
91 float visualLengthMultiplier_ = 2 / 3.f;
92
93 // The cached value for `computeRadiusOrDiameter()`.
94 mutable std::optional<float> cachedValue_;
95};
96
97} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
#define MRMESH_CLASS
Definition MRMesh/MRMeshFwd.h:50
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:62
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:57
void setLocalRadiusAsVector(const MR::Vector3f &radiusVec)
Definition MRRadiusMeasurementObject.h:49
virtual MRMESH_API void setLocalCenter(const MR::Vector3f &center)
float getVisualLengthMultiplier() const
Definition MRRadiusMeasurementObject.h:61
bool getIsSpherical() const
Definition MRRadiusMeasurementObject.h:56
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:52
MRMESH_API Vector3f getWorldRadiusAsVector() const
MRMESH_API void propagateWorldXfChangedSignal_() override
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
MRMESH_API void serializeFields_(Json::Value &root) const override
RadiusMeasurementObject(const RadiusMeasurementObject &other)=default
RadiusMeasurementObject()
Definition MRRadiusMeasurementObject.h:14
Definition MRCameraOrientationPlugin.h:8
Definition MRObject.h:246