~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libaqsistypes/spline.h

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Declares the CqSplineCubic class for generic spline functionality.
 
23
                \author Paul C. Gregory (pgregory@aqsis.com)
 
24
*/
 
25
 
 
26
//? Is .h included already?
 
27
#ifndef SPLINE_H_INCLUDED
 
28
#define SPLINE_H_INCLUDED 1
 
29
 
 
30
#include        <vector>
 
31
 
 
32
#include        "aqsis.h"
 
33
 
 
34
#include        "matrix.h"
 
35
#include        "vector4d.h"
 
36
#include        "sstring.h"
 
37
 
 
38
START_NAMESPACE( Aqsis )
 
39
 
 
40
 
 
41
typedef TqFloat __Basis[ 4 ][ 4 ];
 
42
 
 
43
extern __Basis  gBezierBasis;
 
44
extern __Basis  gBSplineBasis;
 
45
extern __Basis  gCatmullRomBasis;
 
46
extern __Basis  gHermiteBasis;
 
47
extern __Basis  gPowerBasis;
 
48
 
 
49
 
 
50
//----------------------------------------------------------------------
 
51
/** \class CqSplineCubic
 
52
 * Cubic spline curve
 
53
 */
 
54
 
 
55
class CqSplineCubic
 
56
{
 
57
public:
 
58
    CqSplineCubic( TqInt cu = 4 );
 
59
    virtual     ~CqSplineCubic()
 
60
    {}
 
61
 
 
62
    virtual     CqVector4D      Evaluate( TqFloat t ) const;
 
63
    virtual     void    InitFD( TqInt n );
 
64
    virtual     CqVector4D      EvaluateFD();
 
65
    virtual     TqInt   cSections() const;
 
66
 
 
67
    /** Get a reference to the array of control points.
 
68
     */
 
69
    std::vector<CqVector4D>& aControlPoints()
 
70
    {
 
71
        return ( m_aControlPoints );
 
72
    }
 
73
    /** Get a reference to the cubic spline basis matrix.
 
74
     */
 
75
    CqMatrix&   matBasis()
 
76
    {
 
77
        return ( m_matBasis );
 
78
    }
 
79
    /** Set the cubic spline basis matrix.
 
80
     * \param mat Basis matrix.
 
81
     */
 
82
    void        SetmatBasis( CqMatrix& mat )
 
83
    {
 
84
        m_matBasis = mat;
 
85
    }
 
86
    /** Set the cubic spline basis matrix.
 
87
     * \param strName Basis name.
 
88
     */
 
89
    void        SetmatBasis( const CqString& strName )
 
90
    {
 
91
        __Basis * pVals = 0;
 
92
        if ( strName.compare( "bezier" ) == 0 )
 
93
            pVals = &gBezierBasis;
 
94
        else if ( strName.compare( "bspline" ) == 0 )
 
95
            pVals = &gBSplineBasis;
 
96
        else if ( strName.compare( "catmull-rom" ) == 0 )
 
97
            pVals = &gCatmullRomBasis;
 
98
        else if ( strName.compare( "hermite" ) == 0 )
 
99
            pVals = &gHermiteBasis;
 
100
        else if ( strName.compare( "power" ) == 0 )
 
101
            pVals = &gPowerBasis;
 
102
 
 
103
        if ( pVals )
 
104
        {
 
105
            CqMatrix m;
 
106
            m = *pVals;
 
107
            SetmatBasis( m );
 
108
            //                          TqInt i, j;
 
109
            //                          for ( i = 0; i < 4; i++ )
 
110
            //                                  for ( j = 0; j < 4; j++ )
 
111
            //                                          ( *b ) [ i ][ j ] = ( *pVals ) [ i ][ j ];
 
112
        }
 
113
    }
 
114
 
 
115
    /** Get the control point step size for the evaluation window.
 
116
     * \return Integer step size.
 
117
     */
 
118
    TqInt       Step() const
 
119
    {
 
120
        return ( m_Step );
 
121
    }
 
122
    /** Set the control point step size for the evaluation window.
 
123
     * \param Step Integer step size.
 
124
     */
 
125
    void        SetStep( const TqInt Step )
 
126
    {
 
127
        m_Step = Step;
 
128
    }
 
129
 
 
130
    /** Indexed access to the control points.
 
131
     * \param i Integer index.
 
132
     */
 
133
    CqVector4D& operator[] ( TqInt i )
 
134
    {
 
135
        assert( i<m_cu ); return ( m_aControlPoints[ i ] );
 
136
    }
 
137
    /** Indexed access to the control points.
 
138
     * \param i Integer index.
 
139
     */
 
140
    const CqVector4D&   operator[] ( TqInt i ) const
 
141
    {
 
142
        assert( i<m_cu ); return ( m_aControlPoints[ i ] );
 
143
    }
 
144
 
 
145
protected:
 
146
    CqMatrix    m_matBasis;                                             ///< Basis matrix.
 
147
    TqInt       m_Step;                                                 ///< Evaluation window step size.
 
148
    TqInt       m_cu;                                                   ///< Number of control points.
 
149
    std::vector<CqVector4D>     m_aControlPoints;               ///< Array of 4D control points.
 
150
 
 
151
    CqVector4D  m_vecFDPoint;                                   ///< Forward difference evaluation parameters.
 
152
    CqVector4D  m_vecFDDelta;                                   ///< Forward difference evaluation parameters.
 
153
    CqVector4D  m_vecFDDelta2;                                  ///< Forward difference evaluation parameters.
 
154
    CqVector4D  m_vecFDDelta3;                                  ///< Forward difference evaluation parameters.
 
155
}
 
156
;
 
157
 
 
158
 
 
159
//-----------------------------------------------------------------------
 
160
 
 
161
END_NAMESPACE( Aqsis )
 
162
 
 
163
#endif  // !SPLINE_H_INCLUDED