Filter Library Camera Interface Physics

ToolCilImage.h

00001 /*
00002  * ToolCilImage.h - convert CScanBaseBuffer to CIL types.
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) 2005, Leiden Probe Microscopy.
00008  * Copyright (C) 2005, Universiteit Leiden.
00009  *
00010  * Authors: Martin J. Moene (original)
00011  *
00012  * $Id: ToolCilImage.h 386 2006-07-17 11:00:27Z moene $
00013  */
00014 
00015 #ifndef CFL_TOOLCILIMAGE_H
00016 #define CFL_TOOLCILIMAGE_H
00017 
00018 #include <cfl/ScanBaseBuffer.h>         // for class CScanBaseBuffer
00019 
00020 #include <cil/Image.h>              // for class cil::Image<>   FIXME
00021 
00022 #if _MSC_VER > 1000
00023 #pragma once
00024 #endif // _MSC_VER > 1000
00025 
00026 /**
00027  * a scan buffer image.
00028  */
00029 typedef cil::Image< CScanBaseBuffer::ValueType > Image;
00030 
00031 /**
00032  * to radius conversion shim.
00033  */
00034 inline cil::Size2D ToRadius( int x, int y )
00035 {
00036    return cil::Size2D( ( x - 1 ) / 2, ( y - 1 ) / 2 );
00037 }
00038 
00039 /**
00040  * ScanBaseBuffer region conversion shim.
00041  */
00042 inline cil::Region2D ToRegion( const CRect& rcArea )
00043 {
00044    return cil::Region2D(
00045       cil::Point2D( rcArea.left, rcArea.top ),
00046       cil::Size2D ( rcArea.Width(), rcArea.Height() ) );
00047 }
00048 
00049 /**
00050  * ScanBaseBuffer Image conversion shim (handles backward stroke while measuring).
00051  */
00052 inline Image ToImage( CScanBaseBufferPtr lpScanBuffer, bool bDoR2L = false )
00053 {
00054 //    return Image(
00055 //       lpScanBuffer->Data() + bDoR2L * lpScanBuffer->GetFrameSize(),
00056 //          cil::Size2D( lpScanBuffer->Columns(), lpScanBuffer->Rows() )
00057 //    );
00058 
00059    typedef CScanBaseBuffer::SizeType SizeType;
00060 
00061    SizeType       rows    = lpScanBuffer->Rows();
00062    const SizeType columns = lpScanBuffer->Columns();
00063    const SizeType offset  = lpScanBuffer->GetPartialFrameOffset();
00064    const SizeType count   = lpScanBuffer->GetPartialFrameSize();
00065 
00066    /*
00067     * The following logic is used to omit the backward stroke
00068     * from the filter operation while measuring.
00069     * While analyzing, the offset and count are both zero.
00070     */
00071    if ( 0 != count )
00072    {
00073       rows = count / columns;
00074    }
00075 
00076    return Image(
00077       lpScanBuffer->Data() + bDoR2L * lpScanBuffer->GetFrameSize() + offset,
00078          cil::Size2D( columns, rows )
00079    );
00080 }
00081 
00082 /**
00083  * ScanBaseBuffer Image conversion shim (only used while analyzing).
00084  */
00085 inline Image ToImage( CScanBaseBufferPtr lpScanBuffer, bool bDoR2L, const CRect& rcArea )
00086 {
00087    return Image(
00088       lpScanBuffer->Data() + bDoR2L * lpScanBuffer->GetFrameSize(),
00089          cil::Size2D( lpScanBuffer->Columns(), lpScanBuffer->Rows() ), ToRegion( rcArea )
00090    );
00091 }
00092 
00093 #endif // #ifndef CFL_TOOLCILIMAGE_H
00094 
00095 /*
00096  * end of file
00097  */
00098 

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