bool NrrdPlugin::setFile(QStringList files) { m_fileName = files; typedef itk::Image<unsigned char, 3> ImageType; typedef itk::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(m_fileName[0].toAscii().data()); typedef itk::NrrdImageIO NrrdIOType; NrrdIOType::Pointer nrrdIO = NrrdIOType::New(); reader->SetImageIO(nrrdIO); reader->Update(); itk::ImageIOBase::Pointer imageIO = reader->GetImageIO(); m_height = imageIO->GetDimensions(0); m_width = imageIO->GetDimensions(1); m_depth = imageIO->GetDimensions(2); m_voxelSizeX = imageIO->GetSpacing(0); m_voxelSizeY = imageIO->GetSpacing(1); m_voxelSizeZ = imageIO->GetSpacing(2); int et = imageIO->GetComponentType(); if (et == itk::ImageIOBase::UCHAR) m_voxelType = _UChar; if (et == itk::ImageIOBase::CHAR) m_voxelType = _Char; if (et == itk::ImageIOBase::USHORT) m_voxelType = _UShort; if (et == itk::ImageIOBase::SHORT) m_voxelType = _Short; if (et == itk::ImageIOBase::INT) m_voxelType = _Int; if (et == itk::ImageIOBase::FLOAT) m_voxelType = _Float; m_skipBytes = m_headerBytes = 0; m_bytesPerVoxel = 1; if (m_voxelType == _UChar) m_bytesPerVoxel = 1; else if (m_voxelType == _Char) m_bytesPerVoxel = 1; else if (m_voxelType == _UShort) m_bytesPerVoxel = 2; else if (m_voxelType == _Short) m_bytesPerVoxel = 2; else if (m_voxelType == _Int) m_bytesPerVoxel = 4; else if (m_voxelType == _Float) m_bytesPerVoxel = 4; if (m_4dvol) // do not perform further calculations. return true; if (m_voxelType == _UChar || m_voxelType == _Char || m_voxelType == _UShort || m_voxelType == _Short) { findMinMaxandGenerateHistogram(); } else { findMinMax(); generateHistogram(); } return true; }
void MriWatcherGUI::LoadFile(const QString& filename) { ReaderType::Pointer reader = ReaderType::New(); ImageType::Pointer image = reader->GetOutput(); reader->SetFileName( filename.toLatin1().constData() ); try { reader->Update(); } catch( itk::ExceptionObject & e ) { // std::cerr << "Exception in file reader " << std::endl; // std::cerr << e << std::endl; QMessageBox::information( this, "MriWatcher", "Unable to load file:\n" + filename); return; } m_numberofimages++; ImageFrameGUI* m_imageframe = new ImageFrameGUI(m_frame); connect(m_imageframe->g_imageframe, SIGNAL( Clicked(int) ), this, SLOT( ImageFrameClicked() ) ); connect(m_imageframe, SIGNAL( GetFiles(const QString &) ), this, SLOT( LoadOverlay(const QString &) ) ); m_imageframe->g_imageframe->SetManager(&m_imagemanager); m_imageframe->g_imageframe->SetSlider(g_slice_slider); m_imageframe->g_imageframe->SetId(m_direction); QFileInfo info(filename); m_imageframe->g_imageframe->SetImageName(info.baseName() ); m_imageframe->g_imageframe->DrawPosition(g_draw_position->isChecked() ); m_imageframe->g_imageframe->DrawIntensity(g_draw_intensity->isChecked() ); // This string should only be used for display purposes it is not // safe to use this for comparison of types // QString pixeltypestring(reader->GetImageIO()->GetComponentTypeInfo().name()); QString pixeltypestring(QString::fromStdString(reader->GetImageIO()->GetComponentTypeAsString( reader->GetImageIO()->GetComponentType() ) ) ); m_imageframe->g_imageframe->DrawImageName(g_draw_name->isChecked() ); m_imagesize = image->GetLargestPossibleRegion().GetSize(); m_imagespacing = image->GetSpacing(); int m_cimagesize[3]; m_cimagesize[0] = m_imagesize[0]; m_cimagesize[1] = m_imagesize[1]; m_cimagesize[2] = m_imagesize[2]; float m_cpixdim[3]; m_cpixdim[0] = m_imagespacing[0]; m_cpixdim[1] = m_imagespacing[1]; m_cpixdim[2] = m_imagespacing[2]; m_imageframe->g_imageframe->SetImageInfo(m_cimagesize, m_cpixdim, pixeltypestring); m_imageframe->g_imageframe->DrawImageInfo(g_draw_info->isChecked() ); typedef MinimumMaximumImageCalculator<ImageType> CalculatorType; CalculatorType::Pointer calculator = CalculatorType::New(); calculator->SetImage(image); calculator->Compute(); ImageType::PixelType m_min = calculator->GetMinimum(); ImageType::PixelType m_max = calculator->GetMaximum(); if( m_max > m_imagemax ) { m_imagemax = m_max; } if( m_min < m_imagemin ) { m_imagemin = m_min; } m_imageframe->g_imageframe->SetImageMinMax(m_min, m_max); if( m_numberofimages == 1 ) { m_imagemanager.SetSourceImage(image); } m_imageframe->g_imageframe->SetInputImage(image); m_imageframe->g_imageframe->ChangeAlpha(100); ReDraw(); g_slice_slider->setEnabled(true); m_frame->setGeometry(QRect(m_frame->x(), m_frame->y(), m_frame->height(), m_frame->width() ) ); // gridLayout_imageWindows->addWidget(m_imageframe); m_imageframelayout->addWidget(m_imageframe); m_imageframelist.push_back(m_imageframe); // m_imageframe->setLayout(m_imageframelayout); m_imageframe->show(); // g_scrollArea->setWidget(m_imageframe); if( m_imageframelist.size() == 1 ) { m_imagemanager.SetCrosshair(m_imagesize[0] / 2, m_imagesize[1] / 2, m_imagesize[2] / 2); } else { m_imagemanager.UpdateCrosshair(); } if( m_imagesize[0] > m_maxsize[0] ) { m_maxsize[0] = m_imagesize[0]; } if( m_imagesize[1] > m_maxsize[1] ) { m_maxsize[1] = m_imagesize[1]; } if( m_imagesize[2] > m_maxsize[2] ) { m_maxsize[2] = m_imagesize[2]; } UpdateLabel(); /* if (!filename.isEmpty()) { QImage image(filename); if (image.isNull()) { QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(filename)); return; } // imageLabel->setPixmap(QPixmap::fromImage(image)); } */ }