[Insight-developers] Re: [Wrapping] Print problems

Gaetan Lehmann gaetan.lehmann at jouy.inra.fr
Wed Aug 10 10:30:40 EDT 2005


On Wednesday 10 August 2005 14:07, Benoit Regrain wrote:
> Hi,
>
> I would print the content of an ITK object.
> The python source code is following
>
> With the first print, all works. The object is a smart pointer to an image
> With the second print, I obtain an exception. The object is an itkImage
> The exception is :
>        itkLightObject_Print() takes exactly 3 arguments (2 given)
>
> Is anyone reproduce that or am I only in this case ?

The same for me. Swig have strange behaviors with smart pointer :-/
But why do you need to call Print that way ?
 


I profit of your mail to post some ad ;-)
I have patched itk::LightObject to have a __str__() method, so I can do

>>> i = itk.Image.US2()
>>> print i
Image (0x8c99308)
  RTTI typeinfo:   N3itk5ImageItLj2EEE
  Reference Count: 1
  Modified Time: 11
  Debug: Off
  Observers: 
    none
  Source: (none)
  Source output index:  0
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 0
  UpdateMTime: 0
  LargestPossibleRegion: 
    Dimension: 2
    Index: [0, 0]
    Size: [0, 0]
  BufferedRegion: 
    Dimension: 2
    Index: [0, 0]
    Size: [0, 0]
  RequestedRegion: 
    Dimension: 2
    Index: [0, 0]
    Size: [0, 0]
  Spacing: [1, 1]
  Origin: [0, 0]
  Direction: 
1 0
0 1

  PixelContainer: 
    ImportImageContainer (0x8c993e0)
      RTTI typeinfo:   N3itk20ImportImageContainerImtEE
      Reference Count: 1
      Modified Time: 12
      Debug: Off
      Observers: 
        none
      Pointer: 0x8c99410
      Container manages memory: true
      Size: 0
      Capacity: 0

which is more in python style :-)

but it wouldn't solve your problem: with GetPointer(), I get

>>> print i.GetPointer()
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

while it works fine with an ImageFileReader:

>>> print reader.GetPointer()
ImageFileReader (0x8c5f1f0)
  RTTI typeinfo:   
N3itk15ImageFileReaderINS_5ImageItLj3EEENS_25DefaultConvertPixelTraitsItEEEE
  Reference Count: 1
  Modified Time: 10
  Debug: Off
  Observers: 
    none
  Number Of Required Inputs: 0
  Number Of Required Outputs: 1
  Number Of Threads: 1
  ReleaseDataFlag: Off
  ReleaseDataBeforeUpdateFlag: Off
  No Inputs
  Output 0: (0x8c81f20)
  AbortGenerateData: Off
  Progress: 0
  Multithreader: 
    RTTI typeinfo:   N3itk13MultiThreaderE
    Reference Count: 1
    Modified Time: 2
    Debug: Off
    Observers: 
      none
    Thread Count: 1
    Global Maximum Number Of Threads: 0
  ImageIO: (null)
  UserSpecifiedImageIO flag: 0
  m_FileName: Lot1embryon3342ZOOM.tif


> Cheers
>
> -----------------------------------------------------------------
>
> from InsightToolkit import *
> import sys
>
> def itkPrint(object, f=sys.stdout) :
>    try:
>       ss=itkStringStream()
>       object.Print(ss.GetStream())
>       print >> f, ss.GetString()
>    except Exception,e:
>       print Exception,e
>       print >> f, repr(object)
>
> img = itkImageUC2_New()
> itkPrint(img)
> itkPrint(img.GetPointer())
>
>
> -----------------------------------------------------------------
> Benoit Regrain
> Ingénieur d'études CNRS (Creatis)
> email : regrain at creatis.insa-lyon.fr
> phone : (+33) (0) 4.72.43.82.58
> fax : (+33) (0) 4.72.43.85.26
> address :
>    CREATIS - CNRS UMR5515
>    INSA - Bâtiment Blaise Pascal
>    7, avenue Jean Capelle
>    F - 69621 Villeurbanne Cedex
> -----------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.itk.org/mailman/private/insight-developers/attachments/20050810/e794f35f/attachment.pgp


More information about the Insight-developers mailing list