DumpToshibaDTI2.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://gazelle.ihe.net/EVSClient/dicomResult.seam;jsessionid=x+Rf9Zs+ip49P+jC3L8SLZb8?&oid=1.3.6.1.4.1.12559.11.1.2.1.4.1622284
*/
#include "gdcmReader.h"
#include "gdcmPrivateTag.h"
#include "gdcmPrinter.h"
#include "gdcmDictPrinter.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <assert.h>
static bool DumpToshibaDTI2( const char * input, size_t len )
{
static int i = 0;
++i;
if( len % 2 ) return false;
std::vector<char> copy( input, input + len );
std::reverse( copy.begin(), copy.end() );
#if 0
std::ostringstream f;
f << "debug" << i;
std::ofstream of( f.str().c_str(), std::ios::binary );
of.write( &copy[0], copy.size() );
of.close();
#else
std::istringstream is;
std::string dup( copy.data(), copy.size() );
is.str( dup );
gdcm::File file;
gdcm::FileMetaInformation & fmi = file.GetHeader();
fmi.SetDataSetTransferSyntax( gdcm::TransferSyntax::ExplicitVRLittleEndian );
gdcm::DataSet & ds = file.GetDataSet();
ds.Read<gdcm::ExplicitDataElement,gdcm::SwapperNoOp>( is );
//gdcm::DictPrinter p;
gdcm::Printer p;
p.SetFile( file );
p.SetColor( true );
p.Print( std::cout );
#endif
return true;
}
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();
/*
(0029,1001) SQ (Sequence with explicit length #=6) # 18746, 1 Unknown Tag & Data
(fffe,e000) na (Item with explicit length #=2) # 206, 1 Item
(0029,0010) LO [TOSHIBA_MEC_MR3] # 16, 1 PrivateCreator
(0029,1090) OB 00\07\00\06\00\05\00\04\00\03\00\02\00\0c\00\01\00\00\00\00\00\12... # 170, 1 Unknown Tag & Data
(fffe,e00d) na (ItemDelimitationItem for re-encoding) # 0, 0 ItemDelimitationItem
(fffe,e000) na (Item with explicit length #=2) # 866, 1 Item
(0029,0010) LO [TOSHIBA_MEC_MR3] # 16, 1 PrivateCreator
(0029,1090) OB 45\4e\49\50\53\4c\20\52\41\5c\45\4e\49\50\53\4c\54\5c\52\45\53\55... # 830, 1 Unknown Tag & Data
[...]
(0029,1002) SQ (Sequence with explicit length #=1) # 120, 1 Unknown Tag & Data
(fffe,e000) na (Item with explicit length #=2) # 112, 1 Item
(0029,0010) LO [TOSHIBA_MEC_MR3] # 16, 1 PrivateCreator
(0029,1090) OB 00\10\00\02\53\55\10\80\70\0d\30\31\5e\33\52\4d\5f\43\45\4d\5f\41... # 76, 1 Unknown Tag & Data
(fffe,e00d) na (ItemDelimitationItem for re-encoding) # 0, 0 ItemDelimitationItem
*/
const gdcm::PrivateTag tmecmr3(0x0029,0x1,"TOSHIBA_MEC_MR3");
if( !ds.FindDataElement( tmecmr3) ) return 1;
const gdcm::DataElement& mecmr3 = ds.GetDataElement( tmecmr3 );
if ( mecmr3.IsEmpty() ) return 1;
gdcm::SmartPointer<gdcm::SequenceOfItems> seq = mecmr3.GetValueAsSQ();
if ( !seq || !seq->GetNumberOfItems() ) return 1;
size_t n = seq->GetNumberOfItems();
for( size_t i = 1; i <= n; ++i )
{
gdcm::Item &item = seq->GetItem(i);
gdcm::DataSet &subds = item.GetNestedDataSet();
const gdcm::PrivateTag tseq(0x0029,0x90,"TOSHIBA_MEC_MR3");
if( subds.FindDataElement( tseq ) )
{
const gdcm::DataElement & de = subds.GetDataElement( tseq );
const gdcm::ByteValue * bv = de.GetByteValue();
if( !bv ) return 1;
bool b = DumpToshibaDTI2( bv->GetPointer(), bv->GetLength() );
if( !b ) return 1;
}
}
return 0;
}
gdcm::ByteValue
Class to represent binary value (array of bytes).
Definition gdcmByteValue.h:35
gdcm::ByteValue::GetPointer
const char * GetPointer() const
Definition gdcmByteValue.h:110
gdcm::ByteValue::GetLength
VL GetLength() const override
Definition gdcmByteValue.h:77
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::GetByteValue
const ByteValue * GetByteValue() const
Definition gdcmDataElement.h:133
gdcm::DataElement::IsEmpty
bool IsEmpty() const
Check if Data Element is empty.
Definition gdcmDataElement.h:106
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::Read
std::istream & Read(std::istream &is)
gdcm::ExplicitDataElement
Class to read/write a DataElement as Explicit Data Element.
Definition gdcmExplicitDataElement.h:26
gdcm::FileMetaInformation
Class to represent a File Meta Information.
Definition gdcmFileMetaInformation.h:41
gdcm::FileMetaInformation::SetDataSetTransferSyntax
void SetDataSetTransferSyntax(const TransferSyntax &ts)
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::File::GetHeader
const FileMetaInformation & GetHeader() const
Get File Meta Information.
Definition gdcmFile.h:48
gdcm::Item
Class to represent an Item.
Definition gdcmItem.h:46
gdcm::Item::GetNestedDataSet
const DataSet & GetNestedDataSet() const
Definition gdcmItem.h:80
gdcm::Printer
Printer class.
Definition gdcmPrinter.h:60
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::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::SwapperNoOp
Definition gdcmSwapper.h:47
gdcm::TransferSyntax::ExplicitVRLittleEndian
@ ExplicitVRLittleEndian
Definition gdcmTransferSyntax.h:64
gdcmDictPrinter.h
gdcmPrinter.h
gdcmPrivateTag.h
gdcmReader.h