Rumba C++ SDK
maquina::NurbsCurve Class Reference

A nurbs curve value. More...

#include <NurbsCurve.h>

Inheritance diagram for maquina::NurbsCurve:
maquina::Points maquina::Shape maquina::Value

Public Types

enum  Mode { Open = 0, Closed = 1, Periodic = 2 }
 The surface curves mode. More...
 
- Public Types inherited from maquina::Shape
enum  Topology { constant =0, vertex, face, face_varying }
 The different attribute topologies. More...
 

Public Member Functions

Access
const BufferConstFloat read_knots () const
 Return the readable curve knots. More...
 
BufferFloat write_knots ()
 Return the writable curve knots. More...
 
const BufferConstFloat read_weights () const
 Return the readable control points weights. More...
 
BufferFloat write_weights ()
 Return the writable control points weights. More...
 
int degree () const
 Return the curve degree. More...
 
Mode mode () const
 Return the curve degree. More...
 
int span () const
 Return the number of span. More...
 
Imath::V2f range () const
 Return the curve parameter visible range. More...
 
Evaluation
Imath::V3f evaluate (float u) const
 Evaluate the curve at a u coordinate. More...
 
Imath::V3d evaluate (double u) const
 Evaluate the curve at a u coordinate in double precision. More...
 
Imath::V3f evaluate_dp (float u) const
 Evaluate the curve position derivatives at a u coordinate. More...
 
void derivatives (float u, int n, std::vector< Imath::V3f > &derivatives) const
 Evaluate the n first derivatives. More...
 
float length (float start, float end, float error=0.001f) const
 Compute the curve length between the start and end u parameters. More...
 
float param_from_length (float length, bool relative=false, float error=0.001f, int max_try=100) const
 Compute the parameter for the given arc length. More...
 
float closest (const Imath::V3f &p, Imath::V3f *r=nullptr, float error=0.001f, int max_try=10, const gsl::span< const Imath::V3f > &cache={}) const
 Compute the curve closest point to p. More...
 
Modifications
void resample (const gsl::span< const float > &knots, int degree)
 Resample a curve. More...
 
void set_range (const Imath::V2f &range)
 Remap the curve knots between new_min and float new_max. More...
 
void reverse ()
 Reverse the control point order. More...
 
bool split (float u, NurbsCurve &lower, NurbsCurve &upper) const
 Split the curve along the u parameter. More...
 
- Public Member Functions inherited from maquina::Points
 Points ()
 Create an empty. More...
 
 Points (const Value &v)
 Cast a Value in Points. More...
 
BufferV3f write_points ()
 Return the points buffer. More...
 
const BufferConstV3f read_points () const
 Return the points buffer. More...
 
size_t point_count () const
 Return the number of points. More...
 
Imath::Box3f bounding_box () const
 Compute the object points bounding box. More...
 
void compute_vertex_normals (BufferV3f &result) const
 Compute and return the vertex normals. More...
 
- Public Member Functions inherited from maquina::Shape
 Shape ()
 
 Shape (const Value &v)
 Cast a Value object in Shape. More...
 
bool has_attribute (const char *attribute_name, Topology topology) const
 Test if the shape has this attribute. More...
 
template<typename T >
write_attribute (const char *attribute_name, Topology topology)
 Get a write access to an attribute. More...
 
const Value read_attribute (const char *attribute_name, Topology topology) const
 Get a read access to an attribute. More...
 
bool set_attribute (const char *name, Topology topology, const Value &value)
 Set an attribute. More...
 
bool remove_attribute (const char *name, Topology topology)
 Remove an attribute. More...
 
void finalize ()
 Finalize the shape after deformation. More...
 
size_t topology_size (Topology topology) const
 Get the number of faces, edges or vertices. More...
 
Attributes read_attributes () const
 Return a read-only attribute iteration. More...
 
- Public Member Functions inherited from maquina::Value
 Value ()
 
 Value (Value &&other)=default
 
 Value (const Value &other)=default
 
Valueoperator= (Value &&other)=default
 
Valueoperator= (const Value &other)=default
 
virtual ~Value ()=default
 
Value duplicate () const
 Duplicate the value. More...
 
bool as_bool () const
 Returns the value as a bool. More...
 
int as_int () const
 Returns the value as an integer. More...
 
float as_float () const
 Returns the value as a float. More...
 
double as_double () const
 Returns the value as a double. More...
 
const std::string & as_string () const
 Returns the value as a string. More...
 
std::wstring as_wstring () const
 Returns the value as a wstring. More...
 
Imath::V2f as_V2f () const
 Returns the value as a V2f. More...
 
Imath::V3f as_V3f () const
 Returns the value as a V3f. More...
 
Imath::V4f as_V4f () const
 Returns the value as a V4f. More...
 
const Imath::V2das_V2d () const
 Returns the value as a V2d. More...
 
const Imath::V3das_V3d () const
 Returns the value as a V3d. More...
 
const Imath::V4das_V4d () const
 Returns the value as a V4d. More...
 
const Imath::V2ias_V2i () const
 Returns the value as a V2i. More...
 
const Imath::V3ias_V3i () const
 Returns the value as a V3i. More...
 
const Imath::V4ias_V4i () const
 Returns the value as a V4i. More...
 
Imath::M44f as_M44f () const
 Returns the value as a M44f. More...
 
const Imath::M44das_M44d () const
 Returns the value as a M44d. More...
 
const Imath::Box3fas_Box3f () const
 Returns the value as a Box3f. More...
 
const Imath::Color4fas_Color4f () const
 Returns the value as a Color4f. More...
 
Imath::Quatf as_Quatf () const
 Returns the value as a Quatf. More...
 
const Imath::Quatdas_Quatd () const
 Returns the value as a Quatd. More...
 
std::shared_ptr< const UserDataas_user_data () const
 Returns the value as a user data. More...
 
StringView type_name () const
 Return the type name of the Value. More...
 
virtual bool has_node_delegate () const
 Check if this value can produces a NodeDelegate. More...
 
virtual std::shared_ptr< NodeDelegatenode_delegate (const std::shared_ptr< NodeDelegate > &parent, const StringView &name) const
 
bool operator== (const Value &o) const
 Compare the two values. More...
 
bool operator!= (const Value &o) const
 
bool is_instance (const char *value_type_name) const
 Check if this type derives from another value type. More...
 
 operator bool () const
 
 Value (bool)
 Create a boolean value. More...
 
 Value (int)
 Create an integer value. More...
 
 Value (float)
 Create a float value. More...
 
 Value (double)
 Create a double value (stored in a float right now) More...
 
 Value (const char *string)
 Create a string value. More...
 
 Value (const wchar_t *string)
 Create a string value. More...
 
 Value (const std::string &string)
 Create a string value. More...
 
 Value (const std::wstring &string)
 Create a wide string value. More...
 
 Value (const Imath::V2f &)
 Create a Imath::V2f value. More...
 
 Value (const Imath::V3f &)
 Create a Imath::V3f value. More...
 
 Value (const Imath::V4f &)
 Create a Imath::V4f value. More...
 
 Value (const Imath::V2d &)
 Create a Imath::V2d value. More...
 
 Value (const Imath::V3d &)
 Create a Imath::V3d value. More...
 
 Value (const Imath::V4d &)
 Create a Imath::V4d value. More...
 
 Value (const Imath::V2i &)
 Create a Imath::V2i value. More...
 
 Value (const Imath::V3i &)
 Create a Imath::V3i value. More...
 
 Value (const Imath::V4i &)
 Create a Imath::V4i value. More...
 
 Value (const Imath::Color4f &)
 Create a Imath::Color4f value. More...
 
 Value (const Imath::M44f &)
 Create a Imath::M44f value. More...
 
 Value (const Imath::M44d &)
 Create a Imath::M44d value. More...
 
 Value (const Imath::Box3f &)
 Create a Imath::Box3f value. More...
 
 Value (const Imath::Quatf &)
 Create a Imath::Quatf value. More...
 
 Value (const Imath::Quatd &)
 Create a Imath::Quatd value. More...
 
 Value (const std::shared_ptr< const UserData > &user_data)
 Create a user data value. More...
 

Static Public Attributes

static const NurbsCurve default_value
 The default value. More...
 
- Static Public Attributes inherited from maquina::Points
static const Points default_value
 The default value. More...
 
- Static Public Attributes inherited from maquina::Value
static const Value default_value
 The default value. More...
 

Construction

 NurbsCurve ()
 Create an empty curve. More...
 
 NurbsCurve (const BufferConstV3f &points, const BufferConstFloat &knots, int degree, Mode mode)
 Create a curve. More...
 
 NurbsCurve (const BufferConstV3f &points, const BufferConstFloat &knots, const BufferConstFloat &weights, int degree, Mode mode)
 
 NurbsCurve (const Value &v)
 Cast a Value in NurbsCurve. More...
 
static NurbsCurve fit_closed (const BufferConstV3f &points, const BufferConstFloat &points_parameter, const BufferConstFloat &knots, int degree)
 Create a closed curve which fits the points. More...
 
static NurbsCurve fit_open (const BufferConstV3f &points, const BufferConstFloat &points_parameter, const BufferConstFloat &knots, int degree)
 Create an open curve which fits the points. More...
 
static NurbsCurve fit_open2 (const BufferConstV3f &points, const BufferConstFloat &points_parameter, const BufferConstFloat &knots, int degree)
 Create an open curve which fits the points, with constraint first and last control vertices. More...
 
static NurbsCurve fit_open (const BufferConstV3f &points, const BufferConstFloat &points_parameter, const BufferConstFloat &knots, const Imath::V3f &d0, const Imath::V3f &dn, int degree)
 Create an open curve which fits the points using starting and ending differentials. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from maquina::Value
static bool validate_type_name (const char *type_name)
 Return true if the name is a valid type name. More...
 
static Value get_default_value (const char *type_name)
 Return a default value for a given type. More...
 

Detailed Description

A nurbs curve value.

This object is a standard nurbs curve with no other parameter than a position.

Member Enumeration Documentation

◆ Mode

The surface curves mode.

Enumerator
Open 

The curve is open.

Closed 

The curve is closed, the first and last vertices should stay the same.

Periodic 

The curve is periodic, the N-degree first vertices should be the same as the N-degree last ones.

Constructor & Destructor Documentation

◆ NurbsCurve() [1/4]

maquina::NurbsCurve::NurbsCurve ( )

Create an empty curve.

◆ NurbsCurve() [2/4]

maquina::NurbsCurve::NurbsCurve ( const BufferConstV3f points,
const BufferConstFloat knots,
int  degree,
Mode  mode 
)

Create a curve.

◆ NurbsCurve() [3/4]

maquina::NurbsCurve::NurbsCurve ( const BufferConstV3f points,
const BufferConstFloat knots,
const BufferConstFloat weights,
int  degree,
Mode  mode 
)

◆ NurbsCurve() [4/4]

maquina::NurbsCurve::NurbsCurve ( const Value v)

Cast a Value in NurbsCurve.

If v is not a NurbsCurve object, this object will be an empty curve.

Member Function Documentation

◆ closest()

float maquina::NurbsCurve::closest ( const Imath::V3f p,
Imath::V3f r = nullptr,
float  error = 0.001f,
int  max_try = 10,
const gsl::span< const Imath::V3f > &  cache = {} 
) const

Compute the curve closest point to p.

Returns the curve parameter value of the closest point. To speedup many closest queries on the same curve, it is possible to provide a cache of the subdivided curve. The subdivision must be done from start=knots[degree] to end=knots[knots.size()-degree-1] using a uniform parameter step. The default subdivision step count is 6*(knots.size()-degree*2).

Parameters
pThe position to project on the curve
rIf not null, it is filled with the closest curve position
errorThe minimum error in vertex space
max_tryMaximum numbr of try
cacheAn optionnal nurbs subdivision cache

◆ degree()

int maquina::NurbsCurve::degree ( ) const

Return the curve degree.

◆ derivatives()

void maquina::NurbsCurve::derivatives ( float  u,
int  n,
std::vector< Imath::V3f > &  derivatives 
) const

Evaluate the n first derivatives.

derivatives[0] is the position. derivatives[1] is the first derivative. derivatives[degree] is the last derivative.

◆ evaluate() [1/2]

Imath::V3f maquina::NurbsCurve::evaluate ( float  u) const

Evaluate the curve at a u coordinate.

◆ evaluate() [2/2]

Imath::V3d maquina::NurbsCurve::evaluate ( double  u) const

Evaluate the curve at a u coordinate in double precision.

◆ evaluate_dp()

Imath::V3f maquina::NurbsCurve::evaluate_dp ( float  u) const

Evaluate the curve position derivatives at a u coordinate.

Return the dp/du vector which may not be normalized.

◆ fit_closed()

static NurbsCurve maquina::NurbsCurve::fit_closed ( const BufferConstV3f points,
const BufferConstFloat points_parameter,
const BufferConstFloat knots,
int  degree 
)
static

Create a closed curve which fits the points.

Points must have 'degree' points wrapped around. points are the points to fit with a nurbs curve. points_parameter is the nurbs curve parameter value of the points. knots are the nurbs curve knots. knots.size() must be points.size()+degree+1. degree is the degree of the returned curve.

◆ fit_open() [1/2]

static NurbsCurve maquina::NurbsCurve::fit_open ( const BufferConstV3f points,
const BufferConstFloat points_parameter,
const BufferConstFloat knots,
int  degree 
)
static

Create an open curve which fits the points.

points are the points to fit with a nurbs curve. points_parameter is the nurbs curve parameter value of the points. knots are the nurbs curve knots. knots.size() must be points.size()+degree+3. degree is the degree of the returned curve.

◆ fit_open() [2/2]

static NurbsCurve maquina::NurbsCurve::fit_open ( const BufferConstV3f points,
const BufferConstFloat points_parameter,
const BufferConstFloat knots,
const Imath::V3f d0,
const Imath::V3f dn,
int  degree 
)
static

Create an open curve which fits the points using starting and ending differentials.

points are the points to fit with a nurbs curve. points_parameter is the nurbs curve parameter value of the points. knots are the nurbs curve knots. knots.size() must be points.size()+degree+3. d0 is the starting curve differential. dn is the ending curve differential. degree is the degree of the returned curve.

◆ fit_open2()

static NurbsCurve maquina::NurbsCurve::fit_open2 ( const BufferConstV3f points,
const BufferConstFloat points_parameter,
const BufferConstFloat knots,
int  degree 
)
static

Create an open curve which fits the points, with constraint first and last control vertices.

points are the points to fit with a nurbs curve. points_parameter is the nurbs curve parameter value of the points. knots are the nurbs curve knots. knots.size() must be points.size()+degree+3. degree is the degree of the returned curve. The returned curve has n=points.size() control points P, with P1=lerp(P0, P2, 1/3) and Pn-1=lerp(Pn-3, Pn-1, 2/3). points[1] and points[n-2] are ignored.

◆ length()

float maquina::NurbsCurve::length ( float  start,
float  end,
float  error = 0.001f 
) const

Compute the curve length between the start and end u parameters.

Parameters
startThe starting u parameter of the arc
endThe ending u parameter of the arc
errorThe relative accepted error of the result

◆ mode()

Mode maquina::NurbsCurve::mode ( ) const

Return the curve degree.

◆ param_from_length()

float maquina::NurbsCurve::param_from_length ( float  length,
bool  relative = false,
float  error = 0.001f,
int  max_try = 100 
) const

Compute the parameter for the given arc length.

Parameters
lengthThe arc length for which we want a parameter
relativeIf false length is expressed in the curve's length unit, if true, length is a ratio of the curve's length between [0,1].
errorThe relative accepted error of the result
max_tryMaximum try to reach the error

◆ range()

Imath::V2f maquina::NurbsCurve::range ( ) const

Return the curve parameter visible range.

For periodic curves, this is not the same than the first and last knots.

◆ read_knots()

const BufferConstFloat maquina::NurbsCurve::read_knots ( ) const

Return the readable curve knots.

◆ read_weights()

const BufferConstFloat maquina::NurbsCurve::read_weights ( ) const

Return the readable control points weights.

◆ resample()

void maquina::NurbsCurve::resample ( const gsl::span< const float > &  knots,
int  degree 
)

Resample a curve.

Modify the curve knots and degree and rebuild the curve in order to keep its shape if possible.

◆ reverse()

void maquina::NurbsCurve::reverse ( )

Reverse the control point order.

◆ set_range()

void maquina::NurbsCurve::set_range ( const Imath::V2f range)

Remap the curve knots between new_min and float new_max.

This has no effect on the shape of the curve.

◆ span()

int maquina::NurbsCurve::span ( ) const

Return the number of span.

◆ split()

bool maquina::NurbsCurve::split ( float  u,
NurbsCurve lower,
NurbsCurve upper 
) const

Split the curve along the u parameter.

Returns false if the split is not possible, else return true and fill the lower and upper curves with the two curve parts.

◆ write_knots()

BufferFloat maquina::NurbsCurve::write_knots ( )

Return the writable curve knots.

◆ write_weights()

BufferFloat maquina::NurbsCurve::write_weights ( )

Return the writable control points weights.

Member Data Documentation

◆ default_value

const NurbsCurve maquina::NurbsCurve::default_value
static

The default value.


The documentation for this class was generated from the following file: