[Insight-users] Using ImportFilter and PasteImageFilter

Todd Jensen todd.jensen at ieee.org
Thu May 6 07:49:29 EDT 2010






________________________________
From: "insight-users-request at itk.org" <insight-users-request at itk.org>
To: insight-users at itk.org
Sent: Thu, May 6, 2010 4:50:57 AM
Subject: Insight-users Digest, Vol 73, Issue 19

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: Using ImportFilter and PasteImageFilter (Quent)
   2. Re: Wrapping ITK in OSX 10.6 (Lassi Paavolainen)


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

Message: 1
Date: Thu, 6 May 2010 00:30:13 -0700 (PDT)
From: Quent <quentin.bezsilko at gmail.com>
Subject: Re: [Insight-users] Using ImportFilter and PasteImageFilter
To: insight-users at itk.org
Message-ID: <28470202.post at talk.nabble.com>
Content-Type: text/plain; charset=UTF-8

In the following lines:
-------------------------
   unsigned long i, x;
    float * fImage;
    pixList = 
[new2DViewer pixList];
    for(i=0;i<[pixList count]; i++){
        curPix = [pixList objectAtIndex:i];
        x = height * width;
        fImage = [curPix fImage];
        while(x>0){
            
*localBuffer = *fImage;
            localBuffer++;
            
cptLocalBuffer++;
            fImage++;
            x--;
    
    }
    }
-----------------------

you are incrementing the pointer to your allocated buffer (localBuffer++). So, when you use it later in:

-----------------------
importFilter->SetImportPointer(localBuffer, numberOfPixels, true);
-----------------------

It is no longer pointing to the memory space you allocated but just beyond that leading to your unexpected crash. You should rewrite you pixel copy code to something like:

-------------------------
   unsigned long i, x;
   x = height * width;
    float * fImage;
    float* tmpLocalBufferPtr;
    tmpLocalBufferPtr = localBuffer;
    pixList = 
[new2DViewer pixList];
    for(i=0;i<[pixList count]; i++){
        memcpy( tmpLocalBufferPtr, [curPix fImage], x);
        tmpLocalBufferPtr += x;
    }
-----------------------

Todd Jensen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100506/21d5001a/attachment.htm>


More information about the Insight-users mailing list