13 #include <vil/vil_config.h> 19 # include <vcl_msvc_warnings.h> 157 endian_ = calculateEndian();
208 std::cerr<<
"Unknown file type - not a DICOM file...\n" 209 <<
"File header not read\n";
265 std::string dicm_test;
269 fs.
read(dicm_read,4);
273 if (dicm_test ==
"DICM")
282 fs.
read(dicm_read,4);
286 if (dicm_test ==
"DICM")
299 while (num_tries < 2 && !known)
304 vxl_uint_16 group, element;
305 vxl_uint_32 data_block_size, num_elements;
307 fs.
read(&group,
sizeof(vxl_uint_16));
309 fs.
read(&element,
sizeof(vxl_uint_16));
311 fs.
read(&data_block_size,
sizeof(vxl_uint_32));
312 data_block_size =
intSwap(data_block_size);
313 if (data_block_size > 0x1000000) {
314 std::cerr<< __FILE__ <<
": " << __LINE__ <<
" : WARNING:\n" 315 <<
"data_block_size=" << data_block_size <<
" is most probably too large\n";
327 fs.
seek(data_block_size + fs.
tell());
329 fs.
read(&group,
sizeof(vxl_uint_16));
331 fs.
read(&element,
sizeof(vxl_uint_16));
333 fs.
read(&data_block_size,
sizeof(vxl_uint_32));
334 data_block_size =
intSwap(data_block_size);
335 if (data_block_size > 0x1000000) {
336 std::cerr<< __FILE__ <<
": " << __LINE__ <<
" : WARNING:\n" 337 <<
"data_block_size=" << data_block_size <<
" is most probably too large\n";
350 data_block_size == 4)
386 std::cerr <<
"File not open for reading:\n" 387 <<
"vil_dicom_header_format::determineFileType()\n";
397 vxl_uint_16 group, element;
398 vxl_uint_32 data_block_size;
399 std::cerr <<
"vil_dicom_header_format::readHeaderElements - Deprecated function called - use the DCMTK code instead!";
403 fs.
read(&group,
sizeof(vxl_uint_16));
404 fs.
read(&element,
sizeof(vxl_uint_16));
414 if (
sizeof(vxl_uint_32) != fs.
read(&data_block_size,
sizeof(vxl_uint_32)))
416 data_block_size =
intSwap(data_block_size);
417 if (data_block_size > 0x1000000) {
418 std::cerr<< __FILE__ <<
": " << __LINE__ <<
" : WARNING:\n" 419 <<
"data_block_size=" << data_block_size <<
" is most probably too large\n";
462 fs.
seek(data_block_size + fs.
tell());
467 fs.
read(&group,
sizeof(vxl_uint_16));
468 fs.
read(&element,
sizeof(vxl_uint_16));
477 if (
sizeof(vxl_uint_32) != fs.
read(&data_block_size,
sizeof(vxl_uint_32)))
479 data_block_size =
intSwap(data_block_size);
480 if (data_block_size > 0x1000000)
481 std::cerr << __FILE__ <<
": " << __LINE__ <<
" : WARNING\n" 482 <<
"data_block_size=" << data_block_size <<
" is most probably too large\n";
490 #define CASE(X,M,F) \ 492 data_p = new char[dblock_size+1]; \ 495 fs.read(data_p,dblock_size); \ 496 data_p[dblock_size]=0; \ 497 last_read_.M = F(data_p); \ 501 #define CASE_SWP(X,M) \ 503 data_p = new char[dblock_size+1]; \ 506 fs.read(data_p,dblock_size); \ 507 data_p[dblock_size]=0; \ 508 charSwap(data_p, sizeof(vxl_uint_16)); \ 509 last_read_.M = *((vxl_uint_16*)data_p); \ 521 switch ((vxl_uint_16)element)
564 switch ((vxl_uint_16)element)
591 switch ((vxl_uint_16)element)
622 data_p =
new char[dblock_size+1];
625 fs.
read(data_p,dblock_size);
626 data_p[dblock_size]=0;
632 while (gone != 0 && gone !=
'\\')
635 for (
int i=0; i<dblock_size; i++)
636 data_p[i] = data_p[i+1];
662 switch ((vxl_uint_16)element)
696 switch ((vxl_uint_16)element)
715 data_p =
new char[dblock_size+1];
718 fs.
read(data_p,dblock_size);
719 data_p[dblock_size]=0;
725 while (gone != 0 && gone !=
'\\')
728 for (
int i=0; i<dblock_size; i++)
729 data_p[i] = data_p[i+1];
752 switch ((vxl_uint_16)element)
777 switch ((vxl_uint_16)element)
782 std::cout <<
"Procedure group; unread element: " << element << std::endl;
801 switch ((vxl_uint_16)element)
806 std::cout <<
"Non-standard Philips group; unread element: " << element << std::endl;
820 std::string first, last;
832 conv_dblock.int_val = dblock_size;
836 temp[0] = conv_dblock.char_val[0];
837 temp[1] = conv_dblock.char_val[1];
842 temp[0] = conv_dblock.char_val[3];
843 temp[1] = conv_dblock.char_val[2];
850 fs.
read(&dblock_size,
sizeof(
int));
859 fs.
read(&dblock_size,
sizeof(
int));
860 dblock_size =
intSwap(dblock_size);
892 dblock_size = (
unsigned int)((256*conv_dblock.char_val[3]) + conv_dblock.char_val[2]);
896 dblock_size = (
unsigned int)((256*conv_dblock.char_val[2]) + conv_dblock.char_val[3]);
925 dblock_size = (
unsigned int)((256*conv_dblock.char_val[1]) + conv_dblock.char_val[0]);
929 dblock_size = (
unsigned int)((256*conv_dblock.char_val[0]) + conv_dblock.char_val[1]);
977 calc_endian.int_val = 1;
980 return calc_endian.by_val[0] == 1 ?
992 vxl_uint_16 group, element;
993 vxl_uint_32 data_block_size;
1002 fs.
read(&group,
sizeof(vxl_uint_16));
1009 fs.
read(&element,
sizeof(vxl_uint_16));
1013 if (
sizeof(vxl_uint_32) != fs.
read(&data_block_size,
sizeof(vxl_uint_32)))
1016 data_block_size =
intSwap(data_block_size);
1018 if (data_block_size > 0x1000000) {
1019 std::cerr<< __FILE__ <<
": " << __LINE__ <<
" : WARNING:\n" 1020 <<
"data_block_size=" << data_block_size <<
" is most probably too large\n";
1030 char * tfx_type =
new char[data_block_size+1];
1033 fs.
read(tfx_type, data_block_size);
1034 tfx_type[data_block_size]=0;
1038 std::string temp = tfx_type;
1128 fs.
seek(data_block_size + fs.
tell());
1131 ret_pos = fs.
tell();
1135 fs.
read(&group,
sizeof(vxl_uint_16));
1150 vxl_uint_16 result = short_in;
1160 vxl_uint_16 short_val;
1161 vxl_byte byte_val[2];
1165 short_swap.short_val = short_in;
1168 vxl_byte temp = short_swap.byte_val[0];
1169 short_swap.byte_val[0]=short_swap.byte_val[1];
1170 short_swap.byte_val[1]=temp;
1172 result = short_swap.short_val;
1182 vxl_uint_32 result = int_in;
1192 vxl_uint_32 int_val;
1193 vxl_byte byte_val[4];
1197 int_swap.int_val = int_in;
1200 vxl_byte temp = int_swap.byte_val[0];
1201 int_swap.byte_val[0]=int_swap.byte_val[3];
1202 int_swap.byte_val[3]=temp;
1205 temp = int_swap.byte_val[1];
1206 int_swap.byte_val[1] = int_swap.byte_val[2];
1207 int_swap.byte_val[2] = temp;
1209 result = int_swap.int_val;
1225 for (
int i=val_size/2-1; i>=0; --i)
1227 char temp=char_in[i];
1228 char_in[i] = char_in[val_size-i-1];
1229 char_in[val_size-i-1] = temp;
1237 os <<
"\n\nGeneral info fields\n" 1238 <<
" file_type The type of dicom file: " << s.
file_type_ << std::endl
1239 <<
" sys_endian The endian of the architecture: " << s.
sys_endian_ << std::endl
1240 <<
" image_type The encapsulated (or not) image type: " <<s.
image_type_ << std::endl
1242 <<
"\n\nIdentifying fields\n" 1243 <<
" image_id_type The image type from the dicom header: " << s.
image_id_type_ << std::endl
1244 <<
" sop_cl_uid The class unique id for the Service/Object Pair: " << s.
sop_cl_uid_ << std::endl
1245 <<
" sop_in_uid The instance uid for the SOP: " << s.
sop_in_uid_ << std::endl
1246 <<
" study_date The date of the study: " << s.
study_date_ << std::endl
1247 <<
" series_date The date this series was collected: " << s.
series_date_ << std::endl
1248 <<
" acquisition_date The date of acquisition: " << s.
acquisition_date_ << std::endl
1249 <<
" image_date The date of this image: " << s.
image_date_ << std::endl
1250 <<
" study_time The time of the study: " << s.
study_time_ << std::endl
1251 <<
" series_time The time of the series: " << s.
series_time_ << std::endl
1252 <<
" acquisition_time The time acquisition: " << s.
acquisition_time_ << std::endl
1253 <<
" image_time The time of the image: " << s.
image_time_ << std::endl
1254 <<
" accession_number The accession number for this image: " << s.
accession_number_ << std::endl
1255 <<
" modality The imaging modality: " << s.
modality_ << std::endl
1256 <<
" manufacturer The name of the scanner manufacturer: " << s.
manufacturer_ << std::endl
1257 <<
" institution_name The name of the institution: " << s.
institution_name_ << std::endl
1258 <<
" institution_addr The address of the institution: " << s.
institution_addr_ << std::endl
1259 <<
" ref_phys_name The name of the referring physician: " << s.
ref_phys_name_ << std::endl
1260 <<
" station_name The name of the station used: " << s.
station_name_ << std::endl
1261 <<
" study_desc A description of the study: " << s.
study_desc_ << std::endl
1262 <<
" series_desc A description of the series: " << s.
series_desc_ << std::endl
1263 <<
" att_phys_name The name of the attending physician: " << s.
att_phys_name_ << std::endl
1264 <<
" operator_name The name of the MR operator: " << s.
operator_name_ << std::endl
1265 <<
" model_name The name of the MR scanner model: " << s.
model_name_ << std::endl
1267 <<
"\n\nPatient info\n" 1268 <<
" patient_name Patient's name: " << s.
patient_name_ << std::endl
1269 <<
" patient_id Patient's ID: " << s.
patient_id_ << std::endl
1270 <<
" patient_dob The patient's date of birth: " << s.
patient_dob_ << std::endl
1271 <<
" patient_sex The sex of the patient: " << s.
patient_sex_ << std::endl
1272 <<
" patient_age The age of the patient: " << s.
patient_age_ << std::endl
1273 <<
" patient_weight_ The weight of the patient: " << s.
patient_weight_ << std::endl
1274 <<
" patient_hist Any additional patient history: " << s.
patient_hist_ << std::endl
1276 <<
"\n\nAcquisition Info\n" 1277 <<
" scanning_seq A description of the scanning sequence: " << s.
scanning_seq_ << std::endl
1278 <<
" sequence_var A description of the sequence variant: " << s.
sequence_var_ << std::endl
1279 <<
" scan_options A description of various scan options: " << s.
scan_options_ << std::endl
1280 <<
" mr_acq_type The acquisition type for this scan: " << s.
mr_acq_type_ << std::endl
1281 <<
" sequence_name The name of the sequence: " << s.
sequence_name_ << std::endl
1282 <<
" angio_flag The angio flag for this sequence: " << s.
angio_flag_ << std::endl
1283 <<
" slice_thickness_ Slice thickness (for voxel size): " << s.
slice_thickness_ << std::endl
1284 <<
" repetition_time_ Scan repetition time: " << s.
repetition_time_ << std::endl
1285 <<
" echo_time Scan echo time: " << s.
echo_time_ << std::endl
1286 <<
" inversion_time Scan inversion time: " << s.
inversion_time_ << std::endl
1287 <<
" number_of_averages The number of averages for this scan: " << s.
number_of_averages_ << std::endl
1288 <<
" echo_numbers The echo numbers for this scan: " << s.
echo_numbers_ << std::endl
1289 <<
" mag_field_strength The strength of the magnetic field: " << s.
mag_field_strength_ << std::endl
1290 <<
" echo_train_length The length of the echo train: " << s.
echo_train_length_ << std::endl
1291 <<
" pixel_bandwidth The bandwidth of the pixels: " << s.
pixel_bandwidth_ << std::endl
1292 <<
" software_vers_ Versions of the scanner software used: " << s.
software_vers_ << std::endl
1293 <<
" protocol_name The name of the protocol used: " << s.
protocol_name_ << std::endl
1294 <<
" trigger_time The trigger time: " << s.
trigger_time_ << std::endl
1295 <<
" heart_rate The patient's heart rate: " << s.
heart_rate_ << std::endl
1296 <<
" card_num_images The cardiac number of images: " << s.
card_num_images_ << std::endl
1297 <<
" trigger_window The trigger window for this image: " << s.
trigger_window_ << std::endl
1298 <<
" reconst_diameter The reconstruction diameter: " << s.
reconst_diameter_ << std::endl
1299 <<
" receiving_coil_ Details of the receiving coil: " << s.
receiving_coil_ << std::endl
1300 <<
" phase_enc_dir The phase encoding direction: " << s.
phase_enc_dir_ << std::endl
1301 <<
" flip_angle The flip angle: " << s.
flip_angle_ << std::endl
1302 <<
" sar The specific absorption rate: " << s.
sar_ << std::endl
1303 <<
" patient_pos The position of the patient in the scanner: " << s.
patient_pos_ << std::endl
1305 <<
"\n\nRelationship info\n" 1306 <<
" stud_ins_uid The study instance unique id: " << s.
stud_ins_uid_ << std::endl
1307 <<
" ser_ins_uid The series instance unique id: " << s.
ser_ins_uid_ << std::endl
1308 <<
" study_id The id of this study: " << s.
study_id_ << std::endl
1309 <<
" series_number The number of this series: " << s.
series_number_ << std::endl
1310 <<
" acquisition_number The number of the acquisition: " << s.
acquisition_number_ << std::endl
1311 <<
" image_number The number of this image instance: " << s.
image_number_ << std::endl
1312 <<
" pat_orient The orientation of the patient: " << s.
pat_orient_ << std::endl
1315 <<
" frame_of_ref The frame of reference" << s.
frame_of_ref_ << std::endl
1316 <<
" images_in_acq Then number ot images in the acquisition: " << s.
images_in_acq_ << std::endl
1317 <<
" pos_ref_ind The position reference indicator: " << s.
pos_ref_ind_ << std::endl
1318 <<
" slice_location The location of the slice: " << s.
slice_location_ << std::endl
1320 <<
"\n\nImage info\n" 1321 <<
" pix_samps The number of samples per pixel: " << s.
pix_samps_ << std::endl
1322 <<
" photo_interp The photometric interpretation: " << s.
photo_interp_ << std::endl
1323 <<
" size_x The number of columns: " << s.
size_x_ << std::endl
1324 <<
" size_y The number of rows: " << s.
size_y_ << std::endl
1325 <<
" size_z The number of planes: " << s.
size_z_ << std::endl
1326 <<
" high_bit The bit used as the high bit: " << s.
high_bit_ << std::endl
1327 <<
" small_im_pix_val The smallest image pixel value: " << s.
small_im_pix_val_ << std::endl
1328 <<
" large_im_pix_val The largest image pixel value: " << s.
large_im_pix_val_ << std::endl
1329 <<
" pixel_padding_val The value used for padding pixels: " << s.
pixel_padding_val_ << std::endl
1330 <<
" window_centre The value of the image window's centre: " << s.
window_centre_ << std::endl
1331 <<
" window_width The actual width of the image window: " << s.
window_width_ << std::endl
1333 <<
"\n\nInfo from the tags specifically for reading the image data\n" 1334 <<
" spaxing_x The pixel spacing in x: " << s.
spacing_x_ << std::endl
1335 <<
" spacing_y The pixel spacing in y: " << s.
spacing_y_ << std::endl
1336 <<
" spacing_slice The pixel spacing in z: " << s.
spacing_slice_ << std::endl
1337 <<
" res_intercept The image rescale intercept: " << s.
res_intercept_ << std::endl
1338 <<
" res_slope The image rescale slope: " << s.
res_slope_ << std::endl
1339 <<
" pix_rep The pixel representation (+/-): " << s.
pix_rep_ << std::endl
1340 <<
" stored_bits The bits stored: " << s.
stored_bits_ << std::endl
1341 <<
" allocated_bits The bits allocated: " << s.
allocated_bits_ << std::endl
1342 <<
" imager_spacing_x The sensor pixel spacing in x: " << s.
imager_spacing_x_ << std::endl
1343 <<
" imager_spacing_y The sensor pixel spacing in y: " << s.
imager_spacing_y_ << std::endl
1345 <<
"\n\nInfo from the tags specifically for the procedure group\n" 1348 <<
" exposedarea_x The exposed area in x: " << s.
exposedarea_x_ << std::endl
1349 <<
" exposedarea_y The exposed ares in y: " << s.
exposedarea_y_ << std::endl
1352 <<
"\n\nInfo from the tags specifically for the Philips private group (2005)\n"
Stream interface for VIL image loaders.
virtual vil_streampos tell() const =0
Return file pointer.
virtual void seek(vil_streampos position)=0
Goto file pointer.
virtual vil_streampos read(void *buf, vil_streampos n)=0
Read n bytes into buf. Returns number of bytes read.
Stream interface for VIL image loaders.
virtual bool ok() const =0
Return false if the stream is broken.