GDCM: DumpSiemensBase64.cxx

GDCM 3.2.7

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 "gdcmDictPrinter.h"
#include "gdcmCSAHeader.h"
#include "gdcmBase64.h"
#include "gdcmExplicitDataElement.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();
gdcm::CSAHeader csa;
const gdcm::PrivateTag &t1 = csa. GetCSAImageHeaderInfoTag();
if( !ds. FindDataElement( t1 ) ) return 1;
csa. LoadFromDataElement( ds. GetDataElement( t1 ) );
//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();
gdcm::DataElement xde;
try
{
while( xde. Read<gdcm::ExplicitDataElement, gdcm::SwapperNoOp>( ss ) )
{
ds2. Insert( xde );
}
gdcm_assert( ss.eof() );
}
catch(std::exception &)
{
return 1;
}
gdcm::Printer p;
p. SetFile( file );
p. Print(std::cout);
}
return 0;
}
gdcm::Base64::Decode
static size_t Decode(char *dst, size_t dlen, const char *src, size_t slen)
Decode a base64-formatted buffer.
gdcm::Base64::GetDecodeLength
static size_t GetDecodeLength(const char *src, size_t len)
gdcm::ByteValue
Class to represent binary value (array of bytes).
Definition gdcmByteValue.h:36
gdcm::ByteValue::GetPointer
const char * GetPointer() const
Definition gdcmByteValue.h:114
gdcm::ByteValue::GetLength
VL GetLength() const override
Definition gdcmByteValue.h:81
gdcm::CSAElement
Class to represent a CSA Element.
Definition gdcmCSAElement.h:30
gdcm::CSAElement::GetByteValue
const ByteValue * GetByteValue() const
Definition gdcmCSAElement.h:78
gdcm::CSAHeader
Class for CSAHeader.
Definition gdcmCSAHeader.h:64
gdcm::CSAHeader::GetCSAImageHeaderInfoTag
static const PrivateTag & GetCSAImageHeaderInfoTag()
gdcm::CSAHeader::FindCSAElementByName
bool FindCSAElementByName(const char *name)
gdcm::CSAHeader::GetCSAElementByName
const CSAElement & GetCSAElementByName(const char *name)
gdcm::CSAHeader::LoadFromDataElement
bool LoadFromDataElement(DataElement const &de)
Decode the CSAHeader from element 'de'.
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::Read
std::istream & Read(std::istream &is)
Definition gdcmDataElement.h:206
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::Insert
void Insert(const DataElement &de)
Definition gdcmDataSet.h:128
gdcm::ExplicitDataElement
Class to read/write a DataElement as Explicit Data Element.
Definition gdcmExplicitDataElement.h:26
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::Printer
Printer class.
Definition gdcmPrinter.h:60
gdcm::Printer::Print
void Print(std::ostream &os)
Print.
gdcm::Printer::SetFile
void SetFile(File const &f)
Set file.
Definition gdcmPrinter.h:66
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::Read
virtual bool Read()
Main function to read a file.
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::SwapperNoOp
Definition gdcmSwapper.h:47
gdcmBase64.h
gdcmCSAHeader.h
gdcmDictPrinter.h
gdcm_assert
#define gdcm_assert(cond)
Definition gdcmException.h:104
gdcmExplicitDataElement.h
gdcmPrinter.h
gdcmPrivateTag.h
gdcmReader.h
gdcmSwapper.h