[Insight-users] error C2440: 'initializing' : cannot convert from 'const itk::ImageRegion<VImageDimension>' to 'itk::ImageRegion<VImageDimension>'
Dženan Zukić
dzenanz at gmail.com
Mon May 30 15:03:08 EDT 2011
I am not at work so at the moment so I cannot check your code in a compiler.
However your first error is inability to convert const into non-const value
without using const_cast.
For the second error you did not copy-paste the rest of the error message,
namely the part "with TPixel=... and VImageDimension=...".
Anyway I attached a source code of slice extracting program, you might find
it useful.
HTH
On Mon, May 30, 2011 at 14:38, john smith <mkitkinsightuser at gmail.com>wrote:
> Hello, I have written the following code using ITK abd Qt. I am using
> reader as global variable:
>
> typedef unsigned char InputPixelType;
> typedef itk::Image< InputPixelType, 3 > InputImageType;
> typedef itk::ImageFileReader< InputImageType > ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
>
> In my program I have two function. In the first, my program identifies the
> reader as global variable, but in the second I get these errors:
>
> *error C2440: 'initializing' : cannot convert from 'const
> itk::ImageRegion<VImageDimension>' to 'itk::ImageRegion<VImageDimension>'
> error C2664: 'void
> itk::ImageToImageFilter<TInputImage,TOutputImage>::SetInput(const
> itk::Image<TPixel,VImageDimension> *)' : cannot convert parameter 1 from
> 'itk::Image<TPixel,VImageDimension> *' to 'const
> itk::Image<TPixel,VImageDimension> *'*
>
> and this is the function:
>
>
> void MainWindow::z_slice_extract()
> {
>
> typedef unsigned char InputPixelType;
> typedef unsigned char OutputPixelType;
>
> typedef itk::Image< InputPixelType, 3 > InputImageType;
> typedef itk::Image< OutputPixelType, 2 > OutputImageType;
>
> typedef itk::ImageFileReader< InputImageType > ReaderType;
> typedef itk::ImageFileWriter< OutputImageType > WriterType;
>
> WriterType::Pointer writer = WriterType::New();
>
> reader->SetFileName("C:/Users/manolis/Desktop/data/test.png");
>
> writer->SetFileName( "2D.png" );
>
>
> typedef itk::ExtractImageFilter< InputImageType, OutputImageType >
> FilterType;
> FilterType::Pointer filter = FilterType::New();
>
>
> InputImageType::RegionType inputRegion =
> reader->GetOutput()->GetLargestPossibleRegion();
>
> InputImageType::SizeType size = inputRegion.GetSize();
>
> // get the size of the hole 3D image
> unsigned long size_x = size[0];
> unsigned long size_y = size[1];
> unsigned long size_z = size[2];
>
> // get slices of z coordiante
> size[2] = 0;
>
>
> InputImageType::IndexType start = inputRegion.GetIndex();
>
> ui->verticalScrollBar_z->setRange(1,size_z);
> unsigned int sliceNumber = ui->verticalScrollBar_z->value();
> start[2] = sliceNumber;
>
>
>
> InputImageType::RegionType desiredRegion;
> desiredRegion.SetSize( size );
> desiredRegion.SetIndex( start );
>
> filter->SetExtractionRegion( desiredRegion );
>
> filter->SetInput( reader->GetOutput() );
> writer->SetInput( filter->GetOutput() );
>
> try
> {
> writer->Update();
> }
> catch( itk::ExceptionObject & err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> }
>
>
>
> static QGraphicsPixmapItem* pixmapItem;
>
> if (!pixmapItem) {
> // pixmapItem = scene->addPixmap(QPixmap("2D.png"));
>
> QPixmap tmpmap (QPixmap("2D.png"));
> pixmapItem = scene->addPixmap ( tmpmap.scaled (214,256) );
>
> ui->graphicsView_inputImage->setScene(scene);
> } else {
> QPixmap tmpmap (QPixmap("2D.png"));
> pixmapItem->setPixmap(tmpmap.scaled ( 214,256));
> }
>
>
>
>
> // taking the size of the loaded image
> ui->label_4->setText(QString("size x:%1").arg(size_x));
> ui->label_5->setText(QString("size y:%1").arg(size_y));
> ui->label_6->setText(QString("size z:%1").arg(size_z));
>
> return;
> }
>
>
> _____________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110530/8730b1d7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ExtractSlices.cpp
Type: text/x-c++src
Size: 2450 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110530/8730b1d7/attachment.cpp>
More information about the Insight-users
mailing list