GDCM 3.0.24
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 <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 );
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];
if( !gdcm::System::FileExists(filename) )
{
std::cerr << "Could not find file: " << filename << std::endl;
return 1;
}
{
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 );
}
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;
}
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
const Tag & GetTag() const
Get Tag.
Definition gdcmDataElement.h:67
SmartPointer< SequenceOfItems > GetValueAsSQ() const
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
DataElementSet::const_iterator ConstIterator
Definition gdcmDataSet.h:60
ConstIterator Begin() const
Definition gdcmDataSet.h:64
ConstIterator End() const
Definition gdcmDataSet.h:66
Class for manipulation directories.
Definition gdcmDirectory.h:43
std::vector< FilenameType > FilenamesType
Definition gdcmDirectory.h:49
unsigned int Load(FilenameType const &name, bool recursive=false)
FilenamesType const & GetFilenames() const
Set/Get the file names within the directory.
Definition gdcmDirectory.h:58
a DICOM File
Definition gdcmFile.h:34
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
Class to represent an Item.
Definition gdcmItem.h:46
const DataSet & GetNestedDataSet() const
Definition gdcmItem.h:80
Class to represent a Private DICOM Data Element (Attribute) Tag (Group, Element, Owner)
Definition gdcmPrivateTag.h:39
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
void SetFileName(const char *filename_native)
bool ReadUpToTag(const Tag &tag, std::set< Tag > const &skiptags=std::set< Tag >())
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
StringFilter.
Definition gdcmStringFilter.h:30
std::string ToString(const DataElement &de) const
void SetFile(const File &f)
Set/Get File.
Definition gdcmStringFilter.h:63
static bool FileExists(const char *filename)
Check whether the specified file exist on the system.
static bool FileIsDirectory(const char *name)
Check whether the file specified is a directory:
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
Definition gdcmASN1.h:21