From cba27e8db47fefa11652b98dd81d782c13eb9a80 Mon Sep 17 00:00:00 2001 From: jpr Date: Tue, 29 Jun 2004 08:36:10 +0000 Subject: [PATCH] ADD : PrintFile.cxx Write.cxx + tabs hunting --- Example/CMakeLists.txt | 11 ++- Example/PrintDocument.cxx | 62 ++--------------- Example/PrintFile.cxx | 97 ++++++++++++++++++++++++++ Example/Write.cxx | 139 ++++++++++++++++++++++++++++++++++++++ Example/WriteDicom.cxx | 24 +++---- 5 files changed, 262 insertions(+), 71 deletions(-) create mode 100644 Example/PrintFile.cxx create mode 100644 Example/Write.cxx diff --git a/Example/CMakeLists.txt b/Example/CMakeLists.txt index 449533c9..1d6156c8 100644 --- a/Example/CMakeLists.txt +++ b/Example/CMakeLists.txt @@ -8,11 +8,18 @@ INCLUDE_DIRECTORIES( ${GDCM_BINARY_DIR}/ ) -ADD_EXECUTABLE(WriteDicom WriteDicom.cxx) -TARGET_LINK_LIBRARIES(WriteDicom gdcm) ADD_EXECUTABLE(PrintDocument PrintDocument.cxx) TARGET_LINK_LIBRARIES(PrintDocument gdcm) +ADD_EXECUTABLE(PrintFile PrintFile.cxx) +TARGET_LINK_LIBRARIES(PrintFile gdcm) + +ADD_EXECUTABLE(Write Write.cxx) +TARGET_LINK_LIBRARIES(Write gdcm) + +ADD_EXECUTABLE(WriteDicom WriteDicom.cxx) +TARGET_LINK_LIBRARIES(WriteDicom gdcm) + ADD_EXECUTABLE(WriteRead WriteRead.cxx) TARGET_LINK_LIBRARIES(WriteRead gdcm) diff --git a/Example/PrintDocument.cxx b/Example/PrintDocument.cxx index d0314966..617c8616 100644 --- a/Example/PrintDocument.cxx +++ b/Example/PrintDocument.cxx @@ -22,18 +22,11 @@ int main(int argc, char* argv[]) // gdcmFile *e2; gdcmHeader *e1; - bool dropPriv = false; - bool showSeq = true; - bool niou = false; std::string fileName; - if (argc == 1) { - std::cout << argv[0] << - " fileName" << std::endl << - " [nopriv] if you don't want to print Shadow groups" << std::endl << - " [noseq] if you don't want to 'go inside' the SQ's" << std::endl << - " [new] if you want a 'SeQuence indented' printing"<< std::endl; - } + if (argc != 2) { + std::cout << " usage : PrintDocument fileName" << std::endl; + } if (argc > 1) { fileName=argv[1]; @@ -42,55 +35,14 @@ int main(int argc, char* argv[]) fileName += "/test.acr"; } - for (int j=0;jGetHeader(); - e1= new gdcmHeader - (fileName.c_str(), - false, showSeq, - dropPriv); - -// if (argc > 2) { -// int level = atoi(argv[2]); -// e1->SetPrintLevel(level); -// } + (fileName.c_str(),false, true); -e1->SetPrintLevel(2); - - //if (! niou) - // e1->Print(); - //else if (showSeq) - // e1->PrintNiceSQ(); - //else - // e1->PrintNoSQ(); + e1->SetPrintLevel(2); - e1->Print(); + e1->Print(); - std::cout << "\n\n" << std::endl; - std::string transferSyntaxName = e1->GetTransfertSyntaxName(); - std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; - - if ( transferSyntaxName != "Implicit VR - Little Endian" - && transferSyntaxName != "Explicit VR - Little Endian" - && transferSyntaxName != "Deflated Explicit VR - Little Endian" - && transferSyntaxName != "Explicit VR - Big Endian" - && transferSyntaxName != "Uncompressed ACR-NEMA" ) - { - std::cout << std::endl << "===========================================" - << std::endl; - //e2->ParsePixelData(); - std::cout << std::endl << "===========================================" - << std::endl; - } + std::cout << "\n\n" << std::endl; if(e1->IsReadable()) std::cout < + +#include "gdcmException.h" +#include "gdcmCommon.h" + +#include "gdcmDictEntry.h" +#include "gdcmDict.h" +#include "gdcmDictSet.h" +#include "gdcmHeader.h" +#include "gdcmUtil.h" +#include "gdcmBinEntry.h" +#include "gdcmDocEntry.h" +#include "gdcmDocEntrySet.h" +#include "gdcmDocument.h" +#include "gdcmElementSet.h" +#include "gdcmSeqEntry.h" +#include "gdcmSQItem.h" +#include "gdcmValEntry.h" +#include "gdcmFile.h" +int main(int argc, char* argv[]) +{ + + gdcmHeader *e1; + gdcmFile *f1; + std::string fileName; + if (argc != 2) { + std::cout << " usage : PrintDocument fileName" << std::endl; + } + + if (argc > 1) { + fileName=argv[1]; + } else { + fileName += GDCM_DATA_ROOT; + fileName += "/test.acr"; + } + + e1= new gdcmHeader + (fileName.c_str(),false, true); + + f1 = new gdcmFile(e1); + + e1->SetPrintLevel(2); + + e1->Print(); + + std::cout << "\n\n" << std::endl; + + int dataSize = f1->GetImageDataSize(); + std::cout <GetXSize(); + nY=e1->GetYSize(); + nZ=e1->GetZSize(); + std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl; + + pixelType = e1->GetPixelType(); + sPP = e1->GetSamplesPerPixel(); + planarConfig = e1->GetPlanarConfiguration(); + + std::cout << " pixelType=" << pixelType + << " SampleserPixel=" << sPP + << " PlanarConfiguration=" << planarConfig + << std::endl + << " PhotometricInterpretation=" + << e1->GetEntryByNumber(0x0028,0x0004) + << std::endl; + + int numberOfScalarComponents=e1->GetNumberOfScalarComponents(); + std::cout << " NumberOfScalarComponents " << numberOfScalarComponents <GetTransfertSyntaxName(); + std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; + + if ( transferSyntaxName != "Implicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Little Endian" + && transferSyntaxName != "Deflated Explicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Big Endian" + && transferSyntaxName != "Uncompressed ACR-NEMA" ) + { + std::cout << std::endl << "===========================================" + << std::endl; + f1->ParsePixelData(); // gdcmFile Method :-( + std::cout << std::endl << "===========================================" + << std::endl; + } + + if(e1->IsReadable()) + std::cout < +#include "gdcm.h" +#include "gdcmHeader.h" +#include "gdcmDocument.h" + +#include + +int main(int argc, char* argv[]) +{ + std::string toto; + char zozo[200]; + + gdcmHeader* e1; + gdcmFile * f1; + + //gdcmDocument * d; //not used + void* imageData; + int dataSize; + + if (argc < 3) { + std::cerr << "usage: " << std::endl + << argv[0] << " fileName writtingMode " + << std::endl + << "(a : ACR, d : DICOM Implicit VR," + << " x : DICOM Explicit VR, r : RAW)" + << std::endl; + return 0; + } +/* + if (0) { // Just to keep the code for further use + std::cout <GetHeader()->IsReadable()) { + std::cout << "Sorry, not a DICOM / ACR File" < after new gdcmHeader" + << std::endl; + e1->PrintEntry(); + std::cout <IsReadable()) { + std::cerr << "Sorry, not a Readable DICOM / ACR File" <Print(); + + f1 = new gdcmFile(e1); +// --- + + dataSize = f1->GetImageDataSize(); + std::cout <GetXSize(); + nY=e1->GetYSize(); + nZ=e1->GetZSize(); + std::cout << " DIMX=" << nX << " DIMY=" << nY << " DIMZ=" << nZ << std::endl; + + pixelType = e1->GetPixelType(); + sPP = e1->GetSamplesPerPixel(); + planarConfig = e1->GetPlanarConfiguration(); + + std::cout << " pixelType=" << pixelType + << " SampleserPixel=" << sPP + << " PlanarConfiguration=" << planarConfig + << " PhotometricInterpretation=" + << e1->GetEntryByNumber(0x0028,0x0004) + << std::endl; + + int numberOfScalarComponents=e1->GetNumberOfScalarComponents(); + std::cout << "NumberOfScalarComponents " << numberOfScalarComponents <GetTransfertSyntaxName(); + std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; + + if ( transferSyntaxName != "Implicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Little Endian" + && transferSyntaxName != "Deflated Explicit VR - Little Endian" + && transferSyntaxName != "Explicit VR - Big Endian" + && transferSyntaxName != "Uncompressed ACR-NEMA" ) { + std::cout << std::endl << "===========================================" + << std::endl; + f1->ParsePixelData(); + std::cout << std::endl << "===========================================" + << std::endl; + } + imageData= f1->GetImageData(); + + switch (argv[2][0]) { + case 'a' : + // ecriture d'un fichier ACR + // à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.ACR", toto.c_str()); + printf ("WriteACR\n"); + f1->WriteAcr(zozo); + break; + + case 'd' : + // ecriture d'un fichier DICOM Implicit VR + // à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.DCM", toto.c_str()); + printf ("WriteDCM Implicit VR\n"); + f1->WriteDcmImplVR(zozo); + break; + + case 'x' : + // ecriture d'un fichier DICOM Explicit VR + // à partir d'un dcmHeader correct. + + sprintf(zozo, "%s.XDCM", toto.c_str()); + std::cout << "WriteDCM Explicit VR" << std::endl; + f1->WriteDcmExplVR(zozo); + break; + + case 'r' : + // Ecriture d'un Raw File, a afficher avec + // affim filein= dimx= dimy= nbit= signe= + + sprintf(zozo, "%s.RAW", toto.c_str()); + std::cout << "WriteRaw" << std::endl; + f1->WriteRawData(zozo); + break; + + } + return 0; +} + diff --git a/Example/WriteDicom.cxx b/Example/WriteDicom.cxx index 905163cd..a10d1f78 100644 --- a/Example/WriteDicom.cxx +++ b/Example/WriteDicom.cxx @@ -11,19 +11,17 @@ int main(int argc, char* argv[]) { std::cerr << "Usage :" << std::endl << argv[0] << " HeaderFileName DataFileName" << std::endl; - return 0; + return 0; } const char *first = argv[1]; gdcmFile *f1 = new gdcmFile( first ); - + const char *second = argv[2]; gdcmFile *f2 = new gdcmFile( second ); - - // f1->PrintPubElVal(); - + // We assume that DICOM fields of second file actually exists : - + std::string nbFrames = f2->GetHeader()->GetEntryByNumber(0x0028, 0x0008); if(nbFrames != "gdcm::Unfound") { f1->GetHeader()->ReplaceOrCreateByNumber( nbFrames, 0x0028, 0x0008); @@ -35,8 +33,8 @@ int main(int argc, char* argv[]) f2->GetHeader()->GetEntryByNumber(0x0028, 0x0011), 0x0028, 0x0011); // nbCol // Some other tags should be updated: - - // TODO : add a default value + + // TODO : add a default value // TODO : a function which take as input a list of tuple (gr, el) // and that does the job @@ -44,24 +42,22 @@ int main(int argc, char* argv[]) void *imageData = f2->GetImageData(); std::cout << "dataSize :" << dataSize << std::endl; - + // TODO : Shouldn't we merge those two functions ? f1->SetImageData( imageData, dataSize); f1->GetHeader()->SetImageDataSize( dataSize ); - + f1->GetHeader()->Print(); - + std::string s0 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0000); std::string s10 = f2->GetHeader()->GetEntryByNumber(0x7fe0, 0x0010); std::cout << "lgr 7fe0, 0000 " << s0 << std::endl; - std::cout << "lgr 7fe0, 0010 " << s10 << std::endl; + std::cout << "lgr 7fe0, 0010 " << s10 << std::endl; std::cout << "WriteDCM" << std::endl; f1->WriteDcmExplVR("WriteDicom.dcm"); - //f1->WriteDcmImplVR(resultat); - //f1->WriteAcr(resultat); return 0; } -- 2.45.1