39 Vector3f
normal = Vector3f( 1, 0, 0 );
113 using Variant = std::variant<Sphere, ConeSegment, Plane>;
121[[nodiscard]]
inline Primitives::ConeSegment toPrimitive(
const Line3f& line ) {
return { .referencePoint = line.p, .dir = line.d.normalized(), .positiveLength = INFINITY, .negativeLength = INFINITY }; }
122[[nodiscard]]
inline Primitives::ConeSegment toPrimitive(
const LineSegm3f& segm ) {
return { .referencePoint = segm.a, .dir = segm.dir().normalized(), .positiveLength = segm.length() }; }
126 float halfLen = cyl.length / 2;
128 .referencePoint = cyl.
center(),
129 .dir = cyl.direction().normalized(),
130 .positiveSideRadius = cyl.radius, .negativeSideRadius = cyl.radius,
131 .positiveLength = halfLen, .negativeLength = halfLen,
137 .referencePoint = cone.
center(),
138 .dir = cone.direction().normalized(),
139 .positiveSideRadius = std::tan( cone.angle ) * cone.height, .negativeSideRadius = 0,
140 .positiveLength = cone.height, .negativeLength = 0,
247struct Unary<Primitives::ConeSegment>
257template <
typename A,
typename B>
262template <
typename A,
typename B>
265 { t.measure( a, b ) } -> std::same_as<MeasureResult>;
308[[nodiscard]] std::string
name(
const T& primitive )
316template <
typename A,
typename B>
320template <
typename A,
typename B>
331 if ( *dist && ( !std::isfinite( dist->distance ) || !dist->closestPointA.isFinite() || !dist->closestPointB.isFinite() ) )
339 float a = ( dist->closestPointB - dist->closestPointA ).
length();
340 float b = std::abs( dist->distance );
341 return std::abs( a - b ) <= std::max( std::min( a, b ), 0.01f ) * 0.001f;
351 assert( ret.
angle <= ( std::abs( 1 - ret.
angle.
dirA.length() ) < 0.0001f ) );
352 assert( ret.
angle <= ( std::abs( 1 - ret.
angle.
dirB.length() ) < 0.0001f ) );
368 return std::visit( [&](
const auto& elem ){
return (
measure)( elem, b ); }, a );
374 return std::visit( [&](
const auto& elem ){
return (
measure)( a, elem ); }, b );
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:68
length
Definition MRObjectDimensionsEnum.h:14
named object in the data model
Definition MRObject.h:60
Definition MRFeatures.h:317
Definition MRFeatures.h:263
std::variant< Sphere, ConeSegment, Plane > Variant
Definition MRFeatures.h:113
Definition MRFeatures.h:22
std::string name(const T &primitive)
Definition MRFeatures.h:308
MRMESH_API Primitives::ConeSegment primitiveCylinder(const Vector3f &a, const Vector3f &b, float rad)
a and b are centers of the sides.
MeasureResult measure(const A &a, const B &b)
Definition MRFeatures.h:322
MRMESH_API std::shared_ptr< FeatureObject > primitiveToObject(const Primitives::Variant &primitive, float infiniteExtent)
MRMESH_API Primitives::ConeSegment primitiveCircle(const Vector3f &point, const Vector3f &normal, float rad)
normal doesn't need to be normalized.
MRMESH_API std::string_view toString(MeasureResult::Status status)
MRMESH_API Primitives::Sphere transformPrimitive(const AffineXf3f &xf, const Primitives::Sphere &primitive)
MRMESH_API Primitives::ConeSegment primitiveCone(const Vector3f &a, const Vector3f &b, float rad)
a is the center of the base, b is the pointy end.
MRMESH_API std::optional< Primitives::Variant > primitiveFromObjectWithWorldXf(const Object &object)
Primitives::Sphere toPrimitive(const Vector3f &point)
Definition MRFeatures.h:118
MRMESH_API std::optional< Primitives::Variant > primitiveFromObject(const Object &object)
Cylinder3f
Definition MRMesh/MRMeshFwd.h:283
Cone3f
Definition MRMesh/MRMeshFwd.h:288
Definition MRFeatures.h:207
Vector3f pointA
Definition MRFeatures.h:208
Vector3f dirFor(bool b) const
Definition MRFeatures.h:214
MRMESH_API float computeAngleInRadians() const
Vector3f pointB
Definition MRFeatures.h:209
Vector3f dirA
Definition MRFeatures.h:212
bool isSurfaceNormalA
Whether dir{A,B} is a surface normal or a line direction.
Definition MRFeatures.h:217
Vector3f pointFor(bool b) const
Definition MRFeatures.h:210
bool isSurfaceNormalFor(bool b) const
Definition MRFeatures.h:220
Vector3f dirB
Definition MRFeatures.h:213
bool isSurfaceNormalB
Definition MRFeatures.h:218
Definition MRFeatures.h:184
Status status
Definition MRFeatures.h:185
Definition MRFeatures.h:190
Vector3f closestPointA
Definition MRFeatures.h:194
Vector3f closestPointFor(bool b) const
Definition MRFeatures.h:197
Vector3f closestPointB
Definition MRFeatures.h:195
float distance
Definition MRFeatures.h:192
Stores the results of measuring two objects relative to one another.
Definition MRFeatures.h:168
MRMESH_API void swapObjects()
Distance centerDistance
Definition MRFeatures.h:204
Angle angle
Definition MRFeatures.h:224
Distance distance
Definition MRFeatures.h:200
Status
Definition MRFeatures.h:170
@ badRelativeLocation
Can't be computed because of how the objects are located relative to each other.
@ notImplemented
Algorithms set this if this when something isn't yet implemented.
@ notFinite
The result was not finite. This is set automatically if you return non-finite values,...
std::vector< Primitives::Variant > intersections
Definition MRFeatures.h:227
Definition MRFeatures.h:56
friend bool operator==(const ConeSegment &, const ConeSegment &)=default
float length() const
Definition MRFeatures.h:87
MRMESH_API Sphere basePoint(bool negative) const
MRMESH_API ConeSegment extendToInfinity() const
Vector3f referencePoint
Some point on the axis, but not necessarily the true center point. Use centerPoint() for that.
Definition MRFeatures.h:64
MRMESH_API ConeSegment baseCircle(bool negative) const
MRMESH_API ConeSegment untruncateCone() const
float positiveSideRadius
Cap radius in the dir direction.
Definition MRFeatures.h:69
Vector3f dir
The axis direction. Must be normalized.
Definition MRFeatures.h:66
MRMESH_API Sphere centerPoint() const
float negativeLength
Distance from the center to the cap in the direction opposite to dir.
Definition MRFeatures.h:76
MRMESH_API Plane basePlane(bool negative) const
float negativeSideRadius
Cap radius in the direction opposite to dir.
Definition MRFeatures.h:71
MRMESH_API ConeSegment axis() const
float positiveLength
Distance from the center to the cap in the dir direction.
Definition MRFeatures.h:74
bool isZeroRadius() const
Definition MRFeatures.h:83
bool hollow
Definition MRFeatures.h:79
MRMESH_API ConeSegment extendToInfinity(bool negative) const
bool isCircle() const
Definition MRFeatures.h:84
Definition MRFeatures.h:35
Vector3f center
Definition MRFeatures.h:36
MRMESH_API Sphere intersectWithLine(const ConeSegment &line) const
MRMESH_API ConeSegment intersectWithPlane(const Plane &other) const
friend bool operator==(const Plane &, const Plane &)=default
Vector3f normal
Definition MRFeatures.h:39
MRMESH_API MeasureResult measure(const Primitives::ConeSegment &a, const Primitives::ConeSegment &b) const
MRMESH_API MeasureResult measure(const Primitives::ConeSegment &a, const Primitives::Sphere &b) const
MRMESH_API MeasureResult measure(const Primitives::Plane &a, const Primitives::ConeSegment &b) const
MRMESH_API MeasureResult measure(const Primitives::Plane &a, const Primitives::Plane &b) const
MRMESH_API MeasureResult measure(const Primitives::Plane &a, const Primitives::Sphere &b) const
MRMESH_API MeasureResult measure(const Primitives::Sphere &a, const Primitives::Sphere &b) const
Definition MRFeatures.h:258
MRMESH_API std::string name(const Primitives::ConeSegment &prim) const
MRMESH_API std::string name(const Primitives::Plane &prim) const
MRMESH_API std::string name(const Primitives::Sphere &prim) const
Definition MRFeatures.h:240
V center
Definition MRSphere.h:12