15 #include "nurbsCurveEvaluator.h"
23 NurbsCurveEvaluator() {
35 ~NurbsCurveEvaluator() {
50 _vertices.reserve(num_vertices);
52 for (
int i = 0; i < num_vertices; i++) {
69 nassertr(i >= 0 && i < (
int)_vertices.size(), empty_node_path);
71 return _vertices[i].get_space(rel_to);
85 nassertv(i >= 0 && i < (
int)_vertices.size());
88 for (
int n = 0; n < num_values; n++) {
89 vertex.set_extended_vertex(d + n, values[n]);
106 nassertv(i >= 0 && i < (
int)_knots.size());
120 nassertr(i >= 0 && i < (
int)_knots.size(), 0.0f);
137 double min_value = _knots[_order - 1];
139 double range = (max_value - min_value);
141 for (Knots::iterator ki = _knots.begin(); ki != _knots.end(); ++ki) {
142 (*ki) = ((*ki) - min_value) / range;
157 evaluate(const
NodePath &rel_to)
const {
164 get_vertices(vecs, rel_to);
169 (
int)_vertices.size());
189 get_vertices(vecs, rel_to);
192 Vert4Array::iterator vi;
193 for (vi = vecs.begin(); vi != vecs.end(); ++vi) {
200 (
int)_vertices.size());
208 void NurbsCurveEvaluator::
209 output(ostream &out)
const {
224 int num_vertices = (int)_vertices.size();
225 verts.reserve(verts.size() + num_vertices);
227 for (vi = 0; vi < num_vertices; vi++) {
242 int num_vertices = (int)_vertices.size();
243 verts.reserve(verts.size() + num_vertices);
245 for (vi = 0; vi < num_vertices; vi++) {
247 LPoint3 v3(vertex[0] / vertex[3], vertex[1] / vertex[3], vertex[2] / vertex[3]);
257 void NurbsCurveEvaluator::
261 _knots.reserve(num_knots);
263 PN_stdfloat value = 0.0f;
267 _knots.push_back(value);
270 while (i < num_knots - _order) {
272 _knots.push_back(value);
276 while (i < num_knots) {
277 _knots.push_back(value);
281 _knots_dirty =
false;
290 void NurbsCurveEvaluator::
296 _basis.
clear(_order);
297 if ((
int)_vertices.size() > _order - 1) {
298 int min_knot = _order;
299 int max_knot = (int)_vertices.size();
301 for (
int i = min_knot; i <= max_knot; i++) {
302 nassertv(i - 1 >= 0 && i < (
int)_knots.size());
303 if (_knots[i - 1] < _knots[i]) {
310 _basis_dirty =
false;
void set_knot(int i, PN_stdfloat knot)
Sets the value of the nth knot.
void reset(int num_vertices)
Resets all the vertices and knots to their default values, and sets the curve up with the indicated n...
void append_segment(int vertex_index, const PN_stdfloat knots[])
Computes a NURBS basis for one segment of the curve and appends it to the set of basis matrices...
This class is an abstraction for evaluating NURBS curves.
int get_num_knots() const
Returns the number of knot values in the curve.
const LVecBase4 & get_vertex(int i) const
Returns the nth control vertex of the curve, relative to its indicated coordinate space...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
This represents a single control vertex in a NurbsEvaluator.
int get_num_vertices() const
Returns the number of control vertices in the curve.
This is a 4-by-4 transform matrix.
void clear(int order)
Removes all the segments from the curve.
PN_stdfloat get_knot(int i) const
Returns the value of the nth knot.
void get_vertices(Vert4Array &verts, const NodePath &rel_to) const
Fills the indicated vector with the set of vertices in the curve, transformed to the given space...
void normalize_knots()
Normalizes the knot sequence so that the parametric range of the curve is 0 .
This is the base class for all three-component vectors and points.
The result of a NurbsCurveEvaluator.
NodePath get_vertex_space(int i, const NodePath &rel_to) const
Returns the coordinate space of the nth control vertex of the curve, expressed as a NodePath...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
void set_extended_vertices(int i, int d, const PN_stdfloat values[], int num_values)
Simultaneously sets several extended values in the slots d through (d + num_values - 1) from the num_...