GDCM 3.2.1

DumpVisusChange.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "gdcmReader.h"
#include "gdcmDirectory.h"
#include "gdcmStringFilter.h"
#include <vector>
#include <algorithm>
/*
*/
static bool process( std::vector<gdcm::DataElement> & ms, const char * filename)
{
using namespace gdcm;
Tag pd(0x7fe0,0x0000);
std::set<gdcm::Tag> skiptags;
skiptags.insert( pd );
gdcm::Reader reader;
reader.SetFileName( filename );
if( !reader.ReadUpToTag( pd, skiptags ) )
{
std::cerr << "Failure to read: " << filename << std::endl;
return false;
}
gdcm::File &file = reader.GetFile();
gdcm::DataSet &ds1 = file.GetDataSet();
const gdcm::PrivateTag tseq1(0x5533,0x33,"Visus Change");
if( !ds1.FindDataElement( tseq1 ) ) return true;
const gdcm::DataElement& seq1 = ds1.GetDataElement( tseq1 );
SmartPointer<SequenceOfItems> sqi1 = seq1.GetValueAsSQ();
const size_t nitems = sqi1->GetNumberOfItems();
for( size_t item = 1; item < nitems; ++item )
{
Item &item1 = sqi1->GetItem(item);
DataSet &ds2 = item1.GetNestedDataSet();
for(DataSet::ConstIterator it = ds2.Begin(); it != ds2.End(); ++it )
{
DataElement const & de = *it;
// cannot simply use std::set here, see there is a discrepancy in between
// operator== and operator<.
// So only use operator== here:
std::vector<DataElement>::iterator vit = std::find(ms.begin(), ms.end(), de);
if( vit == ms.end() )
ms.push_back(de);
}
}
return true;
}
int main(int argc, char *argv[])
{
bool usefastpath = true;
if( argc < 2 ) return 1;
using namespace gdcm;
const char *filename = argv[1];
gdcm::Directory::FilenamesType filenames;
if( !gdcm::System::FileExists(filename) )
{
std::cerr << "Could not find file: " << filename << std::endl;
return 1;
}
gdcm::Directory dir;
if( gdcm::System::FileIsDirectory(filename) )
{
unsigned int nfiles = dir.Load(filename, false);
if( nfiles == 0 )
{
std::cerr << "Could not find files: " << filename << std::endl;
return 1;
}
filenames = dir.GetFilenames();
}
else
{
filenames.push_back( filename );
}
gdcm::StringFilter sf;
Tag pd(0x7fe0,0x0000);
std::set<gdcm::Tag> skiptags;
skiptags.insert( pd );
gdcm::Reader reader;
reader.SetFileName( filenames[0].c_str() );
if( !reader.ReadUpToTag( pd, skiptags ) )
{
std::cerr << "Could not read file: " << filename << std::endl;
return 1;
}
gdcm::File &file = reader.GetFile();
sf.SetFile(file);
if( usefastpath ) {
// Heuristic, assume if private tag cannot be found in first file, skip the directory
gdcm::DataSet &ds1 = file.GetDataSet();
const gdcm::PrivateTag tseq1(0x5533,0x33,"Visus Change");
if( !ds1.FindDataElement( tseq1 ) ){
std::cerr << "Could not find private tag in first file skipping whole directory: " << filename << std::endl;
return 0;
}
}
std::vector<DataElement> ms;
for(gdcm::Directory::FilenamesType::const_iterator cit = filenames.begin(); cit != filenames.end(); ++cit )
{
if( !process(ms, cit->c_str()) ) {
return 1;
}
}
if( !ms.empty() ) {
std::sort(ms.begin(), ms.end());
std::cout << filename << ",\"";
for(std::vector<DataElement>::const_iterator it = ms.begin(); it != ms.end(); ++it )
{
DataElement const & de = *it;
std::string const & s = sf.ToString( de );
std::cout << de.GetTag() << " " << s << std::endl;
}
std::cout << "\"" << std::endl;
}
return 0;
}
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::GetTag
const Tag & GetTag() const
Get Tag.
Definition gdcmDataElement.h:67
gdcm::DataElement::GetValueAsSQ
SmartPointer< SequenceOfItems > GetValueAsSQ() const
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
gdcm::DataSet::GetDataElement
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
gdcm::DataSet::FindDataElement
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
gdcm::DataSet::ConstIterator
DataElementSet::const_iterator ConstIterator
Definition gdcmDataSet.h:60
gdcm::DataSet::Begin
ConstIterator Begin() const
Definition gdcmDataSet.h:64
gdcm::DataSet::End
ConstIterator End() const
Definition gdcmDataSet.h:66
gdcm::Directory
Class for manipulation directories.
Definition gdcmDirectory.h:43
gdcm::Directory::FilenamesType
std::vector< FilenameType > FilenamesType
Definition gdcmDirectory.h:49
gdcm::Directory::Load
unsigned int Load(FilenameType const &name, bool recursive=false)
gdcm::Directory::GetFilenames
FilenamesType const & GetFilenames() const
Set/Get the file names within the directory.
Definition gdcmDirectory.h:58
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::Item
Class to represent an Item.
Definition gdcmItem.h:46
gdcm::Item::GetNestedDataSet
const DataSet & GetNestedDataSet() const
Definition gdcmItem.h:80
gdcm::PrivateTag
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner)
Definition gdcmPrivateTag.h:39
gdcm::Reader
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
gdcm::Reader::GetFile
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::Reader::ReadUpToTag
bool ReadUpToTag(const Tag &tag, std::set< Tag > const &skiptags=std::set< Tag >())
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::StringFilter
StringFilter.
Definition gdcmStringFilter.h:30
gdcm::StringFilter::ToString
std::string ToString(const DataElement &de) const
gdcm::StringFilter::SetFile
void SetFile(const File &f)
Set/Get File.
Definition gdcmStringFilter.h:63
gdcm::System::FileExists
static bool FileExists(const char *filename)
Check whether the specified file exist on the system.
gdcm::System::FileIsDirectory
static bool FileIsDirectory(const char *name)
Check whether the file specified is a directory:
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcmDirectory.h
gdcmReader.h
gdcmStringFilter.h
gdcm
Definition gdcmASN1.h:21