[Insight-users] SOLVED: Re: integrating the ITK libraries into external application with "Piip"
barbababa
tonimuusimaki at gmail.com
Sun Jun 26 12:58:26 EDT 2011
yes you were right. There were four libraries, namely
DMPlugInBasic.dll
DMPlugInBasic-Dbg.dll
DMPlugInBasic_dll.lib
DMPlugInBasic_dll-Dbg.dll
and the last one built with no warnings.
But when i start the application with the dll it says:
functions signature is invalid
I tried to search solutions and tried to change a lot of things but no
effect. Basically i am just trying
to change the applications image so that itk recognizes it, then do the
discrete gaussian blurring and
then change the filtered itk image back so that the application recognizes
it. The code:
------------------------------------------------------------------------------------------------------
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
#include <itkImage.h>
#include <itkImageRegionIterator.h>
#include "itkDiscreteGaussianImageFilter.h"
#define _GATAN_USE_STL_STRING // Provide conversion from 'DM::String' to
'std::string'
#define _GATANPLUGIN_USES_LIBRARY_VERSION 2
#include "DMPlugInBasic.h"
#define _GATANPLUGIN_USE_CLASS_PLUGINMAIN
#include "DMPlugInMain.h"
using namespace Gatan;
#include <cassert>
#include <string>
class SampleImageProcessingPlugIn : public Gatan::PlugIn::PlugInMain
{
virtual void Start();
virtual void Run();
virtual void Cleanup();
virtual void End();
};
/*
** Implement the 'Horizontal_Derivative' script function.
*/
void ImgProc_Horizontal_Derivative( const DM::Image &src_img_in, DM::Image
&l_deriv_img_out,const double gaussianVariance,const unsigned int
maxKernelWidth )
{
/*
** For ease, we will only deal with 32-bit floating data
** ( 'ImageData::REAL4_DATA' in 'DMPlugInUtility.h' ), so
** if the data is not already that type, create a temporary image
** with the appropriate type.
*/
DM::Image src_img;
if ( src_img_in.GetDataType() != ImageData::REAL4_DATA )
{
src_img = src_img_in.Clone();
src_img.ChangeDataType( ImageData::REAL4_DATA );
}
if ( src_img_in.GetDataType() == ImageData::REAL4_DATA )
{
src_img = src_img_in.Clone();
}
int xsize,ysize;
/*
** You can use the 'GetDimensionSize' methods of 'DM::Image' to
** get the sizes of dimensions instead of 'getsize'
*/
typedef itk::Image< float32, 2 > ImageType;
ImageType::Pointer image = ImageType::New();
ImageType::SizeType size;
ImageType::IndexType start;
xsize = src_img.GetDimensionSize( 0 );
ysize = src_img.GetDimensionSize( 1 );
double spacing[2] =
{src_img.GetDimensionScale(0),src_img.GetDimensionScale(1)};
double origin[2] =
{src_img.GetDimensionOrigin(0),src_img.GetDimensionOrigin(1)};
start[0] = 0;
size[0] = xsize;
start[1] = 0;
size[1] = ysize;
std::string name = src_img.GetName().get_string();
DM::Image l_deriv_img ;
l_deriv_img = DM::NewImage( ( std::string("Left Derivative of ") +
name ).c_str()
, ImageData::REAL4_DATA
, xsize,ysize);
/*
** The 'PlugIn::ImageDataLocker' class locks the data in the image down so
** it is accessible from C++. The second parameter to the constructor
specifies
** how the data is to be locked down. The data in the image might not be
contiguous,
** so the 'PlugIn::ImageDataLocker::lock_data_CONTIGUOUS' flag will force
creation of
** a contiguous temporary if necessary. If that flag is not specified, one
must look
** at the 'ImageData::image_data_t' structure returned by the method
'ImageDataLocker::get_image_data()'
** to get the layout. When the 'ImageDataLocker' object is destructed,
the image data
** is unlocked, and if 'MarkDataChanged' was called on the object, the
data is copied back
** to the source image if a temporary was created.
**
*/
PlugIn::ImageDataLocker src_img_l( src_img,
PlugIn::ImageDataLocker::lock_data_CONTIGUOUS );
PlugIn::ImageDataLocker l_deriv_img_l( l_deriv_img,
PlugIn::ImageDataLocker::lock_data_CONTIGUOUS );
/*
** Here, we get the length and pointers to the data. The data is laid out
in row-major order
** ( dimension 0 first, then 1, 2, etc ), and the lengths and strides in
each dimension
** can be obtained by the 'image_data_t::get_length' and
'image_data_t::get_stride' methods
** respectively. The stride in a dimension is the number of bytes between
the start of
** consecutive data elements in that dimension. Because the data is locked
so it is
** contiguous, we may iterate through the data by ignore the stride,
convert the pointer
** to the data to a pointer to its C++ type, and index using the typed
pointer.
*/
// Check that the data types are what we expect. They should be because we
created them
// with the desired type.
assert( src_img_l.get_image_data().get_data_type() ==
ImageData::REAL4_DATA );
assert( l_deriv_img_l.get_image_data().get_data_type() ==
ImageData::REAL4_DATA );
// Get the lengths in the desired dimensions ( this is the same as 'xsize'
and 'ysize' above ).
ulong x_src_img_len = src_img_l.get_image_data().get_dim_length(0);
ulong y_src_img_len = src_img_l.get_image_data().get_dim_length(1);
// Get pointers to the data
float32 *src_img_data = reinterpret_cast<float32*>(
src_img_l.get_image_data().get_data() );
float32 *l_deriv_img_data = reinterpret_cast<float32*>(
l_deriv_img_l.get_image_data().get_data() );
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
image->SetRegions( region);
image->Allocate();
image->SetSpacing( spacing );
image->SetOrigin( origin );
typedef itk::ImageRegionIterator< ImageType> IteratorType;
IteratorType it( image, region);
it.GoToBegin();
float32 * data= src_img_data;
while( ! it.IsAtEnd() )
{
it.Set( *data);
++it;
++data;
}
typedef itk::DiscreteGaussianImageFilter<ImageType, ImageType >
FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput( image );
filter->SetVariance( gaussianVariance );
filter->SetMaximumKernelWidth( maxKernelWidth );
filter->Update();
ImageType::Pointer myImage = filter->GetOutput();
// this is not probably working
l_deriv_img_data = myImage ->GetBufferPointer();
l_deriv_img_l.MarkDataChanged();
l_deriv_img_out = l_deriv_img;
DM::Result( "(Script) Hello, world! Brought to you by Sample Interfaces
plug-in.\n" );
}
/*
** Provide a proxy for 'ImgProc_Horizontal_Derivative' that can be installed
** as a script function. Note that C++ class references cannot be passed to
the
** script language, only raw pointers, so 'DM::Image' cannot be used as an
argument
** to a script function. Instead, 'DM_ImageToken' is used for image rvalues,
and
** 'DM_ImageToken *' for lvalues. The following function shows how to
convert.
*/
void SF_ImgProc_Horizontal_Derivative( DM_ImageToken src_img, DM_ImageToken
*l_deriv_img_out,const double gaussianVariance,const unsigned int
maxKernelWidth)
{
DM::Image l_deriv_img;
ImgProc_Horizontal_Derivative( src_img, l_deriv_img,gaussianVariance
,maxKernelWidth);
DM::Image::assign_ptr( *l_deriv_img_out, l_deriv_img.get() );
}
///
/// This is called when the plugin is loaded. Whenever DM is
/// launched, it calls 'Start' for each installed plug-in.
/// When it is called, there is no guarantee that any given
/// plugin has already been loaded, so the code should not
/// rely on scripts installed from other plugins. The primary
/// use is to install script functions.
///
void SampleImageProcessingPlugIn::Start()
{
AddFunction( "void ImgProc_Horizontal_Derivative( BasicImage src_img,
BasicImage *l_deriv_img, RealNumber gaussianVariance, Number
maxKernelWidth)", &SF_ImgProc_Horizontal_Derivative );
}
///
/// This is called when the plugin is loaded, after the 'Start' method.
/// Whenever DM is launched, it calls the 'Run' method for
/// each installed plugin after the 'Start' method has been called
/// for all such plugins and all script packages have been installed.
/// Thus it is ok to use script functions provided by other plugins.
///
void SampleImageProcessingPlugIn::Run()
{
}
///
/// This is called when the plugin is unloaded. Whenever DM is
/// shut down, the 'Cleanup' method is called for all installed plugins
/// before script packages are uninstalled and before the 'End'
/// method is called for any plugin. Thus, script functions provided
/// by other plugins are still available. This method should release
/// resources allocated by 'Run'.
///
void SampleImageProcessingPlugIn::Cleanup()
{
}
///
/// This is called when the plugin is unloaded. Whenever DM is shut
/// down, the 'End' method is called for all installed plugins after
/// all script packages have been unloaded, and other installed plugins
/// may have already been completely unloaded, so the code should not
/// rely on scripts installed from other plugins. This method should
/// release resources allocated by 'Start', and in particular should
/// uninstall all installed script functions.
///
void SampleImageProcessingPlugIn::End()
{
}
SampleImageProcessingPlugIn gSampleImageProcessingPlugIn;
-----------------------------------------------------------------------------------------------------
I think the problem is in the "SampleImageProcessingPlugIn::Start()"
and how it connects to
" void SF_ImgProc_Horizontal_Derivative( DM_ImageToken src_img,
DM_ImageToken *l_deriv_img_out,const double gaussianVariance,const unsigned
int maxKernelWidth)"
but i have not managed to solve it.
Does anyone see any obvious mistake here?
Thanks in advance!
cheers,
toni
--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/integrating-the-ITK-libraries-into-external-application-with-VC6-tp6513729p6517643.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list