1 /*=========================================================================
4 Module: $RCSfile: exCurveData.cxx,v $
6 Date: $Date: 2008/03/10 13:12:09 $
7 Version: $Revision: 1.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.
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 "gdcmDataEntry.h"
25 static const char* TypeOfDataArrays[13][2] = {
26 { "TAC" , "time activity curve" },
27 { "PROF" , "image profile" },
28 { "HIST" , "histogram" },
29 { "ROI" , "polygraphic region of interest" },
30 { "TABL" , "table of values" },
31 { "FILT" , "filter kernel" },
32 { "POLY" , "poly line" },
33 { "ECG" , "ecg data" },
34 { "PRESSURE" , "pressure data" },
35 { "FLOW" , "flow data" },
36 { "PHYSIO" , "physio data" },
37 { "RESP" , "Respiration trace" },
41 // Part 3, C.10.2.1.1 Type of data
42 // Convert from acronym to full description
43 const char *ConvertTypeOfData(std::string const &type)
45 const char **p = *TypeOfDataArrays;
48 if( p[0] == type ) // std::string== operator
59 template<class DataValueRepresentation>
60 inline size_t PrintCurveData(DataValueRepresentation* data, unsigned short numPts)
62 for(unsigned int i=0; i<numPts;++i)
64 std::cout << "Pt(" << i << ") = " << data[i] << std::endl;
67 // ok this is ugly but I need the size outside of the function
68 return sizeof(DataValueRepresentation);
71 template <int datarep> struct DataRepToType;
72 template<> struct DataRepToType<0> { typedef unsigned short Type; };
73 template<> struct DataRepToType<1> { typedef signed short Type; };
74 template<> struct DataRepToType<2> { typedef float Type; };
75 template<> struct DataRepToType<3> { typedef double Type; };
76 template<> struct DataRepToType<4> { typedef signed long Type; };
79 // Example (sorry, we've got no more than this one ...)
80 * V 5004|0000 [UL] [Group Length] [1998] x(7ce)
81 * V 5004|0005 [US] [Curve Dimensions] [1] x(1)
82 * V 5004|0010 [US] [Number of Points] [969] x(3c9)
83 * V 5004|0020 [CS] [Type of Data] [PHYSIO]
84 * V 5004|0022 [LO] [Curve Description] []
85 * V 5004|0103 [US] [Data Value Representation] [0] x(0)
86 * B 5004|3000 [OW] [Curve Data] [GDCM_NAME_SPACE::Binary data loaded;length = 1938]
89 int main(int argc, char *argv[])
91 GDCM_NAME_SPACE::File *f;
93 std::cout << "------------------------------------------------" << std::endl;
94 std::cout << "Gets the 'Curve Data' from a full gdcm-readable DICOM " << std::endl;
95 std::cout << "(Note : we just have ONE image : "
96 << "GE_DLX-8-MONO2-Multiframe.dcm"
98 std::cout << "------------------------------------------------" << std::endl;
100 std::string fileName;
104 fileName = "GE_DLX-8-MONO2-Multiframe.dcm";
106 std::cout << fileName << std::endl;
107 // ============================================================
108 // Read the input image.
109 // ============================================================
111 f = GDCM_NAME_SPACE::File::New( );
113 f->SetLoadMode(GDCM_NAME_SPACE::LD_NOSEQ | GDCM_NAME_SPACE::LD_NOSHADOW);
114 f->SetFileName( fileName );
115 bool res = f->Load();
117 if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
119 std::cout << "---------------------------------------------" << std::endl;
121 std::cout << "---------------------------------------------" << std::endl;
124 std::cout << "Sorry, " << fileName <<" not a gdcm-readable "
125 << "DICOM / ACR File"
130 std::cout << " ... is readable " << std::endl;
132 // ============================================================
133 // Check whether image contains Overlays ACR-NEMA style.
134 // ============================================================
136 //* B 5004|3000 [OW] [Curve Data] [GDCM_NAME_SPACE::Binary data loaded;length = 1938]
137 std::string curve_data_str = f->GetEntryString(0x5004, 0x3000);
138 if (curve_data_str == GDCM_NAME_SPACE::GDCM_UNFOUND)
140 std::cout << " Image doesn't contain any Curve Data" << std::endl;
144 std::cout << " File is read! " << std::endl;
147 // ============================================================
148 // Load the Curve Data in memory.
149 // ============================================================
150 std::istringstream convert;
151 //* V 5004|0005 [US] [Curve Dimensions] [1] x(1)
152 std::string curve_dim_str = f->GetEntryString(0x5004,0x0005);
153 unsigned short curve_dim;
154 convert.str(curve_dim_str);
155 convert >> curve_dim;
156 std::cout << "Curve Dimensions: " << curve_dim << std::endl;
157 //* V 5004|0010 [US] [Number of Points] [969] x(3c9)
158 std::string num_points_str = f->GetEntryString(0x5004,0x0010);
159 unsigned short num_points;
160 convert.clear(); //important
161 convert.str(num_points_str);
162 convert >> num_points;
163 std::cout << "Number of Points: " << num_points << std::endl;
164 //* V 5004|0020 [CS] [Type of Data] [PHYSIO]
165 std::string data_type = f->GetEntryString(0x5004,0x0020);
166 std::cout << "Type of Data: " << data_type << std::endl;
167 std::cout << " this is thus a : " << ConvertTypeOfData(data_type) << std::endl;
168 //* V 5004|0022 [LO] [Curve Description] []
169 std::string curve_desc = f->GetEntryString(0x5004,0x0022);
170 std::cout << "Curve Description: " << curve_desc << std::endl;
171 //* V 5004|0103 [US] [Data Value Representation] [0] x(0)
172 std::string data_rep_str = f->GetEntryString(0x5004,0x0103);
173 unsigned short data_rep;
174 convert.clear(); //important
175 convert.str(data_rep_str);
179 GDCM_NAME_SPACE::DocEntry *pCurveDataDoc = f->GetDocEntry(0x5004, 0x3000);
180 GDCM_NAME_SPACE::DataEntry *pCurveData = dynamic_cast<GDCM_NAME_SPACE::DataEntry *>(pCurveDataDoc);
181 uint8_t *curve_data = pCurveData->GetBinArea();
183 // From Part3, C.10.2.1.2 Data value representation (p668)
185 int sizeofdatarep = 0;
189 sz = PrintCurveData((DataRepToType<0>::Type*)(curve_data), num_points);
190 sizeofdatarep = sizeof( DataRepToType<0>::Type );
193 sz = PrintCurveData((DataRepToType<1>::Type*)(curve_data), num_points);
194 sizeofdatarep = sizeof( DataRepToType<1>::Type );
197 sz = PrintCurveData((DataRepToType<2>::Type*)(curve_data), num_points);
198 sizeofdatarep = sizeof( DataRepToType<2>::Type );
201 sz = PrintCurveData((DataRepToType<3>::Type*)(curve_data), num_points);
202 sizeofdatarep = sizeof( DataRepToType<3>::Type );
205 sz = PrintCurveData((DataRepToType<4>::Type*)(curve_data), num_points);
206 sizeofdatarep = sizeof( DataRepToType<4>::Type );
209 std::cerr << "Error don't know the type: " << data_rep_str << std::endl;
213 // Just to make sure that values read are consistant and we won't read out of bound data:
214 assert( sz*num_points*sizeofdatarep == pCurveData->GetLength());
216 // Write out the data as a file:
217 //std::ofstream o("/tmp/curve_data.raw");
218 //o.write((char*)curve_data, num_points*sz);