Exemplo n.º 1
0
void SeriesReader::readSeriesData(unsigned int minSlices) {
	nameGenerator->SetUseSeriesDetails( true );
	nameGenerator->SetDirectory( inputDir );
	typedef std::vector< std::string > SeriesIdContainer;
	const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
	SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
	SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
	while( seriesItr != seriesEnd )	{
		FileNamesContainer fileNames = nameGenerator->GetFileNames(seriesItr->c_str());
		if (fileNames.size() >= minSlices) 
			slist.push_back( fileNames );
		seriesItr++;
	}
}
Exemplo n.º 2
0
SeriesFilelist getSeriesFileNames(const std::string &inputDir, unsigned int minSlices) {
	NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
	nameGenerator->SetUseSeriesDetails( true );
	nameGenerator->SetDirectory( inputDir );
	SeriesFilelist slist;

	typedef std::vector< std::string > SeriesIdContainer;
	const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();
	SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
	SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
	while( seriesItr != seriesEnd )	{
		FileNamesContainer fileNames = nameGenerator->GetFileNames(seriesItr->c_str());
		if (fileNames.size() >= minSlices) 
			slist.push_back( fileNames );
		seriesItr++;
	}

	return slist;
}
Exemplo n.º 3
0
bool ITKImplicit::loadDicom(const std::string & directory)
{
	nameGenerator->SetInputDirectory( directory.c_str() );
	
	typedef std::vector< std::string >   FileNamesContainer;
	FileNamesContainer fileNames;
	fileNames = nameGenerator->GetInputFileNames( );
	unsigned int numberOfFilenames =  fileNames.size();

	for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
	{
		std::cout << "filename # " << fni << " = ";
		std::cout << fileNames[fni] << std::endl;
	}
	
	reader->SetFileNames( fileNames );
		
	try
	{
		reader->Update();		
	}
	catch (itk::ExceptionObject &excp)
	{
		std::cerr << "Exception thrown while reading the image" << std::endl;
		std::cerr << excp << std::endl;
	
		return false;
	}
	
	// 
	// At this point we would have the volumetric data loaded in memory and we can
	// get access to it by invoking the \code{GetOutput()} method in the reader.
	//
	myImage = reader->GetOutput();		
	return true;
}
Exemplo n.º 4
0
void SeriesReader::getSeriesFileNames(unsigned int num, FileNamesContainer &fc) {
	if (slist.size() > num) fc = slist[num];
	else fc.clear();
};
Exemplo n.º 5
0
void QtDcmConvert::convert()
{
    if (QtDcmPreferences::instance()->useDcm2nii())
    {
        QString program = QtDcmPreferences::instance()->getDcm2niiPath();
        QStringList arguments;
        arguments << "-x" << "N";
        arguments << "-r" << "N";
        arguments << "-g" << "N";
        arguments << "-o" << d->outputDirectory << d->inputDirectory;
        
        QProcess * process = new QProcess(this);
        process->setStandardOutputFile(d->tempDirectory + QDir::separator() + "logs" + QDir::separator() + d->serieUID + ".txt");
        process->start(program, arguments);
        process->waitForFinished();

        delete process;
    }
    else
    {
        typedef signed short                                PixelType;
        const unsigned int Dimension = 3;
        typedef itk::Image< PixelType, Dimension >          ImageType;
        typedef itk::ImageSeriesReader< ImageType >         ReaderType;
        typedef itk::ImageFileWriter<ImageType>             WriterType;
        typedef itk::GDCMImageIO                            ImageIOType;
        typedef itk::GDCMSeriesFileNames                    NamesGeneratorType;
        typedef std::vector< std::string >                  FileNamesContainer;
        typedef std::vector< std::string >                  SeriesIdContainer;

//     ImageType::Pointer image = 0;

        ReaderType::Pointer reader = ReaderType::New();
        ImageIOType::Pointer dicomIO = ImageIOType::New();

        NamesGeneratorType::Pointer inputNames = NamesGeneratorType::New();
        inputNames->SetUseSeriesDetails ( true );
        inputNames->AddSeriesRestriction ( "0008|0021" );
        inputNames->AddSeriesRestriction ( "0020,0037" );
        inputNames->LoadSequencesOn();
        inputNames->LoadPrivateTagsOn();
        inputNames->SetInputDirectory ( d->inputDirectory.toStdString() );
        try
        {
            const SeriesIdContainer & seriesUID = inputNames->GetSeriesUIDs();
            std::string seriesIdentifier = seriesUID.begin()->c_str();
            FileNamesContainer filenames = inputNames->GetFileNames ( seriesIdentifier );

            dicomIO->SetFileName ( filenames.begin()->c_str() );
            try
            {
                dicomIO->ReadImageInformation();
            }
            catch ( itk::ExceptionObject &e )
            {
                qDebug() << e.GetDescription();
                return;
            }

            reader->UseStreamingOn();
            reader->SetFileNames ( filenames );
            reader->SetImageIO ( dicomIO );

            try
            {
                reader->Update();
            }
            catch ( itk::ExceptionObject &excp )
            {
                std::cerr << excp << std::endl;
                return;
            }

//         IteratorType itOut;
//
//         image = reader->GetOutput();
//
//         RegionType region;
//         region.SetSize ( 0, image->GetLargestPossibleRegion().GetSize() [0] );
//         region.SetSize ( 1, image->GetLargestPossibleRegion().GetSize() [1] );
//         region.SetSize ( 2, image->GetLargestPossibleRegion().GetSize() [2] );
//         image->SetRegions ( region );
//         image->Allocate();
//         SpacingType spacing;
//         spacing[0] = image->GetSpacing() [0];
//         spacing[1] = image->GetSpacing() [1];
//         spacing[2] = image->GetSpacing() [2];
//         spacing[3] = 1;
//         image->SetSpacing ( spacing );
//         PointType origin;
//         origin[0] = image->GetOrigin() [0];
//         origin[1] = image->GetOrigin() [1];
//         origin[2] = image->GetOrigin() [2];
//         origin[3] = 0;
//         image->SetOrigin ( origin );
//         DirectionType direction;
//         for ( unsigned int i=0; i<4; i++ )
//             for ( unsigned int j=0; j<4; j++ )
//             {
//                 if ( ( i < 3 ) && ( j < 3 ) )
//                     direction[i][j] = image->GetDirection() [i][j];
//                 else
//                     direction[i][j] = ( i == j ) ? 1 : 0;
//             }
//         image->SetDirection ( direction );
//         itOut = IteratorType ( image, region );
//
//         image->SetMetaDataDictionary ( dicomIO->GetMetaDataDictionary() );
//
//
//         itk::ImageRegionIterator<ImageType> itIn ( image, image->GetLargestPossibleRegion() );
//         while ( !itIn.IsAtEnd() )
//         {
//             itOut.Set ( itIn.Get() );
//             ++itIn;
//             ++itOut;
//         }


            WriterType::Pointer writer = WriterType::New();

            QString completeFilename = d->outputDirectory + QDir::separator() + d->outputFilename;

            writer->SetFileName ( completeFilename.toStdString() );
            writer->SetInput ( reader->GetOutput() );
//         writer->SetInput ( image );

            try
            {
                writer->Update();
            }
            catch ( itk::ExceptionObject &ex )
            {
                std::cout << ex << std::endl;
                return;
            }
        }
        catch ( itk::ExceptionObject &ex )
        {
            std::cout << ex << std::endl;
            return;
        }
    }
}