From: malaterre Date: Mon, 10 Oct 2005 20:02:09 +0000 (+0000) Subject: ENH: Adding an example for reading and playing with Curve Data (500x,3000) X-Git-Tag: Version1.2.bp~39 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=1304084bfc9690503a0d701c5a115db734e22d5b;p=gdcm.git ENH: Adding an example for reading and playing with Curve Data (500x,3000) --- diff --git a/Example/exCurveData.cxx b/Example/exCurveData.cxx new file mode 100644 index 00000000..3a520e6f --- /dev/null +++ b/Example/exCurveData.cxx @@ -0,0 +1,178 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: exCurveData.cxx,v $ + Language: C++ + Date: $Date: 2005/10/10 20:02:09 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "gdcmFile.h" +#include "gdcmFileHelper.h" +#include "gdcmCommon.h" +#include "gdcmDebug.h" +#include "gdcmDocEntry.h" +#include "gdcmBinEntry.h" + +// Helper function +template +inline size_t PrintCurveData(DataValueRepresentation* data, unsigned short numPts) +{ + for(unsigned int i=0; i 1 ) + fileName = argv[1]; + else + fileName = "GE_DLX-8-MONO2-Multiframe.dcm"; + + std::cout << fileName << std::endl; +// ============================================================ +// Read the input image. +// ============================================================ + + f = new gdcm::File( ); + + f->SetLoadMode(gdcm::LD_NOSEQ | gdcm::LD_NOSHADOW); + f->SetFileName( fileName ); + bool res = f->Load(); + + if( gdcm::Debug::GetDebugFlag() ) + { + std::cout << "---------------------------------------------" << std::endl; + f->Print(); + std::cout << "---------------------------------------------" << std::endl; + } + if (!res) { + std::cout << "Sorry, " << fileName <<" not a gdcm-readable " + << "DICOM / ACR File" + <GetEntryValue(0x5004, 0x3000); + if (curve_data_str == gdcm::GDCM_UNFOUND) + { + std::cout << " Image doesn't contain any Curve Data" << std::endl; + delete f; + return 1; + } + std::cout << " File is read! " << std::endl; + + +// ============================================================ +// Load the Curve Data in memory. +// ============================================================ + std::istringstream convert; + //* V 5004|0005 [US] [Curve Dimensions] [1] x(1) + std::string curve_dim_str = f->GetEntryValue(0x5004,0x0005); + unsigned short curve_dim; + convert.str(curve_dim_str); + convert >> curve_dim; + std::cout << "Curve Dimensions: " << curve_dim << std::endl; + //* V 5004|0010 [US] [Number of Points] [969] x(3c9) + std::string num_points_str = f->GetEntryValue(0x5004,0x0010); + unsigned short num_points; + convert.clear(); //important + convert.str(num_points_str); + convert >> num_points; + std::cout << "Number of Points: " << num_points << std::endl; + //* V 5004|0020 [CS] [Type of Data] [PHYSIO] + std::string data_type = f->GetEntryValue(0x5004,0x0020); + std::cout << "Type of Data: " << data_type << std::endl; + //* V 5004|0022 [LO] [Curve Description] [] + std::string curve_desc = f->GetEntryValue(0x5004,0x0022); + std::cout << "Curve Description: " << curve_desc << std::endl; + //* V 5004|0103 [US] [Data Value Representation] [0] x(0) + std::string data_rep_str = f->GetEntryValue(0x5004,0x0103); + unsigned short data_rep; + convert.clear(); //important + convert.str(data_rep_str); + convert >> data_rep; + + + gdcm::DocEntry *pCurveDataDoc = f->GetDocEntry(0x5004, 0x3000); + gdcm::BinEntry *pCurveData = dynamic_cast(pCurveDataDoc); + uint8_t *curve_data = pCurveData->GetBinArea(); + + // From Part3, C.10.2.1.2 Data value representation (p668) + size_t sz; + switch( data_rep) + { + case 0: + sz = PrintCurveData((unsigned short*)(curve_data), num_points); + break; + case 1: + sz = PrintCurveData((signed short*)(curve_data), num_points); + break; + case 2: + sz = PrintCurveData((float*)(curve_data), num_points); + break; + case 3: + sz = PrintCurveData((double*)(curve_data), num_points); + break; + case 4: + sz = PrintCurveData((signed long*)(curve_data), num_points); + break; + default: + std::cerr << "Error don't know the type: " << data_rep_str << std::endl; + delete f; + return 1; + } + // Just to make sure that values read are consistant and we won't read out of bound data: + assert( sz*num_points == pCurveData->GetLength()); + + // Write out the data as a file: + //std::ofstream o("/tmp/curve_data.raw"); + //o.write((char*)curve_data, num_points*sz); + //o.close(); + + delete f; + return 0; +} + +