-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdicom.h
1687 lines (1498 loc) · 34.3 KB
/
dicom.h
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
// dicom.h
// currently handles only expicit VR encoding
// implicit VR would require a library
#define _CRT_SECURE_NO_WARNINGS
#ifndef _DICOM_H
#define _DICOM_H
#include <cstdlib>
#include <cstring>
#include <map>
#include <string>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include "hdllist.h"
using namespace std;
enum valrep_t {VR_AE,
VR_AS,
VR_AT,
VR_CS,
VR_DA,
VR_DS,
VR_DT,
VR_FL,
VR_FD,
VR_IS,
VR_LO,
VR_LT,
VR_OB,
VR_OF,
VR_OW,
VR_PN,
VR_SH,
VR_SL,
VR_SQ,
VR_SS,
VR_ST,
VR_TM,
VR_UI,
VR_UL,
VR_UN,
VR_US,
VR_UT};
static map<string, valrep_t> VRMap;
void InitVRMap()
{
VRMap["AE"] = VR_AE;
VRMap["AS"] = VR_AS;
VRMap["AT"] = VR_AT;
VRMap["CS"] = VR_CS;
VRMap["DA"] = VR_DA;
VRMap["DS"] = VR_DS;
VRMap["DT"] = VR_DT;
VRMap["FL"] = VR_FL;
VRMap["FD"] = VR_FD;
VRMap["IS"] = VR_IS;
VRMap["LO"] = VR_LO;
VRMap["LT"] = VR_LT;
VRMap["OB"] = VR_OB;
VRMap["OF"] = VR_OF;
VRMap["OW"] = VR_OW;
VRMap["PN"] = VR_PN;
VRMap["SH"] = VR_SH;
VRMap["SL"] = VR_SL;
VRMap["SQ"] = VR_SQ;
VRMap["SS"] = VR_SS;
VRMap["ST"] = VR_ST;
VRMap["TM"] = VR_TM;
VRMap["UI"] = VR_UI;
VRMap["UL"] = VR_UL;
VRMap["UN"] = VR_UN;
VRMap["US"] = VR_US;
VRMap["UT"] = VR_UT;
}
class DataElement : public HDLListObj
{
public:
DataElement(ifstream& f); // creates a single data element from an ifstream
DataElement(unsigned short newGroup, unsigned short newElement, string newVR,
unsigned long newLength, const void* newValue);
~DataElement();
// virtual functions from abstract base class
void Print(ostream& os=cout); // displays the data contained in the DataElement
void Write(ofstream& f); // writes the DataElement to a file
unsigned long GetSize();
int CheckLength();
int Validate(); // checks the element against a Dicom dictionary
int Modify(void* newVal, unsigned long newLen);
int SetObject(HDLListObj*); // inserts Dicom Objects into SQ objects
unsigned short GetGroup() { return Group; }
unsigned short GetElement() { return Element; }
unsigned long GetLength();
unsigned long GetValue(void* buffer, unsigned long buf_size); // copies the Value to buffer and returns Length
HDLListObj* GetSQObject(int n); // returns the DicomObject in the SQ DataElement indexed by n;
// int GetNumSQObj(); // returns the total number of sequenced objects is function needed?
private:
unsigned short Group;
unsigned short Element;
string VR;
unsigned long Length;
char* Value;
};
class DicomObj : public HDLListObj
{
public:
DicomObj(){ Length = 0;};
DicomObj(ifstream& f); // constructor called for nested Dicom objects
~DicomObj() {};
// virtual functions from abstract base class
void Print(ostream& os=cout); // Prints the contents of the Object
void Write(ofstream& f); // write Dicom object to file with (FFFE, E0000) tag and length.
void ReadFromFile(istream& f); // reads and create elements from a text file;
unsigned long GetSize(); // Length of the Dicom Object (including tags)
int CheckLength(); // verifies that the length field is correct
int Validate();
int SetElement(DataElement*); // inserts a data element into the Dicom Object (in the right place)
int DeleteElement(unsigned short Group, unsigned short Element);
int ModifyElement(unsigned short Group, unsigned short Element, void* newVal, unsigned long newLen);
int FindElement(unsigned short Group, unsigned short Element);
unsigned long GetLength(unsigned short Group, unsigned short Element); // Length of the specified Element
unsigned long GetValue(unsigned short Group, unsigned short Element, void* buff, unsigned long buf_size);
DicomObj* GetSQObject(unsigned short Group, unsigned short Element, int n=0);
private:
unsigned long Length;
};
class RootDicomObj : public DicomObj
{
public:
RootDicomObj();
RootDicomObj(const char* filename, bool hdr_only = false); // constructor called for root Dicom objects
~RootDicomObj() {}; // destructor
// overrides the Write function from the DicomObj class
void Write(ofstream& f); // write Dicom object to file
int Write(const char* filename);
static int depth; // only used for indenting when writing
static bool VRMap_Initialized; // tracks if the VR_Map has been intilized yet
};
int RootDicomObj::depth = 0;
bool RootDicomObj::VRMap_Initialized = false;
DataElement::DataElement(ifstream& f)
{
char temp[4] = {0,0,0,0};
unsigned char SQEndTag[] = {0xFE, 0xFF, 0xDD, 0xE0};
DicomObj* newDCMObj;
unsigned long BytesRead;
f.read((char*)&Group,2);
f.read((char*)&Element,2);
f.read(temp,2);
VR = temp;
Length = 0;
switch(VRMap[VR])
{
case VR_OB: // if VR is OB, OW, OF, SQ, UT, or UN, skip two bytes, then read 4 byte length
case VR_OW:
case VR_OF:
case VR_UT:
case VR_UN:
f.seekg(2,ios::cur);
f.read((char*)&Length,4);
break;
case VR_SQ:
Value = NULL;
f.seekg(2,ios::cur);
f.read((char*)&Length,4);
// this is where we'll be creating new Dicom Objects for SQ data
// for each Dicom Object in the sequence
if(Length==0xFFFFFFFF)
{
// check the tag before passing to the DicomObj creator
f.read(temp,4);
while(memcmp(temp,SQEndTag,4))
{
f.seekg(-4,ios::cur);
newDCMObj = new DicomObj(f);
AddObj(newDCMObj);
f.read(temp,4);
}
// skip the next four bytes and continue
f.seekg(4,ios::cur);
}
else
{
BytesRead = 0;
while(BytesRead < Length)
{
newDCMObj = new DicomObj(f);
AddObj(newDCMObj);
BytesRead += newDCMObj->GetSize();
}
}
return;
default:
f.read((char*)&Length,2);
break;
}
if(Length)
{
Value = new char[Length];
if(Value)
f.read(Value,Length);
else
cout << "Error: unable to allocate memory for data element" << endl;
}
else
Value = NULL;
return;
}
DataElement::DataElement(unsigned short newGroup, unsigned short newElement, string newVR,
unsigned long newLength, const void* newValue)
{
Group = newGroup;
Element = newElement;
VR = newVR;
Length = newLength;
if(newLength % 2)
Length++;
if(Length)
{
Value = new char[Length];
if(Value)
memcpy(Value, newValue, newLength);
else
return; // doesn't try to pad if memory allocation failed
}
else
Value = NULL;
if(newLength % 2) // pad odd field lengths with spaces or zeros
{
switch(VRMap[VR])
{
case VR_AE:
case VR_AS:
case VR_CS:
case VR_DA:
case VR_DS:
case VR_DT:
case VR_IS:
case VR_LO:
case VR_LT:
case VR_PN:
case VR_SH:
case VR_ST:
case VR_UT:
Value[newLength] = 0x20;
break;
default:
Value[newLength] = 0;
}
}
}
DataElement::~DataElement()
{
if(Value)
delete Value;
}
void DataElement::Print(ostream& os)
{
for(int i=0;i<RootDicomObj::depth;i++)
os << " ";
os << "(";
os.width(4);
os.fill('0');
os << hex << Group << ",";
os.width(4);
os << Element << ") ";
os << VR;
os.width(9);
os.fill(' ');
if(Length == 0xFFFFFFFF)
os << "undef";
else
os << dec << Length << " ";
switch(VRMap[VR])
{
case VR_AE:
case VR_AS:
case VR_CS:
case VR_DA:
case VR_DS:
case VR_DT:
case VR_IS:
case VR_LO:
case VR_LT:
case VR_PN:
case VR_SH:
case VR_ST:
case VR_TM:
case VR_UI:
case VR_UT:
if (Length < 80)
os.write(Value, Length);
else {
os.write(Value, 80);
os << "...";
}
break;
case VR_AT: // write the attribute tags as pairs of 16-bit values
for(unsigned int i=0;i<(Length>>2);i++) {
os << "(";
os.width(4);
os.fill('0');
os << hex << *(unsigned short*)(Value + (i*4)) << ",";
os.width(4);
os << *(unsigned short*)(Value + (i*4 + 2)) << ") ";
}
break;
case VR_FD:
os << *(double*)Value;
break;
case VR_FL:
os << *(float*)Value;
break;
case VR_SL:
os << *(long*)Value;
break;
case VR_SS:
os << *(short*)Value;
break;
case VR_UL:
os << *(unsigned long*)Value;
break;
case VR_US:
for(unsigned int i=0;i<(Length-2);i+=2)
os << *(unsigned short*)(Value+i) << "\\";
os << *(unsigned short*)(Value+Length-2);
break;
case VR_SQ:
os << endl;
// do some indentinig
RootDicomObj::depth++;
for(int i=0;i<RootDicomObj::depth;i++)
os << " ";
os << "+++++";
FirstObj();
while(currentObj)
{
os << endl;
((DicomObj*)currentObj)->Print(os);
for(int i=0;i<RootDicomObj::depth;i++)
os << " ";
os << "+++++";
if(!IncrObjPtr())
break;
}
// back out of the indenting
RootDicomObj::depth--;
break;
default: // OB, OF, OW, and UN don't get printed
break;
}
os << endl;
}
// Writes the currect data element to a file
void DataElement::Write(ofstream &f)
{
const unsigned char SQEndTag[] = {0xFE,0xFF,0xDD,0xE0};
f.write((char*)&Group,2);
f.write((char*)&Element,2);
f << VR;
switch(VRMap[VR])
{
case VR_OB: // if VR is OB, OW, OF, SQ, UT, or UN, write two bytes, then write 4 byte length
case VR_OW:
case VR_OF:
case VR_UT:
case VR_UN:
case VR_SQ:
f.put(0);
f.put(0);
f.write((char*)&Length,4);
break;
default:
f.write((char*)&Length,2);
break;
}
switch(VRMap[VR])
{
case VR_SQ:
FirstObj();
while(currentObj)
{
currentObj->Write(f);
if(!IncrObjPtr())
break;
}
if(Length == 0xFFFFFFFF)
{
f.write((char*)SQEndTag, 4);
f.put(0);
f.put(0);
f.put(0);
f.put(0);
}
break;
default:
if(Length)
f.write(Value,Length);
break;
}
}
// Returns the actual size of the element when written to a file,
// including all tags. SQs with unspecified lengths have to be added up
// but SQs with specified lengths return the stored Length. If an
// underlying data structure has changed, CheckLength should be called
// first on the RootDicomObject to ensure that the value stored in the
// Length fields of the SQ elements are correct
unsigned long DataElement::GetSize()
{
unsigned long Size = 0;
switch(VRMap[VR])
{
case VR_OB: // if VR is OB, OW, OF, SQ, UT, or UN, skip two bytes, then read 4 byte length
case VR_OW:
case VR_OF:
case VR_UT:
case VR_UN:
return Length + 12;
case VR_SQ:
if(Length == 0xFFFFFFFF)
{
// read the size of the underlying elements
FirstObj();
while(currentObj)
{
Size += currentObj->GetSize();
if(!IncrObjPtr())
break;
}
return Size + 20;
}
else
return Length + 12;
default:
return Length + 8;
}
}
// copies the contents of the Value field into buffer
// returns Length (number of bytes copied)
unsigned long DataElement::GetValue(void* buffer, unsigned long buf_size)
{
if (VRMap[VR] == VR_SQ) // SQ data isn't stored in value
return -1;
if (buf_size < Length)
return 0;
memcpy(buffer, Value, Length);
return Length;
}
// modifies the contents of the Value field (and sometimes the Length)
// returns 0 if sucessful, -1 otherwise
int DataElement::Modify(void* newVal, unsigned long newLen)
{
if(Length == newLen)
{
memcpy(Value, newVal, newLen);
return 0;
}
else
{
delete Value;
Length = newLen + (newLen % 2); // pad to an even number of bytes if necessary
Value = new char[Length];
if(Value)
{
memcpy(Value, newVal, newLen); // copy data
if(newLen%2) // pad if needed
{
switch(VRMap[VR])
{
case VR_AE:
case VR_AS:
case VR_CS:
case VR_DA:
case VR_DS:
case VR_DT:
case VR_IS:
case VR_LO:
case VR_LT:
case VR_PN:
case VR_SH:
case VR_ST:
case VR_UT:
Value[newLen] = 0x20;
break;
default:
Value[newLen] = 0;
}
}
}
else
return -1; // unable to allocate memory for Value
}
return 0;
}
// Checks the lengths of the SQ DataElements by
// adding up the lengths of the underlying
// returns 1 if a length had to be fixed, 0 otherwise
// Does nothing if the DataElement isn't an SQ
int DataElement::CheckLength()
{
unsigned long Size = 0;
int changes = 0;
// verifies the lengths of SQ objects
if(VRMap[VR]==VR_SQ)
{
// call CheckLength on all underlying objects
FirstObj();
while(currentObj)
{
changes += currentObj->CheckLength(); // called on all DicomObj under the SQ DataElement
if(!IncrObjPtr())
break;
}
if(Length==0xFFFFFFFF)
return changes; // don't modify the length field if the length is undefined
// verify the length by adding up the lengths of nested DicomObjects
FirstObj();
while(currentObj)
{
Size += currentObj->GetSize(); // called on DicomObjects
if(!IncrObjPtr())
break;
}
if(Size != Length)
{
// cout << "Updating length of (" << hex << Group << "," << hex << Element << ")" << endl;
Length = Size;
changes++;
}
}
return changes;
}
int DataElement::SetObject(HDLListObj * newObj)
{
if(VRMap[VR] != VR_SQ)
return -1; // objects can only be inserted into SQ elements
AddObj(newObj);
return 0;
}
// checks that the data element is valid
// returns 0 if OK, -1 if there is an error
int DataElement::Validate()
{
int i;
int len;
int VM = 0; // value multiplicity
char* data;
char* pch;
bool invalid_data = false;
switch(VRMap[VR])
{
case VR_AE:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>16)
invalid_data = true;
while(pch[len-1]==' ') // trim trailing spaces
len--;
i=0;
while(pch[i]==' ') // trim leading spaces
i++;
// check for invalid characters
for(;i<len;i++)
if(pch[i]<' ' || pch[i]>'~')
invalid_data = true;
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_AS:
VM = 1;
if(Length!=4)
return -1;
for(i=0;i<3;i++)
if(Value[i]<'0' || Value[i]>'9')
invalid_data = true;
if(!(Value[3]=='D' || Value[3]=='W' || Value[3]=='M' || Value[3]=='Y'))
invalid_data = true;
break;
case VR_AT:
if(Length%4)
invalid_data = true;
VM = Length/4;
break;
case VR_CS:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>16)
invalid_data = true;
while(pch[len-1]==' ') // trim trailing spaces
len--;
i=0;
while(pch[i]==' ') // trim leading spaces
i++;
// check for invalid characters
for(;i<len;i++)
{
if(pch[i]==' ' || pch[i]=='_')
continue;
if(pch[i]>='0' && pch[i]<='9')
continue;
if(pch[i]>='A' && pch[i]<='Z')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_DA:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if((len!=8) && (len!=10))
invalid_data = true;
// check for invalid characters
while(pch[len-1]==' ') // trim trailing spaces
len--;
for(i=0;i<len;i++)
{
if(pch[i]>='0' && pch[i]<='9')
continue;
if(pch[i]=='.')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_DS:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>16)
invalid_data = true;
// check for invalid characters
while(pch[len-1]==' ') // trim trailing spaces
len--;
i=0;
while(pch[i]==' ') // trim leading spaces
i++;
for(;i<len;i++)
{
if(pch[i]>='0' && pch[i]<='9')
continue;
if(pch[i]=='.' || pch[i]=='+' || pch[i]=='-')
continue;
if(pch[i]=='e' || pch[i]=='E')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_DT:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>26)
invalid_data = true;
while(pch[len-1]==' ') // trim trailing spaces
len--;
for(i=0;i<len;i++)
{
if(pch[i]>='0' && pch[i]<='9')
continue;
if(pch[i]=='.' || pch[i]=='+' || pch[i]=='-')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_FL:
if(Length%4)
invalid_data = true;
VM = Length/4;
break;
case VR_FD:
if(Length%8)
invalid_data = true;
VM = Length/8;
break;
case VR_IS:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>12)
invalid_data = true;
// check for invalid characters
while(pch[len-1]==' ') // trim trailing spaces
len--;
i=0;
while(pch[i]==' ') // trim leading spaces
i++;
for(;i<len;i++)
{
if(pch[i]>='0' && pch[i]<='9')
continue;
if(pch[i]=='+' || pch[i]=='-')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_LO:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>64)
invalid_data = true;
// check for invalid characters
for(i=0;i<len;i++)
{
if(pch[i]>=' ' && pch[i]<='~')
continue;
if(pch[i]=='\x1b')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_LT: // this validation doesn't support extended character sets
VM=1;
if(Length>10240)
invalid_data = true;
for(i=0;i<int(Length);i++)
{
if(Value[i]>=' ' && Value[i]<='~')
continue;
if(Value[i]=='\x0a' || Value[i]=='\x0c' || Value[i]=='\x0d' || Value[i]=='\x1b')
continue;
invalid_data = true;
}
break;
case VR_OB:
case VR_OF:
case VR_OW:
break;
case VR_PN:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>64)
invalid_data = true;
while(pch[len-1]==' ') // trim trailing spaces
len--;
// check for invalid characters
for(i=0;i<len;i++)
{
if(pch[i]>=' ' && pch[i]<='~')
continue;
if(pch[i]=='\x1b')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_SH:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>16)
invalid_data = true;
// check for invalid characters
for(i=0;i<len;i++)
{
if(pch[i]>=' ' && pch[i]<='~')
continue;
if(pch[i]=='\x1b')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_SL:
if(Length%4)
invalid_data = true;
VM = Length/4;
break;
case VR_SQ:
// call validate on each object in the sequence
FirstObj();
while(currentObj)
{
if(currentObj->Validate()==-1)
invalid_data = true;
if(!IncrObjPtr())
break;
}
break;
case VR_SS:
if(Length%2)
invalid_data = true;
VM = Length/2;
break;
case VR_ST: // this validation doesn't support extended character sets
VM=1;
if(Length>1024)
invalid_data = true;
for(i=0;i<int(Length);i++)
{
if(Value[i]>=' ' && Value[i]<='~')
continue;
if(Value[i]=='\x0a' || Value[i]=='\x0c' || Value[i]=='\x0d' || Value[i]=='\x1b')
continue;
invalid_data = true;
}
break;
case VR_TM:
data = new char[Length+2];
strncpy(data,Value,Length);
data[Length] = 0;
pch = strtok(data,"\\");
while(pch!=NULL)
{
len = strlen(pch);
// check length
if(len>16)
invalid_data = true;
while(pch[len-1]==' ') // trim trailing spaces
len--;
// check for invalid characters
for(i=0;i<len;i++)
{
if(pch[i]>='0' && pch[i]<='9')
continue;
if(pch[i]=='.')
continue;
invalid_data = true;
}
pch = strtok(NULL,"\\");
VM++;
}
delete [] data;
break;
case VR_UI: