[Insight-users] Re: Managed ITK in Managed C++

Dan Mueller dan.muel at gmail.com
Mon Sep 17 16:11:15 EDT 2007


Hi Young,

Thanks for your question regarding ManagedITK. In the future, it is
probably best to email your questions to the Insight Users mailing
list: that way other people can search for the answer if they have
similar questions.

> I want to use Managed ITK Segmentation functions with my own application of Managed C++ (Window Forms, CLR, MSVC 8.0). But I have problems calling ITK object directly in Cpp files. Whenever I create an object, the compiler complaints "error C3767: candidate functions(s) not accessible".

The error you are getting could be caused by a number of different
things. To work it out it would be helpful if you could email me the
answers to these questions:
  1. Are you using the pre-compiled or your own compiled version of ManagedITK?
  2. Are you using Visual Studio SP1? The pre-compiled assemblies I
have uploaded to the Insight Journal were compiled with SP1 and
therefore any application you create to use them must use SP1. I can
provide non-SP1 assemblies if you want, or you can install SP1 (which
takes a long time ~ 2 hours) or you could re-compile ManagedITK on
your computer without SP1 (which can take longer ~ 2 - 4 hours).
  3. Are you sure the project you are working on is Managed C++? To
check this, right-click on the project, select "Properties", browse to
"Configuration Properties > General" and find the "Common Language
Runtime Support" field. It should read "Common Language Runtime
Support (/clr)" or similar.

Let me also say, if you are using C++/CLI (Managed C++) then I would
recommend calling the native ITK classes directly (ie. not to use
ManagedITK). This approach allows you direct access to the ITK
modules, rather than going through an intermediate wrapper
(ManagedITK). Obviously for other CLR languages (C#, IronPython, etc.)
this is not an option, so the wrapper must be used. You may want to
look at the following Insight Users post for some advice if you decide
to go down that path:
  http://public.kitware.com/pipermail/insight-users/2006-October/019652.html

If you still want to use ManagedITK from C++/CLI then it can done in
the following manner:
  1. Open Visual Studio
  2. Select File > New Project
  3. Expand "Visual C++" and select "CLR"
  4. Choose "CLR Console Application" or "Windows Forms Application"
  5. Right-click the project, select "Properties", browse to
"Configuration Properties > General > C++", add the directory
containing the ManagedITK assemblies to the "Resolve #using
References" field
  6. At the top of you code, add a #using statement for each assembly
you want to reference: eg. #using <ManagedITK.Common.dll>
  7. Construct your filter pipeline
  8. Build the project
  9. Copy the required ManagedITK assemblies to the output directory

Here is an example of a Console application I quickly created and
verified works correctly (a Windows Form application would look very
similar):

// ManagedItkCpp.cpp : main project file.

#include "stdafx.h"
#using <ManagedITK.Common.dll>
#using <ManagedITK.ThresholdFilters.dll>

using namespace System;

int main(array<System::String ^> ^args)
{
    // Read image
    Console::WriteLine(L"Reading input...");
    itk::itkImage_F2^ input = itk::itkImage_F2::New();
    input->Read("C:/Temp/cthead1.png");

    // Create filter
    Console::WriteLine(L"Setting up filter...");
    itk::itkBinaryThresholdImageFilter_IF2IF2^ filter =
itk::itkBinaryThresholdImageFilter_IF2IF2::New();
    filter->SetInput(input);
    int lower = 100; int upper = 255;
    int inside = 255; int outside = 0;
    filter->LowerThreshold = gcnew itk::itkPixel_F(lower);
    filter->UpperThreshold = gcnew itk::itkPixel_F(upper);
    filter->InsideValue = gcnew itk::itkPixel_F(inside);
    filter->OutsideValue = gcnew itk::itkPixel_F(outside);

    // Run filter and write output
    Console::WriteLine(L"Running filter...");
    itk::itkImage_F2^ output = itk::itkImage_F2::New();
    filter->GetOutput(output);
    filter->Update();
    Console::WriteLine(L"Writing output...");
    output->Write("C:/Temp/cthead1-Threshold.mhd");	
    return 0;
}

HTH

Cheers, Dan
dan dot muel at gmail dot com

On 18/09/2007, Young <ykim5 at buffalo.edu> wrote:
> Hi Dan,
>
> I want to use Managed ITK Segmentation functions with my own application of Managed C++ (Window Forms, CLR, MSVC 8.0). But I have problems calling ITK object directly in Cpp files. Whenever I create an object, the compiler complaints "error C3767: candidate functions(s) not accessible".
>
> I know there are C# examples you made, but it's hard for me to create C++ conversion from them. I could probably make library in C# and call it in C++, but I just think it should not be necessary with all existing itk mamaged library.
> Do you also have C++ examples for recent Managed ITK too?
> Or any couple of examples if not?
>
> Thanks,
> Young.


More information about the Insight-users mailing list