Filter Library Camera Interface Physics

ScanFilterFourierBase.cpp

00001 /*
00002  * ScanFilterFourierBase.cpp - base class for FFT.
00003  *
00004  * This file is part of the Camera Filter Library.
00005  * Computer Aided Measurement Environment for Realtime Atomic imaging (Camera)
00006  *
00007  * Copyright (C) 2004-2005, Leiden Probe Microscopy.
00008  * Copyright (C) 2004-2005, Universiteit Leiden.
00009  *
00010  * Authors: M. Seynen (original), Martin J. Moene
00011  *
00012  * $Id: ScanFilterFourierBase.cpp 400 2006-09-28 13:34:02Z moene $
00013  */
00014 
00015 #include "stdafx.h"                     // for common (pre-compiled) headers
00016 //#include <cfl/stdafx.h>                 // for common (pre-compiled) headers
00017 #include <cfl/resource.h>               // for messages and other resources
00018 
00019 #include <Camera/InterfaceDll.h>        // Camera--Filter Library interface
00020 
00021 #include <cfl/ScanFilterFourierBase.h>  // this filter's header
00022 
00023 #pragma warning( disable: 4018 4100 4116 4146 4244 4663)
00024 #include <cil/Math.h>                   // for cil::min()
00025 #pragma warning( default: 4018 4100 4116 4146 4244 4663)
00026 
00027 #undef min                              // use cil::min instead of macro
00028 #undef max                              // use cil::max instead of macro
00029 
00030 /*
00031  * configuration defines:
00032  */
00033 
00034 // currently none
00035 
00036 /*
00037  * end of configuration defines.
00038  */
00039 
00040 #ifdef _DEBUG
00041 #undef THIS_FILE
00042 static char THIS_FILE[]=__FILE__;
00043 #define new DEBUG_NEW
00044 #endif
00045 
00046 #define CFL_SCHEMAVERSION_FILTERFOURIERBASE 0   // permanent storage schema version
00047                                                 // serialization
00048 IMPLEMENT_SERIAL( CScanFilterFourierBase, CScanFilter, CFL_SCHEMAVERSION_FILTERFOURIERBASE)
00049 
00050 /**
00051  * constructor.
00052  */
00053 CScanFilterFourierBase::CScanFilterFourierBase()
00054 {
00055    ; // do nothing
00056 }
00057 
00058 /**
00059  * destructor.
00060  */
00061 CScanFilterFourierBase::~CScanFilterFourierBase()
00062 {
00063    ; // do nothing
00064 }
00065 
00066 /**
00067  * store or retrieve the object's settings;
00068  * see also CScanFilterNull::Serialize().
00069  */
00070 void CScanFilterFourierBase::Serialize(CArchive& ar)
00071 {
00072    CScanFilter::Serialize( ar );
00073 
00074    if ( ar.IsStoring() )
00075    {
00076       ; // do nothing
00077    }
00078    else
00079    {
00080       ; // do nothing
00081    }
00082 };
00083 
00084 /**
00085  * build a temporary amplitude buffer (real type).
00086  */
00087 CScanFilterFourierBase::RealType CScanFilterFourierBase::BuildTmpAmpBuffer(int n1, int n2, BOOL bL2R, BOOL bR2L, FourierElementType** alr, FourierElementType** arl, RealType *dAmpBuffer)
00088 {
00089    RealType dAmplitute;
00090    RealType dMax = 0.0;
00091 
00092    /*
00093     * convert all Real/Img data from alr/arl to the log10(|A|) and store in the AmpBuffer;
00094     * keep track of biggest value so that we scale the results to owr 16 bit data in a ScanBuffer;
00095     * swap the quadrants while we go
00096     */
00097    for (int y = 0; y < n1 / 2; ++y )
00098    {
00099       for ( int x = 0; x < n2 * 2 / 2; x += 2 )
00100       {
00101          if ( bL2R )
00102          {
00103             //Q0 -> Q2
00104             //                          dAmplitute = lpm::log10( lpm::sqrt( pow(alr[y][x] , 2.0) + pow(alr[y][x+1] , 2.0) ));
00105             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( alr[y][x] ) + lpm::sqr( alr[y][x+1] ) ) );
00106             dMax = lpm::absmax( dAmplitute, dMax );
00107             dAmpBuffer[n2/2 + n2*n1/2 + y*n2 + x/2] = dAmplitute;
00108 
00109             //Q1 -> Q3
00110             //                          dAmplitute = log10(sqrt( pow(alr[y][x+n2],2.0) + pow(alr[y][x+n2+1] , 2.0) ));
00111             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( alr[y][x+n2] ) + lpm::sqr( alr[y][x+n2+1] ) ) );
00112             dMax = lpm::absmax( dAmplitute, dMax );
00113             dAmpBuffer[n2*n1/2 + y*n2 + x/2] = dAmplitute;
00114 
00115             //Q2 -> Q0
00116             //                          dAmplitute = log10(sqrt( pow(alr[y+n1/2][x+n2],2.0) + pow(alr[y+n1/2][x+n2+1] , 2.0) ));
00117             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( alr[y+n1/2][x+n2] ) + lpm::sqr( alr[y+n1/2][x+n2+1] ) ) );
00118             dMax = lpm::absmax( dAmplitute, dMax );
00119             dAmpBuffer[y*n2 + x/2] = dAmplitute;
00120 
00121             //Q3 -> Q1
00122             //                          dAmplitute = log10(sqrt( pow(alr[y+n1/2][x],2.0) + pow(alr[y+n1/2][x+1] , 2.0) ));
00123             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( alr[y+n1/2][x] ) + lpm::sqr( alr[y+n1/2][x+1] ) ) );
00124             dMax = lpm::absmax( dAmplitute, dMax );
00125             dAmpBuffer[n2/2 + y*n2 + x/2] = dAmplitute;
00126          }
00127 
00128          if ( bR2L )
00129          {
00130             //Q0 -> Q2
00131             //                          dAmplitute = log10(sqrt( pow(arl[y][x] , 2.0) + pow(arl[y][x+1] , 2.0) ));
00132             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( arl[y][x] ) + lpm::sqr( arl[y][x+1] ) ) );
00133             dMax = lpm::absmax( dAmplitute, dMax );
00134             dAmpBuffer[n1*n2 + n2/2 + n2*n1/2 + y*n2 + x/2] = dAmplitute;
00135 
00136             //Q1 -> Q3
00137             //                          dAmplitute = log10(sqrt( pow(arl[y][x+n2],2.0) + pow(arl[y][x+n2+1] , 2.0) ));
00138             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( arl[y][x+n2] ) + lpm::sqr( arl[y][x+n2+1] ) ) );
00139             dMax = lpm::absmax( dAmplitute, dMax );
00140             dAmpBuffer[n1*n2 + n2*n1/2 + y*n2 + x/2] = dAmplitute;
00141 
00142             //Q2 -> Q0
00143             //                          dAmplitute = log10(sqrt( pow(arl[y+n1/2][x+n2],2.0) + pow(arl[y+n1/2][x+n2+1] , 2.0) ));
00144             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( arl[y+n1/2][x+n2] ) + lpm::sqr( arl[y+n1/2][x+n2+1] ) ) );
00145             dMax = lpm::absmax( dAmplitute, dMax );
00146             dAmpBuffer[n1*n2 + y*n2 + x/2] = dAmplitute;
00147 
00148             //Q3 -> Q1
00149             //                          dAmplitute = log10(sqrt( pow(arl[y+n1/2][x],2.0) + pow(arl[y+n1/2][x+1] , 2.0) ));
00150             dAmplitute = lpm::log10( lpm::sqrt( lpm::sqr( arl[y+n1/2][x] ) + lpm::sqr( arl[y+n1/2][x+1] ) ) );
00151             dMax = lpm::absmax( dAmplitute, dMax );
00152             dAmpBuffer[n1*n2 + n2/2 + y*n2 + x/2] = dAmplitute;
00153          }
00154       }
00155    }
00156 
00157    return dMax;
00158 }
00159 
00160 /**
00161  * copy a temporary amplitude buffer to the scanbuffer (scaled).
00162  */
00163 void CScanFilterFourierBase::CopyAmpBufferToScanBuffer( int n1, int n2, BOOL bL2R, BOOL bR2L, RealType *dAmpBuffer, RealType dMax )
00164 {
00165    m_lpsbOut->ResizeDataBuffer( CSize( n2, n1 ) );
00166 
00167    // Set output buffer stuff
00168    RealType dScale = 20000.0 / dMax;
00169    m_lpsbOut->m_dDataScaleFactor = 1.0 / dScale;
00170    m_lpsbOut->m_nDataOffset = 0;
00171 
00172    // becase we now user log10 of the amplitude, it is possible that
00173    // a log10 ( x<=0 ) is in the AmpBuffer (-1#INF)
00174    // if so, convert this value to the minimum (-20.000);
00175 
00176    if ( bR2L && bL2R )
00177    {
00178       for (int i = 0; i < 2 * n1 * n2; ++i )
00179       {
00180          m_lpsbOut->m_pwData[i] = ( dAmpBuffer[i] < -100 ) ? (ValueType) -20000 : (ValueType)( dScale * dAmpBuffer[i] );
00181       }
00182    }
00183    else if (bL2R)
00184    {
00185       for (int i = 0; i < n1 * n2; ++i )
00186       {
00187          m_lpsbOut->m_pwData[i] = ( dAmpBuffer[i] < -100 ) ? (ValueType) -20000 : (ValueType)( dScale * dAmpBuffer[i] );
00188       }
00189    }
00190    else
00191    {
00192       for (int i = 0; i < n1 * n2; ++i )
00193       {
00194          m_lpsbOut->m_pwData[i] = ( dAmpBuffer[i] < -100 ) ? (ValueType) -20000 : (ValueType)( dScale * dAmpBuffer[i+n1*n2] );
00195       }
00196    }
00197 }
00198 
00199 /*
00200  * end of file
00201  */
00202 

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy