1 /*=========================================================================
4 Module: $RCSfile: exCurveData.cxx,v $
6 Date: $Date: 2008/03/10 14:30:08 $
7 Version: $Revision: 1.9 $
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( strncmp(p[0], type.c_str(), strlen(p[0])) == 0 ) // 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 f->SetMaxSizeLoadEntry(0xffff);
116 bool res = f->Load();
118 if( GDCM_NAME_SPACE::Debug::GetDebugFlag() )
120 std::cout << "---------------------------------------------" << std::endl;
122 std::cout << "---------------------------------------------" << std::endl;
125 std::cout << "Sorry, " << fileName <<" not a gdcm-readable "
126 << "DICOM / ACR File"
131 std::cout << " ... is readable " << std::endl;
133 // ============================================================
134 // Check whether image contains Overlays ACR-NEMA style.
135 // ============================================================
137 const uint16_t curvedatagroup = 0x5000;
138 //* B 5004|3000 [OW] [Curve Data] [GDCM_NAME_SPACE::Binary data loaded;length = 1938]
139 std::string curve_data_str = f->GetEntryString(curvedatagroup, 0x3000);
140 if (curve_data_str == GDCM_NAME_SPACE::GDCM_UNFOUND)
142 std::cout << " Image doesn't contain any Curve Data" << std::endl;
146 std::cout << " File is read! " << std::endl;
149 // ============================================================
150 // Load the Curve Data in memory.
151 // ============================================================
152 std::istringstream convert;
153 //* V 5004|0005 [US] [Curve Dimensions] [1] x(1)
154 std::string curve_dim_str = f->GetEntryString(curvedatagroup,0x0005);
155 unsigned short curve_dim;
156 convert.str(curve_dim_str);
157 convert >> curve_dim;
158 std::cout << "Curve Dimensions: " << curve_dim << std::endl;
159 //* V 5004|0010 [US] [Number of Points] [969] x(3c9)
160 std::string num_points_str = f->GetEntryString(curvedatagroup,0x0010);
161 unsigned short num_points;
162 convert.clear(); //important
163 convert.str(num_points_str);
164 convert >> num_points;
165 std::cout << "Number of Points: " << num_points << std::endl;
166 //* V 5004|0020 [CS] [Type of Data] [PHYSIO]
167 std::string data_type = f->GetEntryString(curvedatagroup,0x0020);
168 std::cout << "Type of Data: " << data_type << std::endl;
169 const char *datatype = ConvertTypeOfData(data_type);
170 std::cout << " this is thus a : " << (datatype ? datatype : "") << std::endl;
171 //* V 5004|0022 [LO] [Curve Description] []
172 std::string curve_desc = f->GetEntryString(curvedatagroup,0x0022);
173 std::cout << "Curve Description: " << curve_desc << std::endl;
174 //* V 5004|0103 [US] [Data Value Representation] [0] x(0)
175 std::string data_rep_str = f->GetEntryString(curvedatagroup,0x0103);
176 unsigned short data_rep;
177 convert.clear(); //important
178 convert.str(data_rep_str);
182 GDCM_NAME_SPACE::DocEntry *pCurveDataDoc = f->GetDocEntry(curvedatagroup, 0x3000);
183 GDCM_NAME_SPACE::DataEntry *pCurveData = dynamic_cast<GDCM_NAME_SPACE::DataEntry *>(pCurveDataDoc);
184 uint8_t *curve_data = pCurveData->GetBinArea();
186 // From Part3, C.10.2.1.2 Data value representation (p668)
188 int sizeofdatarep = 0;
192 sz = PrintCurveData((DataRepToType<0>::Type*)(curve_data), num_points);
193 sizeofdatarep = sizeof( DataRepToType<0>::Type );
196 sz = PrintCurveData((DataRepToType<1>::Type*)(curve_data), num_points);
197 sizeofdatarep = sizeof( DataRepToType<1>::Type );
200 sz = PrintCurveData((DataRepToType<2>::Type*)(curve_data), num_points);
201 sizeofdatarep = sizeof( DataRepToType<2>::Type );
204 sz = PrintCurveData((DataRepToType<3>::Type*)(curve_data), num_points);
205 sizeofdatarep = sizeof( DataRepToType<3>::Type );
208 sz = PrintCurveData((DataRepToType<4>::Type*)(curve_data), num_points);
209 sizeofdatarep = sizeof( DataRepToType<4>::Type );
212 std::cerr << "Error don't know the type: " << data_rep_str << std::endl;
216 // Just to make sure that values read are consistant and we won't read out of bound data:
217 //assert( sz*num_points*sizeofdatarep == pCurveData->GetLength());
219 // Write out the data as a file:
220 //std::ofstream o("/tmp/curve_data.raw");
221 //o.write((char*)curve_data, num_points*sz);