Skip to content
Proyectos

Acerca de

Biblioteca de C++ para curvas y superficies NURBS

Herramientas de desarrollo

Cómo se miden estas cifras

Crecimiento de estrellas medido

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
Recopilando historial

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

tinynurbs

Build Status

This is a lightweight header-only C++14 library for Non-Uniform Rational B-Spline curves and surfaces. The API is simple to use and the code is readable while being efficient.

Some of the main features include:

  • Supports non-rational and rational curves and surfaces of any order
  • Evaluate point and derivatives of any order
  • Knot insertion, splitting without affecting the original shape
  • Wavefront OBJ format I/O

The library is under development.

Dependencies

  • glm (version 0.9.9 where PR #584 is merged is required since tinynurbs uses the glm::vec<dim, T> type)
  • C++14 compliant compiler

Usage

The entire API consists of free functions named curve* and surface* which accept a Curve / RationalCurve and Surface / RationalSurface object, respectively. Some example usage is given below.

Create a non-rational planar curve:

tinynurbs::Curve<float> crv; // Planar curve using float32
crv.control_points = {glm::vec3(-1, 0, 0), // std::vector of 3D points
                      glm::vec3(0, 1, 0),
                      glm::vec3(1, 0, 0)
                     };
crv.knots = {0, 0, 0, 1, 1, 1}; // std::vector of floats
crv.degree = 2;

Check if created curve is valid:

if (!tinynurbs::curveIsValid(crv)) {
    // check if degree, knots and control points are configured as per
    // #knots == #control points + degree + 1
}

Evaluate point and tangent on curve:

glm::vec3 pt = tinynurbs::curvePoint(crv, 0.f);
// Outputs a point [-1, 0]
glm::vec3 tgt = tinynurbs::curveTangent(crv, 0.5f);
// Outputs a vector [1, 0]

Insert a single knot at u=0.25 and double knot at u=0.75:

crv = tinynurbs::curveKnotInsert(crv, 0.25);
crv = tinynurbs::curveKnotInsert(crv, 0.75, 2);

Left: original curve, Right: after knot insertion

curve knotinsert

Write the curve to an OBJ file:

tinynurbs::curveSaveOBJ("output_curve.obj", crv);

creates a file with the following contents:

v -1 0 0 1
v -0.75 0.5 0 1
v 0 1.25 0 1
v 0.5 0.75 0 1
v 0.75 0.5 0 1
v 1 0 0 1
cstype bspline
deg 2
curv 0 1 1 2 3 4 5 6
parm u 0 0 0 0.25 0.75 0.75 1 1 1
end

Create a rational surface shaped like a hemisphere:

tinynurbs::RationalSurface<float> srf;
srf.degree_u = 3;
srf.degree_v = 3;
srf.knots_u = {0, 0, 0, 0, 1, 1, 1, 1};
srf.knots_v = {0, 0, 0, 0, 1, 1, 1, 1};

// 2D array of control points using tinynurbs::array2<T> container
// Example from geometrictools.com/Documentation/NURBSCircleSphere.pdf
srf.control_points = {4, 4, 
                      {glm::vec3(0, 0, 1), glm::vec3(0, 0, 1), glm::vec3(0, 0, 1), glm::vec3(0, 0, 1),
                       glm::vec3(2, 0, 1), glm::vec3(2, 4, 1),  glm::vec3(-2, 4, 1),  glm::vec3(-2, 0, 1),
                       glm::vec3(2, 0, -1), glm::vec3(2, 4, -1), glm::vec3(-2, 4, -1), glm::vec3(-2, 0, -1),
                       glm::vec3(0, 0, -1), glm::vec3(0, 0, -1), glm::vec3(0, 0, -1), glm::vec3(0, 0, -1)
                      }
                     };
srf.weights = {4, 4,
               {1,       1.f/3.f, 1.f/3.f, 1,
               1.f/3.f, 1.f/9.f, 1.f/9.f, 1.f/3.f,
               1.f/3.f, 1.f/9.f, 1.f/9.f, 1.f/3.f,
               1,       1.f/3.f, 1.f/3.f, 1
               }
              };

Split the surface into two along v=0.25:

tinynurbs::RationalSurface<float> left, right;
std::tie(left, right) = tinynurbs::surfaceSplitV(srf, 0.25);

Left: original surface, Right: after splitting

split surface

Write the surface to an OBJ file:

tinynurbs::surfaceSaveOBJ("output_surface.obj", srf);

creates a file with the following contents:

v 0 0 1 1
v 2 0 1 0.333333
v 2 0 -1 0.333333
v 0 0 -1 1
v 0 0 1 0.333333
v 2 4 1 0.111111
v 2 4 -1 0.111111
v 0 0 -1 0.333333
v 0 0 1 0.333333
v -2 4 1 0.111111
v -2 4 -1 0.111111
v 0 0 -1 0.333333
v 0 0 1 1
v -2 0 1 0.333333
v -2 0 -1 0.333333
v 0 0 -1 1
cstype rat bspline
deg 3 3
surf 0 1 0 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
parm u 0 0 0 0 1 1 1 1
parm v 0 0 0 0 1 1 1 1
end

Parameter and knot conventions

Knot insertion and splitting expect a valid curve or surface and a parameter strictly inside the active knot domain. A parameter outside that interval, or one whose multiplicity exceeds the degree, raises std::invalid_argument. Insertion at an interior knot whose multiplicity equals the degree returns the original geometry. Modification uses equality of stored knot values. The public knotMultiplicity query retains its epsilon-based behavior.

A valid knot vector is finite and nondecreasing. It has at least degree plus one control points along its axis and nonzero spans at both active domain boundaries. A surface normal is unit length at regular points. If the computed tangents are linearly dependent, the normal is the zero vector.

Primary Reference

  • "The NURBS Book," Les Piegl and Wayne Tiller, Springer-Verlag, 1995.

Explorar proyectos relacionados

Cargando…