Commit 0dcd0210 authored by Gert Wollny's avatar Gert Wollny
Browse files

New upstream version 3.0.3

parent 10600606
Loading
Loading
Loading
Loading
+63 −32
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@
#include "gdcmTrace.h"
#include "gdcmVersion.h"
#include "gdcmSimpleSubjectWatcher.h"
#include "gdcmGlobal.h"
#include "gdcmDicts.h"
#include "gdcmDict.h"
#include "gdcmDictEntry.h"

#include <string>
#include <iostream>
@@ -57,10 +61,13 @@ static void PrintHelp()
  std::cout << "Parameter (required):" << std::endl;
  std::cout << "  -d --dir                  DICOM directory" << std::endl;
  std::cout << "  -t --tag %d,%d            DICOM tag(s) to look for" << std::endl;
  std::cout << "  -k --keyword %s           DICOM keyword(s) to look for" << std::endl;
  std::cout << "  -P --private-tag %d,%d,%s DICOM private tag(s) to look for" << std::endl;
  std::cout << "Options:" << std::endl;
  std::cout << "  -p --print      Print output." << std::endl;
  std::cout << "  -r --recursive  Recusively descend directory." << std::endl;
  std::cout << "  -r --recursive  Recursively descend directory." << std::endl;
  std::cout << "     --strict     Use strict parser (faster but less tolerant with bogus DICOM files)." << std::endl;
  std::cout << "     --table      Use Table output." << std::endl;
  std::cout << "General Options:" << std::endl;
  std::cout << "  -V --verbose    more verbose (warning+error)." << std::endl;
  std::cout << "  -W --warning    print warning info." << std::endl;
@@ -75,7 +82,7 @@ typedef std::vector<gdcm::PrivateTag> VectorPrivateTags;
template < typename TScanner >
static int DoIt(
  gdcm::Directory const & d,
  bool const & print ,
  bool const & print , int table,
    VectorTags const & tags,
  VectorPrivateTags const & privatetags)
{
@@ -96,7 +103,13 @@ static int DoIt(
    std::cerr << "Scanner failed" << std::endl;
    return 1;
    }
  if (print) s.Print( std::cout );
  if (print)
    {
    if(table)
      s.PrintTable( std::cout );
    else
      s.Print( std::cout );
    }

  return 0;
}
@@ -114,8 +127,12 @@ int main(int argc, char *argv[])
  VectorPrivateTags privatetags;
  gdcm::Tag tag;
  gdcm::PrivateTag privatetag;
  static const gdcm::Global &g = gdcm::Global::GetInstance();
  static const gdcm::Dicts &dicts = g.GetDicts();
  static const gdcm::Dict &pubdict = dicts.GetPublicDict();

  int strict = 0;
  int table = 0;
  int verbose = 0;
  int warning = 0;
  int debug = 0;
@@ -127,25 +144,27 @@ int main(int argc, char *argv[])
    //int this_option_optind = optind ? optind : 1;
    int option_index = 0;
    static struct option long_options[] = {
        {"dir", 1, nullptr, 0},
        {"tag", 1, nullptr, 0},
        {"recursive", 1, nullptr, 0},
        {"print", 1, nullptr, 0},
        {"private-tag", 1, nullptr, 0},
        {"strict", 0, &strict, 1},
        {"dir", required_argument, nullptr, 'd'},
        {"tag", required_argument, nullptr, 't'},
        {"recursive", no_argument, nullptr, 'r'},
        {"print", no_argument, nullptr, 'p'},
        {"private-tag", required_argument, nullptr, 'P'},
        {"keyword", required_argument, nullptr, 'k'},
        {"strict", no_argument, &strict, 1},
        {"table", no_argument, &table, 1},

// General options !
        {"verbose", 0, &verbose, 1},
        {"warning", 0, &warning, 1},
        {"debug", 0, &debug, 1},
        {"error", 0, &error, 1},
        {"help", 0, &help, 1},
        {"version", 0, &version, 1},
        {"verbose", no_argument, nullptr, 'V'},
        {"warning", no_argument, nullptr, 'W'},
        {"debug", no_argument, nullptr, 'D'},
        {"error", no_argument, nullptr, 'E'},
        {"help", no_argument, nullptr, 'H'},
        {"version", no_argument, nullptr, 'v'},

        {nullptr, 0, nullptr, 0}
    };

    c = getopt_long (argc, argv, "d:t:rpP:VWDEhv",
    c = getopt_long (argc, argv, "d:t:rpP:k:VWDEhv",
      long_options, &option_index);
    if (c == -1)
      {
@@ -155,18 +174,10 @@ int main(int argc, char *argv[])
    switch (c)
      {
    case 0:
      if (optarg)
        {
        //const char *s = long_options[option_index].name;
        //printf ("option %s", s);
        //if (optarg)
        //  {
        //  if( option_index == 0 ) /* input */
        //    {
        //    assert( strcmp(s, "input") == 0 );
        //    }
        //  printf (" with arg %s", optarg);
        //  }
        //printf ("\n");
        const char *s = long_options[option_index].name; (void)s;
        assert(0);
        }
      break;

@@ -180,6 +191,20 @@ int main(int argc, char *argv[])
      //std::cerr << optarg << std::endl;
      break;

    case 'k':
      {
      const char * keyword = optarg;
      /*const gdcm::DictEntry &dictentry =*/ pubdict.GetDictEntryByKeyword(keyword, tag);
      if( tag != gdcm::Tag(0xffff,0xffff) )
        tags.push_back( tag );
      else
        {
        std::cerr << "Invalid keyword: " << keyword << std::endl;
        return 1;
        }
      }
      break;

    case 'P':
      privatetag.ReadFromCommaSeparatedString(optarg);
      privatetags.push_back( privatetag );
@@ -290,10 +315,16 @@ int main(int argc, char *argv[])

  gdcm::Directory d;
  unsigned int nfiles = d.Load( dirname.c_str(), recursive );
  if( !nfiles )
    {
    std::cerr << "No files found in: " << dirname << std::endl;
    return 1;
    }
  if( verbose ) d.Print( std::cout );
  if( !table )
    std::cout << "done retrieving file list " << nfiles << " files found." <<  std::endl;

  if( strict )
    return DoIt<gdcm::StrictScanner>(d,print,tags,privatetags);
  return DoIt<gdcm::Scanner>(d,print,tags,privatetags);
    return DoIt<gdcm::StrictScanner>(d,print,table,tags,privatetags);
  return DoIt<gdcm::Scanner>(d,print,table,tags,privatetags);
}
+22 −18
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ endif()
#----------------------------------------------------------------------------

project(GDCM
  VERSION 3.0.2
  VERSION 3.0.3
  LANGUAGES CXX C
)
## NOTE: the "DESCRIPTION" feature of project() was introduced in cmake 3.10.0
@@ -590,22 +590,6 @@ if(GDCM_STANDALONE)
else()
  set(BUILD_APPLICATIONS OFF)
endif()
add_subdirectory(Utilities)
add_subdirectory(Source)

if(GDCM_STANDALONE)
  add_subdirectory(Wrapping)
  if(GDCM_WRAP_CSHARP)
    add_subdirectory(Wrapping/Csharp)
  endif()
endif()

if(GDCM_STANDALONE)
  # After Wrapping please
  if(BUILD_EXAMPLES)
    add_subdirectory(Examples)
  endif()
endif()

#-----------------------------------------------------------------------------
# Need pthread for the following class:
@@ -618,7 +602,7 @@ if(GDCM_STANDALONE)
endif()

if(GDCM_STANDALONE)
  if(BUILD_TESTING)
  if(GDCM_BUILD_TESTING)
    configure_file(${GDCM_SOURCE_DIR}/CMake/CTestCustom.ctest.in
        ${GDCM_BINARY_DIR}/CMake/CTestCustom.ctest @ONLY)
    file(WRITE ${GDCM_BINARY_DIR}/CTestCustom.cmake
@@ -635,6 +619,21 @@ if(GDCM_STANDALONE)
  endif()
endif()

# After enable_testing()
add_subdirectory(Utilities)
add_subdirectory(Source)

if(GDCM_STANDALONE)
  add_subdirectory(Wrapping)
endif()

if(GDCM_STANDALONE)
  # After Wrapping please
  if(BUILD_EXAMPLES)
    add_subdirectory(Examples)
  endif()
endif()

#-----------------------------------------------------------------------------
if(GDCM_STANDALONE)
  option(GDCM_DOCUMENTATION "Build source documentation using doxygen." OFF)
@@ -680,6 +679,11 @@ include(CMake/InstallRequiredVTKLibraries.cmake)
endif()
endif()

# Make sure to run doxygen after everything else (in particular vtkgdcm):
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/Utilities/doxygen)
  add_subdirectory(Utilities/doxygen)
endif()

#-----------------------------------------------------------------------------
# CPack stuff
if(GDCM_STANDALONE) # disabled for ITK distribution of gdcm
+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ set(EXAMPLES_SRCS
  PrintLUT
  EmptyMask
  DumpSiemensBase64
  DumpVisusChange
  TemplateEmptyImage
  MakeTemplate
  DeriveSeries
+143 −0
Original line number Diff line number Diff line
/*=========================================================================

  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;
}
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ unsigned int Directory::Load(FilenameType const &name, bool recursive)
      Toplevel = name;
      return Explore( Toplevel, recursive );
      }
  return false;
  return 0;
}

unsigned int Directory::Explore(FilenameType const &name, bool recursive)
Loading