14#ifndef GDCMSEQUENCEOFFRAGMENTS_H
15#define GDCMSEQUENCEOFFRAGMENTS_H
49 return SequenceLengthField;
54 SequenceLengthField = length;
72 bool GetBuffer(
char *buffer,
unsigned long length)
const;
73 bool GetFragBuffer(
unsigned int fragNb,
char *buffer,
unsigned long &length)
const;
85template <
typename TSwap>
86std::istream&
Read(std::istream &is,
bool readvalues =
true)
88 assert( SequenceLengthField.IsUndefined() );
89 ReadPreValue<TSwap>(is);
90 return ReadValue<TSwap>(is, readvalues);
93template <
typename TSwap>
100 Table.Read<TSwap>(is);
108 is.seekg(-4, std::ios::cur);
111 if (
Table.GetTag() ==
Tag(0xd8ff,0xe0ff) )
116 if( FillFragmentWithJPEG( frag, is ) )
118 Fragments.push_back( frag );
124 throw "Catch me if you can";
129 Table.Read<TSwap>(is);
135template <
typename TSwap>
138 const Tag seqDelItem(0xfffe,0xe0dd);
143 while( frag.
Read<TSwap>(is) && frag.
GetTag() != seqDelItem )
146 Fragments.push_back( frag );
148 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
153#ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
159 if( frag.
GetTag() ==
Tag(0xfffe,0xe000) )
161 gdcmWarningMacro(
"Pixel Data Fragment could be corrupted. Use file at own risk" );
162 Fragments.push_back( frag );
166 else if ( frag.
GetTag() ==
Tag(0xddff,0x00e0) )
168 assert( Fragments.size() == 1 );
169 const ByteValue *bv = Fragments[0].GetByteValue();
174 " at the end: stripped !" );
187 assert( Fragments.size() );
188 const size_t lastf = Fragments.size() - 1;
189 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
193 is.seekg( -9, std::ios::cur );
198 Fragments.push_back( frag );
200 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
211 assert( Fragments.size() );
212 const size_t lastf = Fragments.size() - 1;
213 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
217 is.seekg( -10, std::ios::cur );
222 Fragments.push_back( frag );
224 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
236 assert( Fragments.size() );
237 const size_t lastf = Fragments.size() - 1;
238 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
242 is.seekg( -11, std::ios::cur );
247 Fragments.push_back( frag );
249 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
256 << Fragments.size() <<
" Offset " << is.tellg() <<
". Use file at own risk."
265template <
typename TSwap>
266std::ostream
const &
Write(std::ostream &os)
const
268 if( !
Table.Write<TSwap>(os) )
270 assert(0 &&
"Should not happen");
275 it->Write<TSwap>(os);
278 const Tag seqDelItem(0xfffe,0xe0dd);
279 seqDelItem.
Write<TSwap>(os);
281 zero.
Write<TSwap>(os);
297 void Print(std::ostream &os)
const override {
298 os <<
"SQ L= " << SequenceLengthField <<
"\n";
299 os <<
"Table:" <<
Table <<
"\n";
302 os <<
" " << *it <<
"\n";
304 assert( SequenceLengthField.IsUndefined() );
306 const Tag seqDelItem(0xfffe,0xe0dd);
315 return Table == sqf.Table &&
316 SequenceLengthField == sqf.SequenceLengthField &&
317 Fragments == sqf.Fragments;
322 VL SequenceLengthField;
324 FragmentVector Fragments;
327 bool FillFragmentWithJPEG(
Fragment & frag, std::istream & is );
Class to represent a BasicOffsetTable.
Definition gdcmBasicOffsetTable.h:27
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
const VL & GetVL() const
Get VL.
Definition gdcmDataElement.h:74
const Tag & GetTag() const
Get Tag.
Definition gdcmDataElement.h:67
Exception.
Definition gdcmException.h:44
const char * what() const override
what implementation
Definition gdcmException.h:86
Class to represent a Fragment.
Definition gdcmFragment.h:44
std::istream & ReadBacktrack(std::istream &is)
Definition gdcmFragment.h:110
std::istream & Read(std::istream &is)
Definition gdcmFragment.h:56
Class to represent a Sequence Of Fragments.
Definition gdcmSequenceOfFragments.h:32
bool operator==(const Value &val) const override
Definition gdcmSequenceOfFragments.h:312
std::istream & Read(std::istream &is, bool readvalues=true)
Definition gdcmSequenceOfFragments.h:86
void SetLength(VL length) override
Sets the actual SQ length.
Definition gdcmSequenceOfFragments.h:53
void AddFragment(Fragment const &item)
Appends a Fragment to the already added ones.
bool WriteBuffer(std::ostream &os) const
FragmentVector::iterator Iterator
Definition gdcmSequenceOfFragments.h:37
Iterator Begin()
Definition gdcmSequenceOfFragments.h:39
BasicOffsetTable & GetTable()
Definition gdcmSequenceOfFragments.h:83
std::istream & ReadPreValue(std::istream &is)
Definition gdcmSequenceOfFragments.h:94
bool GetFragBuffer(unsigned int fragNb, char *buffer, unsigned long &length) const
VL GetLength() const override
Returns the SQ length, as read from disk.
Definition gdcmSequenceOfFragments.h:48
const Fragment & GetFragment(SizeType num) const
ConstIterator Begin() const
Definition gdcmSequenceOfFragments.h:41
ConstIterator End() const
Definition gdcmSequenceOfFragments.h:42
void Print(std::ostream &os) const override
Definition gdcmSequenceOfFragments.h:297
unsigned long ComputeByteLength() const
SizeType GetNumberOfFragments() const
void Clear() override
Clear.
static SmartPointer< SequenceOfFragments > New()
Definition gdcmSequenceOfFragments.h:289
Iterator End()
Definition gdcmSequenceOfFragments.h:40
FragmentVector::size_type SizeType
Definition gdcmSequenceOfFragments.h:36
std::istream & ReadValue(std::istream &is, bool)
Definition gdcmSequenceOfFragments.h:136
const BasicOffsetTable & GetTable() const
Definition gdcmSequenceOfFragments.h:82
FragmentVector::const_iterator ConstIterator
Definition gdcmSequenceOfFragments.h:38
SequenceOfFragments()
constructor (UndefinedLength by default)
Definition gdcmSequenceOfFragments.h:45
std::ostream const & Write(std::ostream &os) const
Definition gdcmSequenceOfFragments.h:266
std::vector< Fragment > FragmentVector
Definition gdcmSequenceOfFragments.h:35
bool GetBuffer(char *buffer, unsigned long length) const
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
Table.
Definition gdcmTable.h:29
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
uint16_t GetGroup() const
Returns the 'Group number' of the given Tag.
Definition gdcmTag.h:55
const std::ostream & Write(std::ostream &os) const
Write a tag in binary rep.
Definition gdcmTag.h:169
uint16_t GetElement() const
Returns the 'Element number' of the given Tag.
Definition gdcmTag.h:57
Value Length.
Definition gdcmVL.h:30
const std::ostream & Write(std::ostream &os) const
Definition gdcmVL.h:99
Class to represent the value of a Data Element.
Definition gdcmValue.h:32
#define gdcmAssertAlwaysMacro(arg)
AssertAlways.
Definition gdcmTrace.h:228
#define gdcmWarningMacro(msg)
Warning.
Definition gdcmTrace.h:142
#define gdcmDebugMacro(msg)
Debug.
Definition gdcmTrace.h:119
#define GDCM_EXPORT
Definition gdcmWin32.h:34