X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FDense2007ToDicom.cxx;h=e8c30c4dd40bb88ba7886d1700137362a2c51ef9;hb=2ee517af46f7cbf72facbd11ff4e0bb727029fa0;hp=7cb0fda5095ec7da357e076505d84682dfea9b00;hpb=86525d44682743610d75b6037e4a8ba216bff9b5;p=gdcm.git diff --git a/Example/Dense2007ToDicom.cxx b/Example/Dense2007ToDicom.cxx index 7cb0fda5..e8c30c4d 100755 --- a/Example/Dense2007ToDicom.cxx +++ b/Example/Dense2007ToDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: Dense2007ToDicom.cxx,v $ Language: C++ - Date: $Date: 2007/09/18 10:54:23 $ - Version: $Revision: 1.2 $ + Date: $Date: 2007/10/29 17:13:59 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,6 +20,10 @@ #include //#include +#if defined(__BORLANDC__) +#include +#endif + #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDebug.h" @@ -38,6 +42,7 @@ void LoadPeakStrain(std::ifstream &from, std::string imageName); void LoadStrain(std::ifstream &from, std::string imageName); void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName); +int verbose; int main(int argc, char *argv[]) { @@ -69,7 +74,7 @@ int main(int argc, char *argv[]) if (am->ArgMgrDefined("debug")) GDCM_NAME_SPACE::Debug::DebugOn(); - int verbose = am->ArgMgrDefined("verbose"); + verbose = am->ArgMgrDefined("verbose"); // if unused Param we give up if ( am->ArgMgrPrintUnusedLabels() ) @@ -248,7 +253,8 @@ std::cout << "------------stop skipping ---------------- " << std::endl; char c; int i; - for (i=0; i> X[i]; for (;;) { if (!from.get(c)) @@ -257,7 +263,8 @@ std::cout << "------------stop skipping ---------------- " << std::endl; from.putback(c); break; } - } + } + from >> Y[i]; for (;;) { if (!from.get(c)) @@ -267,13 +274,15 @@ std::cout << "------------stop skipping ---------------- " << std::endl; break; } } - from >> Z[i]; - } + from >> Z[i]; + + } // end for i> ecc_strain[i]; + if (verbose) std::cout << ecc_strain[i] << std::endl; } @@ -281,6 +290,7 @@ std::cout << "------------stop skipping ---------------- " << std::endl; float *err_strain = new float[NP]; for (i=0; i> err_strain[i]; + if (verbose) std::cout << err_strain[i] << std::endl; } @@ -288,6 +298,7 @@ std::cout << "------------stop skipping ---------------- " << std::endl; float *e11_strain = new float[NP]; for (i=0; i> e11_strain[i]; + if (verbose) std::cout << e11_strain[i] << std::endl; } @@ -295,6 +306,7 @@ std::cout << "------------stop skipping ---------------- " << std::endl; float *e22_strain = new float[NP]; for (i=0; i> e22_strain[i]; + if (verbose) std::cout << e22_strain[i] << std::endl; } @@ -516,7 +528,8 @@ std::cout << "------------stop skipping ---------------- " << std::endl; std::cout << "--------------- Ecc_strain ------------------" << std::endl; float *ecc_strain = new float[NP]; for (i=0; i> ecc_strain[i]; + from >> ecc_strain[i]; + if (verbose) std::cout << ecc_strain[i] << std::endl; } @@ -524,6 +537,7 @@ std::cout << "------------stop skipping ---------------- " << std::endl; float *err_strain = new float[NP]; for (i=0; i> err_strain[i]; + if (verbose) std::cout << err_strain[i] << std::endl; } @@ -531,6 +545,7 @@ std::cout << "------------stop skipping ---------------- " << std::endl; float *e11_strain = new float[NP]; for (i=0; i> e11_strain[i]; + if (verbose) std::cout << e11_strain[i] << std::endl; } @@ -538,6 +553,7 @@ std::cout << "------------stop skipping ---------------- " << std::endl; float *e22_strain = new float[NP]; for (i=0; i> e22_strain[i]; + if (verbose) std::cout << e22_strain[i] << std::endl; } @@ -567,9 +583,10 @@ std::cout << "------------stop skipping ---------------- " << std::endl; void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::string dcmImageName) { - float minX = 999., minY = 999., minZ = 999.; + float minX = 99999., minY = 99999., minZ = 99999.; float maxX = 0., maxY = 0., maxZ = 0.; int i; + for (i=0; i Z[i]) minZ = Z[i]; - } - std::cout << "Min X,Y,Z " << minX << " " << minY << " " << minZ << std::endl; - std::cout << "Max X,Y,Z " << maxX << " " << maxY << " " << maxZ << std::endl; - std::cout << "Size X,Y,Z " << maxX-minX << " " << maxY-minY << " " << maxZ-minZ << std::endl; + std::cout << "Min X,Y,Z " << minX << " " << minY << " " << minZ << std::endl; + std::cout << "Max X,Y,Z " << maxX << " " << maxY << " " << maxZ << std::endl; + std::cout << "Size X,Y,Z " << maxX-minX << " " << maxY-minY << " " << maxZ-minZ << std::endl; +// uint16_t *img = new uint16_t[int(maxX+0.5)*int(maxY+0.5)]; + uint16_t *img = new uint16_t[int(maxX*4.)*int(maxY*4.)]; + + // Set whole image to 0 + for(int i3=0;i3InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns - str.str(""); - str << (int)maxY; - file->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows + str.str(""); + str << (int)(maxX*4.); + file->InsertEntryString(str.str(),0x0028,0x0011,"US"); // Columns + str.str(""); + str << (int)(maxY*4.); + file->InsertEntryString(str.str(),0x0028,0x0010,"US"); // Rows + // Set the pixel type // 16; //8, 16, 32 - file->InsertEntryString("16",0x0028,0x0100,"US"); // Bits Allocated - str.str(""); - str << 16; // may be 12 or 16 if componentSize =16 - file->InsertEntryString("16",0x0028,0x0101,"US"); // Bits Stored - file->InsertEntryString("15",0x0028,0x0102,"US"); // High Bit + file->InsertEntryString("16",0x0028,0x0100,"US"); // Bits Allocated + str.str(""); + str << 16; // may be 12 or 16 if componentSize =16 + file->InsertEntryString("16",0x0028,0x0101,"US"); // Bits Stored + file->InsertEntryString("15",0x0028,0x0102,"US"); // High Bit // Set the pixel representation // 0/1 , 0=unsigned - file->InsertEntryString("1",0x0028,0x0103, "US"); // Pixel Representation + file->InsertEntryString("1",0x0028,0x0103, "US"); // Pixel Representation // Set the samples per pixel // 1:Grey level, 3:RGB - file->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel + file->InsertEntryString("1",0x0028,0x0002, "US"); // Samples per Pixel /* // Set Rescale Intercept @@ -639,18 +670,19 @@ void MakeDicomImage(float *tabVal, float *X, float *Y, float *Z, int NP, std::st file->InsertEntryString(str.str(),0x0028,0x1053,"DS"); */ - GDCM_NAME_SPACE::FileHelper *fileH; - fileH = GDCM_NAME_SPACE::FileHelper::New(file); - // cast is just to avoid warnings (*no* conversion) - fileH->SetImageData((uint8_t *)img,int(maxX*maxY)*sizeof(uint16_t)); - fileH->SetWriteModeToRaw(); - fileH->SetWriteTypeToDcmExplVR(); + GDCM_NAME_SPACE::FileHelper *fileH; + fileH = GDCM_NAME_SPACE::FileHelper::New(file); + // cast is just to avoid warnings (*no* conversion) + //fileH->SetImageData((uint8_t *)img,int(maxX*maxY)*sizeof(uint16_t)); // troubles when maxX, mayY are *actually* float! + fileH->SetImageData((uint8_t *)img,int(maxX*4.)*int(maxY*4.)*sizeof(uint16_t)); + fileH->SetWriteModeToRaw(); + fileH->SetWriteTypeToDcmExplVR(); - if( !fileH->Write(dcmImageName)) - std::cout << "Failed for [" << dcmImageName << "]\n" - << " File is unwrittable" << std::endl; + if( !fileH->Write(dcmImageName)) + std::cout << "Failed for [" << dcmImageName << "]\n" + << " File is unwrittable" << std::endl; - file->Print(); + //file->Print(); delete img; file->Delete();