void Filemanager::setupFiles() { m_filesModel = new FilesModel(); m_files = new FilesView( Ui::Filemanager::centralWidget ); m_files->setObjectName(QString::fromUtf8("m_files")); m_files->setModel( m_filesModel ); // setting the gui part for the view m_files->setAlternatingRowColors( true ); m_files->setFlow( QListView::TopToBottom ); m_files->setWrapping( true ); m_files->setMovement( QListView::Static ); m_files->setLayoutMode( QListView::Batched ); m_files->setResizeMode( QListView::Adjust ); m_files->setViewMode( QListView::ListMode ); m_files->setSelectionBehavior( QListView::SelectRows ); m_files->setSelectionMode( QListView::ExtendedSelection ); // setting the view's mouse properties m_files->setAcceptDrops( true ); m_files->setDragEnabled( true ); m_files->setContextMenuPolicy( Qt::CustomContextMenu ); m_files->setDragEnabled( true ); m_files->setDropIndicatorShown( true ); m_files->setEditTriggers( QAbstractItemView::NoEditTriggers ); connect( m_files, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(filesRightClick(const QPoint&)) ); connect( m_files, SIGNAL(drop(QDropEvent*)), this, SLOT(filesDrop(QDropEvent*)) ); connect( m_files, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(filesDoubleClicked(const QModelIndex&)) ); connect( m_files, SIGNAL(keyPress(QKeyEvent*)), this, SLOT(filesKeyPress(QKeyEvent*)) ); // creating a popup menu for rightClick on files m_filesRightClickMenu.addAction("Execute", this, SLOT(filesExecute())); m_filesRightClickMenu.addSeparator(); m_filesRightClickMenu.addAction("Cut", this, SLOT(filesCut())); m_filesRightClickMenu.addAction("Copy", this, SLOT(filesCopy())); m_filesRightClickMenu.addAction("Paste", this, SLOT(filesPaste())); m_filesRightClickMenu.addSeparator(); m_filesRightClickMenu.addAction("Delete", this, SLOT(filesDelete())); }
void Filemanager::filesKeyPress( QKeyEvent* event ) { // getting the key that was pressed Qt::Key pressedKey = static_cast<Qt::Key>(event->key()); // choosing an appropiate action switch( pressedKey ) { // in case of 'Enter' we execute the file or change directory case Qt::Key_Return: filesExecute(); break; // in case of 'Delete' we delete the selected items, be it a folder or simple file case Qt::Key_Delete: filesDelete(); break; // Ctrl+C - the copy operation case Qt::Key_C: if( Qt::ControlModifier == event->modifiers() ) filesCopy(); break; // Ctrl+X - the cut operation case Qt::Key_X: if( Qt::ControlModifier == event->modifiers() ) filesCut(); break; // Ctrl+V - the paste operation case Qt::Key_V: if( Qt::ControlModifier == event->modifiers() ) filesPaste(); break; default: break; } }
vtkSmartPointer<vtkImageData> GNC::GCS::ControladorCarga::CargarITKMultidimensionalRGB(IComando* cmd, ListaRutas& listaFicheros, double* spacing) { vtkSmartPointer<vtkImageData> img = vtkSmartPointer<vtkImageData>::New(); wxCriticalSectionLocker locker(*m_pCriticalSection); typedef itk::RGBPixel<unsigned char> PixelType; typedef itk::Image<PixelType, 3 > ImageType; typedef itk::GDCMImageIO ImageIOType; typedef itk::ImageSeriesReader<ImageType> GenericReaderType; ImageIOType::Pointer dicomIO = ImageIOType::New(); GenericReaderType::Pointer reader = GenericReaderType::New(); CargaItkProgressCallback::Pointer cbProgreso = CargaItkProgressCallback::New(); reader->SetImageIO(dicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } reader->SetFileNames(filesCopy); } else { throw GNC::GCS::ControladorCargaException( "No input files", "ControladorCarga/CargaMultidimensionalRGB"); } reader->SetUseStreaming(true); //reader->GetOutput()->ReleaseDataFlagOn(); cbProgreso->SetCommand(cmd); cbProgreso->SetTexto(_Std("Interpreting properties")); reader->AddObserver (itk::ProgressEvent(), cbProgreso); try { reader->UpdateOutputInformation(); } catch (itk::ExceptionObject& ex) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Error reading the study: ") + ex.GetDescription(), "ControladorCarga/CargaMultidimensionalRGB"); } catch (...) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Internal error reading the study: "), "ControladorCarga/CargaMultidimensionalRGB"); } GenericReaderType::OutputImageType::SizeType dims = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); img->SetDimensions(dims[0], dims[1], dims[2]); img->SetOrigin(dicomIO->GetOrigin(0), dicomIO->GetOrigin(1), dicomIO->GetOrigin(2)); if(spacing == NULL) { double chk_spacing[3] = {dicomIO->GetSpacing(0), dicomIO->GetSpacing(1), dicomIO->GetSpacing(2)}; if (chk_spacing[0] < std::numeric_limits<double>::epsilon() || chk_spacing[1] < std::numeric_limits<double>::epsilon()) { std::stringstream ss; ss << _Std("Spacing is not valid: (") << chk_spacing[0] << ", " << chk_spacing[1] << ", " << chk_spacing[2] << ")"; GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Events::EventoMensajes(NULL,ss.str(),GNC::GCS::Events::EventoMensajes::PopUpMessage,GNC::GCS::Events::EventoMensajes::Aviso)); chk_spacing[0] = 1.0f; chk_spacing[1] = 1.0f; chk_spacing[2] = 1.0f; } img->SetSpacing(chk_spacing); } else { double chk_spacing[3] = {spacing[0], spacing[1], spacing[2]}; if (chk_spacing[0] < std::numeric_limits<double>::epsilon() || chk_spacing[1] < std::numeric_limits<double>::epsilon()) { std::stringstream ss; ss << _Std("Spacing of the image is invalid: (") << chk_spacing[0] << ", " << chk_spacing[1] << ", " << chk_spacing[2] << ")"; GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Events::EventoMensajes(NULL,ss.str(),GNC::GCS::Events::EventoMensajes::PopUpMessage,GNC::GCS::Events::EventoMensajes::Aviso)); chk_spacing[0] = 1.0f; chk_spacing[1] = 1.0f; chk_spacing[2] = 1.0f; } img->SetSpacing(chk_spacing); } //std::cout << "number of scalar components" << dicomIO->GetNumberOfComponents(); try { img->AllocateScalars(VTK_UNSIGNED_CHAR, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensionalRGB"); } reader->SetUseStreaming(true); //reader->GetOutput()->ReleaseDataFlagOn(); reader->GetOutput()->GetPixelContainer()->SetImportPointer((GenericReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); cbProgreso->SetTexto(_Std("Reading dataset")); reader->AddObserver (itk::ProgressEvent(), cbProgreso); try { reader->UpdateLargestPossibleRegion(); } catch (itk::ExceptionObject& ex) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Error reading the study:") + ex.GetDescription(), "ControladorCarga/CargaMultidimensionalRGB"); } catch (...) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Internal error while reading the study:"), "ControladorCarga/CargaMultidimensionalRGB"); } if (reader->GetAbortGenerateData()) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Process canceled by user."), "ControladorCarga/CargaMultidimensional"); } return img; }
vtkSmartPointer<vtkImageData> GNC::GCS::ControladorCarga::CargarITKMultidimensionalUnsignedShort(IComando* cmd, ListaRutas& listaFicheros, int* orientacion, double* spacing) { vtkSmartPointer<vtkImageData> img = vtkSmartPointer<vtkImageData>::New(); //int bitsStored, highBit, bitsAllocated,pixelRepresentation = 0; wxCriticalSectionLocker locker(*m_pCriticalSection); typedef double PixelType; typedef itk::Image<PixelType, 3 > ImageType; typedef itk::GDCMImageIO ImageIOType; typedef itk::ImageSeriesReader<ImageType> GenericReaderType; ImageIOType::Pointer dicomIO = ImageIOType::New(); GenericReaderType::Pointer reader = GenericReaderType::New(); CargaItkProgressCallback::Pointer cbProgreso = CargaItkProgressCallback::New(); try { reader->SetImageIO(dicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } reader->SetFileNames(filesCopy); } else { throw GNC::GCS::ControladorCargaException( "No input files", "ControladorCarga/CargarITKMultidimensionalUnsignedShort"); } //reader->GetOutput()->ReleaseDataFlagOn(); cbProgreso->SetCommand(cmd); cbProgreso->SetTexto(_Std("Reading properties")); reader->AddObserver (itk::ProgressEvent(), cbProgreso); reader->UpdateOutputInformation(); } catch (itk::ExceptionObject& ex) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Error reading the study: ") + ex.GetDescription(), "ControladorCarga/CargaMultidimensional"); } catch (std::exception& ex) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Internal error reading the study: "), std::string("ControladorCarga/CargaMultidimensional") + ex.what()); } catch (...) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Internal error reading the study: "), "ControladorCarga/CargaMultidimensional"); } if (orientacion != NULL) { ImageType::Pointer im = reader->GetOutput(); ImageType::DirectionType dir = im->GetDirection(); /* std::cout << dir[0][0] << ", " << dir[0][1] << ", " << dir[0][2] << std::endl; std::cout << dir[1][0] << ", " << dir[1][1] << ", " << dir[1][2] << std::endl; std::cout << dir[2][0] << ", " << dir[2][1] << ", " << dir[2][2] << std::endl; */ if( std::abs( dir[0][2] ) > std::abs(dir[1][2]) && std::abs( dir[0][2]) > std::abs(dir[2][2])) { //std::cout << "SAGITAL" << std::endl; *orientacion = 0; } else if( std::abs( dir[1][2] ) > std::abs(dir[0][2]) && std::abs( dir[1][2]) > std::abs(dir[2][2])) { //std::cout << "CORONAL" << std::endl; *orientacion = 1; } else if( std::abs( dir[2][2] ) > std::abs(dir[0][2]) && std::abs( dir[2][2]) > std::abs(dir[1][2])) { //std::cout << "AXIAL" << std::endl; *orientacion = 2; } } GenericReaderType::OutputImageType::SizeType dims = reader->GetOutput()->GetLargestPossibleRegion().GetSize(); img->SetDimensions(dims[0], dims[1], dims[2]); img->SetOrigin(dicomIO->GetOrigin(0), dicomIO->GetOrigin(1), dicomIO->GetOrigin(2)); if(spacing == NULL) { double chk_spacing[3] = {dicomIO->GetSpacing(0), dicomIO->GetSpacing(1), dicomIO->GetSpacing(2)}; if (chk_spacing[0] < std::numeric_limits<double>::epsilon() || chk_spacing[1] < std::numeric_limits<double>::epsilon()) { std::stringstream ss; ss << _Std("Spacing is not valid: (") << chk_spacing[0] << ", " << chk_spacing[1] << ", " << chk_spacing[2] << ")"; GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Events::EventoMensajes(NULL,ss.str(),GNC::GCS::Events::EventoMensajes::PopUpMessage,GNC::GCS::Events::EventoMensajes::Aviso)); chk_spacing[0] = 1.0f; chk_spacing[1] = 1.0f; chk_spacing[2] = 1.0f; } img->SetSpacing(chk_spacing); } else { double chk_spacing[3] = {spacing[0], spacing[1], spacing[2]}; if (chk_spacing[0] < std::numeric_limits<double>::epsilon() || chk_spacing[1] < std::numeric_limits<double>::epsilon()) { std::stringstream ss; ss << _Std("Spacing is not valid: (") << chk_spacing[0] << ", " << chk_spacing[1] << ", " << chk_spacing[2] << ")"; GNC::GCS::ControladorEventos::Instance()->ProcesarEvento(new GNC::GCS::Events::EventoMensajes(NULL,ss.str(),GNC::GCS::Events::EventoMensajes::PopUpMessage,GNC::GCS::Events::EventoMensajes::Aviso)); chk_spacing[0] = 1.0f; chk_spacing[1] = 1.0f; chk_spacing[2] = 1.0f; } img->SetSpacing(chk_spacing); } itk::ProcessObject::Pointer processObject; switch(dicomIO->GetComponentType()) { case ImageIOType::UCHAR: { typedef unsigned char TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_UNSIGNED_CHAR, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::CHAR: { typedef char TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_CHAR, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::USHORT: { typedef unsigned short TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_UNSIGNED_SHORT, dicomIO->GetNumberOfComponents()); } catch(const std::bad_alloc&) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Internal Error"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::SHORT: { typedef short TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_SHORT, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::UINT: { typedef unsigned int TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_UNSIGNED_INT, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::INT: { typedef int TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_INT, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::ULONG: { typedef unsigned long TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_UNSIGNED_LONG, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::LONG: { typedef long TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_LONG, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::FLOAT: { typedef float TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_FLOAT, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::DOUBLE: { typedef double TypedPixelType; typedef itk::Image<TypedPixelType, 3 > TypedImageType; typedef itk::ImageSeriesReader<TypedImageType> TypedReaderType; try { img->AllocateScalars(VTK_DOUBLE, dicomIO->GetNumberOfComponents()); } catch (...) { throw GNC::GCS::ControladorCargaException( _Std("Error loading the study: Out of memory"), "ControladorCarga/CargaMultidimensional"); } TypedReaderType::Pointer treader = TypedReaderType::New(); ImageIOType::Pointer tdicomIO = ImageIOType::New(); treader->SetImageIO(tdicomIO); if (listaFicheros.size() > 0) { std::vector<std::string> filesCopy(listaFicheros.size()); GNC::GCS::IControladorCarga::ListaRutas::iterator it = listaFicheros.begin(); std::vector<std::string>::size_type off = 0; while (it != listaFicheros.end()) { filesCopy[off++] = *(it++); } treader->SetFileNames(filesCopy); } treader->SetUseStreaming(true); //treader->GetOutput()->ReleaseDataFlagOn(); treader->GetOutput()->GetPixelContainer()->SetImportPointer((TypedReaderType::OutputImageType::PixelType*)(img->GetScalarPointer()), dims[0] * dims[1] * dims[2], false ); processObject = treader; } break; case ImageIOType::UNKNOWNCOMPONENTTYPE: default: throw GNC::GCS::ControladorCargaException( _Std("Error reading the study: unsupported pixel format"), "ControladorCarga/CargaMultidimensional"); } cbProgreso->SetTexto("Leyendo dataset"); processObject->AddObserver (itk::ProgressEvent(), cbProgreso); try { processObject->UpdateLargestPossibleRegion(); } catch (itk::ExceptionObject& ex) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Error reading the study: ") + ex.GetDescription(), "ControladorCarga/CargaMultidimensional"); } catch (...) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Internal error reading the study: "), "ControladorCarga/CargaMultidimensional"); } if (processObject->GetAbortGenerateData()) { reader->ResetPipeline(); throw GNC::GCS::ControladorCargaException( _Std("Process canceled by user."), "ControladorCarga/CargaMultidimensional"); } //se modifica si es necesario /* { typedef itk::MetaDataObject< std::string > MetaDataStringType; for (itk::MetaDataDictionary::ConstIterator it = dicomIO->GetMetaDataDictionary().Begin(); it != dicomIO->GetMetaDataDictionary().End(); ++it) { itk::MetaDataObjectBase::Pointer entry = it->second; MetaDataStringType::Pointer entryvalue = dynamic_cast<MetaDataStringType *> (entry.GetPointer()); if(it->first == "0028|0100") { //bits allocated std::istringstream is(entryvalue->GetMetaDataObjectValue()); is >>bitsAllocated; } else if(it->first == "0028|0101") { //bits stored std::istringstream is(entryvalue->GetMetaDataObjectValue()); is >>bitsStored; } else if(it->first == "0028|0102") {//high bit std::istringstream is(entryvalue->GetMetaDataObjectValue()); is >>highBit; } else if(it->first == "0028|0103") {//pixel representation=> 0 es unsigned 1 es signed std::istringstream is(entryvalue->GetMetaDataObjectValue()); is >>pixelRepresentation; } } if(bitsAllocated != bitsStored) { switch(dicomIO->GetComponentType()) { case ImageIOType::UCHAR: pixelRepresentation = 0; //a partir de aqui se trata el pixelrepresentation case ImageIOType::CHAR: { unsigned char* data = (unsigned char*) img->GetScalarPointer(); unsigned char desplazamientoSigno; desplazamientoSigno = highBit; unsigned char maskComprobarSigno = 1; maskComprobarSigno <<= desplazamientoSigno; unsigned char maskClearParteAltaPositivo = 0; //se meten unos en la parte baja if(pixelRepresentation == 0) { for(int i = 0; i<= desplazamientoSigno; ++i) { maskClearParteAltaPositivo <<=1; maskClearParteAltaPositivo |=1; } } else { for(int i = 0; i< desplazamientoSigno; ++i) { maskClearParteAltaPositivo <<=1; maskClearParteAltaPositivo |=1; } } //se meten unos en la parte alta unsigned char maskSetParteAltaNegativo = 0x80; if(pixelRepresentation != 0) { for(int i=0; i< 8-desplazamientoSigno; ++i) { maskSetParteAltaNegativo >>=1; maskSetParteAltaNegativo |=0x80; } } int size = dims[0] * dims[1] * dims[2]; if(pixelRepresentation == 0) { if(maskClearParteAltaPositivo != 0xFF) { // si es ff no tiene sentido hacer nada int size = dims[0] * dims[1] * dims[2] * 2; for(int i= 0; i< size; i+=2) { //es positivo data[i] &= maskClearParteAltaPositivo; } } } else { for(int i= 0; i< size; ++i) { if((data[i] & maskComprobarSigno) == 0) { //es positivo data[i] &= maskClearParteAltaPositivo; } else { //es negativo => aplicar el complemento a dos... data[i] |= maskSetParteAltaNegativo; } } } } break; case ImageIOType::USHORT: pixelRepresentation = 0; //a partir de aqui se trata el pixelrepresentation case ImageIOType::SHORT: { unsigned char* data = (unsigned char*) img->GetScalarPointer(); unsigned char posicionInicial; unsigned char desplazamientoSigno; if(highBit>=8) { //little endian desplazamientoSigno = highBit - 8 ; posicionInicial = 1; } else { //bigEndian desplazamientoSigno = highBit; posicionInicial = 0; } unsigned char maskComprobarSigno = 1; maskComprobarSigno <<= desplazamientoSigno; unsigned char maskClearParteAltaPositivo = 0; //se meten unos en la parte baja if(pixelRepresentation == 0) { for(int i = 0; i<= desplazamientoSigno; ++i) { maskClearParteAltaPositivo <<=1; maskClearParteAltaPositivo |=1; } } else { for(int i = 0; i< desplazamientoSigno; ++i) { maskClearParteAltaPositivo <<=1; maskClearParteAltaPositivo |=1; } } //se meten unos en la parte alta unsigned char maskSetParteAltaNegativo = 0x80; if(pixelRepresentation != 0) { for(int i=0; i< 8-desplazamientoSigno; ++i) { maskSetParteAltaNegativo >>=1; maskSetParteAltaNegativo |=0x80; } } int size = dims[0] * dims[1] * dims[2] * 2; if(pixelRepresentation == 0) { if(maskClearParteAltaPositivo != 0xFF) { // si es ff no tiene sentido hacer nada int size = dims[0] * dims[1] * dims[2] * 2; for(int i= posicionInicial; i< size; i+=2) { //es positivo data[i] &= maskClearParteAltaPositivo; } } } else { for(int i= posicionInicial; i< size; i+=2) { if((data[i] & maskComprobarSigno) == 0) { //es positivo data[i] &= maskClearParteAltaPositivo; } else { //es negativo => aplicar el complemento a dos... data[i] |= maskSetParteAltaNegativo; } } } } break; case ImageIOType::UINT: { //d momento no hago na } break; case ImageIOType::INT: { //d momento no hago na } break; case ImageIOType::ULONG: { //d momento no hago na } break; case ImageIOType::LONG: { //d momento no hago na } break; case ImageIOType::FLOAT: case ImageIOType::DOUBLE: break; case ImageIOType::UNKNOWNCOMPONENTTYPE: default: throw GNC::GCS::ControladorCargaException( std::string("Error reading the study: Formato de pixel no soportado"), "ControladorCarga/CargaMultidimensional"); } } }*/ return img; }