[Insight-users] ITK Filter in an Osirix plugin
Luis Ibanez
luis.ibanez at kitware.com
Wed May 26 12:48:14 EDT 2010
Hi Quent,
The likely source of the problem is the line
// After the copy, I need to decrement the pointer
// It doesn't work if I don't ...
localBuffer -= numberOfPixels;
You shouldn't need to do that after you call
// Buffer containing the data
float * localBuffer = new float[numberOfPixels];
memcpy(localBuffer, [viewerController volumePtr], numberOfPixels);
since memcpy doesn't change your localBuffer pointer.
You may have to do some verification of your
"volumePtr" variable.
Also, you may find useful to look at the Tutorials
http://www.itk.org/ITK/help/tutorials.html
in particular to:
"Getting Started V: Integrating ITK in your Application."
http://www.itk.org/CourseWare/Training/GettingStarted-V.pdf
Regards,
Luis
--------------------------------------------------------------------
On Mon, May 10, 2010 at 4:04 AM, Quent <quentin.bezsilko at gmail.com> wrote:
>
> Hi all,
> I'm working on an osirix plugin and I've already succeeded in importing the
> data from the Osirix viewer to itk to create an itk::ImportImageFilter
> object.
> What I need to do now is to create a filter on this importFilter. I've
> already tried to create a MeanImageFilter but it simply did not work because
> of a segmentation fault caused by a call to a dynamic_cast function. The
> problem is I did not call any such function.
>
> After creating the filter, I'll have to bring the pixels from the filter
> back to the Osirix viewer and see the modifications made by the filter. For
> this part, I know how I will proceed to do it.
>
> I think the ImportImageFiter object works fine because no error was produced
> while I was running the program with gdb and without the MeanImageFilter.
> Here is the source code :
>
> - (long) filterImage:(NSString*) menuName{
>
> // Duplication of the Osirix viewer
> ViewerController * new2DViewer = [self duplicateCurrent2DViewerWindow];
> id waitWindow = [viewerController startWaitWindow:@"Essai modification de
> l'image"];
>
> // Defining the variables for the ImportFilter
> typedef itk::Image <float, 3> ImageType;
>
> ImageType::RegionType region;
> ImageType::SizeType size;
>
> double spacing[3];
>
> typedef itk::Image <float, 3> InputImageType;
> typedef itk::Image <float, 3> OutputImageType;
>
> typedef itk::ImportImageFilter <float, 3> ImportFilterType;
> ImportFilterType::Pointer importFilter = ImportFilterType::New();
>
> typedef itk::ImageFileReader <InputImageType> ReaderType;
> typedef itk::ImageFileWriter <ImageType> WriterType;
>
> WriterType::Pointer writer = WriterType::New();
> ReaderType::Pointer reader = ReaderType::New();
>
> NSArray * pixList = [new2DViewer pixList];
> DCMPix * curPix = [pixList objectAtIndex:0];
>
> int height = [curPix pheight];
> int width = [curPix pwidth];
> int depth = [pixList count];
>
> size[0] = width; size[1] = height; size[2] = depth;
> region.SetSize(size);
>
> ImageType::IndexType start;
> start.Fill(0);
> region.SetIndex(start);
>
> const unsigned int numberOfPixels = height * width * depth;
>
> double spaceX = [curPix pixelSpacingX];
> double spaceY = [curPix pixelSpacingY];
> double spaceZ = [curPix sliceInterval];
>
> if(spaceZ == 0){
> spaceZ = [curPix sliceThickness];
> }
>
> spacing[0] = spaceX; spacing[1] = spaceY; spacing[2] = spaceZ;
>
> double ox = [curPix originX];
> double oy = [curPix originY];
> double oz = [curPix originZ];
>
> double origin[3];
> origin[0] = ox; origin[1] = oy; origin[2] = oz;
>
> // Buffer containing the data
> float * localBuffer = new float[numberOfPixels];
> memcpy(localBuffer, [viewerController volumePtr], numberOfPixels);
>
> // After the copy, I need to decrement the pointer
> // It doesn't work if I don't ...
> localBuffer -= numberOfPixels;
>
> importFilter->SetRegion(region);
> importFilter->SetSpacing(spacing);
> importFilter->SetOrigin(origin);
> importFilter->SetImportPointer(localBuffer, numberOfPixels, false);
>
> // Creating the ImportFilter
> try{
> importFilter->Update();
> NSRunCriticalAlertPanel(@"importFilter->Update()", @"OK", nil, nil, nil);
> }
> catch(itk::ExceptionObject & err){
> FILE * fichier = fopen("/Users/u703inserm/Desktop/fichier.txt", "w");
> if(fichier != NULL){
> fputs("Exception ImportFilter", fichier);
> fputs(err.GetDescription(), fichier);
> }
> }
> // Works fine until there
>
> // Here starts the problem
> // Application of a filter : MeanImageFilter (Osirix crashes)
> typedef itk::MeanImageFilter <ImageType, ImageType> FilterType;
> FilterType::Pointer filter = FilterType::New();
> filter->SetInput(importFilter->GetOutput());
>
> try{
> filter->Update();
> }
> catch (itk::ExceptionObject & err) {
> FILE * fichier = fopen("/Users/u703inserm/Desktop/fichier.txt", "w");
> if(fichier != NULL){
> fputs("Exception ImportFilter", fichier);
> fputs(err.GetDescription(), fichier);
> }
> }
>
> [new2DViewer endWaitWindow:waitWindow];
> [new2DViewer needsDisplayUpdate];
> return 0;
> }
>
> And the error is :
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_INVALID_ADDRESS at address: 0x6e6b6e4d
> 0x92cbafe6 in __dynamic_cast ()
>
> I appreciate any help,
> Thanks
> Quentin
>
> --
> View this message in context: http://old.nabble.com/ITK-Filter-in-an-Osirix-plugin-tp28508674p28508674.html
> Sent from the ITK - Users mailing list archive at Nabble.com.
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list