GDCM 3.2.1

GenAllVR.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 "gdcmGlobal.h"
#include "gdcmDummyValueGenerator.h"
#include "gdcmMediaStorage.h"
#include "gdcmWriter.h"
#include "gdcmItem.h"
#include "gdcmImageReader.h"
#include "gdcmSequenceOfItems.h"
#include "gdcmFile.h"
#include "gdcmTag.h"
#include "gdcmDict.h"
#include "gdcmDictEntry.h"
#include "gdcmDicts.h"
#include "gdcmTransferSyntax.h"
#include "gdcmUIDGenerator.h"
#include "gdcmFileExplicitFilter.h"
#include <cstdlib>
#include <cstring>
gdcm::Tag FindTagFromVR(gdcm::Dict const &dict, gdcm::VR const &vr)
{
using gdcm::Dict;
Dict::ConstIterator beg = dict.Begin();
Dict::ConstIterator end = dict.End();
Dict::ConstIterator it;
for( it = beg; it != end; ++it)
{
const gdcm::Tag &t = it->first;
const gdcm::DictEntry &de = it->second;
const gdcm::VR &vr_de = de.GetVR();
if( vr == vr_de && !de.GetRetired() && t.GetGroup() >= 0x8 )
{
return t;
}
}
return gdcm::Tag(0xffff,0xffff);
}
struct rnd_gen {
rnd_gen(char const* r = "abcdefghijklmnopqrstuvwxyz0123456789")
: range(r), len(std::strlen(r)) { }
char operator ()() const {
return range[static_cast<std::size_t>(std::rand() * (1.0 / ((double)RAND_MAX + 1.0 )) * (double)len)];
}
private:
char const* range;
std::size_t len;
};
/*
*/
int main(int argc, char *argv[])
{
if( argc < 2 )
{
std::cerr << argv[0] << " output.dcm" << std::endl;
return 1;
}
const char *outfilename = argv[1];
static const gdcm::Global &g = gdcm::Global::GetInstance();
static const gdcm::Dicts &dicts = g.GetDicts();
static const gdcm::Dict &pubdict = dicts.GetPublicDict();
using gdcm::VR;
using gdcm::Tag;
gdcm::Writer w;
gdcm::File &f = w.GetFile();
gdcm::DataSet &ds = f.GetDataSet();
gdcm::FileExplicitFilter fef;
//fef.SetChangePrivateTags( true );
fef.SetFile( w.GetFile() );
if( !fef.Change() )
{
std::cerr << "Failed to change" << std::endl;
return 1;
}
gdcm::SmartPointer<gdcm::SequenceOfItems> sq = new gdcm::SequenceOfItems();
sq->SetLengthToUndefined();
// gdcm::DummyValueGenerator dvg;
const std::size_t len = 10;
char ss[len+1];
ss[len] = '\0';
const char owner_str[] = "GDCM CONFORMANCE TESTS";
gdcm::DataElement owner( gdcm::Tag(0x4d4d, 0x10) );
owner.SetByteValue(owner_str, (uint32_t)strlen(owner_str));
owner.SetVR( gdcm::VR::LO );
// Create an item
gdcm::Item it;
it.SetVLToUndefined();
gdcm::DataSet &nds = it.GetNestedDataSet();
// nds.Insert(owner);
// nds.Insert(de);
// Insert sequence into data set
gdcm::DataElement des( gdcm::Tag(0x4d4d,0x1001) );
des.SetVR(gdcm::VR::SQ);
des.SetValue(*sq);
des.SetVLToUndefined();
ds.Insert(owner);
ds.Insert(des);
// avoid INVALID = 0
for(int i = 1; i < 27; ++i)
{
VR vr = (VR::VRType)(1LL << i);
Tag t = FindTagFromVR( pubdict, vr );
if( vr != VR::UN && vr != VR::SQ )
{
gdcm_assert( t != Tag(0xffff,0xffff) );
gdcm::DataElement de( t );
std::generate_n(ss, len, rnd_gen());
de.SetVR( vr );
de.SetByteValue( ss, (uint32_t)std::strlen( ss ) );
nds.Insert( de );
}
}
sq->AddItem(it);
// Make sure to override any UID stuff
gdcm::UIDGenerator uid;
gdcm::DataElement de( Tag(0x8,0x18) ); // SOP Instance UID
de.SetVR( VR::UI );
const char *u = uid.Generate();
de.SetByteValue( u, (uint32_t)strlen(u) );
ds.Insert( de );
de.SetTag( Tag(0x8,0x16) ); // SOP Class UID
de.SetVR( VR::UI );
gdcm::MediaStorage ms( gdcm::MediaStorage::RawDataStorage );
de.SetByteValue( ms.GetString(), (uint32_t)strlen(ms.GetString()));
ds.Insert( de );
gdcm::FileMetaInformation &fmi = f.GetHeader();
//fmi.SetDataSetTransferSyntax( gdcm::TransferSyntax::ImplicitVRLittleEndian );
fmi.SetDataSetTransferSyntax( gdcm::TransferSyntax::ExplicitVRLittleEndian );
w.SetCheckFileMetaInformation( true );
w.SetFileName( outfilename );
if (!w.Write() )
{
return 1;
}
return 0;
}
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::SetVLToUndefined
void SetVLToUndefined()
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
gdcm::DataSet::Insert
void Insert(const DataElement &de)
Definition gdcmDataSet.h:128
gdcm::DictEntry
Class to represent an Entry in the Dict.
Definition gdcmDictEntry.h:37
gdcm::DictEntry::GetVR
const VR & GetVR() const
Set/Get VR.
Definition gdcmDictEntry.h:53
gdcm::DictEntry::GetRetired
bool GetRetired() const
Set/Get Retired flag.
Definition gdcmDictEntry.h:71
gdcm::Dict
Class to represent a map of DictEntry.
Definition gdcmDict.h:45
gdcm::Dict::End
ConstIterator End() const
Definition gdcmDict.h:62
gdcm::Dict::Begin
ConstIterator Begin() const
Definition gdcmDict.h:61
gdcm::Dicts
Class to manipulate the sum of knowledge (all the dict user load)
Definition gdcmDicts.h:29
gdcm::Dicts::GetPublicDict
const Dict & GetPublicDict() const
gdcm::FileExplicitFilter
FileExplicitFilter class.
Definition gdcmFileExplicitFilter.h:39
gdcm::FileExplicitFilter::SetFile
void SetFile(const File &f)
Set/Get File.
Definition gdcmFileExplicitFilter.h:60
gdcm::FileExplicitFilter::Change
bool Change()
Set FMI Transfer Syntax.
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::Global
Global.
Definition gdcmGlobal.h:50
gdcm::Global::GetDicts
Dicts const & GetDicts() const
gdcm::Global::GetInstance
static Global & GetInstance()
return the singleton instance
gdcm::Item
Class to represent an Item.
Definition gdcmItem.h:46
gdcm::Item::GetNestedDataSet
const DataSet & GetNestedDataSet() const
Definition gdcmItem.h:80
gdcm::MediaStorage
MediaStorage.
Definition gdcmMediaStorage.h:44
gdcm::MediaStorage::RawDataStorage
@ RawDataStorage
Definition gdcmMediaStorage.h:85
gdcm::SequenceOfItems
Class to represent a Sequence Of Items.
Definition gdcmSequenceOfItems.h:40
gdcm::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::Tag::GetGroup
uint16_t GetGroup() const
Returns the 'Group number' of the given Tag.
Definition gdcmTag.h:55
gdcm::TransferSyntax::ExplicitVRLittleEndian
@ ExplicitVRLittleEndian
Definition gdcmTransferSyntax.h:64
gdcm::UIDGenerator
Class for generating unique UID.
Definition gdcmUIDGenerator.h:28
gdcm::UIDGenerator::Generate
const char * Generate()
gdcm::VR
VR class.
Definition gdcmVR.h:55
gdcm::VR::LO
@ LO
Definition gdcmVR.h:70
gdcm::VR::SQ
@ SQ
Definition gdcmVR.h:81
gdcm::Writer
Writer ala DOM (Document Object Model)
Definition gdcmWriter.h:49
gdcm::Writer::GetFile
File & GetFile()
Definition gdcmWriter.h:67
gdcm::Writer::SetCheckFileMetaInformation
void SetCheckFileMetaInformation(bool b)
Undocumented function, do not use (= leave default)
Definition gdcmWriter.h:70
gdcm::Writer::Write
virtual bool Write()
Main function to tell the writer to write.
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcmDictEntry.h
gdcmDict.h
gdcmDicts.h
gdcmDummyValueGenerator.h
gdcm_assert
#define gdcm_assert(cond)
Definition gdcmException.h:104
gdcmFileExplicitFilter.h
gdcmFile.h
gdcmGlobal.h
gdcmImageReader.h
gdcmItem.h
gdcmMediaStorage.h
gdcmReader.h
gdcmSequenceOfItems.h
gdcmTag.h
gdcmTransferSyntax.h
gdcmUIDGenerator.h
gdcmWriter.h