1 /*=========================================================================
4 Module: $RCSfile: exCurveData.cxx,v $
6 Date: $Date: 2005/10/10 20:02:09 $
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 =========================================================================*/
19 #include "gdcmFileHelper.h"
20 #include "gdcmCommon.h"
21 #include "gdcmDebug.h"
22 #include "gdcmDocEntry.h"
23 #include "gdcmBinEntry.h"
26 template<class DataValueRepresentation>
27 inline size_t PrintCurveData(DataValueRepresentation* data, unsigned short numPts)
29 for(unsigned int i=0; i<numPts;++i)
31 std::cout << "Pt(" << i << ") = " << data[i] << std::endl;
34 // ok this is ugly but I need the size outside of the function
35 return sizeof(DataValueRepresentation);
39 // Example (sorry, we've got no more than this one ...)
40 * V 5004|0000 [UL] [Group Length] [1998] x(7ce)
41 * V 5004|0005 [US] [Curve Dimensions] [1] x(1)
42 * V 5004|0010 [US] [Number of Points] [969] x(3c9)
43 * V 5004|0020 [CS] [Type of Data] [PHYSIO]
44 * V 5004|0022 [LO] [Curve Description] []
45 * V 5004|0103 [US] [Data Value Representation] [0] x(0)
46 * B 5004|3000 [OW] [Curve Data] [gdcm::Binary data loaded;length = 1938]
49 int main(int argc, char *argv[])
53 std::cout << "------------------------------------------------" << std::endl;
54 std::cout << "Gets the 'Curve Data' from a full gdcm-readable DICOM " << std::endl;
55 std::cout << "(Note : we just have ONE image : "
56 << "GE_DLX-8-MONO2-Multiframe.dcm"
58 std::cout << "------------------------------------------------" << std::endl;
64 fileName = "GE_DLX-8-MONO2-Multiframe.dcm";
66 std::cout << fileName << std::endl;
67 // ============================================================
68 // Read the input image.
69 // ============================================================
71 f = new gdcm::File( );
73 f->SetLoadMode(gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW);
74 f->SetFileName( fileName );
77 if( gdcm::Debug::GetDebugFlag() )
79 std::cout << "---------------------------------------------" << std::endl;
81 std::cout << "---------------------------------------------" << std::endl;
84 std::cout << "Sorry, " << fileName <<" not a gdcm-readable "
90 std::cout << " ... is readable " << std::endl;
92 // ============================================================
93 // Check whether image contains Overlays ACR-NEMA style.
94 // ============================================================
96 //* B 5004|3000 [OW] [Curve Data] [gdcm::Binary data loaded;length = 1938]
97 std::string curve_data_str = f->GetEntryValue(0x5004, 0x3000);
98 if (curve_data_str == gdcm::GDCM_UNFOUND)
100 std::cout << " Image doesn't contain any Curve Data" << std::endl;
104 std::cout << " File is read! " << std::endl;
107 // ============================================================
108 // Load the Curve Data in memory.
109 // ============================================================
110 std::istringstream convert;
111 //* V 5004|0005 [US] [Curve Dimensions] [1] x(1)
112 std::string curve_dim_str = f->GetEntryValue(0x5004,0x0005);
113 unsigned short curve_dim;
114 convert.str(curve_dim_str);
115 convert >> curve_dim;
116 std::cout << "Curve Dimensions: " << curve_dim << std::endl;
117 //* V 5004|0010 [US] [Number of Points] [969] x(3c9)
118 std::string num_points_str = f->GetEntryValue(0x5004,0x0010);
119 unsigned short num_points;
120 convert.clear(); //important
121 convert.str(num_points_str);
122 convert >> num_points;
123 std::cout << "Number of Points: " << num_points << std::endl;
124 //* V 5004|0020 [CS] [Type of Data] [PHYSIO]
125 std::string data_type = f->GetEntryValue(0x5004,0x0020);
126 std::cout << "Type of Data: " << data_type << std::endl;
127 //* V 5004|0022 [LO] [Curve Description] []
128 std::string curve_desc = f->GetEntryValue(0x5004,0x0022);
129 std::cout << "Curve Description: " << curve_desc << std::endl;
130 //* V 5004|0103 [US] [Data Value Representation] [0] x(0)
131 std::string data_rep_str = f->GetEntryValue(0x5004,0x0103);
132 unsigned short data_rep;
133 convert.clear(); //important
134 convert.str(data_rep_str);
138 gdcm::DocEntry *pCurveDataDoc = f->GetDocEntry(0x5004, 0x3000);
139 gdcm::BinEntry *pCurveData = dynamic_cast<gdcm::BinEntry*>(pCurveDataDoc);
140 uint8_t *curve_data = pCurveData->GetBinArea();
142 // From Part3, C.10.2.1.2 Data value representation (p668)
147 sz = PrintCurveData((unsigned short*)(curve_data), num_points);
150 sz = PrintCurveData((signed short*)(curve_data), num_points);
153 sz = PrintCurveData((float*)(curve_data), num_points);
156 sz = PrintCurveData((double*)(curve_data), num_points);
159 sz = PrintCurveData((signed long*)(curve_data), num_points);
162 std::cerr << "Error don't know the type: " << data_rep_str << std::endl;
166 // Just to make sure that values read are consistant and we won't read out of bound data:
167 assert( sz*num_points == pCurveData->GetLength());
169 // Write out the data as a file:
170 //std::ofstream o("/tmp/curve_data.raw");
171 //o.write((char*)curve_data, num_points*sz);