Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
BSplineData.h
1 /*
2 Copyright (c) 2006, Michael Kazhdan and Matthew Bolitho
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 Redistributions of source code must retain the above copyright notice, this list of
9 conditions and the following disclaimer. Redistributions in binary form must reproduce
10 the above copyright notice, this list of conditions and the following disclaimer
11 in the documentation and/or other materials provided with the distribution.
12 
13 Neither the name of the Johns Hopkins University nor the names of its contributors
14 may be used to endorse or promote products derived from this software without specific
15 prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
18 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
20 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
22 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26 DAMAGE.
27 */
28 
29 #ifndef BSPLINE_DATA_INCLUDED
30 #define BSPLINE_DATA_INCLUDED
31 
32 
33 #include "PPolynomial.h"
34 #include "Array.h"
35 
36 template< int Degree >
38 {
39  // cppcheck-suppress negativeIndex
40  int coeffs[Degree+1];
41  BSplineElementCoefficients( void ) { memset( coeffs , 0 , sizeof( int ) * ( Degree+1 ) ); }
42  int& operator[]( unsigned int idx ){ if (idx <= Degree) return coeffs[idx]; return coeffs[0];}
43  const int& operator[]( unsigned int idx ) const {if (idx <= Degree) return coeffs[idx]; return coeffs[0];}
44 };
45 template< int Degree >
46 struct BSplineElements : public std::vector< BSplineElementCoefficients< Degree > >
47 {
48  static const int _off = (Degree+1)/2;
49  void _addLeft ( int offset , int boundary );
50  void _addRight( int offset , int boundary );
51 public:
52  enum
53  {
54  NONE = 0,
55  DIRICHLET = -1,
56  NEUMANN = 1
57  };
58  // Coefficients are ordered as "/" "-" "\"
59  int denominator;
60 
61  BSplineElements( void ) { denominator = 1; }
62  BSplineElements( int res , int offset , int boundary=NONE , int inset=0 );
63 
64  void upSample( BSplineElements& high ) const;
65  void differentiate( BSplineElements< Degree-1 >& d ) const;
66 
67  void print( FILE* fp=stdout ) const
68  {
69  for( int i=0 ; i< this->size() ; i++ )
70  {
71  printf( "%d]" , i );
72  for( int j=0 ; j<=Degree ; j++ ) printf( " %d" , (*this)[i][j] );
73  printf( " (%d)\n" , denominator );
74  }
75  }
76 };
77 
78 template< int Degree , class Real >
80 {
81  bool useDotRatios;
82  int boundaryType;
83 public:
85  {
86  Polynomial< Degree > polys[Degree+1];
87  Polynomial< Degree >& operator[] ( unsigned int idx ) { return polys[idx]; }
88  const Polynomial< Degree >& operator[] ( unsigned int idx ) const { return polys[idx]; }
89  void printnl( void ) const { for( int d=0 ; d<=Degree ; d++ ) polys[d].printnl(); }
90  BSplineComponents scale( double s ) const { BSplineComponents b ; for( unsigned int d=0 ; d<=Degree ; d++ ) b[d] = polys[d].scale(s) ; return b; }
91  BSplineComponents shift( double s ) const { BSplineComponents b ; for( unsigned int d=0 ; d<=Degree ; d++ ) b[d] = polys[d].shift(s) ; return b; }
92  };
93  const static int VV_DOT_FLAG = 1;
94  const static int DV_DOT_FLAG = 2;
95  const static int DD_DOT_FLAG = 4;
96  const static int VALUE_FLAG = 1;
97  const static int D_VALUE_FLAG = 2;
98 
99  int depth , functionCount , sampleCount;
100  Pointer( Real ) vvDotTable;
101  Pointer( Real ) dvDotTable;
102  Pointer( Real ) ddDotTable;
103  Pointer( Real ) valueTables;
104  Pointer( Real ) dValueTables;
105  PPolynomial< Degree > baseFunction , leftBaseFunction , rightBaseFunction , leftRightBaseFunction;
106  PPolynomial< Degree-1 > dBaseFunction , dLeftBaseFunction , dRightBaseFunction , dLeftRightBaseFunction;
107  BSplineComponents baseBSpline , leftBSpline , rightBSpline , leftRightBSpline;
108  Pointer( PPolynomial< Degree > ) baseFunctions;
109  Pointer( BSplineComponents ) baseBSplines;
110 
111  BSplineData(void);
112  ~BSplineData(void);
113 
114  virtual void setDotTables( int flags , bool inset=false );
115  virtual void clearDotTables( int flags );
116 
117  virtual void setValueTables( int flags , double smooth=0 );
118  virtual void setValueTables( int flags , double valueSmooth , double normalSmooth );
119  virtual void clearValueTables( void );
120 
121  void setSampleSpan( int idx , int& start , int& end , double smooth=0 ) const;
122 
123  /********************************************************
124  * Sets the translates and scales of the basis function
125  * up to the prescribed depth
126  * <maxDepth> the maximum depth
127  * <useDotRatios> specifies if dot-products of derivatives
128  * should be pre-divided by function integrals
129  * <reflectBoundary> spcifies if function space should be
130  * forced to be reflectively symmetric across the boundary
131  ********************************************************/
132  void set( int maxDepth , bool useDotRatios=true , int boundaryType=BSplineElements< Degree >::NONE );
133 
134  inline int Index( int i1 , int i2 ) const;
135  static inline int SymmetricIndex( int i1 , int i2 );
136  static inline int SymmetricIndex( int i1 , int i2 , int& index );
137 };
138 
139 template< int Degree1 , int Degree2 > void SetBSplineElementIntegrals( double integrals[Degree1+1][Degree2+1] );
140 
141 #include "BSplineData.inl"
142 #endif // BSPLINE_DATA_INCLUDED