Panda3D
 All Classes Functions Variables Enumerations
nurbsCurveResult.h
1 // Filename: nurbsCurveResult.h
2 // Created by: drose (03Dec02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef NURBSCURVERESULT_H
16 #define NURBSCURVERESULT_H
17 
18 #include "pandabase.h"
19 #include "referenceCount.h"
20 #include "nurbsBasisVector.h"
21 #include "vector_stdfloat.h"
22 #include "epvector.h"
23 
24 class NurbsVertex;
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : NurbsCurveResult
28 // Description : The result of a NurbsCurveEvaluator. This object
29 // represents a curve in a particular coordinate space.
30 // It can return the point and/or tangent to the curve
31 // at any point.
32 //
33 // This is not related to NurbsCurve, CubicCurveseg or
34 // any of the ParametricCurve-derived objects in this
35 // module. It is a completely parallel implementation
36 // of NURBS curves, and will probably eventually replace
37 // the whole ParametricCurve class hierarchy.
38 ////////////////////////////////////////////////////////////////////
39 class EXPCL_PANDA_PARAMETRICS NurbsCurveResult : public ReferenceCount {
40 public:
41  NurbsCurveResult(const NurbsBasisVector &basis,
42  const LVecBase4 vecs[], const NurbsVertex *verts,
43  int num_vertices);
44 
45 PUBLISHED:
46  INLINE ~NurbsCurveResult();
47 
48  INLINE PN_stdfloat get_start_t() const;
49  INLINE PN_stdfloat get_end_t() const;
50 
51  INLINE bool eval_point(PN_stdfloat t, LVecBase3 &point);
52  INLINE bool eval_tangent(PN_stdfloat t, LVecBase3 &tangent);
53  INLINE PN_stdfloat eval_extended_point(PN_stdfloat t, int d);
54  INLINE bool eval_extended_points(PN_stdfloat t, int d,
55  PN_stdfloat result[], int num_values);
56 
57  INLINE int get_num_segments() const;
58  void eval_segment_point(int segment, PN_stdfloat t, LVecBase3 &point) const;
59  void eval_segment_tangent(int segment, PN_stdfloat t, LVecBase3 &tangent) const;
60  PN_stdfloat eval_segment_extended_point(int segment, PN_stdfloat t, int d) const;
61  void eval_segment_extended_points(int segment, PN_stdfloat t, int d,
62  PN_stdfloat result[], int num_values) const;
63  INLINE PN_stdfloat get_segment_t(int segment, PN_stdfloat t) const;
64 
65  void adaptive_sample(PN_stdfloat tolerance);
66  INLINE int get_num_samples() const;
67  INLINE PN_stdfloat get_sample_t(int n) const;
68  INLINE const LPoint3 &get_sample_point(int n) const;
69  MAKE_SEQ(get_sample_ts, get_num_samples, get_sample_t);
70  MAKE_SEQ(get_sample_points, get_num_samples, get_sample_points);
71 
72 private:
73  int find_segment(PN_stdfloat t);
74  int r_find_segment(PN_stdfloat t, int top, int bot) const;
75 
76  void r_adaptive_sample(int segment, PN_stdfloat t0, const LPoint3 &p0,
77  PN_stdfloat t1, const LPoint3 &p1, PN_stdfloat tolerance_2);
78  static PN_stdfloat sqr_dist_to_line(const LPoint3 &point, const LPoint3 &origin,
79  const LVector3 &vec);
80 
81  NurbsBasisVector _basis;
82  const NurbsVertex *_verts;
83 
84  // We pre-compose the basis matrix and the geometry vectors, so we
85  // have these handy for evaluation. There is one entry in the
86  // _composed for each entry in basis._segments.
87  typedef epvector<LMatrix4> ComposedGeom;
88  ComposedGeom _composed;
89 
90  int _last_segment;
91  PN_stdfloat _last_from;
92  PN_stdfloat _last_to;
93 
94  class AdaptiveSample {
95  public:
96  INLINE AdaptiveSample(PN_stdfloat t, const LPoint3 &point);
97  PN_stdfloat _t;
98  LPoint3 _point;
99  };
101  AdaptiveResult _adaptive_result;
102 };
103 
104 #include "nurbsCurveResult.I"
105 
106 #endif
107 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This represents a single control vertex in a NurbsEvaluator.
Definition: nurbsVertex.h:36
This encapsulates a series of matrices that are used to represent the sequential segments of a NurbsC...
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
A base class for all things that want to be reference-counted.
The result of a NurbsCurveEvaluator.