14 #ifndef GDCMSEQUENCEOFFRAGMENTS_H
15 #define GDCMSEQUENCEOFFRAGMENTS_H
49 return SequenceLengthField;
54 SequenceLengthField = length;
61 void AddFragment(
Fragment const &item);
65 unsigned long ComputeByteLength()
const;
69 VL ComputeLength()
const;
72 bool GetBuffer(
char *buffer,
unsigned long length)
const;
73 bool GetFragBuffer(
unsigned int fragNb,
char *buffer,
unsigned long &length)
const;
75 SizeType GetNumberOfFragments()
const;
76 const Fragment& GetFragment(SizeType num)
const;
80 bool WriteBuffer(std::ostream &os)
const;
85 template <
typename TSwap>
86 std::istream&
Read(std::istream &is)
88 assert( SequenceLengthField.IsUndefined() );
89 ReadPreValue<TSwap>(is);
90 return ReadValue<TSwap>(is);
93 template <
typename TSwap>
100 Table.Read<TSwap>(is);
107 is.seekg(-4, std::ios::cur);
108 if (
Table.GetTag() ==
Tag(0xd8ff,0xe0ff) )
111 is.seekg( 8340, std::ios::cur );
114 Fragments.push_back( frag );
119 throw "Catch me if you can";
126 template <
typename TSwap>
129 const Tag seqDelItem(0xfffe,0xe0dd);
134 while( frag.
Read<TSwap>(is) && frag.
GetTag() != seqDelItem )
137 Fragments.push_back( frag );
139 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
144 #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
150 if( frag.
GetTag() ==
Tag(0xfffe,0xe000) )
152 gdcmWarningMacro(
"Pixel Data Fragment could be corrupted. Use file at own risk" );
153 Fragments.push_back( frag );
157 else if ( frag.
GetTag() ==
Tag(0xddff,0x00e0) )
159 assert( Fragments.size() == 1 );
160 const ByteValue *bv = Fragments[0].GetByteValue();
161 assert( (
unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe );
163 Fragments[0].SetByteValue( bv->GetPointer(), bv->GetLength() - 1 );
165 " at the end: stripped !" );
178 assert( Fragments.size() );
179 const size_t lastf = Fragments.size() - 1;
180 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
184 is.seekg( -9, std::ios::cur );
189 Fragments.push_back( frag );
191 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
202 assert( Fragments.size() );
203 const size_t lastf = Fragments.size() - 1;
204 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
208 is.seekg( -10, std::ios::cur );
213 Fragments.push_back( frag );
215 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
227 assert( Fragments.size() );
228 const size_t lastf = Fragments.size() - 1;
229 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
233 is.seekg( -11, std::ios::cur );
238 Fragments.push_back( frag );
240 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
247 << Fragments.size() <<
" Offset " << is.tellg() <<
". Use file at own risk."
256 template <
typename TSwap>
257 std::ostream
const &
Write(std::ostream &os)
const
259 if( !
Table.Write<TSwap>(os) )
261 assert(0 &&
"Should not happen");
266 it->Write<TSwap>(os);
269 const Tag seqDelItem(0xfffe,0xe0dd);
270 seqDelItem.
Write<TSwap>(os);
272 zero.
Write<TSwap>(os);
288 void Print(std::ostream &os)
const {
289 os <<
"SQ L= " << SequenceLengthField <<
"\n";
290 os <<
"Table:" <<
Table <<
"\n";
293 os <<
" " << *it <<
"\n";
295 assert( SequenceLengthField.IsUndefined() );
297 const Tag seqDelItem(0xfffe,0xe0dd);
306 return Table == sqf.Table &&
307 SequenceLengthField == sqf.SequenceLengthField &&
308 Fragments == sqf.Fragments;
313 VL SequenceLengthField;
315 FragmentVector Fragments;
325 #endif //GDCMSEQUENCEOFFRAGMENTS_H
FragmentVector::size_type SizeType
Definition: gdcmSequenceOfFragments.h:36
std::istream & ReadBacktrack(std::istream &is)
Definition: gdcmFragment.h:120
std::vector< Fragment > FragmentVector
Definition: gdcmSequenceOfFragments.h:35
void SetByteValue(const char *array, VL length)
Definition: gdcmDataElement.h:123
const BasicOffsetTable & GetTable() const
Definition: gdcmSequenceOfFragments.h:82
std::istream & ReadPreValue(std::istream &is)
Definition: gdcmSequenceOfFragments.h:94
Iterator End()
Definition: gdcmSequenceOfFragments.h:40
Class to represent the value of a Data Element.
Definition: gdcmValue.h:29
static SmartPointer< SequenceOfFragments > New()
Definition: gdcmSequenceOfFragments.h:280
VL GetLength() const
Definition: gdcmByteValue.h:72
void SetLength(VL length)
Sets the actual SQ length.
Definition: gdcmSequenceOfFragments.h:53
const VL & GetVL() const
Get VL.
Definition: gdcmDataElement.h:74
#define GDCM_EXPORT
Definition: gdcmWin32.h:34
#define gdcmWarningMacro(msg)
Warning.
Definition: gdcmTrace.h:141
Value Length.
Definition: gdcmVL.h:29
#define gdcmDebugMacro(msg)
Debug.
Definition: gdcmTrace.h:119
Class to represent a Fragment.
Definition: gdcmFragment.h:43
Iterator Begin()
Definition: gdcmSequenceOfFragments.h:39
uint16_t GetElement() const
Returns the 'Element number' of the given Tag.
Definition: gdcmTag.h:57
Class to represent a Sequence Of Fragments.
Definition: gdcmSequenceOfFragments.h:31
#define gdcmAssertAlwaysMacro(arg)
AssertAlways.
Definition: gdcmTrace.h:223
VL GetLength() const
Returns the SQ length, as read from disk.
Definition: gdcmSequenceOfFragments.h:48
std::istream & ReadValue(std::istream &is)
Definition: gdcmSequenceOfFragments.h:127
BasicOffsetTable & GetTable()
Definition: gdcmSequenceOfFragments.h:83
const char * what() const
what implementation
Definition: gdcmException.h:76
const std::ostream & Write(std::ostream &os) const
Write a tag in binary rep.
Definition: gdcmTag.h:169
Class to represent binary value (array of bytes)
Definition: gdcmByteValue.h:33
const std::ostream & Write(std::ostream &os) const
Definition: gdcmVL.h:99
std::ostream const & Write(std::ostream &os) const
Definition: gdcmSequenceOfFragments.h:257
ConstIterator End() const
Definition: gdcmSequenceOfFragments.h:42
Class for Smart Pointer.
Definition: gdcmObject.h:26
SequenceOfFragments()
constructor (UndefinedLength by default)
Definition: gdcmSequenceOfFragments.h:45
std::istream & Read(std::istream &is)
Definition: gdcmFragment.h:59
std::istream & Read(std::istream &is)
Definition: gdcmSequenceOfFragments.h:86
const Tag & GetTag() const
Get Tag.
Definition: gdcmDataElement.h:67
Class to represent a BasicOffsetTable.
Definition: gdcmBasicOffsetTable.h:26
Table.
Definition: gdcmTable.h:28
const char * GetPointer() const
Definition: gdcmByteValue.h:134
bool operator==(const Value &val) const
Definition: gdcmSequenceOfFragments.h:303
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element). Basically an uint32_t which...
Definition: gdcmTag.h:38
uint16_t GetGroup() const
Returns the 'Group number' of the given Tag.
Definition: gdcmTag.h:55
FragmentVector::iterator Iterator
Definition: gdcmSequenceOfFragments.h:37
FragmentVector::const_iterator ConstIterator
Definition: gdcmSequenceOfFragments.h:38
void Print(std::ostream &os) const
Definition: gdcmSequenceOfFragments.h:288
Exception.
Definition: gdcmException.h:33
ConstIterator Begin() const
Definition: gdcmSequenceOfFragments.h:41