00001
00046 #ifndef INC_MI32_FFTFUNC_H
00047 #define INC_MI32_FFTFUNC_H
00048
00049 #ifndef INC_MI32_DOUBLEAR_H
00050 #include <mi32/doublear.h>
00051 #endif
00052
00053 #ifndef INC_RVC_IMAGE_H
00054 #include <rvc/image.h>
00055 #endif
00056
00057 #include <complex>
00058
00059
00060 typedef std::complex<double> DCOMPLEX;
00061
00062 #ifndef GENERATING_DOXYGEN_OUTPUT
00063 namespace RVC {
00064 class OBJITEM;
00065 class RASTER;
00066 }
00067 namespace SML {
00068 class CONTEXT;
00069 }
00070 #endif // GENERATING_DOXYGEN_OUTPUT
00071
00072
00074 enum FTFORMAT {
00075 FTFORMAT_RI_RI = 0,
00076 FTFORMAT_RI_MP = 1,
00077 FTFORMAT_MP_RI = 2,
00078 FTFORMAT_MP_MP = 3,
00079 FTFORMAT_RI = FTFORMAT_RI_RI,
00080 FTFORMAT_MP = FTFORMAT_MP_MP
00081 };
00082
00083 class FFT2D {
00084
00085 public:
00086
00087 static ERRVALUE Forward (
00088 const RVC::RASTER& input,
00089 RVC::OBJITEM& objitem,
00090 const RVC::IMAGE::DATATYPE& datatype = RVC::IMAGE::DATATYPE_ComplexRI,
00091 const LRECT2D rect = LRECT2D(1,1,0,0)
00092 );
00093
00094 static ERRVALUE Inverse (
00095 const RVC::RASTER& input,
00096 RVC::OBJITEM& objitem,
00097 const RVC::IMAGE::CELLTYPE& celltype = RVC::IMAGE::CELLTYPE_Float_32,
00098 const LRECT2D rect = LRECT2D(1,1,0,0)
00099 );
00100
00101 static INT32 AdjustToPower2 (
00102 const INT32 num
00103 );
00104
00105 private:
00106 #ifndef GENERATING_DOXYGEN_OUTPUT
00107
00108 static ERRVALUE CopyGeoreference (
00109 const RVC::RASTER& input,
00110 RVC::RASTER& output,
00111 const LRECT2D& rect
00112 );
00113 #endif // GENERATING_DOXYGEN_OUTPUT
00114
00115 };
00116
00117 class FFT1D {
00118
00119 public:
00120
00121 static void SMLClassInstall (
00122 SML::CONTEXT *context
00123 );
00124
00126 FFT1D (
00127 );
00128
00130 ~FFT1D (
00131 );
00132
00134 ERRVALUE Init (
00135 const INT32 numEntries
00136 );
00137
00139 void Close (
00140 );
00141
00143 void Forward (
00144 DOUBLE_ARRAY<DCOMPLEX>& inout
00145 );
00146
00148 void Forward (
00149 const DOUBLE_ARRAY<DCOMPLEX>& in,
00150 DOUBLE_ARRAY<DCOMPLEX>& out
00151 );
00152
00154 void Forward (
00155 const DOUBLE_ARRAY<DCOMPLEX>& in,
00156 DOUBLE_ARRAY<double>& outx,
00157 DOUBLE_ARRAY<double>& outy,
00158 const FTFORMAT format = FTFORMAT_RI
00159 );
00160
00162 void Forward (
00163 const DOUBLE_ARRAY<double>& inx,
00164 const DOUBLE_ARRAY<double>& iny,
00165 DOUBLE_ARRAY<DCOMPLEX>& out,
00166 const FTFORMAT format = FTFORMAT_RI
00167 );
00168
00170 void Forward (
00171 DOUBLE_ARRAY<double>& inoutx,
00172 DOUBLE_ARRAY<double>& inouty,
00173 const FTFORMAT format = FTFORMAT_RI_RI
00174 );
00175
00177 void Forward (
00178 const DOUBLE_ARRAY<double>& inx,
00179 const DOUBLE_ARRAY<double>& iny,
00180 DOUBLE_ARRAY<double>& outx,
00181 DOUBLE_ARRAY<double>& outy,
00182 const FTFORMAT format = FTFORMAT_RI_RI
00183 );
00184
00186 void Inverse (
00187 DOUBLE_ARRAY<DCOMPLEX>& inout
00188 );
00189
00191 void Inverse (
00192 const DOUBLE_ARRAY<DCOMPLEX>& in,
00193 DOUBLE_ARRAY<DCOMPLEX>& out
00194 );
00195
00197 void Inverse (
00198 const DOUBLE_ARRAY<DCOMPLEX>& in,
00199 DOUBLE_ARRAY<double>& outx,
00200 DOUBLE_ARRAY<double>& outy,
00201 const FTFORMAT format = FTFORMAT_RI
00202 );
00203
00205 void Inverse (
00206 const DOUBLE_ARRAY<double>& inx,
00207 const DOUBLE_ARRAY<double>& iny,
00208 DOUBLE_ARRAY<DCOMPLEX>& out,
00209 const FTFORMAT format = FTFORMAT_RI
00210 );
00211
00213 void Inverse (
00214 DOUBLE_ARRAY<double>& inoutx,
00215 DOUBLE_ARRAY<double>& inouty,
00216 const FTFORMAT format = FTFORMAT_RI_RI
00217 );
00218
00220 void Inverse (
00221 const DOUBLE_ARRAY<double>& inx,
00222 const DOUBLE_ARRAY<double>& iny,
00223 DOUBLE_ARRAY<double>& outx,
00224 DOUBLE_ARRAY<double>& outy,
00225 const FTFORMAT format = FTFORMAT_RI_RI
00226 );
00227
00228 private:
00229 #ifndef GENERATING_DOXYGEN_OUTPUT
00230
00231 const DCOMPLEX m_Null;
00232
00233 INT32 m_NumEntries;
00234 DOUBLE_ARRAY<DCOMPLEX> m_Work;
00235 DOUBLE_ARRAY<DCOMPLEX> m_Temp;
00236 DOUBLE_ARRAY<DCOMPLEX> m_MinusRoot;
00237 DOUBLE_ARRAY<DCOMPLEX> m_PlusRoot;
00238
00239 bool IsValid (
00240 const INT32 numEntries
00241 ) const;
00242
00243 static void Copy (
00244 const DOUBLE_ARRAY<DCOMPLEX>& in,
00245 DOUBLE_ARRAY<DCOMPLEX>& out,
00246 INT32 numItems
00247 );
00248
00249 static void Copy (
00250 const DOUBLE_ARRAY<DCOMPLEX>& in,
00251 DOUBLE_ARRAY<double>& outx,
00252 DOUBLE_ARRAY<double>& outy,
00253 INT32 numItems,
00254 bool ri
00255 );
00256
00257 static void Copy (
00258 const DOUBLE_ARRAY<double>& inx,
00259 const DOUBLE_ARRAY<double>& iny,
00260 DOUBLE_ARRAY<DCOMPLEX>& out,
00261 INT32 numItems,
00262 bool ri
00263 );
00264
00265 void PadWorkNull (
00266 INT32 startindex
00267 );
00268
00269 void Transform (
00270 DOUBLE_ARRAY<DCOMPLEX>& root,
00271 INT32 N,
00272 INT32 K,
00273 bool forward
00274 );
00275
00277 FFT1D (const FFT1D&);
00278 FFT1D& operator= (const FFT1D&);
00279 #endif
00280 };
00281
00282
00283 class FT1D {
00284
00285 public:
00286
00287 static void SMLClassInstall (
00288 SML::CONTEXT *context
00289 );
00290
00292 FT1D (
00293 );
00294
00296 ~FT1D (
00297 );
00298
00300 ERRVALUE Init (
00301 const UINT32 numInputEntries,
00302 const UINT32 numOutputEntries
00303 );
00304
00306 void Close (
00307 );
00308
00310 void Forward (
00311 DOUBLE_ARRAY<DCOMPLEX>& inout,
00312 const UINT32 numInputEntries = 0,
00313 const UINT32 numOutputEntries = 0
00314 );
00315
00317 void Forward (
00318 const DOUBLE_ARRAY<DCOMPLEX>& in,
00319 DOUBLE_ARRAY<DCOMPLEX>& out,
00320 const UINT32 numInputEntries = 0,
00321 const UINT32 numOutputEntries = 0
00322 );
00323
00325 void Forward (
00326 const DOUBLE_ARRAY<DCOMPLEX>& in,
00327 DOUBLE_ARRAY<double>& outx,
00328 DOUBLE_ARRAY<double>& outy,
00329 const FTFORMAT format = FTFORMAT_RI,
00330 const UINT32 numInputEntries = 0,
00331 const UINT32 numOutputEntries = 0
00332 );
00333
00335 void Forward (
00336 const DOUBLE_ARRAY<double>& inx,
00337 const DOUBLE_ARRAY<double>& iny,
00338 DOUBLE_ARRAY<DCOMPLEX>& out,
00339 const FTFORMAT format = FTFORMAT_RI,
00340 const UINT32 numInputEntries = 0,
00341 const UINT32 numOutputEntries = 0
00342 );
00343
00345 void Forward (
00346 DOUBLE_ARRAY<double>& inoutx,
00347 DOUBLE_ARRAY<double>& inouty,
00348 const FTFORMAT format = FTFORMAT_RI_RI,
00349 const UINT32 numInputEntries = 0,
00350 const UINT32 numOutputEntries = 0
00351 );
00352
00354 void Forward (
00355 const DOUBLE_ARRAY<double>& inx,
00356 const DOUBLE_ARRAY<double>& iny,
00357 DOUBLE_ARRAY<double>& outx,
00358 DOUBLE_ARRAY<double>& outy,
00359 const FTFORMAT format = FTFORMAT_RI_RI,
00360 const UINT32 numInputEntries = 0,
00361 const UINT32 numOutputEntries = 0
00362 );
00363
00365 void Inverse (
00366 DOUBLE_ARRAY<DCOMPLEX>& inout,
00367 const UINT32 numInputEntries = 0,
00368 const UINT32 numOutputEntries = 0
00369 );
00370
00372 void Inverse (
00373 const DOUBLE_ARRAY<DCOMPLEX>& in,
00374 DOUBLE_ARRAY<DCOMPLEX>& out,
00375 const UINT32 numInputEntries = 0,
00376 const UINT32 numOutputEntries = 0
00377 );
00378
00380 void Inverse (
00381 const DOUBLE_ARRAY<DCOMPLEX>& in,
00382 DOUBLE_ARRAY<double>& outx,
00383 DOUBLE_ARRAY<double>& outy,
00384 const FTFORMAT format = FTFORMAT_RI,
00385 const UINT32 numInputEntries = 0,
00386 const UINT32 numOutputEntries = 0
00387 );
00388
00390 void Inverse (
00391 const DOUBLE_ARRAY<double>& inx,
00392 const DOUBLE_ARRAY<double>& iny,
00393 DOUBLE_ARRAY<DCOMPLEX>& out,
00394 const FTFORMAT format = FTFORMAT_RI,
00395 const UINT32 numInputEntries = 0,
00396 const UINT32 numOutputEntries = 0
00397 );
00398
00400 void Inverse (
00401 DOUBLE_ARRAY<double>& inoutx,
00402 DOUBLE_ARRAY<double>& inouty,
00403 const FTFORMAT format = FTFORMAT_RI_RI,
00404 const UINT32 numInputEntries = 0,
00405 const UINT32 numOutputEntries = 0
00406 );
00407
00409 void Inverse (
00410 const DOUBLE_ARRAY<double>& inx,
00411 const DOUBLE_ARRAY<double>& iny,
00412 DOUBLE_ARRAY<double>& outx,
00413 DOUBLE_ARRAY<double>& outy,
00414 const FTFORMAT format = FTFORMAT_RI_RI,
00415 const UINT32 numInputEntries = 0,
00416 const UINT32 numOutputEntries = 0
00417 );
00418
00419 private:
00420 #ifndef GENERATING_DOXYGEN_OUTPUT
00421
00422 INT32 m_NumInputEntries;
00423 INT32 m_NumOutputEntries;
00424 DOUBLE_ARRAY<DCOMPLEX> m_In;
00425 DOUBLE_ARRAY<DCOMPLEX> m_Out;
00426
00427 UINT32 CalculateNum (
00428 const UINT32 numNew,
00429 const UINT32 numGiven,
00430 const UINT32 numInput
00431 ) const;
00432
00433 bool IsValid (
00434 const UINT32 numInputEntries,
00435 const UINT32 numOutputEntries
00436 ) const;
00437
00438 static void Copy (
00439 const DOUBLE_ARRAY<DCOMPLEX>& in,
00440 DOUBLE_ARRAY<DCOMPLEX>& out,
00441 INT32 numItems
00442 );
00443
00444 static void Copy (
00445 const DOUBLE_ARRAY<DCOMPLEX>& in,
00446 DOUBLE_ARRAY<double>& outx,
00447 DOUBLE_ARRAY<double>& outy,
00448 INT32 numItems,
00449 bool ri
00450 );
00451
00452 static void Copy (
00453 const DOUBLE_ARRAY<double>& inx,
00454 const DOUBLE_ARRAY<double>& iny,
00455 DOUBLE_ARRAY<DCOMPLEX>& out,
00456 INT32 numItems,
00457 bool ri
00458 );
00459
00460 void Transform (
00461 const DOUBLE_ARRAY<DCOMPLEX>& in,
00462 const UINT32 numInputs,
00463 DOUBLE_ARRAY<DCOMPLEX>& out,
00464 const UINT32 numOutputs,
00465 bool forward
00466 );
00467
00469 FT1D (const FT1D&);
00470 FT1D& operator= (const FT1D&);
00471
00472 #endif
00473 };
00474
00475
00476 class TIMESERIES {
00477 public:
00478
00479 enum FLAG {
00480 FLAG_None = 0x0000,
00481 FLAG_UseFastFourierTransformation = 0x0001,
00482 FLAG_SmoothSeries = 0x0002,
00483 FLAG_RemoveTrend = 0x0004
00484 };
00485
00486 enum INTERPOLATION {
00487 INTERPOLATION_Linear,
00488 INTERPOLATION_CubicSpline
00489 };
00490
00491 static void SMLClassInstall (
00492 SML::CONTEXT *context
00493 );
00494
00495 TIMESERIES (
00496 ) :
00497 m_Flags(FLAG_None)
00498 { }
00499
00500 ~TIMESERIES (
00501 ) {
00502 }
00503
00505 FLAG GetFlags (
00506 ) {
00507 return m_Flags;
00508 };
00509
00511 void SetFlags (
00512 const FLAG flags
00513 ) {
00514 m_Flags = flags;
00515 };
00516
00518 void SetInterpolation (
00519 const INTERPOLATION interpolation
00520 ) {
00521 m_Interpolation = interpolation;
00522 return;
00523 };
00524
00525
00527 void Transform (
00528 const DOUBLE_ARRAY<double>& input,
00529 DOUBLE_ARRAY<double>& outx,
00530 DOUBLE_ARRAY<double>& outy,
00531 const FTFORMAT format = FTFORMAT_RI,
00532 const UINT32 numInputEntries = 0,
00533 const UINT32 numOutputEntries = 0
00534 );
00535
00536 private:
00537 #ifndef GENERATING_DOXYGEN_OUTPUT
00538
00539 class LINEAR_INTERPOLATOR;
00540 class CUBICSPLINE_INTERPOLATOR;
00541
00542 class INTERPOLATOR {
00543 public:
00544
00545 enum TYPE {
00546 TYPE_Linear = 0,
00547 TYPE_CubicSpline = 1
00548 };
00549
00550 static INTERPOLATOR& GetInterpolator (
00551 const TYPE type
00552 ) {
00553 if (type == TYPE_CubicSpline) return s_CubicSplineInterpolator;
00554 return s_LinearInterpolator;
00555 }
00556
00557 virtual ~INTERPOLATOR (
00558 ) {
00559 }
00560
00561 ERRVALUE Interpolate (
00562 DOUBLE_ARRAY<double>& inout,
00563 const INT32 numNewItems
00564 ) {
00565 DOUBLE_ARRAY<double> temp;
00566 int err = Interpolate(inout,temp,numNewItems);
00567 if (err < 0) return err;
00568 inout = temp;
00569 return 0;
00570 };
00571
00572 virtual ERRVALUE Interpolate (
00573 const DOUBLE_ARRAY<double>& in,
00574 DOUBLE_ARRAY<double>& out,
00575 const INT32 numNewItems
00576 ) = 0;
00577
00578 protected:
00579
00580 INTERPOLATOR (
00581 ) {
00582 };
00583
00584 private:
00585
00586 static LINEAR_INTERPOLATOR s_LinearInterpolator;
00587 static CUBICSPLINE_INTERPOLATOR s_CubicSplineInterpolator;
00588
00589 INTERPOLATOR (
00590 const INTERPOLATOR &rhs
00591 );
00592
00593 INTERPOLATOR& operator= (
00594 const INTERPOLATOR& rhs
00595 );
00596
00597 };
00598 friend class INTERPOLATOR;
00599
00600 class LINEAR_INTERPOLATOR : public INTERPOLATOR {
00601 public:
00602 LINEAR_INTERPOLATOR (
00603 ) {
00604 };
00605
00606 ERRVALUE Interpolate (
00607 const DOUBLE_ARRAY<double>& in,
00608 DOUBLE_ARRAY<double>& out,
00609 const INT32 numNewItems
00610 );
00611 };
00612
00613 class CUBICSPLINE_INTERPOLATOR : public INTERPOLATOR {
00614 public:
00615 CUBICSPLINE_INTERPOLATOR (
00616 ) {
00617 }
00618
00619 ERRVALUE Interpolate (
00620 const DOUBLE_ARRAY<double>& in,
00621 DOUBLE_ARRAY<double>& out,
00622 const INT32 numNewItems
00623 );
00624
00625 private:
00626
00627 DOUBLE_ARRAY<double> m_D;
00628 DOUBLE_ARRAY<double> m_W;
00629 DOUBLE_ARRAY<double> m_P;
00630
00631 };
00632
00633 class SMOOTHFILTER {
00634 public:
00635 ERRVALUE Filter (
00636 DOUBLE_ARRAY<double>& inout
00637 );
00638 };
00639
00640 class TRENDREMOVAL {
00641 public:
00642 ERRVALUE RemoveTrend (
00643 DOUBLE_ARRAY<double>& inout
00644 );
00645 };
00646
00647 FLAG m_Flags;
00648 INTERPOLATION m_Interpolation;
00649
00650 FFT1D m_FFT;
00651 FT1D m_FT;
00652
00653 DOUBLE_ARRAY<DCOMPLEX> m_Input;
00654 DOUBLE_ARRAY<double> m_Work;
00655 DOUBLE_ARRAY<double> m_Temp;
00656
00657 SMOOTHFILTER m_SmoothFilter;
00658 TRENDREMOVAL m_TrendRemoval;
00659
00660 TIMESERIES (const TIMESERIES&);
00661 TIMESERIES& operator= (const TIMESERIES&);
00662
00663 void Convert (
00664 const DOUBLE_ARRAY<double>& in,
00665 DOUBLE_ARRAY<DCOMPLEX>& out
00666 );
00667
00668 UINT32 GetUpperBound (
00669 const UINT32 value
00670 ) const;
00671
00672 #endif // GENERATING_DOXYGEN_OUTPUT
00673 };
00674
00675 #ifndef GENERATING_DOXYGEN_OUTPUT
00676 DEFINE_ENUM_OP_BITWISE(TIMESERIES::FLAG)
00677 #endif
00678
00679 #endif