Panda3D

nurbsCurveResult.h

00001 // Filename: nurbsCurveResult.h
00002 // Created by:  drose (03Dec02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef NURBSCURVERESULT_H
00016 #define NURBSCURVERESULT_H
00017 
00018 #include "pandabase.h"
00019 #include "referenceCount.h"
00020 #include "nurbsBasisVector.h"
00021 #include "vector_stdfloat.h"
00022 
00023 class NurbsVertex;
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : NurbsCurveResult
00027 // Description : The result of a NurbsCurveEvaluator.  This object
00028 //               represents a curve in a particular coordinate space.
00029 //               It can return the point and/or tangent to the curve
00030 //               at any point.
00031 //
00032 //               This is not related to NurbsCurve, CubicCurveseg or
00033 //               any of the ParametricCurve-derived objects in this
00034 //               module.  It is a completely parallel implementation
00035 //               of NURBS curves, and will probably eventually replace
00036 //               the whole ParametricCurve class hierarchy.
00037 ////////////////////////////////////////////////////////////////////
00038 class EXPCL_PANDA_PARAMETRICS NurbsCurveResult : public ReferenceCount {
00039 public:
00040   NurbsCurveResult(const NurbsBasisVector &basis, 
00041                    const LVecBase4 vecs[], const NurbsVertex *verts,
00042                    int num_vertices);
00043 
00044 PUBLISHED:
00045   INLINE ~NurbsCurveResult();
00046 
00047   INLINE PN_stdfloat get_start_t() const;
00048   INLINE PN_stdfloat get_end_t() const;
00049 
00050   INLINE bool eval_point(PN_stdfloat t, LVecBase3 &point);
00051   INLINE bool eval_tangent(PN_stdfloat t, LVecBase3 &tangent);
00052   INLINE PN_stdfloat eval_extended_point(PN_stdfloat t, int d);
00053   INLINE bool eval_extended_points(PN_stdfloat t, int d, 
00054                                    PN_stdfloat result[], int num_values);
00055   
00056   INLINE int get_num_segments() const;
00057   void eval_segment_point(int segment, PN_stdfloat t, LVecBase3 &point) const;
00058   void eval_segment_tangent(int segment, PN_stdfloat t, LVecBase3 &tangent) const;
00059   PN_stdfloat eval_segment_extended_point(int segment, PN_stdfloat t, int d) const;
00060   void eval_segment_extended_points(int segment, PN_stdfloat t, int d,
00061                                     PN_stdfloat result[], int num_values) const;
00062   INLINE PN_stdfloat get_segment_t(int segment, PN_stdfloat t) const;
00063 
00064   void adaptive_sample(PN_stdfloat tolerance);
00065   INLINE int get_num_samples() const;
00066   INLINE PN_stdfloat get_sample_t(int n) const;
00067   INLINE const LPoint3 &get_sample_point(int n) const;
00068   MAKE_SEQ(get_sample_ts, get_num_samples, get_sample_t);
00069   MAKE_SEQ(get_sample_points, get_num_samples, get_sample_points);
00070   
00071 private:
00072   int find_segment(PN_stdfloat t);
00073   int r_find_segment(PN_stdfloat t, int top, int bot) const;
00074 
00075   void r_adaptive_sample(int segment, PN_stdfloat t0, const LPoint3 &p0, 
00076                          PN_stdfloat t1, const LPoint3 &p1, PN_stdfloat tolerance_2);
00077   static PN_stdfloat sqr_dist_to_line(const LPoint3 &point, const LPoint3 &origin, 
00078                                 const LVector3 &vec);
00079 
00080   NurbsBasisVector _basis;
00081   const NurbsVertex *_verts;
00082 
00083   // We pre-compose the basis matrix and the geometry vectors, so we
00084   // have these handy for evaluation.  There is one entry in the
00085   // _composed for each entry in basis._segments.
00086   typedef epvector<LMatrix4> ComposedGeom;
00087   ComposedGeom _composed;
00088 
00089   int _last_segment;
00090   PN_stdfloat _last_from;
00091   PN_stdfloat _last_to;
00092 
00093   class AdaptiveSample {
00094   public:
00095     INLINE AdaptiveSample(PN_stdfloat t, const LPoint3 &point);
00096     PN_stdfloat _t;
00097     LPoint3 _point;
00098   };
00099   typedef pvector<AdaptiveSample> AdaptiveResult;
00100   AdaptiveResult _adaptive_result;
00101 };
00102 
00103 #include "nurbsCurveResult.I"
00104 
00105 #endif
00106 
 All Classes Functions Variables Enumerations