1 /*=========================================================================
4 Module: $RCSfile: exCurveData.cxx,v $
6 Date: $Date: 2005/10/18 08:35:43 $
7 Version: $Revision: 1.4 $
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);
72 // Example (sorry, we've got no more than this one ...)
73 * V 5004|0000 [UL] [Group Length] [1998] x(7ce)
74 * V 5004|0005 [US] [Curve Dimensions] [1] x(1)
75 * V 5004|0010 [US] [Number of Points] [969] x(3c9)
76 * V 5004|0020 [CS] [Type of Data] [PHYSIO]
77 * V 5004|0022 [LO] [Curve Description] []
78 * V 5004|0103 [US] [Data Value Representation] [0] x(0)
79 * B 5004|3000 [OW] [Curve Data] [gdcm::Binary data loaded;length = 1938]
82 int main(int argc, char *argv[])
86 std::cout << "------------------------------------------------" << std::endl;
87 std::cout << "Gets the 'Curve Data' from a full gdcm-readable DICOM " << std::endl;
88 std::cout << "(Note : we just have ONE image : "
89 << "GE_DLX-8-MONO2-Multiframe.dcm"
91 std::cout << "------------------------------------------------" << std::endl;
97 fileName = "GE_DLX-8-MONO2-Multiframe.dcm";
99 std::cout << fileName << std::endl;
100 // ============================================================
101 // Read the input image.
102 // ============================================================
104 f = new gdcm::File( );
106 f->SetLoadMode(gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW);
107 f->SetFileName( fileName );
108 bool res = f->Load();
110 if( gdcm::Debug::GetDebugFlag() )
112 std::cout << "---------------------------------------------" << std::endl;
114 std::cout << "---------------------------------------------" << std::endl;
117 std::cout << "Sorry, " << fileName <<" not a gdcm-readable "
118 << "DICOM / ACR File"
123 std::cout << " ... is readable " << std::endl;
125 // ============================================================
126 // Check whether image contains Overlays ACR-NEMA style.
127 // ============================================================
129 //* B 5004|3000 [OW] [Curve Data] [gdcm::Binary data loaded;length = 1938]
130 std::string curve_data_str = f->GetEntryString(0x5004, 0x3000);
131 if (curve_data_str == gdcm::GDCM_UNFOUND)
133 std::cout << " Image doesn't contain any Curve Data" << std::endl;
137 std::cout << " File is read! " << std::endl;
140 // ============================================================
141 // Load the Curve Data in memory.
142 // ============================================================
143 std::istringstream convert;
144 //* V 5004|0005 [US] [Curve Dimensions] [1] x(1)
145 std::string curve_dim_str = f->GetEntryString(0x5004,0x0005);
146 unsigned short curve_dim;
147 convert.str(curve_dim_str);
148 convert >> curve_dim;
149 std::cout << "Curve Dimensions: " << curve_dim << std::endl;
150 //* V 5004|0010 [US] [Number of Points] [969] x(3c9)
151 std::string num_points_str = f->GetEntryString(0x5004,0x0010);
152 unsigned short num_points;
153 convert.clear(); //important
154 convert.str(num_points_str);
155 convert >> num_points;
156 std::cout << "Number of Points: " << num_points << std::endl;
157 //* V 5004|0020 [CS] [Type of Data] [PHYSIO]
158 std::string data_type = f->GetEntryString(0x5004,0x0020);
159 std::cout << "Type of Data: " << data_type << std::endl;
160 std::cout << " this is thus a : " << ConvertTypeOfData(data_type) << std::endl;
161 //* V 5004|0022 [LO] [Curve Description] []
162 std::string curve_desc = f->GetEntryString(0x5004,0x0022);
163 std::cout << "Curve Description: " << curve_desc << std::endl;
164 //* V 5004|0103 [US] [Data Value Representation] [0] x(0)
165 std::string data_rep_str = f->GetEntryString(0x5004,0x0103);
166 unsigned short data_rep;
167 convert.clear(); //important
168 convert.str(data_rep_str);
172 gdcm::DocEntry *pCurveDataDoc = f->GetDocEntry(0x5004, 0x3000);
173 gdcm::DataEntry *pCurveData = dynamic_cast<gdcm::DataEntry *>(pCurveDataDoc);
174 uint8_t *curve_data = pCurveData->GetBinArea();
176 // From Part3, C.10.2.1.2 Data value representation (p668)
181 sz = PrintCurveData((unsigned short*)(curve_data), num_points);
184 sz = PrintCurveData((signed short*)(curve_data), num_points);
187 sz = PrintCurveData((float*)(curve_data), num_points);
190 sz = PrintCurveData((double*)(curve_data), num_points);
193 sz = PrintCurveData((signed long*)(curve_data), num_points);
196 std::cerr << "Error don't know the type: " << data_rep_str << std::endl;
200 // Just to make sure that values read are consistant and we won't read out of bound data:
201 assert( sz*num_points == pCurveData->GetLength());
203 // Write out the data as a file:
204 //std::ofstream o("/tmp/curve_data.raw");
205 //o.write((char*)curve_data, num_points*sz);