Panda3D
|
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_float.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 LVecBase4f vecs[], const NurbsVertex *verts, 00042 int num_vertices); 00043 00044 PUBLISHED: 00045 INLINE ~NurbsCurveResult(); 00046 00047 INLINE float get_start_t() const; 00048 INLINE float get_end_t() const; 00049 00050 INLINE bool eval_point(float t, LVecBase3f &point); 00051 INLINE bool eval_tangent(float t, LVecBase3f &tangent); 00052 INLINE float eval_extended_point(float t, int d); 00053 INLINE bool eval_extended_points(float t, int d, 00054 float result[], int num_values); 00055 00056 INLINE int get_num_segments() const; 00057 void eval_segment_point(int segment, float t, LVecBase3f &point) const; 00058 void eval_segment_tangent(int segment, float t, LVecBase3f &tangent) const; 00059 float eval_segment_extended_point(int segment, float t, int d) const; 00060 void eval_segment_extended_points(int segment, float t, int d, 00061 float result[], int num_values) const; 00062 INLINE float get_segment_t(int segment, float t) const; 00063 00064 void adaptive_sample(float tolerance); 00065 INLINE int get_num_samples() const; 00066 INLINE float get_sample_t(int n) const; 00067 INLINE const LPoint3f &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(float t); 00073 int r_find_segment(float t, int top, int bot) const; 00074 00075 void r_adaptive_sample(int segment, float t0, const LPoint3f &p0, 00076 float t1, const LPoint3f &p1, float tolerance_2); 00077 static float sqr_dist_to_line(const LPoint3f &point, const LPoint3f &origin, 00078 const LVector3f &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 pvector<LMatrix4f> ComposedGeom; 00087 ComposedGeom _composed; 00088 00089 int _last_segment; 00090 float _last_from; 00091 float _last_to; 00092 00093 class AdaptiveSample { 00094 public: 00095 INLINE AdaptiveSample(float t, const LPoint3f &point); 00096 float _t; 00097 LPoint3f _point; 00098 }; 00099 typedef pvector<AdaptiveSample> AdaptiveResult; 00100 AdaptiveResult _adaptive_result; 00101 }; 00102 00103 #include "nurbsCurveResult.I" 00104 00105 #endif 00106