- commit
- 8c437edfe3e0c9a42c29b9317f53fd6c3e66ee70
- parent
- 45dc3f165b3cc43bb16c9ab01ba1161c34934a59
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2010-11-20 17:22
polynominla interpolytion init
Diffstat
| M | makefile | 2 | +- |
| M | makefile.in | 2 | +- |
| M | src/gui/retimer_wx.cpp | 2 | +- |
| M | src/gui/retimer_wx.cpp.in | 2 | +- |
| A | src/intmode_poly.h | 124 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| M | src/marker.cpp | 7 | +++++++ |
| M | xiRetimer | 0 |
7 files changed, 135 insertions, 4 deletions
diff --git a/makefile b/makefile
@@ -5,7 +5,7 @@ LDFLAGS = `sdl-config --libs` `pkg-config --libs sndfile rubberband` `wx-config 5 5 xiRetimer: .gui .back 6 6 $(CC) -o xiRetimer *.o $(LDFLAGS) 7 78 -1 .gui: .back src/gui/*.cpp src/gui/*.h-1 8 .gui: src/gui/*.cpp src/gui/*.h 9 9 $(CC) $(CFLAGS) -c src/gui/*.cpp src/gui/*.h 10 10 touch .gui 11 11
diff --git a/makefile.in b/makefile.in
@@ -5,7 +5,7 @@ LDFLAGS = `sdl-config --libs` `pkg-config --libs sndfile @_PKGC@` `wx-config --l 5 5 @NAME@: .gui .back 6 6 $(CC) -o @NAME@ *.o $(LDFLAGS) 7 78 -1 .gui: .back src/gui/*.cpp src/gui/*.h-1 8 .gui: src/gui/*.cpp src/gui/*.h 9 9 $(CC) $(CFLAGS) -c src/gui/*.cpp src/gui/*.h 10 10 touch .gui 11 11
diff --git a/src/gui/retimer_wx.cpp b/src/gui/retimer_wx.cpp
@@ -206,7 +206,7 @@ PrefsDialog::PrefsDialog( wxWindow* parent, wxWindowID id, const wxString& title 206 206 l_intmode->Wrap( -1 ); 207 207 fgSizer4->Add( l_intmode, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); 208 208209 -1 wxString c_intmodeChoices[] = { wxT("Linear") };-1 209 wxString c_intmodeChoices[] = { wxT("Linear"), wxT("Polynominal") }; 210 210 int c_intmodeNChoices = sizeof( c_intmodeChoices ) / sizeof( wxString ); 211 211 c_intmode = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, c_intmodeNChoices, c_intmodeChoices, 0 ); 212 212 c_intmode->SetSelection( 0 );
diff --git a/src/gui/retimer_wx.cpp.in b/src/gui/retimer_wx.cpp.in
@@ -206,7 +206,7 @@ PrefsDialog::PrefsDialog( wxWindow* parent, wxWindowID id, const wxString& title 206 206 l_intmode->Wrap( -1 ); 207 207 fgSizer4->Add( l_intmode, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); 208 208209 -1 wxString c_intmodeChoices[] = { wxT("Linear") };-1 209 wxString c_intmodeChoices[] = { wxT("Linear"), wxT("Polynominal") }; 210 210 int c_intmodeNChoices = sizeof( c_intmodeChoices ) / sizeof( wxString ); 211 211 c_intmode = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, c_intmodeNChoices, c_intmodeChoices, 0 ); 212 212 c_intmode->SetSelection( 0 );
diff --git a/src/intmode_poly.h b/src/intmode_poly.h
@@ -0,0 +1,124 @@
-1 1 #ifndef __INTMODE_POLY_H
-1 2 #define __INTMODE_POLY_H
-1 3
-1 4 #include <iostream>
-1 5 #include "marker.h"
-1 6
-1 7 /*
-1 8 This defines a interpolytion mode used in marker
-1 9 // TODO doesnt really work yet
-1 10 // TODO lots of optimisation to do
-1 11 */
-1 12
-1 13 float** invertMatrix(float** A) {
-1 14 float** X=new float*[3];
-1 15 for (int i=0; i<3; ++i) {
-1 16 X[i]=new float[3];
-1 17 }
-1 18 int i,j;
-1 19 float n=0; // determinant of A
-1 20
-1 21 n+=A[0][0]*A[1][1]*A[2][2];
-1 22 n+=A[0][1]*A[1][2]*A[2][0];
-1 23 n+=A[0][2]*A[1][0]*A[2][1];
-1 24
-1 25 n-=A[0][0]*A[1][2]*A[2][1];
-1 26 n-=A[0][1]*A[1][0]*A[2][2];
-1 27 n-=A[0][2]*A[1][1]*A[2][0];
-1 28
-1 29 if(n*n<=0.1) {
-1 30 for (int i=0; i<3; ++i) {
-1 31 for (int j=0; j<3; ++j) {
-1 32 X[i][j]=0;
-1 33 }
-1 34 X[i][i]=1;
-1 35 }
-1 36 return X;
-1 37 }
-1 38
-1 39 X[0][0]=A[1][1]*A[2][2]-(A[2][1]*A[1][2]);
-1 40 X[0][1]=(-1)*(A[0][1]*A[2][2]-(A[0][2]*A[2][1]));
-1 41 X[0][2]=A[0][1]*A[1][2]-(A[0][2]*A[1][1]);
-1 42
-1 43 X[1][0]=(-1)*(A[1][0]*A[2][2]-A[1][2]*A[2][0]);
-1 44 X[1][1]=A[0][0]*A[2][2]-A[0][2]*A[2][0];
-1 45 X[1][2]=(-1)*(A[0][0]*A[1][2]-A[0][2]*A[1][0]);
-1 46
-1 47 X[2][0]=A[1][0]*A[2][1]-A[1][1]*A[2][0];
-1 48 X[2][1]=(-1)*(A[0][0]*A[2][1]-A[0][1]*A[2][0]);
-1 49 X[2][2]=A[0][0]*A[1][1]-A[1][0]*A[0][1];
-1 50
-1 51 for(i=0;i<3;i++) {
-1 52 for(j=0;j<3;j++) {
-1 53 X[i][j]=X[i][j]/n;
-1 54 }
-1 55 }
-1 56
-1 57 return X;
-1 58 }
-1 59
-1 60 float int_poly(Marker* marker, float old) {
-1 61 int i=marker->getAreaOld(old);
-1 62 int n=marker->getLength();
-1 63
-1 64 float x1=marker->getOld(i);
-1 65 float x2=marker->getOld(i+1);
-1 66 float y1=marker->getNew(i);
-1 67 float y2=marker->getNew(i+1);
-1 68 float d1;
-1 69 float d2;
-1 70 if (i<=0)
-1 71 d1=(marker->getNew(1)-marker->getNew(0))/(marker->getOld(1)-marker->getOld(0));
-1 72 else
-1 73 d1=(marker->getNew(i-1)-y2)/(marker->getOld(i-1)-x2);
-1 74 if (i>=n-2)
-1 75 d2=(marker->getNew(n-1)-marker->getNew(n-2))/(marker->getOld(n-1)-marker->getOld(n-2));
-1 76 else
-1 77 d2=(y1-marker->getNew(i+2))/(x1-marker->getOld(i+2));
-1 78
-1 79 float** M=new float*[3];
-1 80 for (int j=0; j<3; ++j) {
-1 81 M[j]=new float[3];
-1 82 }
-1 83
-1 84 M[0][0]=3*x1*x1*x1;
-1 85 M[0][1]=2*x1*x1;
-1 86 M[0][2]=x1;
-1 87
-1 88 M[1][0]=3*x2*x2*x2;
-1 89 M[1][1]=2*x2*x2;
-1 90 M[1][2]=x2;
-1 91
-1 92 M[2][0]=x2*x2*x2-x1*x1*x1;
-1 93 M[2][1]=x2*x2-x1*x1;
-1 94 M[2][2]=x2-x1;
-1 95
-1 96 float** I=invertMatrix(M);
-1 97
-1 98 for (int j=0; j<3; ++j) {
-1 99 delete[] M[j];
-1 100 }
-1 101 delete[] M;
-1 102
-1 103 float a=I[0][0]*d1*x1+I[0][1]*d2*x2+I[0][2]*(y2-y1);
-1 104 float b=I[1][0]*d1*x1+I[1][1]*d2*x2+I[1][2]*(y2-y1);
-1 105 float c=I[2][0]*d1*x1+I[2][1]*d2*x2+I[2][2]*(y2-y1);
-1 106 float d=y1-a*x1*x1*x1-b*x1*x1-c*x1;
-1 107
-1 108 for (int j=0; j<3; ++j) {
-1 109 delete[] I[j];
-1 110 }
-1 111 delete[] I;
-1 112
-1 113 /*
-1 114 std::cout << " a " << a;
-1 115 std::cout << " b " << b;
-1 116 std::cout << " c " << c;
-1 117 std::cout << " d " << d;
-1 118 std::cout << std::endl;
-1 119 */
-1 120
-1 121 return a*old*old*old+b*old*old+c*old+d;
-1 122 }
-1 123
-1 124 #endif
diff --git a/src/marker.cpp b/src/marker.cpp
@@ -1,5 +1,7 @@ 1 1 #include "marker.h" 2 2 -1 3 #include "intmode_poly.h" -1 4 3 5 Marker::Marker() { 4 6 anew; 5 7 aold; @@ -66,6 +68,7 @@ float Marker::getLengthf() { 66 68 } 67 69 68 70 float Marker::getRatio(float o) { -1 71 // deprivated 69 72 // derivate of old2new 70 73 // hardcode the derivate to improve performance 71 74 switch (getInterpolationMode()) { @@ -129,6 +132,9 @@ float Marker::old2new(float o) { 129 132 // for performance reasons you should also hard code the interpolation modes to getRatio(float) and new2old 130 133 switch (getInterpolationMode()) { 131 134 // case 0: // linear is default -1 135 case 1: { // polynominal spline -1 136 return int_poly(this, o); -1 137 } break; 132 138 default: { 133 139 int i=getAreaOld(o); 134 140 if (i<0 || i+1>getLength()-1) return 0; @@ -152,6 +158,7 @@ float Marker::new2old(float n) { 152 158 return (n-getNew(i))/(getNew(i+1)-getNew(i))*(getOld(i+1)-getOld(i))+getOld(i); 153 159 } break; 154 160 default: { -1 161 // TODO 155 162 // approximate o; 156 163 float o=n; 157 164 for (int i=1; i<10; ++i) {