summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmsplinesegment.h
blob: 5e97ff494c0516d5074f7d6e7ba3b80e4487c8bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//-*-C++-*-
/*
**************************************************************************
                                 description
                             --------------------
    copyright            : (C) 2002 by Andreas Zehender
    email                : zehender@kde.org
**************************************************************************

**************************************************************************
*                                                                        *
*  This program is free software; you can redistribute it and/or modify  *
*  it under the terms of the GNU General Public License as published by  *
*  the Free Software Foundation; either version 2 of the License, or     *
*  (at your option) any later version.                                   *
*                                                                        *
**************************************************************************/


#ifndef PMSPLINESEGMENT_H
#define PMSPLINESEGMENT_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "pmvector.h"
#include <qvaluelist.h>

/**
 * Helper class for splines
 *
 * Each instance of this class represents one spline segment. A point
 * on the segment is given by the equation
 *
 * fi(t) = A[i] * t^3 + B[i] * t^2 + C[i] * t + D[i]
 *
 * with t ranging from 0 to 1.
 */
class PMSplineSegment
{
public:
   /**
    * Standard constructor
    */
   PMSplineSegment( )
   {
      m_a[0] = m_b[0] = m_c[0] = m_d[0] = 0.0;
      m_a[1] = m_b[1] = m_c[1] = m_d[1] = 0.0;
   }
   /**
    * Copy constructor
    */
   PMSplineSegment( const PMSplineSegment& s )
   {
      int i;
      for( i = 0; i < 2; i++ )
      {
         m_a[i] = s.m_a[i];
         m_b[i] = s.m_b[i];
         m_c[i] = s.m_c[i];
         m_d[i] = s.m_d[i];
      }
   }
   /**
    * Assigns s to the segment
    */
   PMSplineSegment& operator= ( const PMSplineSegment& s )
   {
      int i;
      for( i = 0; i < 2; i++ )
      {
         m_a[i] = s.m_a[i];
         m_b[i] = s.m_b[i];
         m_c[i] = s.m_c[i];
         m_d[i] = s.m_d[i];
      }
      return *this;
   }
   
   /**
    * Returns a 2D vector with the point on the spline segment
    */
   PMVector point( double t ) const;
   /**
    * Returns the gradient on the spline
    */
   PMVector gradient( double t ) const;
   
   /**
    * Calculates the spline parameters for the linear spline type
    */
   void calculateLinear( const PMVector& p1, const PMVector& p2 );
   /**
    * Calculates the spline parameters for the quadratic spline type
    */
   void calculateQuadratic( const PMVector& p1, const PMVector& p2,
                            const PMVector& p3 );
   /**
    * Calculates the spline parameters for the cubic spline type
    */
   void calculateCubic( const PMVector& p1, const PMVector& p2,
                        const PMVector& p3, const PMVector& p4 );
   /**
    * Calculates the spline parameters for the bezier spline type
    */
   void calculateBezier( const PMVector& p1, const PMVector& p2,
                         const PMVector& p3, const PMVector& p4 );
   /**
    * Calculates the spline parameters for the quadric bezier
    */
   void calculateQuadricBezier( const PMVector& p1, const PMVector& p2,
                                const PMVector& p3 );
   
private:
   double m_a[2], m_b[2], m_c[2], m_d[2];
};

typedef QValueList<PMSplineSegment> PMSegmentList;
typedef QValueList<PMSegmentList> PMSegmentListList;

#endif