GDCM 3.0.24
DumpSiemensBase64.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.
=========================================================================*/
/*
* https://groups.google.com/forum/#!msg/comp.protocols.dicom/2kZ2lLP8EcM/WzjFrtjnAgAJ
*/
#include "gdcmReader.h"
#include "gdcmPrivateTag.h"
#include "gdcmPrinter.h"
#include "gdcmCSAHeader.h"
#include "gdcmBase64.h"
#include "gdcmSwapper.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <assert.h>
int main(int argc, char *argv[])
{
if( argc < 2 ) return 1;
const char *filename = argv[1];
gdcm::Reader reader;
reader.SetFileName( filename );
if( !reader.Read() )
{
std::cerr << "Failed to read: " << filename << std::endl;
return 1;
}
const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
if( !ds.FindDataElement( t1 ) ) return 1;
//const char name[] = "MRDiffusion";
const char name[] = "MR_ASL";
if( csa.FindCSAElementByName(name) )
{
const gdcm::CSAElement & el = csa.GetCSAElementByName(name);
const gdcm::ByteValue* bv = el.GetByteValue();
std::string str( bv->GetPointer(), bv->GetLength() );
str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
size_t dl = gdcm::Base64::GetDecodeLength( str.c_str(), str.size() );
std::vector<char> buf;
buf.resize( dl );
size_t dl2 = gdcm::Base64::Decode( buf.data(), buf.size(), str.c_str(), str.size() );
(void)dl2;
std::stringstream ss;
ss.str( std::string(buf.data(), buf.size()) );
gdcm::File file;
gdcm::DataSet &ds2 = file.GetDataSet();
try
{
{
ds2.Insert( xde );
}
assert( ss.eof() );
}
catch(std::exception &)
{
return 1;
}
p.SetFile( file );
p.Print(std::cout);
}
return 0;
}
static size_t Decode(char *dst, size_t dlen, const char *src, size_t slen)
Decode a base64-formatted buffer.
static size_t GetDecodeLength(const char *src, size_t len)
Class to represent binary value (array of bytes)
Definition gdcmByteValue.h:35
const char * GetPointer() const
Definition gdcmByteValue.h:110
VL GetLength() const override
Definition gdcmByteValue.h:77
Class to represent a CSA Element.
Definition gdcmCSAElement.h:30
const ByteValue * GetByteValue() const
Definition gdcmCSAElement.h:78
Class for CSAHeader.
Definition gdcmCSAHeader.h:64
static const PrivateTag & GetCSAImageHeaderInfoTag()
bool FindCSAElementByName(const char *name)
const CSAElement & GetCSAElementByName(const char *name)
bool LoadFromDataElement(DataElement const &de)
Decode the CSAHeader from element 'de'.
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
std::istream & Read(std::istream &is)
Definition gdcmDataElement.h:206
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:
void Insert(const DataElement &de)
Definition gdcmDataSet.h:128
Class to read/write a DataElement as Explicit Data Element.
Definition gdcmExplicitDataElement.h:26
a DICOM File
Definition gdcmFile.h:34
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
Printer class.
Definition gdcmPrinter.h:60
void Print(std::ostream &os)
Print.
void SetFile(File const &f)
Set file.
Definition gdcmPrinter.h:66
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
virtual bool Read()
Main function to read a file.
void SetFileName(const char *filename_native)
Definition gdcmSwapper.h:47