1 /*=========================================================================
2
3 Program: GDCM (Grassroots DICOM). A DICOM library
4
5 Copyright (c) 2006-2011 Mathieu Malaterre
6 All rights reserved.
7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14 #include "gdcmReader.h"
15 #include "gdcmWriter.h"
16 #include "gdcmFile.h"
17 #include "gdcmOrientation.h"
18 #include "gdcmAttribute.h"
19
20 // Very simple orientation changer, fix invalid dataset
main(int argc,char * argv[])21 int main(int argc, char* argv[] )
22 {
23 // assume AXIAL input for now
24 if( argc < 3 )
25 {
26 std::cerr << argv[0] << " input.dcm output.dcm" << std::endl;
27 return 1;
28 }
29 const char *filename = argv[1];
30 const char *outfilename = argv[2];
31
32 gdcm::Reader reader;
33 reader.SetFileName( filename );
34 if (! reader.Read() )
35 {
36 return 1;
37 }
38
39 const double axial[] = { 1,0,0, 0,1,0 };
40 (void)axial;
41 const double coronal[] = { 0,0,1, 1,0,0 };
42 (void)coronal;
43 const double sagittal[] = { 0,1,0, 0,0,1 };
44 (void)sagittal;
45 gdcm::Attribute<0x0020,0x0032> at1; // IPP
46 (void)at1;
47 gdcm::Attribute<0x0020,0x0037> at2; // IOP
48 (void)at2;
49
50 gdcm::File & f = reader.GetFile();
51 gdcm::DataSet & ds = f.GetDataSet();
52 at1.SetFromDataSet( ds );
53 #if 0
54 at2.SetFromDataSet( ds );
55 const double * iop = at2.GetValues();
56 if( !std::equal(iop, iop + 6, axial ) )
57 {
58 gdcm::Orientation::OrientationType type = gdcm::Orientation::GetType ( iop );
59 std::cerr << "Wrong orientation: " << gdcm::Orientation::GetLabel( type ) << std::endl;
60 return 1;
61 }
62 at2.SetValues( sagittal );
63 ds.Replace( at2.GetAsDataElement() );
64 #endif
65
66 // for sagittal: swap element 0 & 2
67 const double tmp0 = at1.GetValue(0);
68 const double tmp2 = at1.GetValue(2);
69 (void)tmp2;
70 //at1.SetValue(tmp2, 0);
71 //at1.SetValue(tmp0, 2);
72 at1.SetValue( - tmp0 );
73 ds.Replace( at1.GetAsDataElement() );
74
75 gdcm::Writer writer;
76 writer.SetFile( f );
77 writer.SetFileName( outfilename );
78 if ( !writer.Write() )
79 {
80 return 1;
81 }
82
83 return 0;
84 }
85