<div>Reinhard,</div>
<div>I added a test Testing/Code/Common/itkImportContainerTest that exercises the ImportImageContainer class. As it turns out, the code coverage was fairly low for this class. As I wrote it, I discovered that the class can be tricky to use.
</div>
<div> </div>
<div>If you are on a linux system, I suggest that you run your code with valgrind,s memtest. <a href="http://valgrind.org/">http://valgrind.org/</a></div>
<div> </div>
<div>I suspect that your code is mucking improperly with the import pointer. If you can't run valgrind, perhaps you could post a small program that illustrates the error and we could help analyze it.</div>
<div> </div>
<div>Bill<br></div>
<div class="gmail_quote">On Dec 9, 2007 5:55 PM, Reinhard Hameeteman <<a href="mailto:k.hameeteman+maillist@gmail.com">k.hameeteman+maillist@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi Luis,<br><br>Thanks for taking a look.<br><br>Let me try to untangle things by reducing it to one method:
<br><br>I want to pass the output buffer of the itk filter (an itk::Image<<br>itk::Vector< float, 3>, 3> image) to my application. So the itk filter<br>is responsible for allocating the buffer, but is told not to
<br>deallocate the buffer when getting out of scope like this:<br><br>// create my own image<br>CustomImageType m_MemberImage.;<br><br>// pointer to an aray of 3 floats<br>vecf3 * pixelPointer;<br><br>// get pointer to itk output buffer
<br>pixelPointer = itkFilter->GetOutput()->GetPixelContainer()->GetImportPointer();<br><br>// pass the itk buffer to my own application<br>m_MemberImage.setData( pixelPointer );<br><br>// tell itk filter not to destroy the buffer
<br>
<div class="Ih2E3d">itkFilter->GetOutput()->GetPixelContainer()->SetContainerManageMemory(false);<br><br></div>This works fine until I want to deallocated the image buffer using:<br>delete[] pixelPointer;<br><br>
I've used this method before with itk::Image< short, 3> images and it<br>worked fine, but now with the vector image my program crashes upon<br>deleting the buffer.<br><br>Sorry for the confusing, I hope this clarifies it a bit.
<br><font color="#888888"><br>Reinhard<br></font>
<div>
<div></div>
<div class="Wj3C7c"><br><br>On Dec 9, 2007 2:37 AM, Luis Ibanez <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>> wrote:<br>><br>> Hi Reinhard,<br>><br>><br>> I'm afraid that by now,
<br>> your questions are too entangled to address them correctly.<br>><br>><br>> Let me rephrase the questions and please correct me if I'm getting<br>> them wrong.<br>><br>><br>> 1) you are running an ITK pipeline and you want the output of the
<br>> pipeline to store its result in a block of memory that you have<br>> pre-allocated from your application.<br>><br>><br>> 2) You want to do this with a filter that produces as output an<br>> image whose pixel type is Vector<float,3>.
<br>><br>><br>> 3) You are attempting to use the following method:<br>><br>> m_Filter->GetOutput()->SetRegions(region);<br>><br>> m_Filter->GetOutput()->GetPixelContainer()->SetImportPointer(
<br>> static_cast< OutputPixelType * >( applicationAllocatedBuffer ),<br>> totalNumberOfPixels, false);<br>><br>> m_Filter->GetOutput()->Allocate( );<br>><br>><br>> 4) When you run it, it crashes at the moment of dealocating the
<br>> memory.<br>><br>><br>><br>> Is that right ?<br>><br>><br>> If so, this leads to suspect that<br>><br>><br>> A) you have not allocated the right size of memory in your application
<br>><br>><br>> or<br>><br>><br>> B) your assumptions about the organization of the pixel components<br>> in memory are not correct.<br>><br>><br>><br>> Please provide a fresh description of the state of your problem.
<br>><br>><br>> Thanks<br>><br>><br>><br>> Luis<br>><br>><br>><br>><br>> ---------------------------<br>><br>> Reinhard Hameeteman wrote:<br>> > To comment on my own questions:
<br>> > The error in the second approach, was due to an invalid pointer the<br>> > was passed to the itk filter.<br>> > However the other 2 questions still remain. And since this approach<br>> > preferable because you allocate the memory once it is needed and not
<br>> > long before that (depending on your filter), I would very much get<br>> > some comments on those issues.<br>> > Is someone capable of doing so?<br>> ><br>> > Reinhard<br>> ><br>
> ><br>> > On Dec 3, 2007 11:50 AM, Reinhard Hameeteman<br>> > <<a href="mailto:k.hameeteman+maillist@gmail.com">k.hameeteman+maillist@gmail.com</a>> wrote:<br>> ><br>> >>Hi,<br>> >>
<br>> >>I am experiencing similar problems as described in<br>> >><a href="http://www.itk.org/pipermail/insight-users/2005-December/016027.html" target="_blank">http://www.itk.org/pipermail/insight-users/2005-December/016027.html
</a>.<br>> >>I use an itk pipeline within another image processing framework<br>> >>(MeVisLab). To avoid unnecessary memory copying I want to pass a<br>> >>pointer to the image data output from a itk filter output to an other
<br>> >>data structure. As Luis described in e.g.<br>> >><a href="http://www.itk.org/pipermail/insight-users/2007-May/022343.html" target="_blank">http://www.itk.org/pipermail/insight-users/2007-May/022343.html
</a> there<br>> >>are 2 methods:<br>> >>1) Mummify the buffer of the output filter<br>> >>2) Provide the memory buffer to the output filter so when it computes<br>> >>the output image, it is already stored in the buffer that you
<br>> >>provided.<br>> >><br>> >>Until now, I used method 1 with success. Like this:<br>> >>CustomDatatType m_MemberImage.;<br>> >>m_MemberImage.setData(<br>> >>itkFilter->GetOutput()->GetPixelContainer()->GetImportPointer() );
<br>> >>itkFilter->GetOutput()->GetPixelContainer()->SetContainerManageMemory(false);<br>> >><br>> >>However this only works when I have a scalar voxel type and now I have<br>> >>created a pipeline that produces a itk::Image< itk::Vector< float, 3
<br>> >><br>> >>>, 3> image. The creation of the image and the passing of the pointer<br>> >><br>> >>to my own data structure works fine. But as soon as I try to release<br>> >>the memory, my program crashes. This does not happen when the voxel
<br>> >>type is of type int which is still unexplained.<br>> >><br>> >>I used the second method as mentioned by Luis like this:<br>> >><br>> >> CustomDatatType m_MemberImage;
<br>> >> // Set size of m_MemberImage and allocate memory<br>> >><br>> >> // Set size of itk output image<br>> >> region.SetSize( size );<br>> >> region.SetIndex( start );
<br>> >> itkFilter->GetOutput(1)->SetRegions( region);<br>> >><br>> >> // Set pointer of filter image to allocated data<br>> >> ItkFilterType::VectorVoxelType * pixelData;<br>
> >> pixelData = static_cast<ItkFilterType::VectorVoxelType* >(<br>> >>m_MemberImage.getData() );<br>> >> itkFilter->GetOutput(1)-><br>> >> GetPixelContainer()->
<br>> >> SetImportPointer(pixelData, m_MemberImage.getSize(), false);<br>> >><br>> >>Using this method, there is still a problem with the vector voxel<br>> >>typed image. Using an image with int voxels things works fine, but as
<br>> >>soon as the mentioned vector voxel type is used, access violations<br>> >>occur when the itk filter writes to the output buffer. This suggests<br>> >>that somehow the size of the buffer or the datatype is not set
<br>> >>correctly. I checked both and they are ok.<br>> >><br>> >>My questions:<br>> >>- Could someone comment on the difference in deleting a scalar and<br>> >>vector voxel typed image buffer.
<br>> >>- Is there more generally, any difference in the memory management of<br>> >>scalar and multiple component voxel typed images?<br>> >>- Are there any suggestions on where to look for the problem in the
<br>> >>second approach?<br>> >><br>> >>Thanks a lot.<br>> >><br>> ><br>> > _______________________________________________<br>> > Insight-users mailing list<br>> >
<a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>> > <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>> ><br>
><br>_______________________________________________<br>Insight-users mailing list<br><a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">
http://www.itk.org/mailman/listinfo/insight-users</a><br></div></div></blockquote></div><br>