Well, I have fixed that but when I am running my program, I do not get any errors. But when I start debug then an exception of Qt is caught. I can really understand why? I give you my code.The strange think is that when I declare my directory without using push_button_File() function, but inside the z_slice_extract(), I take my results correctly. Couls somebody help me?<br>
<br><br>#include "mainwindow.h"<br>#include "ui_mainwindow.h"<br>#include "canvas.h"<br><br>#include "itkImage.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>
#include "itkExtractImageFilter.h"<br>#include <itkSize.h><br><br>QString fileName;<br><br> unsigned long size_x;<br> unsigned long size_y;<br> unsigned long size_z;<br><br><br><br>MainWindow::MainWindow(QWidget *parent) :<br>
QMainWindow(parent),<br> ui(new Ui::MainWindow)<br>{<br> ui->setupUi(this);<br><br> ui->graphicsView_inputImage->setScene(scene=new Canvas());<br><br> connect(scene,SIGNAL(mousejustpressed(int,int)),this,SLOT(mousejustpressed(int,int)));<br>
<br> QObject::connect(ui->pushButton_openFile, SIGNAL(clicked()), this, SLOT(push_button_File()));<br><br> QObject::connect(ui->pushButton_slice_z, SIGNAL(clicked()), this, SLOT(z_slice_extract()));<br><br><br>
<br>}<br><br>void MainWindow::push_button_File()<br>{<br><br> QString fileName = QFileDialog::getOpenFileName(this,<br> tr("Open File"), QDir::currentPath());<br> <br><br>}<br>
<br><br>void MainWindow::z_slice_extract()<br>{<br><br> ///unsigned char to display in .png format<br> typedef unsigned char InputPixelType;<br> typedef unsigned char OutputPixelType;<br><br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br>
typedef itk::Image< OutputPixelType, 2 > OutputImageType;<br><br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br> typedef itk::ImageFileWriter< OutputImageType > WriterType;<br><br>
ReaderType::Pointer reader = ReaderType::New();<br> WriterType::Pointer writer = WriterType::New();<br><br> reader->SetFileName( fileName.toStdString() );<br> writer->SetFileName( "2D.png" );<br><br>
<br> typedef itk::ExtractImageFilter< InputImageType, OutputImageType > FilterType;<br> FilterType::Pointer filter = FilterType::New();<br><br> reader->Update();<br> InputImageType::RegionType inputRegion =<br>
reader->GetOutput()->GetLargestPossibleRegion();<br><br> InputImageType::SizeType size = inputRegion.GetSize();<br> <br> // get the size of the hole 3D image<br> unsigned long size_x = size[0];<br> unsigned long size_y = size[1];<br>
unsigned long size_z = size[2];<br> <br> // get slices of z coordiante<br> size[2] = 0; <br><br><br> InputImageType::IndexType start = inputRegion.GetIndex();<br> // const unsigned int sliceNumber = 90;<br> ui->verticalScrollBar_z->setRange(1,size_z);<br>
unsigned int sliceNumber = ui->verticalScrollBar_z->value();<br> start[2] = sliceNumber;<br> // ui->verticalScrollBar_z->setValue(sliceNumber);<br> <br><br> InputImageType::RegionType desiredRegion;<br> desiredRegion.SetSize( size );<br>
desiredRegion.SetIndex( start );<br><br> filter->SetExtractionRegion( desiredRegion );<br><br> filter->SetInput( reader->GetOutput() );<br> writer->SetInput( filter->GetOutput() );<br><br> try<br>
{<br> writer->Update(); <br> }<br> catch( itk::ExceptionObject & err )<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;<br> std::cerr << err << std::endl;<br>
}<br><br><br> scene->addPixmap(QPixmap("2D.png"));<br> ui->graphicsView_resultImage->setScene(scene);<br> // ui->graphicsView_resultImage->set;<br><br>/** static QGraphicsPixmapItem* pixmapItem;<br>
<br> if (!pixmapItem) {<br> // pixmapItem = scene->addPixmap(QPixmap("2D.png"));<br><br> QPixmap tmpmap (QPixmap("2D.png"));<br> pixmapItem = scene->addPixmap ( tmpmap.scaled (214,256) );<br>
<br> ui->graphicsView_inputImage->setScene(scene);<br> } else {<br> QPixmap tmpmap (QPixmap("2D.png"));<br> pixmapItem->setPixmap(tmpmap.scaled ( 214,256));<br> }<br>
*/<br> <br><br><br> // taking the size of the loaded image<br> ui->label_4->setText(QString("size x:%1").arg(size_x));<br> ui->label_5->setText(QString("size y:%1").arg(size_y));<br>
ui->label_6->setText(QString("size z:%1").arg(size_z));<br><br> return;<br>}<br><br><br><br><br><br>void MainWindow::mousejustpressed(int x,int y)<br>{<br> int k1=256-y;<br><br><br> unsigned char value;<br>
<br> QImage image(scene->sceneRect().size().toSize(), <br> QImage::Format_RGB32);<br> <br> QPainter painter(&image);<br> scene->render(&painter);<br> <br> value=image.pixel(x,k1);<br> <br>
<br> /**QImage buffer = QImage(1,1, QImage::Format_RGB32);<br> QPainter painter(&buffer);<br> scene->render(&painter, QRectF(0.0, 0.0, 1.0, 1.0), QRectF(x, y, 1.0, 1.0));<br> int value = qGray(buffer.pixel(0,0));<br>
*/<br><br> ui->label->setText(QString("x:%1").arg(x));<br> ui->label_2->setText(QString("y:%1").arg(k1));<br> ui->label_3->setText(QString("pixel value:%1").arg(value));<br>
<br><br>}<br><br><br>MainWindow::~MainWindow()<br>{<br> delete ui;<br>}<br><br><br><br><br><div class="gmail_quote">2011/5/30 David Doria <span dir="ltr"><<a href="mailto:daviddoria@gmail.com">daviddoria@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="gmail_quote"><div class="im">On Mon, May 30, 2011 at 5:25 AM, john smith <span dir="ltr"><<a href="mailto:mkitkinsightuser@gmail.com" target="_blank">mkitkinsightuser@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I am using Qt add in for visual studio 2010 and I have typed this. But still gettting these errors:<br><i>1>e:\qt applications\mainwindow_globalreader\mainwindow\mainwindow\mainwindow.h(49): error C2065: 'ImageType' : undeclared identifier<br>
1>e:\qt applications\mainwindow_globalreader\mainwindow\mainwindow\mainwindow.h(50): error C2955: 'itk::ImageFileReader' : use of class template requires template argument list<br>1> c:\itk\source\code\io\itkImageFileReader.h(93) : see declaration of 'itk::ImageFileReader'<br>
1>e:\qt applications\mainwindow_globalreader\mainwindow\mainwindow\mainwindow.h(50): fatal error C1903: unable to recover from previous error(s); stopping compilation<br>1> mainwindow.cpp</i><br><br>I have include the header fules "itkImage.h" ,"itkImageFileReader.h".Could somebody help me?<br>
<br>class MainWindow : public QMainWindow<br>{<br> ..............<div><br><br>private: <br>typedef itk::ImageFileReader< ImageType > ReaderType;<br></div>ReaderType::Pointer reader;<br><br>};<br><br>
<br>MainWindow::MainWindow(QWidget *parent) :<br>
QMainWindow(parent),<br> ui(new Ui::MainWindow)<br>{<br>............<br>...........<br> typedef unsigned char InputPixelType;<br> typedef itk::Image< InputPixelType, 3 > InputImageType;<br> typedef itk::ImageFileReader< InputImageType > ReaderType;<div>
<br>
ReaderType::Pointer reader = ReaderType::New();<br> <br>}<br></div></blockquote></div><div><br><br>As the error says, you have not defined ImageType. You need something like<br><br>typedef itk::Image<unsigned char, 2> ImageType;<br>
<br>David<br>
<br></div></div>
</blockquote></div><br>