00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CFILTLIB_SCANBASEBUFFER_H
00016 #define CFILTLIB_SCANBASEBUFFER_H
00017
00018 #if _MSC_VER > 1000
00019 #pragma once
00020 #endif // _MSC_VER > 1000
00021
00022 #ifdef _AFXEXT
00023
00024 #define CLASS_DECL _declspec(dllexport)
00025 #else
00026
00027 #define CLASS_DECL _declspec(dllimport)
00028 #endif
00029
00030
00031
00032
00033
00034
00035 class CLASS_DECL CScanBaseBuffer : public CObject
00036 {
00037 public:
00038
00039
00040
00041 typedef CObject Super;
00042
00043
00044
00045
00046 typedef CScanBaseBuffer Self;
00047
00048
00049
00050
00051 typedef short ValueType;
00052
00053
00054
00055
00056 typedef ValueType* Pointer;
00057
00058
00059
00060
00061 typedef const ValueType* ConstPointer;
00062
00063
00064
00065
00066 typedef double RealType;
00067
00068
00069
00070
00071 typedef RealType FourierElementType;
00072
00073
00074
00075
00076 typedef DWORD SizeType;
00077
00078
00079
00080
00081 typedef DWORD FlagType;
00082
00083
00084
00085
00086 typedef DWORD MaskType;
00087
00088
00089
00090
00091 typedef RealType SpacingType;
00092
00093
00094
00095
00096 typedef RealType LengthType;
00097
00098
00099
00100
00101
00102
00103
00104
00105 virtual ~CScanBaseBuffer();
00106
00107
00108
00109
00110 CScanBaseBuffer();
00111
00112
00113
00114
00115
00116
00117
00118
00119 bool HasLeftToRightScan() const;
00120
00121
00122
00123
00124 bool HasRightToLeftScan() const;
00125
00126
00127
00128
00129 bool IsBidirectionalScan() const;
00130
00131
00132
00133
00134 bool IsCompleteFrame() const;
00135
00136
00137
00138
00139 bool IsNewBuffer() const;
00140
00141
00142
00143
00144 bool IsEmptyBuffer() const;
00145
00146
00147
00148
00149 bool IsLoadedBuffer() const;
00150
00151
00152
00153
00154 bool IsModifiedBuffer() const;
00155
00156
00157
00158
00159 bool IsInMemoryBuffer() const;
00160
00161
00162
00163
00164
00165
00166
00167
00168 SizeType Columns() const;
00169
00170
00171
00172
00173 SizeType Rows() const;
00174
00175
00176
00177
00178 Pointer Data();
00179
00180
00181
00182
00183 ConstPointer Data() const;
00184
00185
00186
00187
00188 FourierElementType** FourierDataL2R();
00189
00190
00191
00192
00193 FourierElementType const* const* FourierDataL2R() const;
00194
00195
00196
00197
00198 FourierElementType** FourierDataR2L();
00199
00200
00201
00202
00203 FourierElementType const* const* FourierDataR2L() const;
00204
00205
00206
00207
00208 SizeType GetFrameSize() const;
00209
00210
00211
00212
00213 SizeType GetPartialFrameOffset() const;
00214
00215
00216
00217
00218 SizeType GetPartialFrameSize() const;
00219
00220
00221
00222
00223 LengthType GetFrameWidth() const;
00224
00225
00226
00227
00228 LengthType GetFrameHeight() const;
00229
00230
00231
00232
00233 SpacingType GetSpacingX() const;
00234
00235
00236
00237
00238 SpacingType GetSpacingY() const;
00239
00240
00241
00242
00243 SpacingType GetSpacingZ() const;
00244
00245
00246
00247
00248 LengthType GetLengthX( SizeType dx ) const;
00249
00250
00251
00252
00253 LengthType GetLengthY( SizeType dy ) const;
00254
00255
00256
00257
00258 LengthType GetAbsoluteHeight( ValueType adcValue ) const;
00259
00260
00261
00262
00263 SizeType GetRowsForFFT() const;
00264
00265
00266
00267
00268 SizeType GetColumnsForFFT() const;
00269
00270
00271
00272
00273 static SizeType GetSizeForFFT( SizeType size );
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 BOOL CheckAndSetBufferSize();
00284
00285
00286
00287
00288 void ClearDataBuffer();
00289
00290
00291
00292
00293 void ClearFourierBuffer();
00294
00295
00296
00297
00298 BOOL CreateInputBuffer( const CSize& size );
00299
00300
00301
00302
00303 BOOL CreateOutputBufferFor( const Self& input, SizeType extra = 0 );
00304
00305
00306
00307
00308 BOOL ResizeDataBuffer( const CSize& size, SizeType extra = 0 );
00309
00310
00311
00312
00313 BOOL CreateFourierBuffer();
00314
00315
00316
00317
00318 BOOL DeleteFourierBuffer();
00319
00320
00321
00322
00323
00324 BOOL CopyFourierBufferFrom( const Self& other );
00325
00326
00327
00328 protected:
00329
00330
00331
00332
00333
00334
00335
00336 void Copy( const Self& rhs );
00337
00338
00339
00340
00341 void AllocateDataBuffer( SizeType extra = 0 );
00342
00343
00344
00345
00346 void AllocateFourierBuffer();
00347
00348
00349
00350
00351 void ReleaseAllBuffers();
00352
00353
00354
00355
00356 void ReleaseDataBuffer();
00357
00358
00359
00360
00361 void ReleaseFourierBuffer();
00362
00363
00364
00365
00366
00367 BOOL IsUsableOutputBufferFor( const Self& input );
00368
00369
00370
00371 private:
00372
00373
00374
00375
00376
00377
00378
00379 CScanBaseBuffer( const Self& rhs );
00380
00381
00382
00383
00384 Self& operator= ( const Self& rhs );
00385
00386
00387
00388 public:
00389
00390
00391
00392 FlagType m_dwFlags;
00393
00394
00395
00396
00397 SizeType m_dwSizeX;
00398
00399
00400
00401
00402 SizeType m_dwSizeY;
00403
00404
00405
00406
00407 SizeType m_dwPixels;
00408
00409
00410
00411
00412 Pointer m_pwData;
00413
00414
00415
00416
00417 FourierElementType** m_pdFourierL2R;
00418
00419
00420
00421
00422 FourierElementType** m_pdFourierR2L;
00423
00424
00425
00426
00427 CString m_csBufferName;
00428
00429
00430
00431
00432 CString m_csDataName;
00433
00434
00435
00436
00437 CString m_csDataUnit;
00438
00439
00440
00441
00442 RealType m_dDataScaleFactor;
00443
00444
00445
00446
00447 int m_nDataOffset;
00448
00449
00450
00451
00452
00453 MaskType m_dwParameterMask;
00454
00455
00456
00457
00458 RealType m_dSlopeX;
00459
00460
00461
00462
00463 RealType m_dSlopeY;
00464
00465
00466
00467
00468 RealType m_dAvg;
00469
00470
00471
00472
00473 int m_nMinZ;
00474
00475
00476
00477
00478 int m_nMaxZ;
00479
00480
00481
00482
00483 RealType m_dSecMom;
00484
00485
00486
00487
00488 SizeType m_dwPixelOffset;
00489
00490
00491
00492
00493 SizeType m_dwPixelCount;
00494
00495
00496
00497
00498 RealType m_dXStepSize;
00499
00500
00501
00502
00503 RealType m_dYStepSize;
00504
00505
00506
00507
00508 SizeType m_dwOrgScanXSize;
00509
00510
00511
00512
00513 SizeType m_dwOrgScanYSize;
00514
00515
00516
00517
00518 RealType m_dScanAngle;
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 enum tStatus
00529 {
00530 SB_NOTLOADED=0,
00531 SB_LOADED,
00532 SB_NEW,
00533 SB_TEMP,
00534 SB_MODIFIED,
00535 };
00536
00537
00538
00539
00540 typedef tStatus StatusType;
00541
00542 protected:
00543 DECLARE_DYNCREATE( CScanBaseBuffer );
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 StatusType m_eStatus;
00568
00569 SizeType m_dwMemoryAllocated;
00570 LARGE_INTEGER m_liRAWIndex;
00571 LARGE_INTEGER m_liEditIndex;
00572 };
00573
00574
00575
00576
00577
00578
00579
00580
00581 inline bool CScanBaseBuffer::HasLeftToRightScan() const
00582 {
00583 return 0 != ( m_dwFlags & SPM_SDBF_LEFT2RIGHT );
00584 }
00585
00586
00587
00588
00589 inline bool CScanBaseBuffer::HasRightToLeftScan() const
00590 {
00591 return 0 != ( m_dwFlags & SPM_SDBF_RIGHT2LEFT );
00592 }
00593
00594
00595
00596
00597 inline bool CScanBaseBuffer::IsBidirectionalScan() const
00598 {
00599 return HasLeftToRightScan() && HasRightToLeftScan();
00600 }
00601
00602
00603
00604
00605 inline CScanBaseBuffer::SizeType CScanBaseBuffer::Columns() const
00606 {
00607 return m_dwSizeX;
00608 }
00609
00610
00611
00612
00613 inline CScanBaseBuffer::SizeType CScanBaseBuffer::Rows() const
00614 {
00615 return m_dwSizeY;
00616 }
00617
00618
00619
00620
00621 inline CScanBaseBuffer::Pointer CScanBaseBuffer::Data()
00622 {
00623 return m_pwData;
00624 }
00625
00626
00627
00628
00629 inline CScanBaseBuffer::ConstPointer CScanBaseBuffer::Data() const
00630 {
00631 return m_pwData;
00632 }
00633
00634
00635
00636
00637 inline CScanBaseBuffer::FourierElementType** CScanBaseBuffer::FourierDataL2R()
00638 {
00639 return m_pdFourierL2R;
00640 }
00641
00642
00643
00644
00645 inline CScanBaseBuffer::FourierElementType const* const * CScanBaseBuffer::FourierDataL2R() const
00646 {
00647 return m_pdFourierL2R;
00648 }
00649
00650
00651
00652
00653 inline CScanBaseBuffer::FourierElementType** CScanBaseBuffer::FourierDataR2L()
00654 {
00655 return m_pdFourierR2L;
00656 }
00657
00658
00659
00660
00661 inline CScanBaseBuffer::FourierElementType const* const* CScanBaseBuffer::FourierDataR2L() const
00662 {
00663 return m_pdFourierR2L;
00664 }
00665
00666
00667
00668
00669 inline CScanBaseBuffer::SizeType CScanBaseBuffer::GetFrameSize() const
00670 {
00671 return m_dwSizeY * m_dwSizeX;
00672 }
00673
00674
00675
00676
00677 inline CScanBaseBuffer::SizeType CScanBaseBuffer::GetPartialFrameOffset() const
00678 {
00679 return m_dwPixelOffset;
00680 }
00681
00682
00683
00684
00685 inline CScanBaseBuffer::SizeType CScanBaseBuffer::GetPartialFrameSize() const
00686 {
00687 return m_dwPixelCount;
00688 }
00689
00690
00691
00692
00693 inline bool CScanBaseBuffer::IsCompleteFrame() const
00694 {
00695 #if 0
00696 CString s;
00697 s.Format( "IN: PixelCount:%d Pixels:%d FrameSize:%d",
00698 m_dwPixelCount, m_dwPixels, GetFrameSize() );
00699
00700 Q_LOG( _T(s) );
00701 #endif
00702
00703 return m_dwPixels == ( 1 + IsBidirectionalScan() ) * GetFrameSize();
00704
00705
00706
00707 }
00708
00709
00710
00711
00712 inline bool CScanBaseBuffer::IsNewBuffer() const
00713 {
00714 return SB_NEW == m_eStatus;
00715 }
00716
00717
00718
00719
00720 inline bool CScanBaseBuffer::IsEmptyBuffer() const
00721 {
00722 return SB_NOTLOADED == m_eStatus;
00723 }
00724
00725
00726
00727
00728 inline bool CScanBaseBuffer::IsLoadedBuffer() const
00729 {
00730 return SB_LOADED == m_eStatus;
00731 }
00732
00733
00734
00735
00736 inline bool CScanBaseBuffer::IsModifiedBuffer() const
00737 {
00738 return SB_MODIFIED == m_eStatus;
00739 }
00740
00741
00742
00743
00744 inline bool CScanBaseBuffer::IsInMemoryBuffer() const
00745 {
00746 return SB_TEMP == m_eStatus;
00747 }
00748
00749
00750
00751
00752 inline CScanBaseBuffer::SpacingType CScanBaseBuffer::GetSpacingX() const
00753 {
00754 return m_dXStepSize * 1e-12;
00755 }
00756
00757
00758
00759
00760 inline CScanBaseBuffer::SpacingType CScanBaseBuffer::GetSpacingY() const
00761 {
00762 return m_dYStepSize * 1e-12;
00763 }
00764
00765
00766
00767
00768 inline CScanBaseBuffer::SpacingType CScanBaseBuffer::GetSpacingZ() const
00769 {
00770
00771
00772
00773 RealType unit = 1e-9;
00774
00775 if ( m_csDataUnit.IsEmpty() )
00776 return m_dDataScaleFactor * unit;
00777
00778 switch ( m_csDataUnit.GetAt(0) )
00779 {
00780 case 'p': unit = 1e-12; break;
00781 case 'n': unit = 1e-9; break;
00782 case 'u': unit = 1e-6; break;
00783 case 'm': unit = 1e-3; break;
00784 case 'k': unit = 1e+3; break;
00785 case 'M': unit = 1e+6; break;
00786 case 'G': unit = 1e+9; break;
00787 }
00788
00789 return m_dDataScaleFactor * unit;
00790 }
00791
00792
00793
00794
00795 inline CScanBaseBuffer::LengthType CScanBaseBuffer::GetLengthX( SizeType dx ) const
00796 {
00797 return dx * GetSpacingX();
00798 }
00799
00800
00801
00802
00803 inline CScanBaseBuffer::LengthType CScanBaseBuffer::GetLengthY( SizeType dy ) const
00804 {
00805 return dy * GetSpacingY();
00806 }
00807
00808
00809
00810
00811 inline CScanBaseBuffer::LengthType CScanBaseBuffer::GetAbsoluteHeight( ValueType adcValue ) const
00812 {
00813 return ( adcValue + m_nDataOffset ) * GetSpacingZ();
00814 }
00815
00816
00817
00818
00819 inline CScanBaseBuffer::SizeType CScanBaseBuffer::GetRowsForFFT() const
00820 {
00821 return GetSizeForFFT( Rows() );
00822 }
00823
00824
00825
00826
00827 inline CScanBaseBuffer::SizeType CScanBaseBuffer::GetColumnsForFFT() const
00828 {
00829 return GetSizeForFFT( Columns() );
00830 }
00831
00832
00833
00834
00835 inline CScanBaseBuffer::SizeType CScanBaseBuffer::GetSizeForFFT( SizeType size )
00836 {
00837 return static_cast< SizeType >( pow( 2.0, ceil( log( static_cast<double>( size ) ) / log( 2.0 ) ) ) );
00838 }
00839
00840 #endif // ifndef CFILTLIB_SCANBASEBUFFER_H
00841
00842
00843
00844
00845