]> Creatis software - gdcm.git/blob - Testing/TestMakeIcon.cxx
Fix mistypings
[gdcm.git] / Testing / TestMakeIcon.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: TestMakeIcon.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/08/29 15:56:41 $
7   Version:   $Revision: 1.14 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 #include "gdcmDebug.h"
19 #include "gdcmGlobal.h"
20 #include "gdcmCommon.h"
21 #include "gdcmFile.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmDataEntry.h"
24 #include "gdcmSeqEntry.h"
25 #include "gdcmSQItem.h"
26
27 // 0088 0200 SQ 1 Icon Image Sequence 
28
29 int TestMakeIcon (int argc, char *argv[])
30 {
31    // hard coded small image name
32    std::string input = GDCM_DATA_ROOT;
33    input += "/"; 
34    input += "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
35
36    std::string output = "testIcon.dcm";
37
38    GDCM_NAME_SPACE::Debug::DebugOn();
39
40    if ( argc == 3 )
41    {
42       input  = argv[1];
43       output = argv[2];
44    }
45    else if ( argc < 3  )
46    {
47       std::cout << "   Usage: " << argv[0]
48                 << " input filename.dcm output Filename.dcm" << std::endl;
49    }
50
51    GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New( );
52    f->SetFileName( input );
53    f->Load( );
54
55    if ( ! f->IsReadable() )
56    {
57       std::cout << " Failed to Open/Parse file" << input << std::endl;
58       f->Delete();
59       return 1;
60    }  
61    GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f); 
62    uint8_t *pixels = fh->GetImageData();
63    uint32_t lgth   = fh->GetImageDataSize();
64
65    GDCM_NAME_SPACE::SeqEntry *icon = f->InsertSeqEntry(0x0088, 0x0200);
66    GDCM_NAME_SPACE::SQItem *sqi = GDCM_NAME_SPACE::SQItem::New(1);
67    icon->AddSQItem(sqi, 1);
68    sqi->Delete();
69
70    // icone is just defined like the image
71    // The purpose is NOT to imagine an icon, 
72    // just check the stuff works
73
74    uint16_t binVal[3]={0x52f7,0xf358,0xad9b};
75  
76    sqi->InsertEntryString( "MONOCHROME2", 0x0028,0x0004, "CS");
77    sqi->InsertEntryString( "128", 0x0028,0x0010, "US");
78    sqi->InsertEntryString( "8",   0x0028,0x0100, "US");
79    sqi->InsertEntryString( "8",   0x0028,0x0101, "US");
80    sqi->InsertEntryString( "7",   0x0028,0x0102, "US");
81    sqi->InsertEntryString( "0",   0x0028,0x0103, "US");
82    sqi->InsertEntryBinArea(  (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OB");
83    sqi->InsertEntryBinArea(  pixels, lgth, 0x7fe0,0x0010,"OB");
84    // just to see if it's stored a the right place
85    sqi->InsertEntryString( "128", 0x0028,0x0011, "US");
86     
87    fh->WriteDcmExplVR(output);
88
89    f->Delete();
90    fh->Delete();
91
92    f = GDCM_NAME_SPACE::File::New();
93    f->SetFileName(output);
94    f->Load();
95    f->Print();
96    std::cout << "End of Print" << std::endl;
97
98    icon = f->GetSeqEntry(0x0088, 0x0200);
99    if (!icon)
100    {
101       std::cout << "Sequence 0088|0200 not found" << std::endl
102                 << "   ... Failed" << std::endl;
103       f->Delete();
104       return 1;
105    }
106    std::cout << "Sequence 0088|0200 found" << std::endl;
107    
108    sqi = icon->GetFirstSQItem();
109
110    if ( !sqi )
111    {
112       std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
113                 << "   ... Failed" << std::endl;
114       f->Delete();
115       return 1;
116    }
117
118    std::cout << "First Item found" << std::endl;
119
120    // Test for entry 0028|0010
121    if ( !sqi->GetDataEntry(0x0028,0x0010) )
122    {
123       std::cout << "GetDataEntry 0028|0010 not found" << std::endl
124                 << "   ... Failed" << std::endl;
125       f->Delete();
126       return 1;
127    }
128    std::cout << "First Item ->DataEntry 0028|0010 found" << std::endl;
129    if ( sqi->GetDataEntry(0x0028,0x0010)->GetString() != "128" )
130    {
131       std::cout << "Value 0028|0010 don't match" << std::endl
132                 << "Read : " << sqi->GetDataEntry(0x0028,0x0010)->GetString()
133                 << " - Expected : 128" << std::endl
134                 << "   ... Failed" << std::endl;
135       f->Delete();
136       return 1;
137    }
138
139    // Test for entry 0028|0011
140    if ( !sqi->GetDataEntry(0x0028,0x0011) )
141    {
142       std::cout << "GetDataEntry 0028|0011 not found" << std::endl
143                 << "   ... Failed" << std::endl;
144       f->Delete();
145       return 1;
146    }
147    std::cout << "First Item ->DataEntry 0028|0011 found" << std::endl;
148    if ( sqi->GetDataEntry(0x0028,0x0011)->GetString() != "128" )
149    {
150       std::cout << "Value 0028|0011 don't match" << std::endl
151                 << "Read : " << sqi->GetDataEntry(0x0028,0x0011)->GetString()
152                 << " - Expected : 128" << std::endl
153                 << "   ... Failed" << std::endl;
154       f->Delete();
155       return 1;
156    }
157
158    // Test for entry 0028|0100
159    if ( !sqi->GetDataEntry(0x0028,0x0100) )
160    {
161       std::cout << "GetDataEntry 0028|0100 not found" << std::endl
162                 << "   ... Failed" << std::endl;
163       f->Delete();
164       return 1;
165    }
166    std::cout << "First Item ->DataEntry 0028|0100 found" << std::endl;
167    if ( sqi->GetDataEntry(0x0028,0x0100)->GetString() != "8" )
168    {
169       std::cout << "Value 0028|0100 don't match" << std::endl
170                 << "Read : " << sqi->GetDataEntry(0x0028,0x0100)->GetString()
171                 << " - Expected : 8" << std::endl
172                 << "   ... Failed" << std::endl;
173       f->Delete();
174       return 1;
175    }
176
177    // Test for entry 0028|0101
178    if ( !sqi->GetDataEntry(0x0028,0x0101) )
179    {
180       std::cout << "GetDataEntry 0028|0101 not found" << std::endl
181                 << "   ... Failed" << std::endl;
182       f->Delete();
183       return 1;
184    }
185    std::cout << "First Item ->DataEntry 0028|0101 found" << std::endl;
186    if ( sqi->GetDataEntry(0x0028,0x0101)->GetString() != "8" )
187    {
188       std::cout << "Value 0028|0101 don't match" << std::endl
189                 << "Read : " << sqi->GetDataEntry(0x0028,0x0101)->GetString()
190                 << " - Expected : 8" << std::endl
191                 << "   ... Failed" << std::endl;
192       f->Delete();
193       return 1;
194    }
195
196    // Test for entry 0028|0102
197    if ( !sqi->GetDataEntry(0x0028,0x0102) )
198    {
199       std::cout << "DataEntry 0028|0102 not found" << std::endl
200                 << "   ... Failed" << std::endl;
201       f->Delete();
202       return 1;
203    }
204    std::cout << "First Item ->DataEntry 0028|0102 found" << std::endl;
205    if ( sqi->GetDataEntry(0x0028,0x0102)->GetString() != "7" )
206    {
207       std::cout << "Value 0028|0102 don't match" << std::endl
208                 << "Read : " << sqi->GetDataEntry(0x0028,0x0102)->GetString()
209                 << " - Expected : 7" << std::endl
210                 << "   ... Failed" << std::endl;
211       f->Delete();
212       return 1;
213    }
214
215    // Test for entry 0028|0103
216    if ( !sqi->GetDataEntry(0x0028,0x0103) )
217    {
218       std::cout << "GetDataEntry 0028|0010 not found" << std::endl
219                 << "   ... Failed" << std::endl;
220       f->Delete();
221       return 1;
222    }
223    std::cout << "First Item ->DataEntry 0028|0103 found" << std::endl;
224    if ( sqi->GetDataEntry(0x0028,0x0103)->GetString() != "0" )
225    {
226       std::cout << "Value 0028|0103 don't match" << std::endl
227                 << "Read : " << sqi->GetDataEntry(0x0028,0x0103)->GetString()
228                 << " - Expected : 0" << std::endl
229                 << "   ... Failed" << std::endl;
230       f->Delete();
231       return 1;
232    }
233
234    // Test for entry 0005|0010
235    if ( !sqi->GetDataEntry(0x0005,0x0010) )
236    {
237       std::cout << "GetDataEntry 0005|0010 not found" << std::endl
238                 << "   ... Failed" << std::endl;
239       f->Delete();
240       return 1;
241    }
242    std::cout << "First Item ->GetDataEntry 0005|0010 found" << std::endl;
243    if( sqi->GetDataEntry(0x0005,0x0010)->GetLength() != 6 )
244    {
245       std::cout << "GetDataEntry size 0005|0010 don't match" << std::endl
246                 << "Read : " << sqi->GetDataEntry(0x0005,0x0010)->GetLength()
247                 << " - Expected : 6" << std::endl
248                 << "   ... Failed" << std::endl;
249       f->Delete();
250       return 1;
251    }
252
253    std::cout << "Length GetDataEntry 0005|0010 OK" << std::endl;
254
255    if( memcmp(sqi->GetDataEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 )
256    {
257       std::cout << "Value 0005|0010 don't match (DataEntry)" << std::endl
258                 << "   ... Failed" << std::endl;
259       f->Delete();
260       return 1;
261    }
262    std::cout << "Value DataEntry 0005|0010 OK" << std::endl;
263
264    f->Delete();
265    std::cout << "   ... OK" << std::endl;
266
267    return 0;
268 }