1 /*=========================================================================
4 Module: $RCSfile: exMakeIcon.cxx,v $
6 Date: $Date: 2007/08/29 16:26:05 $
7 Version: $Revision: 1.1 $
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.
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.
17 =========================================================================*/
18 #include "gdcmDebug.h"
19 #include "gdcmGlobal.h"
20 #include "gdcmCommon.h"
22 #include "gdcmFileHelper.h"
23 #include "gdcmDataEntry.h"
24 #include "gdcmSeqEntry.h"
25 #include "gdcmSQItem.h"
27 // 0088 0200 SQ 1 Icon Image Sequence
29 int main (int argc, char *argv[])
31 // hard coded small image name
32 std::string input = GDCM_DATA_ROOT;
34 input += "LIBIDO-8-ACR_NEMA-Lena_128_128.acr";
36 std::string output = "/tmp/testIcon.dcm";
38 GDCM_NAME_SPACE::Debug::DebugOn();
47 std::cout << " Usage: " << argv[0]
48 << " input filename.dcm output Filename.dcm" << std::endl;
51 GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New( );
52 f->SetFileName( input );
55 if ( ! f->IsReadable() )
57 std::cout << " Failed to Open/Parse file" << input << std::endl;
61 GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
62 uint8_t *pixels = fh->GetImageData();
63 uint32_t lgth = fh->GetImageDataSize();
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);
70 // icone is just defined like the image
71 // The purpose is NOT to imagine an icon,
72 // just check the stuff works
74 sqi->InsertEntryString( "MONOCHROME2", 0x0028,0x0004, "CS");
75 sqi->InsertEntryString( "128", 0x0028,0x0010, "US");
76 sqi->InsertEntryString( "8", 0x0028,0x0100, "US");
77 sqi->InsertEntryString( "8", 0x0028,0x0101, "US");
78 sqi->InsertEntryString( "7", 0x0028,0x0102, "US");
79 sqi->InsertEntryString( "0", 0x0028,0x0103, "US");
80 sqi->InsertEntryBinArea( pixels, lgth, 0x7fe0,0x0010,"OB");
81 // just to see if it's stored at the right place
82 sqi->InsertEntryString( "128", 0x0028,0x0011, "US");
84 fh->WriteDcmExplVR(output);
89 f = GDCM_NAME_SPACE::File::New();
90 f->SetFileName(output);
93 std::cout << "End of Print" << std::endl;
96 // ---------- Check everything is OK in the written image:
98 icon = f->GetSeqEntry(0x0088, 0x0200);
101 std::cout << "Sequence 0088|0200 not found" << std::endl
102 << " ... Failed" << std::endl;
106 std::cout << "Sequence 0088|0200 found" << std::endl;
108 sqi = icon->GetFirstSQItem();
112 std::cout << "Sequence 0088|0200 has no SQItem" << std::endl
113 << " ... Failed" << std::endl;
118 std::cout << "First Item found" << std::endl;
120 // Test for entry 0028|0010
121 if ( !sqi->GetDataEntry(0x0028,0x0010) )
123 std::cout << "GetDataEntry 0028|0010 not found" << std::endl
124 << " ... Failed" << std::endl;
128 std::cout << "First Item ->DataEntry 0028|0010 found" << std::endl;
129 if ( sqi->GetDataEntry(0x0028,0x0010)->GetString() != "128" )
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;
139 // Test for entry 0028|0011
140 if ( !sqi->GetDataEntry(0x0028,0x0011) )
142 std::cout << "GetDataEntry 0028|0011 not found" << std::endl
143 << " ... Failed" << std::endl;
147 std::cout << "First Item ->DataEntry 0028|0011 found" << std::endl;
148 if ( sqi->GetDataEntry(0x0028,0x0011)->GetString() != "128" )
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;
158 // Test for entry 0028|0100
159 if ( !sqi->GetDataEntry(0x0028,0x0100) )
161 std::cout << "GetDataEntry 0028|0100 not found" << std::endl
162 << " ... Failed" << std::endl;
166 std::cout << "First Item ->DataEntry 0028|0100 found" << std::endl;
167 if ( sqi->GetDataEntry(0x0028,0x0100)->GetString() != "8" )
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;
177 // Test for entry 0028|0101
178 if ( !sqi->GetDataEntry(0x0028,0x0101) )
180 std::cout << "GetDataEntry 0028|0101 not found" << std::endl
181 << " ... Failed" << std::endl;
185 std::cout << "First Item ->DataEntry 0028|0101 found" << std::endl;
186 if ( sqi->GetDataEntry(0x0028,0x0101)->GetString() != "8" )
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;
196 // Test for entry 0028|0102
197 if ( !sqi->GetDataEntry(0x0028,0x0102) )
199 std::cout << "DataEntry 0028|0102 not found" << std::endl
200 << " ... Failed" << std::endl;
204 std::cout << "First Item ->DataEntry 0028|0102 found" << std::endl;
205 if ( sqi->GetDataEntry(0x0028,0x0102)->GetString() != "7" )
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;
215 // Test for entry 0028|0103
216 if ( !sqi->GetDataEntry(0x0028,0x0103) )
218 std::cout << "GetDataEntry 0028|0010 not found" << std::endl
219 << " ... Failed" << std::endl;
223 std::cout << "First Item ->DataEntry 0028|0103 found" << std::endl;
224 if ( sqi->GetDataEntry(0x0028,0x0103)->GetString() != "0" )
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;
234 // ---------- End of checking