[Insight-users] warning: dereferencing type-punned pointer will break strict-aliasing rules

Roman Grothausmann roman.grothausmann at helmholtz-berlin.de
Wed Jun 16 04:13:20 EDT 2010


Dear mailing list members,


If I compile a simple program using 
BinaryMorphologicalOpeningImageFilter I get a warning now that I don't 
know how to resolve:

localusr/include/InsightToolkit/Review/itkKernelImageFilter.txx: In 
member function ‘void itk::KernelImageFilter<TInputImage, TOutputImage, 
TKernel>::SetRadius(const typename TInputImage::SizeType&) [with 
TInputImage = itk::Image<unsigned char, 3u>, TOutputImage = 
itk::Image<unsigned char, 3u>, TKernel = 
itk::BinaryBallStructuringElement<unsigned char, 3u, 
itk::NeighborhoodAllocator<unsigned char> >]’:
itk/simple/opening_bin_morph03.cxx:59:   instantiated from here
localusr/include/InsightToolkit/Review/itkKernelImageFilter.txx:50: 
warning: dereferencing type-punned pointer will break strict-aliasing rules
Linking CXX executable opening_bin_morph03

What can I do about it?

Any help is very much appreciated
Roman

__________________________________

//program to apply a bin. morph. opening

#include <itkImageFileReader.h>
#include <itkImageFileWriter.h>

#include <itkBinaryMorphologicalOpeningImageFilter.h>
#include <itkBinaryBallStructuringElement.h>
#include "itkFilterWatcher2.h"

int main( int argc, char * argv[] )
     {
     if( argc != 4 )
         {
         std::cerr << "Usage: " << argv[0];
         std::cerr << " inputImage";
         std::cerr << " outputImage";
         std::cerr << " kernelRadius";
         std::cerr << std::endl;
         return EXIT_FAILURE;
         }

     typedef  unsigned char InputPixelType;
     typedef  unsigned char OutputPixelType;

     const unsigned int Dimension = 3;

     typedef itk::Image<InputPixelType,  Dimension>   InputImageType;
     typedef itk::Image<OutputPixelType,  Dimension>   OutputImageType;

     typedef itk::ImageFileReader<InputImageType>  ReaderType;
     typedef itk::ImageFileWriter<OutputImageType>  WriterType;
     WriterType::Pointer writer = WriterType::New();

     ReaderType::Pointer reader = ReaderType::New();
     reader->SetFileName(argv[1]);


     typedef itk::BinaryBallStructuringElement<InputPixelType, 
Dimension> StructuringElementType;


     typedef itk::BinaryMorphologicalOpeningImageFilter<InputImageType, 
OutputImageType, StructuringElementType> FilterType;
     FilterType::Pointer filter = FilterType::New();

     StructuringElementType  structuringElement;

     structuringElement.SetRadius(atoi(argv[3]));
     structuringElement.CreateStructuringElement();


     filter->SetInput(reader->GetOutput());
     filter->SetKernel(structuringElement);
     FilterWatcher watcher(filter, "filter");
     filter->Update();

     writer->SetFileName(argv[2]);
     writer->SetInput(filter->GetOutput());
     writer->Update();

     return EXIT_SUCCESS;
     }




-- 
Roman Grothausmann

Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
Bereich Funktionale Materialien
Institut für angewandte Materialforschung
Hahn-Meitner-Platz 1
D-14109 Berlin	

Tel.: +49-(0)30-8062-2816
Fax.: +49-(0)30-8062-3059

Vorsitzender des Aufsichtsrats: Prof. Dr. Dr. h.c. mult. Joachim Treusch
Stellvertretende Vorsitzende: Dr. Beatrix Vierkorn-Rudolph
Geschäftsführer: Prof. Dr. Anke Rita Kaysser-Pyzalla, Prof. Dr. Dr. h.c. 
Wolfgang Eberhardt, Dr. Ulrich Breuer
Sitz der Gesellschaft: Berlin
Handelsregister: AG Charlottenburg, 89 HRB 5583



More information about the Insight-users mailing list