1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
/*=========================================================================
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 "gdcmPDBHeader.h"
#include "gdcmPrivateTag.h"
#include "gdcmDataElement.h"
#include "gdcmDataSet.h"
#include "gdcmExplicitDataElement.h"
#include "gdcmSwapper.h"
#include "gdcmDeflateStream.h"
namespace gdcm
{
/*
* In some GE MEDICAL SYSTEMS image one can find a Data Element: 0025,xx1b,GEMS_SERS_01
* which is documented as Protocol Data Block (compressed).
* in fact this is a simple text format compressed using the gzip algorithm
*
* Typically one could do:
*
* $ gdcmraw -i input.dcm -o output.raw -t 0025,101b
*
* Skip the binary length (little endian encoding):
*
* $ dd bs=4 skip=1 if=output.raw of=foo
*
* Check file type:
*
* $ file foo
* foo: gzip compressed data, was "Ex421Ser8Scan1", from Unix
*
* Gunzip !
* $ gzip -dc < foo > bar
* $ cat bar
*
* THANKS to: John Reiser (BitWagon.com) for hints
*
* For sample see:
* GE_MR_0025xx1bProtocolDataBlock.dcm
* ( <=> http://server.oersted.dtu.dk/personal/jw/jwpublic/courses/31540/mri/second_set/dicom/t2/b17.dcm)
*/
/* Typical output:
*
* ENTRY "Head First"
* POSITION "Supine"
* ANREF "NA"
* COIL "HEAD"
* PLANE "OBLIQUE"
* SEDESCFLAG "1"
* SEDESC "AX FSE T2"
* IMODE "2D"
* PSEQ "FSE-XL"
* IOPT "FC, EDR, TRF, Fast"
* PLUG "22"
* FILTCHOICE "None"
* BWRT "-1"
* TRICKSIMG "1"
* TAG_SPACE "7"
* TAG_TYPE "None"
* USERCV0 "0.00"
* USERCV6 "0.00"
* USERCV7 "0.00"
* USERCV21 "0.00"
* USERCV_MASK "2097344"
* TE "102.0"
* NECHO "1"
* TR "5720.0"
* NUMACQS "1"
* ETL "17"
* BPMMODE "0"
* AUTOTRGTYPE "0"
* PSDTRIG "0"
* SLICEORDER "1"
* VIEWORDER "1"
* TRREST "0"
* TRACTIVE "0"
* SLICEASSET "1.00"
* PHASEASSET "1.00"
* SEPSERIES "0"
* AUTOTRIGWIN "0"
* FOV "24.0"
* SLTHICK "2.0"
* SPC "2.0"
* GRXOPT "0"
* SLOC1 "L11.8"
* SLOC2 "P29.9"
* SLOC3 "I50.0"
* ELOC1 "L11.6"
* ELOC2 "P29.4"
* ELOC3 "S53.9"
* NOSLC "27"
* SL3PLANE "0"
* SL3PLANE1 "0"
* SL3PLANE2 "0"
* SL3PLANE3 "0"
* SPCPERPLANE1 "0.0"
* SPCPERPLANE2 "0.0"
* SPCPERPLANE3 "0.0"
* MATRIXX "448"
* MATRIXY "224"
* SWAPPF "A/P"
* NEX "4.00"
* CONTRAST "No"
* CONTAM "Yes "
* TBLDELTA "0.00"
* PHASEFOV "0.75"
* RBW "31.25"
* AUTOSHIM "Auto"
* PHASECORR "Yes"
* FLDIR "Freq"
* NUMACCELFACTOR "1.00"
* PAUSEDELMASKACQ "1"
* NOTES ".pn/_3"
* GRIP_NUMSLGROUPS "1"
* GRIP_SLGROUP1 "-11.703952 -29.677423 1.949659 0.002380 0.004775 0.999985 0.999997 0.000175 -0.002380 0.000186 -0.999988 0.004775 27 0.000000 1 0 0"
* GRIP_SATGROUP1 "0"
* GRIP_SATGROUP2 "0"
* GRIP_SATGROUP3 "0"
* GRIP_SATGROUP4 "0"
* GRIP_SATGROUP5 "0"
* GRIP_SATGROUP6 "0"
* GRIP_TRACKER "0"
* GRIP_SPECTRO "0"
* GRIP_NUMPSCVOL "0"
* GRIP_PSCVOL1 "0"
* GRIP_PSCVOL2 "0"
* GRIP_PSCVOLFOV "0.000000"
* GRIP_PSCVOLTHICK "0.000000"
* AUTOSUBOPTIONS "0"
* AUTOSCIC "0"
* AUTOVOICE "0"
* PRESETDELAY "0.0"
* MASKPHASE "0"
* MASKPAUSE "0"
* TOTALNOSTATION "0"
* STATION "0"
*/
PDBElement PDBHeader::PDBEEnd = PDBElement( );
const PDBElement& PDBHeader::GetPDBEEnd() const
{
return PDBEEnd;
}
int PDBHeader::readprotocoldatablock(const char *input, size_t inputlen, bool verbose)
{
(void)verbose;
// First 4 bytes are the length (again)
uint32_t len = *(uint32_t*)input;
SwapperNoOp::SwapArray(&len,1);
//if( verbose )
// std::cout << len << "," << inputlen << std::endl;
if( len + 4 + 1 == inputlen )
{
//if( verbose )
// std::cout << "gzip stream was padded with an extra 0 \n";
}
else if( len + 4 == inputlen )
{
//if( verbose )
// std::cout << "gzip stream was not padded with an extra 0 \n";
}
else
{
//std::cerr << "Found the Protocol Data Block but could not read length..." << std::endl;
return 1;
}
// Alright we need to check if the binary blob was padded, if padded we need to
// discard the trailing \0 to please gzip:
std::string str( input + 4, input + len );
std::istringstream is( str );
zlib_stream::zip_istream gzis( is );
// if (gzis.is_gzip())
// {
// std::cout<<"crc check: "<<( gzis.check_crc() ? "ok" : "failed");
// std::cout << std::endl;
// }
std::string out;
//while( gzis >> out )
while( std::getline(gzis , out ) )
{
PDBElement pdbel;
//std::cout << out << std::endl;
std::istringstream is2( out );
std::string name, value;
is2 >> name;
std::getline(is2, value);
pdbel.SetName( name.c_str() );
// remove the first space character and the first & last " character
std::string value2( value.begin()+2, value.end()-1);
pdbel.SetValue( value2.c_str() );
InternalPDBDataSet.push_back( pdbel );
}
//std::cout << out.size();
return 0;
}
/*
int DumpProtocolDataBlock(const std::string & filename, bool verbose)
{
gdcm::Reader reader;
reader.SetFileName( filename.c_str() );
if( !reader.Read() )
{
std::cerr << "Failed to read: " << filename << std::endl;
return 1;
}
const gdcm::DataSet& ds = reader.GetFile().GetDataSet();
const gdcm::PrivateTag tprotocoldatablock(0x0025,0x1b,"GEMS_SERS_01");
if( !ds.FindDataElement( tprotocoldatablock) )
{
std::cerr << "Could not find tag: " << tprotocoldatablock << std::endl;
return 1;
}
const gdcm::DataElement& protocoldatablock= ds.GetDataElement( tprotocoldatablock);
if ( protocoldatablock.IsEmpty() ) return 1;
const gdcm::ByteValue * bv = protocoldatablock.GetByteValue();
std::cout << "Dumping: " << tprotocoldatablock << std::endl;
int ret = readprotocoldatablock( bv->GetPointer(), bv->GetLength(), verbose );
return ret;
}
*/
bool PDBHeader::LoadFromDataElement(DataElement const &protocoldatablock)
{
InternalPDBDataSet.clear();
if ( protocoldatablock.IsEmpty() ) return false;
const gdcm::ByteValue * bv = protocoldatablock.GetByteValue();
//std::cout << "Dumping: " << tprotocoldatablock << std::endl;
int ret = readprotocoldatablock( bv->GetPointer(), bv->GetLength(), false);
if(ret) return false;
return true;
}
void PDBHeader::Print(std::ostream &os) const
{
std::vector<PDBElement>::const_iterator it = InternalPDBDataSet.begin();
for(; it != InternalPDBDataSet.end(); ++it)
{
os << *it << std::endl;
}
}
const PDBElement &PDBHeader::GetPDBElementByName(const char *name)
{
std::vector<PDBElement>::const_iterator it = InternalPDBDataSet.begin();
for(; it != InternalPDBDataSet.end(); ++it)
{
const char *itname = it->GetName();
if( strcmp(name, itname) == 0 )
{
return *it;
}
}
return GetPDBEEnd();
}
bool PDBHeader::FindPDBElementByName(const char *name)
{
std::vector<PDBElement>::const_iterator it = InternalPDBDataSet.begin();
for(; it != InternalPDBDataSet.end(); ++it)
{
const char *itname = it->GetName();
if( strcmp(name, itname) == 0 )
{
return true;
}
}
return false;
}
static const char pdbheader[] = "GEMS_SERS_01";
static const gdcm::PrivateTag t1(0x0025,0x001b,pdbheader);
const PrivateTag & PDBHeader::GetPDBInfoTag()
{
return t1;
}
} // end namespace gdcm
|