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 "gdcmFileStreamer.h" 15 #include "gdcmTag.h" 16 #include "gdcmTrace.h" 17 #include "gdcmImageRegionReader.h" 18 #include "gdcmImageHelper.h" 19 #include "gdcmWriter.h" 20 #include "gdcmImageWriter.h" 21 #include "gdcmTagKeywords.h" 22 #include "gdcmUIDGenerator.h" 23 main(int argc,char * argv[])24int main(int argc, char *argv[]) 25 { 26 if( argc < 2 ) return 1; 27 const char * filename = argv[1]; 28 gdcm::ImageRegionReader irr; 29 irr.SetFileName( filename ); 30 const bool b3 = irr.ReadInformation(); 31 std::cout << b3 << std::endl; 32 gdcm::Image & img = irr.GetImage(); 33 std::cout << img << std::endl; 34 // const gdcm::Region & r = irr.GetRegion(); 35 // std::cout << r << std::endl; 36 gdcm::ImageWriter w; 37 gdcm::File & file = w.GetFile(); 38 gdcm::DataSet & ds = file.GetDataSet(); 39 40 gdcm::UIDGenerator uid; 41 namespace kwd = gdcm::Keywords; 42 kwd::FrameOfReferenceUID frameref; 43 frameref.SetValue( uid.Generate() ); 44 // ContentDate 45 char date[22]; 46 const size_t datelen = 8; 47 int res = gdcm::System::GetCurrentDateTime(date); 48 (void)res; 49 kwd::ContentDate contentdate; 50 // Do not copy the whole cstring: 51 contentdate.SetValue( gdcm::DAComp( date, datelen ) ); 52 ds.Insert( contentdate.GetAsDataElement() ); 53 // ContentTime 54 const size_t timelen = 6 + 1 + 6; // time + milliseconds 55 kwd::ContentTime contenttime; 56 // Do not copy the whole cstring: 57 contenttime.SetValue( gdcm::TMComp(date+datelen, timelen) ); 58 ds.Insert( contenttime.GetAsDataElement() ); 59 60 gdcm::MediaStorage ms0 = w.ComputeTargetMediaStorage(); 61 std::cout << ms0 << std::endl; 62 kwd::SeriesNumber seriesnumber = { 1 }; 63 kwd::InstanceNumber instancenum = { 1 }; 64 kwd::StudyID studyid = { "St1" }; 65 kwd::PatientID patientid = { "P1" }; 66 kwd::SOPClassUID sopclassuid; 67 kwd::PositionReferenceIndicator pri; 68 //kwd::Laterality lat; 69 //kwd::BodyPartExamined bodypartex = { "HEAD" }; 70 kwd::BodyPartExamined bodypartex = { "ANKLE" }; 71 kwd::PatientOrientation pator; 72 kwd::BurnedInAnnotation bia = { "NO" }; 73 kwd::ConversionType convtype = { "SYN" }; 74 kwd::PresentationLUTShape plutshape = { "IDENTITY" }; // MONOCHROME2 75 // gdcm will pick the Word in case Byte class is not compatible: 76 gdcm::MediaStorage ms = gdcm::MediaStorage::MultiframeGrayscaleByteSecondaryCaptureImageStorage; 77 sopclassuid.SetValue( ms.GetString() ); 78 ds.Insert( instancenum.GetAsDataElement() ); 79 ds.Insert( sopclassuid.GetAsDataElement() ); 80 ds.Insert( seriesnumber.GetAsDataElement() ); 81 ds.Insert( patientid.GetAsDataElement() ); 82 ds.Insert( studyid.GetAsDataElement() ); 83 ds.Insert( frameref.GetAsDataElement() ); 84 ds.Insert( pri.GetAsDataElement() ); 85 //ds.Insert( lat.GetAsDataElement() ); 86 ds.Insert( bodypartex.GetAsDataElement() ); 87 ds.Insert( pator.GetAsDataElement() ); 88 ds.Insert( bia.GetAsDataElement() ); 89 ds.Insert( convtype.GetAsDataElement() ); 90 ds.Insert( plutshape.GetAsDataElement() ); 91 // gdcm::MediaStorage ms1 = w.ComputeTargetMediaStorage(); 92 // std::cout << ms1 << std::endl; 93 std::cout << ds << std::endl; 94 gdcm::PixelFormat & pf = img.GetPixelFormat(); 95 pf.SetPixelRepresentation(0); // always overwrite 96 img.SetSlope(1); 97 img.SetIntercept(0); 98 w.SetImage( img ); 99 w.SetFileName( "TemplateImage.dcm" ); 100 if( !w.Write() ) 101 { 102 return 1; 103 } 104 105 return 0; 106 } 107 108