-
Notifications
You must be signed in to change notification settings - Fork 0
/
DCMImage.cpp
2073 lines (1915 loc) · 51.1 KB
/
DCMImage.cpp
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DCMImage.cpp: implementation of the CDCMImage class.
//
//////////////////////////////////////////////////////////////////////
#include "DCMImage.h"
#include "qfile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDCMImage::CDCMImage()
{
little_endian_specified=0;
m_pixel_success = 0;
explicit_specified=0;
slope_and_intercept_specified=0;
number_of_frames_specified=0;
frame_time_specified=0;
frame_time_vector_specified=0;
photometric_specified=0;
window_center_specified=0;
window_width_specified=0;
PixelRepresentation=0;
PhotometricInterpretation=0;
memset(TransferSyntax,0,100);
BitsAllocated=0;
BitsStored=0;
HighBit=0;
WindowCenter=0;
WindowWidth=0;
SamplesPerPixel=0;
MaxPixelValue=0;
MinPixelValue=0;
m_Slope=0;
m_Intercept=0;
Rows=0;
Colums=0;
ImageWidth=0;
ImageHeight=0;
m_SaveImageWidth=m_SaveImageHeight=0;
m_SavePixelSizeX=m_SavePixelSizeY=0.;
BoxWidth=0;
BoxHeight=0;
BoxXpos=0;
BoxYpos=0;
WatchXpos=0;
WatchYpos=0;
WatchWidth=0;
WatchHeight=0;
SltXpos=0;
SltYpos=0;
SltWidth=0;
SltHeight=0;
SltImgCenX=0;
SltImgCenY=0;
NumberOfFrames=0;
FrameTime=0.;
FrameTimeVector=0;
RepetitionTime=0;
EchoTime=0;
FrameDelay=0.;
memset(ImageNumber,0,100);
memset(ImageDate,0,100);
memset(ImageTime,0,100);
memset(ImageType,0,100);
memset(PatientName,0,100);
memset(PatientID,0,100);
memset(PatientAge,0,100);
memset(PatientSex,0,100);
memset(StudyID,0,100);
memset(StudyTime,0,100);
memset(StudyDate,0,100);
memset(SeriesNumber,0,100);
memset(SeriesDate,0,100);
memset(SeriesTime,0,100);
memset(AcquisitionDate,0,100);
memset(AcquisitionTime,0,100);
memset(Modality,0,100);
memset(Manufacturer,0,100);
memset(ManufacturerMode,0,100);
memset(InstitutionAddress,0,100);
memset(InstitutionName,0,100);
memset(DFOV,0,100);
memset(KVP,0,100);
memset(TubeCurrent,0,100);
memset(DetectorTilt,0,100);
memset(BodyPart,0,100);
memset(SliceLocation,0,100);
memset(SliceThickness,0,100);
memset(ImageOrientation,0,6*sizeof(double));
memset(OrientMark,0,4);
memset(SaveOrientMark,0,4);
memset(ImagePosition,0,3*sizeof(double));
PixelValueData=NULL;
SavePixelValueData=NULL;
WatchData=NULL;
OW_specified=0;
Selected=0;
Deleted=0;
StateChanged=0;
//BoxColor=RGB(0,0,0);
DisplayMethod=0;
NoRegionX=NoRegionY=NoRegionWidth=NoRegionHeight=0;
m_PixelSizeX=0.;
m_PixelSizeY=0.;
m_SavePixelSizeX=0.;
m_SavePixelSizeY=0.;
m_TopValue=0;
m_bShowInfo=TRUE;
m_bContrast=FALSE;
SaveWinWidth=0.;
SaveWinCenter=0.;
m_RotateState=0;
m_bUpDown=FALSE;
m_bLeftRight=FALSE;
SaveSltXpos=SaveSltYpos=SaveSltWidth=SaveSltHeight=0;
m_bShow_One_Localizer= FALSE;
m_Highlight_ImageNum= 0;
m_Highlight_SeriesNum= 0;
m_NumOfLocalizers=0;
m_bLocalizer=FALSE;
m_bShowLocalizers= FALSE;
m_bLocalizerOK=FALSE;
m_NumberOfNo=0;
m_CurrentNo=0;
m_bShowNo=TRUE;
//m_hdib=0;
//m_ImageNum_Array.RemoveAll();
//m_SeriesNum_Array.RemoveAll();
//NotationArray.RemoveAll();
}
CDCMImage::~CDCMImage()
{
int i;
if(PixelValueData!=NULL)
{
delete []PixelValueData;
PixelValueData=NULL;
}
if(WatchData!=NULL)
{
delete []WatchData;
WatchData=NULL;
}
if(SavePixelValueData!=NULL)
delete[] SavePixelValueData;
//m_ImageNum_Array.RemoveAll();
//m_ImageNum_Array.FreeExtra();
//m_SeriesNum_Array.RemoveAll();
//m_SeriesNum_Array.FreeExtra();
// for( i=0;i<m_NumberOfNo;i++)
// {
// delete NotationArray[i];
// }
// NotationArray.RemoveAll();
// NotationArray.FreeExtra();
// ::GlobalFree((HGLOBAL)m_hdib);
}
////////////////////////////////////////////////////////////////////
int CDCMImage::HandleItem(ifstream &fp, int group, int element)
//fp is juxt moved over tag.//
{
int length;
length = read32(fp);
if(length == 0xffffffff)
{
group = read16( fp );
element = read16( fp );
HandleDataSet( fp, group, element );
fp.seekg(4, ios::cur);
//the length of this item is undefined,so there is a //
//itel delim item after the dataset. because the tag is already//
//read in HandleDataSet(),so just move over 4 BYTES.//
}
else
{
fp.seekg(length, ios::cur);
//length of the item is given ,so just move over.//
}
return 1;
}
////////////////////////////////////////////////////////////////////
int CDCMImage::HandleDataSet(ifstream &fp, int group, int element)
//given group and element handle dataset.//
{
char ch2[3];
int value_is_read;
int buff_allocated=0;
int oldGroup,oldElement;//group tag,element tag
long vlength,reallength;
int ii,i,c;
char sTemp[500];
char sTemp1[500];
vType ValueType;
slope_and_intercept_specified=0;
photometric_specified=0; //if not speicified ,least value is black //
number_of_frames_specified=0;//if not specified ,there is one frame only //
frame_time_specified=0;
frame_time_vector_specified=0;
oldGroup = group;
oldElement = element;
while(1)
{
if(explicit_specified)
//read over the VR //
{
fp.read((char *)&ch2, 2);
if (((ch2[0]=='S')&&(ch2[1]=='Q'))||
((ch2[0]=='O')&&(ch2[1]=='B'))||
((ch2[0]=='O')&&(ch2[1]=='W'))||
((ch2[0]=='U')&&(ch2[1]=='N')))
fp.seekg(2L, ios::cur);
}
if(!explicit_specified)
{
vlength=read32(fp);
}
else
{
if (((ch2[0]=='S')&&(ch2[1]=='Q'))||
((ch2[0]=='O')&&(ch2[1]=='B'))||
((ch2[0]=='O')&&(ch2[1]=='W'))||
((ch2[0]=='U')&&(ch2[1]=='N')))
vlength=read32(fp);
else
vlength=read16(fp);
}
//=====================================================//
//value length is known,but before we know how to read //
// the value ,there is another thing needed to known, //
//that is the value type. //
//all types are string,so should be read one byte by //
//one byte except accasions below,in these accasions //
//byte ordering should be considered: //
//2 byte US,SS,OW //
//4 byte UL,SL,FL //
//8 byte FD //
//=====================================================//
value_is_read=0;
//=====================================================//
//not only save these values ,but also to mark that //
//we do have these values!-----------------------------//
//=====================================================//
ValueType=unknown;
int j;
switch(group)
{
case 0x0008:
switch(element)
{
//case 0x0000:
// vlength = read32(fp);
// break;
case 0x0008:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
value_is_read=1;
c=0;
j=0;
for(i=0;i<vlength;i++)
{
sTemp1[j++]=sTemp[i];
if((sTemp[i]=='\\')||(i==vlength-1))
{
if(sTemp[i]=='\\') sTemp1[j-1]=0;
else sTemp1[j]=0;
j=0;
if(strcmp(sTemp1,"LOCALIZER")==0)
m_bLocalizer=1;
else
continue;
}
}
break;
case 0x0022:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy_s(AcquisitionDate, sizeof(AcquisitionDate)/sizeof(AcquisitionDate[0]), sTemp);
value_is_read=1;
break;
case 0x0032:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy_s(AcquisitionTime, sizeof(AcquisitionDate)/sizeof(AcquisitionDate[0]), sTemp);
value_is_read=1;
break;
case 0x0060:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy_s(Modality, sizeof(Modality)/sizeof(Modality[0]), sTemp);
value_is_read=1;
break;
case 0x0080:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy_s(InstitutionName, sizeof(InstitutionName)/sizeof(InstitutionName[0]), sTemp);
value_is_read=1;
break;
case 0x1090:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy_s(ManufacturerMode, sizeof(ManufacturerMode)/sizeof(ManufacturerMode[0]), sTemp);
value_is_read=1;
break;
}
break;
case 0x0010:
switch(element)
{
case 0x0050:
//SQ//
ValueType=SQ;
break;
case 0x0010:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(PatientName, sTemp);
value_is_read=1;
break;
case 0x0040:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(PatientSex,sTemp);
value_is_read=1;
break;
case 0x1010:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(PatientAge,sTemp);
value_is_read=1;
break;
case 0x0020:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(PatientID,sTemp);
value_is_read=1;
break;
}
break;
case 0x0018:
switch(element)
{
case 0x0082:
case 0x1032://SQ//
ValueType=SQ;
break;
case 0x1063://DS :Frametime//
break;
case 0x1065://DS :FrameTime//
//HOW TO GET THE ARRAY?//
break;
case 0x1066://DS :Frame Delay//
break;
case 0x0015:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(BodyPart,sTemp);
value_is_read=1;
break;
case 0x0050:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(SliceThickness,sTemp);
value_is_read=1;
break;
case 0x0060:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(KVP,sTemp);
value_is_read=1;
break;
case 0x1151:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(TubeCurrent,sTemp);
value_is_read=1;
break;
case 0x1084:
case 0x1100:
case 0x1110:
case 0x1111:
case 0x1115:
case 0x1120:
case 0x1125:
case 0x1130:
case 0x1140:
case 0x1145:
case 0x2112:
case 0x6011://SQ//
ValueType=SQ;
break;
}
break;
case 0x0020:
switch(element)
{
case 0x0010:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(StudyID,sTemp);
value_is_read=1;
break;
case 0x0011:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(SeriesNumber,sTemp);
value_is_read=1;
break;
case 0x0013:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy_s(ImageNumber,100, sTemp);
value_is_read=1;
break;
case 0x0032://Image Position//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
value_is_read=1;
c=0;
for(i=0;i<vlength;i++)
{
if(sTemp[i]=='\\')
{
sTemp[i]=0;
ImagePosition[c++]=atof(sTemp);
memset(sTemp,' ',i+1);
}
if(c==2)
{
ImagePosition[2]=atof(sTemp);
break;
}
}
break;
case 0x0037://Image Orientation//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
value_is_read=1;
c=0;
for(i=0;i<vlength;i++)
{
if(sTemp[i]=='\\')
{
sTemp[i]=0;
ImageOrientation[c++]=atof(sTemp);
memset(sTemp,' ',i+1);
}
if(c==5)
{
ImageOrientation[5]=atof(sTemp);
break;
}
}
break;
case 0x1041:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
strcpy(SliceLocation,sTemp);
value_is_read=1;
break;
}
break;
case 0x0028:
switch(element)
{
case 0x0002://US//
SamplesPerPixel=read16(fp);
value_is_read=1;
//*if RGB display**//
//if(SamplesPerPixel!=1)
// return 0;
break;
case 0x0004://CS//
value_is_read=1;
photometric_specified=1;
fp.read(sTemp, vlength);
for( ii=0;;ii++)
if(sTemp[ii]==0x20)
{
sTemp[ii]=0;
break;
}
if(strcmp(sTemp,"MONOCHROME2")==0)
PhotometricInterpretation=2;
else if(strcmp(sTemp,"MONOCHROME1")==0)
PhotometricInterpretation=1;
else if(strcmp(sTemp,"RGB")==0)
PhotometricInterpretation=4;
else PhotometricInterpretation =3;
break;
case 0x0008://IS//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
NumberOfFrames=atoi(sTemp);
number_of_frames_specified=1;
value_is_read=1;
break;
case 0x0009://AT//
value_is_read=1;
fp.read(sTemp, vlength);
sTemp[vlength]=0;
if(strcmp(sTemp,"(0018,1063)")==0)
frame_time_specified=1;
else if(strcmp(sTemp,"(0018,1065)")==0)
frame_time_vector_specified=1;
break;
case 0x0010://US//
Rows=read16(fp);
m_SaveImageHeight= ImageHeight=Rows;
value_is_read=1;
break;
case 0x0011://US//
Colums=read16(fp);
m_SaveImageWidth= ImageWidth=Colums;
value_is_read=1;
break;
case 0x0030:
fp.read(sTemp, vlength);
sTemp[vlength]=0;
value_is_read=1;
for (i=0; i <vlength;i++ )
if (sTemp[i]=='\\') break;
m_PixelSizeY =( float )atof(sTemp);
if (i>=vlength)
m_PixelSizeX=m_PixelSizeY ;
else
{
sTemp[i]=0;
m_PixelSizeX = ( float )atof( sTemp+i+1 );
}
m_SavePixelSizeX=m_PixelSizeX;
m_SavePixelSizeY=m_PixelSizeY;
break;
case 0x0100://US//
BitsAllocated=read16(fp);
value_is_read=1;
break;
case 0x0101://US//
BitsStored=read16(fp);
value_is_read=1;
break;
case 0x0102://US//
HighBit=read16(fp);
value_is_read=1;
break;
case 0x0103://US//
PixelRepresentation=read16(fp);
value_is_read=1;
break;
case 0x0106:
//Smallest Image Pixel Value//
//US or SS,so,donot know how to handle//
break;
case 0x0107:
//Largest Image Pixel Value//
//US or SS //
break;
case 0x1050://DS//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
WindowCenter=(float)atof(sTemp);
value_is_read=1;
window_center_specified=1;
break;
case 0x1051://DS//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
WindowWidth=(float)atof(sTemp);
value_is_read=1;
window_width_specified=1;
break;
case 0x1052://SQ//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
value_is_read=1;
slope_and_intercept_specified=1;
m_Intercept=atoi(sTemp);
break;
case 0x1053://SQ//
fp.read(sTemp, vlength);
sTemp[vlength]=0;
value_is_read=1;
slope_and_intercept_specified=1;
m_Slope=atoi(sTemp);
break;
case 0x3000://SQ//
ValueType=SQ;
break;
case 0x3010://SQ//
ValueType=SQ;
break;
}//end switch in the case//
break;
case 0x0032:
switch(element)
{
case 0x1064://SQ//
ValueType=SQ;
break;
}
break;
case 0x0038:
switch(element)
{
case 0x0004:
case 0x0044://SQ//
ValueType=SQ;
break;
}
break;
case 0x0040://text
break;
case 0x2000:
switch(element)
{
case 0x0500://SQ//
ValueType=SQ;
break;
}
break;
case 0x2010:
switch(element)
{
case 0x0500:
case 0x0510:
case 0x0520://SQ//
ValueType=SQ;
break;
}
break;
case 0x2020:
switch(element)
{
case 0x0110:
case 0x0111:
case 0x0130:
case 0x0140://SQ/
ValueType=SQ;
break;
}
break;
case 0x2040:
switch(element)
{
case 0x0010:
case 0x0500://SQ//
ValueType=SQ;
break;
}
break;
case 0x2100:
switch(element)
{
case 0x0500://SQ//
ValueType=SQ;
break;
}
break;
case 0x4008:
switch(element)
{
case 0x0050:
case 0x0111:
case 0x0117:
case 0x0118://SQ//
ValueType=SQ;
break;
}
break;
case 0x7fe0:
switch(element)
{
case 0x0010://pixcel is encountered!
if(!slope_and_intercept_specified)
{
m_Slope=1;
m_Intercept=0;
}
if(!number_of_frames_specified)
NumberOfFrames=1;
// SamplesPerPixel=1;
//*or 3*//
reallength=Rows*Colums*SamplesPerPixel*NumberOfFrames*BitsAllocated/8;
fp.seekg(vlength-reallength, ios::cur);
//perhaps there is something unuseful before the pixel data,//
//so, skip them. //
//see below ,mutiple frames is considered? //
uint8 *buff;
int n;
int bytes_per_pixel;
int unsigned_flag;
bytes_per_pixel=BitsAllocated/8*SamplesPerPixel;
unsigned_flag=1-PixelRepresentation;
buff=(uint8*)malloc(ImageHeight*ImageWidth*bytes_per_pixel);
fp.read((char *)buff, ImageHeight*ImageWidth*bytes_per_pixel);
if(little_endian_specified==0)
flip_16bit_data(buff,ImageWidth,ImageHeight);
if(bytes_per_pixel==1)
{
if(unsigned_flag) PixelValueData=to_32bit_data((uint8*)buff, ImageWidth,ImageHeight);
else PixelValueData=to_32bit_data((int8*)buff, ImageWidth,ImageHeight);
}
else if(bytes_per_pixel==2)
{
if(unsigned_flag) PixelValueData=to_32bit_data((uint16*)buff, ImageWidth,ImageHeight);
else PixelValueData=to_32bit_data((int16*)buff, ImageWidth,ImageHeight);
}
if(buff!=NULL) delete[]buff;
handle_photometric_interpretation(PixelValueData,ImageWidth,ImageHeight);
if(slope_and_intercept_specified)
apply_slope_intercept (PixelValueData,ImageWidth,ImageHeight,m_Slope,m_Intercept);
MinPixelValue=MaxPixelValue=PixelValueData[0];
for(i=0;i<ImageWidth*ImageHeight;i++)
{
if(PixelValueData[i]>MaxPixelValue)
MaxPixelValue=PixelValueData[i];
if(PixelValueData[i]<MinPixelValue)
MinPixelValue=PixelValueData[i];
}
if((!window_center_specified)||(!window_width_specified))
{
WindowWidth =(float)(MaxPixelValue-MinPixelValue);
WindowCenter=(float)(MaxPixelValue-MinPixelValue)/2+MinPixelValue;
}
//像素值在PixelValueData[] 里
//每行有ImageWidth 个像素
//有ImageHeight 行//////////////////////////////////////////////
/* CFile file;
PWORD pPixel;
DWORD d;
int xSize,ySize;
xSize=ySize=512;
CFileException e;
file.Open("e:\\zgh\\hehe", CFile::modeCreate | CFile::modeWrite, &e );
pPixel = new WORD[xSize*ySize];
for(j=0;j<ySize;j++)
for(i=0;i<xSize;i++)
{
d= PixelValueData[j*ImageWidth+i];
*(pPixel+j*ySize+i)=(WORD)((d-MinPixelValue)*2300./(MaxPixelValue-MinPixelValue));
}
file.Write(pPixel, xSize*ySize*2);
file.Close();
*/
// CmpOrientationMark();
//pixel is read ok.//
return 100;//okokokokokokokokokokokoko
///////////////////////////////////////
break;
}
}
if(!value_is_read)
//if((ValueType==SQ)&&(vlength==0xffffffff))
if(vlength==0xffffffff)//an sequence of items with undefined length is found,handle it.//
{
while(1)
{
group = read16(fp);
element = read16(fp);
if(group ==0xfffe && element ==0xe0dd)
{
//a data element is ok ,handle next.//
fp.seekg(4, ios::cur);
break;
}
HandleItem(fp,group,element);
}//wnd of while.//
}
else
fp.seekg(vlength, ios::cur);
group=read16(fp);
element=read16(fp);
//
if(!((group ==oldGroup && element > oldElement )||(group > oldGroup)))
{
return 0;//read failed!//
}
//when encountered with 0xfffe group ,a dataset is handled over ,so return;
if(group ==0xfffe && element ==0xe000)
return 1;//item
if(group ==0xfffe && element ==0xe00d)
return 2;//item delim item.
if(group ==0xfffe && element ==0xe0dd)
return 3;//sequence delim item.
oldGroup = group;
oldElement = element;
}//end of while///////////////////////
return 1;
}
////////////////////////////////////////////////////////////////////
int CDCMImage::GetPixelData(QString FilePath)
/***return 1 if getbpixel data successfully ************/
/***return 0 if failed---------------------------------*/
{
ifstream reader;
reader.open(FilePath.toAscii(), ios::binary|ios::in);
if(reader.is_open() == false)
return 0;
char ch;
char ch2[3];
int dicm_success=0,transfer_syntax_success=0,Pixel_success=0;
int little_endian_specified2;
int buff_allocated=0;
int group,element,oldGroup,oldElement;//group tag,element tag
long vlength;
int i;
char sTemp[500];
//==Add For Ours==//
//fseek(fp,128,1);
//==Add For Ours==//
for(i = 0; i < 300; i ++)
{
reader.read( &ch, 1 );
if(ch == 'D')
{
reader.read( (char *)&ch2, 3 );
if( ( ch2[0]=='I' )&&( ch2[1]=='C' )&&( ch2[2]=='M' ) )
{
dicm_success = 1;
break;
}
}
}
little_endian_specified2=0;
//===============================================================//
//end of while,recognize 'DICM' successfully //
//or read end of file //
//===============================================================//
if( dicm_success )
{
little_endian_specified = 1;
explicit_specified = 1;
//===============================================================//
//then get TransferSyntax in the 0002 group which is encoded in //
//little_endian transfer syntax,to do this in the following while//
//loop //
//===============================================================//
oldElement = -1;
oldGroup = 0x0002;
while(1)
{
group = read16( reader );
element = read16( reader );
if(group != 0x0002)
{
oldGroup = group;
oldElement = element;
break;
}
if( !(group == 0x0002 && element > oldElement))
{
reader.close();
return 0;//failed!//
}
oldElement = element;
//===============================================================//
//break out of the while statement, //
//because already read over the 0x0002 group //
//===============================================================//
reader.read( (char *)&ch2, 2 );//read over VR
if((ch2[0]='O')&&(ch2[1]=='B'))
{
reader.seekg(2L, ios::cur);
//fp->Seek(2L,1);
vlength = read32( reader );
}
else
vlength = read16( reader );
if( ( group==0x0002 )&&( element==0x0010 ))
// what we want to know is here!then read value:transfer syntax//
{
reader.read(sTemp, vlength);
sTemp[vlength]=0;
if(strcmp(sTemp, "1.2.840.10008.1.2")==0)
{
little_endian_specified2=1;
explicit_specified=0;
}
else if(strcmp(sTemp,"1.2.840.10008.1.2.1")==0)
little_endian_specified2=1;
else if(strcmp(sTemp,"1.2.840.10008.1.2.2")==0)
little_endian_specified2=2;
else
little_endian_specified2=3;
transfer_syntax_success=1;
}
else
//seek over value //
{
reader.seekg(vlength, ios::cur);
}
}//end of while
}//end of if dicm_success
else
//'DICM' recognizing failed,suppose there is no head //
// ,so move the pointer to the begin of the file !//
{
reader.seekg( 0L, ios::beg );
//==Add For Ours==//
//fseek(fp,128,1);
//==Add For Ours==//
little_endian_specified = 1;
explicit_specified = 0;//implicit
oldGroup = group = read16( reader );
oldElement = element = read16( reader );
}
//===============================================================//
if(little_endian_specified2==0)
//little_endian_specified not given in the head ,so it is implicit //
//and little_endian_specified by default -------------------------//
{
little_endian_specified=1;