14 #ifndef GDCMSEQUENCEOFFRAGMENTS_H
15 #define GDCMSEQUENCEOFFRAGMENTS_H
39 Iterator
Begin() {
return Fragments.begin(); }
40 Iterator
End() {
return Fragments.end(); }
41 ConstIterator
Begin()
const {
return Fragments.begin(); }
42 ConstIterator
End()
const {
return Fragments.end(); }
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,
bool readvalues =
true)
88 assert( SequenceLengthField.IsUndefined() );
89 ReadPreValue<TSwap>(is);
90 return ReadValue<TSwap>(is, readvalues);
93 template <
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";
131 template <
typename TSwap>
134 const Tag seqDelItem(0xfffe,0xe0dd);
139 while( frag.
Read<TSwap>(is) && frag.
GetTag() != seqDelItem )
142 Fragments.push_back( frag );
144 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
149 #ifdef GDCM_SUPPORT_BROKEN_IMPLEMENTATION
155 if( frag.
GetTag() ==
Tag(0xfffe,0xe000) )
157 gdcmWarningMacro(
"Pixel Data Fragment could be corrupted. Use file at own risk" );
158 Fragments.push_back( frag );
162 else if ( frag.
GetTag() ==
Tag(0xddff,0x00e0) )
164 assert( Fragments.size() == 1 );
165 const ByteValue *bv = Fragments[0].GetByteValue();
166 assert( (
unsigned char)bv->GetPointer()[ bv->GetLength() - 1 ] == 0xfe );
168 Fragments[0].SetByteValue( bv->GetPointer(), bv->GetLength() - 1 );
170 " at the end: stripped !" );
183 assert( Fragments.size() );
184 const size_t lastf = Fragments.size() - 1;
185 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
189 is.seekg( -9, std::ios::cur );
194 Fragments.push_back( frag );
196 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
207 assert( Fragments.size() );
208 const size_t lastf = Fragments.size() - 1;
209 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
213 is.seekg( -10, std::ios::cur );
218 Fragments.push_back( frag );
220 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
232 assert( Fragments.size() );
233 const size_t lastf = Fragments.size() - 1;
234 const ByteValue *bv = Fragments[ lastf ].GetByteValue();
238 is.seekg( -11, std::ios::cur );
243 Fragments.push_back( frag );
245 assert( frag.
GetTag() == seqDelItem && frag.
GetVL() == 0 );
252 << Fragments.size() <<
" Offset " << is.tellg() <<
". Use file at own risk."
261 template <
typename TSwap>
262 std::ostream
const &
Write(std::ostream &os)
const
264 if( !
Table.Write<TSwap>(os) )
266 assert(0 &&
"Should not happen");
269 for(ConstIterator it = Begin();it != End(); ++it)
271 it->Write<TSwap>(os);
274 const Tag seqDelItem(0xfffe,0xe0dd);
275 seqDelItem.
Write<TSwap>(os);
277 zero.
Write<TSwap>(os);
293 void Print(std::ostream &os)
const {
294 os <<
"SQ L= " << SequenceLengthField <<
"\n";
295 os <<
"Table:" <<
Table <<
"\n";
296 for(ConstIterator it = Begin();it != End(); ++it)
298 os <<
" " << *it <<
"\n";
300 assert( SequenceLengthField.IsUndefined() );
302 const Tag seqDelItem(0xfffe,0xe0dd);
311 return Table == sqf.Table &&
312 SequenceLengthField == sqf.SequenceLengthField &&
313 Fragments == sqf.Fragments;
318 VL SequenceLengthField;
320 FragmentVector Fragments;
323 bool FillFragmentWithJPEG(
Fragment & frag, std::istream & is );
333 #endif //GDCMSEQUENCEOFFRAGMENTS_H
FragmentVector::size_type SizeType
Definition: gdcmSequenceOfFragments.h:36
std::istream & ReadBacktrack(std::istream &is)
Definition: gdcmFragment.h:117
std::vector< Fragment > FragmentVector
Definition: gdcmSequenceOfFragments.h:35
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:31
static SmartPointer< SequenceOfFragments > New()
Definition: gdcmSequenceOfFragments.h:285
VL GetLength() const
Definition: gdcmByteValue.h:78
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
std::istream & ReadValue(std::istream &is, bool)
Definition: gdcmSequenceOfFragments.h:132
std::istream & Read(std::istream &is, bool readvalues=true)
Definition: gdcmSequenceOfFragments.h:86
VL GetLength() const
Returns the SQ length, as read from disk.
Definition: gdcmSequenceOfFragments.h:48
BasicOffsetTable & GetTable()
Definition: gdcmSequenceOfFragments.h:83
const char * what() const
what implementation
Definition: gdcmException.h:86
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:35
const std::ostream & Write(std::ostream &os) const
Definition: gdcmVL.h:99
std::ostream const & Write(std::ostream &os) const
Definition: gdcmSequenceOfFragments.h:262
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:56
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:111
bool operator==(const Value &val) const
Definition: gdcmSequenceOfFragments.h:308
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:293
Exception.
Definition: gdcmException.h:43
ConstIterator Begin() const
Definition: gdcmSequenceOfFragments.h:41