[Insight-users] RE:: Compiler Settings for using ITK in a VS2005 CLR

Frank Gao gao at mdimaging.com
Wed Apr 26 13:32:06 EDT 2006


Thanks to Alireza.  This seems to be very helpful, not only for .NET
applications. I did the similar thing earlier to get the settings right for
integration with WTL.

In an earlier post I was looking for something that ITK and VTK provide
purely image services other than window interactions. This is to expect that
any GUI tools, esp. Windows Forms can take advantage of the toolkits, but
couldn't go too far.

Alireza, Mike, and other expert, would you please share something if any to
make Windows Forms a render window? This is such a significant topic now.

Thanks,

Frank


-----Original Message-----
From: insight-users-bounces+gao=mdimaging.com at itk.org
[mailto:insight-users-bounces+gao=mdimaging.com at itk.org]On Behalf Of
insight-users-request at itk.org
Sent: Tuesday, April 25, 2006 5:27 PM
To: insight-users at itk.org
Subject: Insight-users Digest, Vol 24, Issue 59

Send Insight-users mailing list submissions to
        insight-users at itk.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.itk.org/mailman/listinfo/insight-users
or, via email, send a message with subject or body 'help' to
        insight-users-request at itk.org

You can reach the person managing the list at
        insight-users-owner at itk.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Insight-users digest..."


Today's Topics:

   1. Re: Compiler Settings for using ITK in a VS2005 CLR       project
      (Mike Feur)


----------------------------------------------------------------------

Message: 1
Date: Tue, 25 Apr 2006 17:26:22 -0700 (PDT)
From: Mike Feur <mikefeur_02 at yahoo.com>
Subject: Re: [Insight-users] Compiler Settings for using ITK in a
        VS2005 CLR      project
To: alireza akhundi asl <a_akhundi at yahoo.com>
Cc: insight-users at itk.org
Message-ID: <20060426002622.55570.qmail at web37803.mail.mud.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"

Thanks Alireza.  That was a huge help.  You saved me a day or two at least.

Adding the additional dependencies in step 4 below was the key to getting
the code to compile.  I still need to write the GUI wrapper (we will
probably opt for a C# windows forms) but I think I have it figured out now
and will post back if there are some additional problems with steps 7 and 9
from below which I haven't tested yet.

Thanks again,
Mike

alireza akhundi asl <a_akhundi at yahoo.com> wrote: Hi Mike
  I had this problem for a long time. to solve this problem you can use
these steps:
  1-in your new solution add new class library project ( C#,C++, ...).

  2-in property page of your class lib in c/c++ ->general->additional
include directories, add this header files (D:\program files\itk is folder
of your built itk):
  "D:\Program Files\itk\Utilities\vxl\core";"D:\Program
Files\itk\Utilities\vxl\vcl";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\vxl\core";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\vxl\vcl";"D:\Program
Files\InsightToolkit-2.4.1\Utilities";"D:\Program
Files\itk\Utilities";"D:\Program Files\itk\Utilities\gdcm";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\nifti\znzlib";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\nifti\niftilib";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\expat";"D:\Program
Files\itk\Utilities\expat";"D:\Program
Files\itk\Utilities\DICOMParser";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\DICOMParser";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\NrrdIO";"D:\Program
Files\InsightToolkit-2.4.1\Utilities\MetaIO";"D:\Program
Files\InsightToolkit-2.4.1\Code\SpatialObject";"D:\Program
Files\InsightToolkit-2.4.1\Code\Numerics\NeuralNetworks";"D:\Program
Files\InsightToolkit-2.4.1\Code\Numerics\Statistics";"D:\Program
 Files\InsightToolkit-2.4.1\Code\Numerics\FEM";"D:\Program
Files\InsightToolkit-2.4.1\Code\IO";"D:\Program
Files\InsightToolkit-2.4.1\Code\Numerics";"D:\Program
Files\InsightToolkit-2.4.1\Code\Common";"D:\Program
Files\InsightToolkit-2.4.1\Code\BasicFilters";"D:\Program
Files\InsightToolkit-2.4.1\Code\Algorithms";"D:\Program Files\itk";

  3-in linker->general->additional library Directories add path of your itk
lib files (again D:\program files\itk is folder of your built itk):
  D:\Program Files\itk\bin\debug

  4-in linker->input->Additional dependencies add this lib files:
  msvcrtd.lib mscoree.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib odbccp32.lib  kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib
odbc32.lib odbccp32.lib ITKBasicFilters.lib ITKCommon.lib ITKIO.lib
ITKNrrdIO.lib itkgdcm.lib itkjpeg12.lib itkjpeg16.lib wsock32.lib
snmpapi.lib itkpng.lib itktiff.lib itkjpeg8.lib ITKSpatialObject.lib
ITKNumerics.lib ITKCommon.lib itkvnl_inst.lib itkvnl_algo.lib itkvnl.lib
itkvcl.lib itknetlib.lib itksys.lib ITKMetaIO.lib ITKDICOMParser.lib
ITKEXPAT.lib ITKniftiio.lib ITKznz.lib itkzlib.lib

  5-write your function: (my class name is itkclass and the function is
iterator and namespace is itk_base)


  // itk_base.h
  #pragma once
  #include "itkImage.h"
  #include "itkRGBPixel.h"
  #include "itkImageRegionIteratorWithIndex.h"
  #include "itkImageFileReader.h"
  #include "itkImageFileWriter.h"
  using namespace System;
  using namespace System::Collections;

  namespace itk_base {
  typedef itk::RGBPixel<unsigned char> RGBPixelType;
  typedef itk::Image<RGBPixelType,2> ImageType;
  typedef itk::ImageRegionIteratorWithIndex<ImageType> IteratorType;
  typedef itk::ImageFileReader<ImageType> ReaderType;
  typedef itk::ImageFileWriter<ImageType> WriterType;
  public ref class itkclass
  {
  // TODO: Add your methods for this class here.
  public:
  static void iterator()
  {
  ImageType::ConstPointer inputImage;
  ReaderType::Pointer reader=ReaderType::New();
  reader->SetFileName("D:\\Program
Files\\InsightToolkit-2.4.1\\Examples\\Data\\BrainProtonDensitySliceShifted1
3x17y.png");
  reader->Update();
  inputImage=reader->GetOutput();
  ImageType::Pointer outputImage = ImageType::New();
   outputImage->SetRegions( inputImage->GetRequestedRegion() );
  outputImage->CopyInformation(inputImage);
  outputImage->Allocate();
  ImageType::IndexType requestedIndex
=outputImage->GetRequestedRegion().GetIndex();
  ImageType::SizeType requestedSize
=outputImage->GetRequestedRegion().GetSize();
  IteratorType outputIt( outputImage, outputImage->GetRequestedRegion() );
  for ( outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
  {
  ImageType::IndexType idx = outputIt.GetIndex();
  idx[0] = requestedIndex[0] + requestedSize[0] - 1 - idx[0];
  outputIt.Set( inputImage->GetPixel(idx) );
  }
  }
  };
  }

  6-add new windows form application project to your solution:

  7-in property page of your  windows form application in
c/c++ ->general->Resolve #using References add the path of the dll that is
built in your class lib for example in my case : F:\myexamples\debug (
isupposed that you are using C++ )

  8-for example add a button and use function in this form:

  private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
  itkclass::iterator();
  }

  9- dont forget to add #using <itk_base.dll> in your windows form's header
file.
  for example:

  #pragma once
  #using <itk_base.dll>
  namespace test {
  using namespace System;
  using namespace System::ComponentModel;
  using namespace System::Collections;
  using namespace System::Windows::Forms;
  using namespace System::Data;
  using namespace System::Drawing;
  using namespace itk_base;
  /// <summary>
  /// Summary for Form1
  ///
  /// WARNING: If you change the name of this class, you will need to change
the
  /// 'Resource File Name' property for the managed resource compiler tool
  /// associated with all .resx files this class depends on. Otherwise,
  /// the designers will not be able to  interact properly with localized
  /// resources associated with this form.
  /// </summary>
  public ref class Form1 : public System::Windows::Forms::Form
  {
  public:
  Form1(void)
  {
  InitializeComponent();
  //
  //TODO: Add the constructor code here
  //
  }
  protected:
  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  ~Form1()
  {
  if (components)
  {
  delete components;
  }
  }
  private: System::Windows::Forms::Button^ button1;
  protected:
  private:
  /// <summary>
  /// Required designer variable.
  /// </summary>
  System::ComponentModel::Container ^components;
  #pragma region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  void InitializeComponent(void)
  {
  this->button1 = (gcnew System::Windows::Forms::Button());
  this->SuspendLayout();
  //
  // button1
  //
  this->button1->Location = System::Drawing::Point(191, 67);
  this->button1->Name = L"button1";
  this->button1->Size = System::Drawing::Size(49, 27);
  this->button1->TabIndex = 0;
  this->button1->Text = L"button1";
  this->button1->UseVisualStyleBackColor = true;
  this->button1->Click += gcnew System::EventHandler(this,
&Form1::button1_Click);
  //
  // Form1
  //
  this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  this->ClientSize = System::Drawing::Size(292, 266);
  this->Controls->Add(this->button1);
  this->Name = L"Form1";
  this->Text = L"Form1";
  this->ResumeLayout(false);
  }
  #pragma endregion
  private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e) {
  itkclass::iterator();
  }
  };
  }


Mike Feur <mikefeur_02 at yahoo.com> wrote:
  Hi Tom,

Thanks for the reply.  My plan is to write simple reference classes to wrap
the unmanaged (itk) code.   This should work just fine for incorporating
unmanaged C++ code.  For instance:

//****Managed wrapper class*****
public ref class  MikeWrapper
    {
    public:
        MikeWrapper(Int32 initial);
        void PrintValue();
    private:
        MikeClass<int> *pMike;

//**Unmanaged C++ class****
template<typename T>
    class MikeClass
    {
    public:
        MikeClass(T  value) {
            myvec.push_back(value);
        }
        void PrintValue(){
            std::cout<< myvec[0] << std::endl;
        }

    private:
        std::vector<T>  myvec;
    };

//********************

  At this point, the GUI can be written in a CLR language ( (C++/CLI, C#)
and just access the wrapper class.

My tripping point is the compiler settings. The header for the unmanaged
class  calls itkImage.h and thus needs to have the correct ITK compiler
settings, include directories and libraries.  I can't use CMake
unfortunately because it only sets up normal unmanaged C++ projects. John
Biddiscombe posted some tips back in 2004 on how to do this in this list,
but I can't seem to make it work.

Thanks for reading again.




Thomas Lambertz <thomas at hexerei-software.de> wrote:   Hello Mike,

the difference between C++/CLI and conventional unmanaged C++ is much
more than only a compilerstep. For example there are no raw-pointer  in
CLI and there are many other types that have changed. So it doesnt work
to set up a project for CLI by only changing some parameters in CMake.
>From my point of view there4s no way to compile ITK as CLI without
rewriting nearly the complete code (but i am prepared to learn).
Resulting performance may be another contraindication.

Have you considered a mixedmode application ? I have approached it that
way. My GUI runs as a CLI-app while access to ITK is encapsulated in an
unmanaged DLL (you have to spent some attention on memory-management).
Needs some work on a wrapper but the benefits of the new gui-handling
may pay of for you.

Statically linking the (conventional) ITK library against a mixedmode
application by using "#pragma (un)managed" and some marshalling may also
work.I am sure there are more suitable solutions...

Regards,
Tom


Mike Feur wrote:
> Hello,
>
> I am trying to  create a Common Language Runtime C++/CLI project that
> includes ITK code in Visual Studio 2005.
>
> There is no Cmake file for me to use. I have tried manually copying
> over all the include directories from a Cmake created ITK project. I
> am getting linker errors such as
>
> "error LNK2001: unresolved external symbol "public: virtual void
> __thiscall itk::EventObject::Print(class std::basic_ostream< ....."
>
> I tried including the appropriate lib files by adding the
> "...\InsightBin\bin\debug" directory to the "Configuration
> Properties\Linker\General\Additional Library Directories" dialog box
> in the Property Pages for the Solution, but still no luck.
>
>
> Any suggestions or instructions of how to integrate ITK into a CLR
> solution?
>
> Best of all would be a Cmake file to use, similar to the one
> available for MFC.
>
>
>  Thanks for taking the time to read this.
>
t
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users


---------------------------------
  Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+
countries) for 2"/min or
less._______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users




---------------------------------
New Yahoo! Messenger with Voice. Call regular phones from your PC and save
big.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://public.kitware.com/pipermail/insight-users/attachments/20060425/e053b
d4c/attachment.html

------------------------------

_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users


End of Insight-users Digest, Vol 24, Issue 59
*********************************************



More information about the Insight-users mailing list