X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FReWrite.cxx;h=6e01d868167dd343502e2ecb6d445a702c948f83;hb=6d07e1c5ea5f9199082dc3e6873509a189d4f0f7;hp=ac672f06f28e53daebbd247d1d60cc1977404830;hpb=6431ad8820a924bfddca7707abdf8a537fef61af;p=gdcm.git diff --git a/Example/ReWrite.cxx b/Example/ReWrite.cxx index ac672f06..6e01d868 100644 --- a/Example/ReWrite.cxx +++ b/Example/ReWrite.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: ReWrite.cxx,v $ Language: C++ - Date: $Date: 2007/03/06 10:19:00 $ - Version: $Revision: 1.21 $ + Date: $Date: 2007/08/24 10:48:08 $ + Version: $Revision: 1.30 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -32,36 +32,40 @@ int main(int argc, char *argv[]) " (usefull when the file header is not very straight). ", " ", " usage: ReWrite filein=inputFileName fileout=outputFileName ", - " [mode=write mode] [noshadow] [noseq][debug] ", + " [mode=write mode] [monochrome1] [noshadow] [noseq][debug] ", " --> The following line to 'rubout' a burnt-in Patient name ", " [rubout=xBegin,xEnd,yBegin,yEnd [ruboutvalue=n (<255)] ] ", - " --> The 2 following lines, to extract a sub image withon some frames ", + " --> The 2 following lines, to extract a sub image within some frames ", " [ROI=xBegin,xEnd,yBegin,yEnd] ", " [firstframe=beg] [lastframe=end] ", " ", " mode = a (ACR), x (Explicit VR Dicom), r (RAW : only pixels) ", + " j (jpeg lossless), 2 (jpeg2000) ", + " monochrome1 = user wants MONOCHROME1 photom. interp. (0=white) ", " noshadowseq: user doesn't want to load Private Sequences ", " noshadow : user doesn't want to load Private groups (odd number)", " noseq : user doesn't want to load Sequences ", - " rgb : user wants to tranform LUT (if any) to RGB pixels ", + " rgb : user wants to transform LUT (if any) to RGB pixels ", + " warning : developper wants to run the program in 'warning mode'", " debug : developper wants to run the program in 'debug mode' ", FINISH_USAGE - // ----- Initialize Arguments Manager ------ - gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); + // ----- Initialize Arguments Manager ------ + + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); if (argc == 1 || am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' delete am; - return 0; + return 1; } char *fileName = am->ArgMgrWantString("filein",usage); if ( fileName == NULL ) { std::cout << "'filein= ...' is mandatory" << std::endl; delete am; - return 0; + return 1; } char *outputFileName = am->ArgMgrWantString("fileout",usage); @@ -69,27 +73,32 @@ int main(int argc, char *argv[]) { std::cout << "'fileout= ...' is mandatory" << std::endl; delete am; - return 0; + return 1; } const char *mode = am->ArgMgrGetString("mode","X"); - int loadMode = gdcm::LD_ALL; + int loadMode = GDCM_NAME_SPACE::LD_ALL; if ( am->ArgMgrDefined("noshadowseq") ) - loadMode |= gdcm::LD_NOSHADOWSEQ; + loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ; else { if ( am->ArgMgrDefined("noshadow") ) - loadMode |= gdcm::LD_NOSHADOW; + loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW; if ( am->ArgMgrDefined("noseq") ) - loadMode |= gdcm::LD_NOSEQ; + loadMode |= GDCM_NAME_SPACE::LD_NOSEQ; } bool rgb = ( 0 != am->ArgMgrDefined("RGB") ); + bool monochrome1 = ( 0 != am->ArgMgrDefined("monochrome1") ); + if (am->ArgMgrDefined("debug")) - gdcm::Debug::DebugOn(); - + GDCM_NAME_SPACE::Debug::DebugOn(); + + if (am->ArgMgrDefined("warning")) + GDCM_NAME_SPACE::Debug::WarningOn(); + bool fail = false; int *boundVal; int ruboutVal; @@ -142,29 +151,29 @@ int main(int argc, char *argv[]) // ----------- End Arguments Manager --------- - gdcm::File *f = gdcm::File::New(); + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); f->SetLoadMode( loadMode ); + f->SetFileName( fileName ); bool res = f->Load(); - if ( !res ) + if ( !res ) { f->Delete(); - return 0; + return 1; } if (!f->IsReadable()) { std::cerr << "Sorry, not a Readable DICOM / ACR File" <Delete(); - return 0; + return 1; } - - gdcm::FileHelper *fh = gdcm::FileHelper::New(f); - void *imageData; + GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f); + uint8_t *imageData; int dataSize; - int nX,nY,nZ,sPP,planarConfig; + int nX,nY,nZ,sPP,planarConfig; std::string pixelType, transferSyntaxName; nX=f->GetXSize(); nY=f->GetYSize(); @@ -189,7 +198,9 @@ int main(int argc, char *argv[]) transferSyntaxName = f->GetTransferSyntaxName(); std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]" << std::endl; - + + if(monochrome1) + fh->SetPhotometricInterpretationToMonochrome1(); if (rgb) { @@ -213,7 +224,7 @@ int main(int argc, char *argv[]) // Since we just ReWrite the image, we know no modification // was performed on the pixels. // We don't want this image appears as a 'Secondary Captured image' - fh->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE); + fh->SetContentType(GDCM_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE); /// \todo : think about rubbing out a part of a *multiframe* image! @@ -264,6 +275,87 @@ int main(int argc, char *argv[]) } } + +//------------------------------ Set the Writing mode --------------------------------- + + switch (mode[0]) + { + case 'A' : + case 'a' : + // Writting an ACR file + // from a full gdcm readable File + std::cout << "WriteACR" << std::endl; + fh->SetWriteTypeToAcr(); + break; + + case 'D' : // Not documented in the 'usage', because the method + case 'd' : // is known to be bugged. + // Writting a DICOM Implicit VR file + // from a full gdcm readable File + std::cout << "WriteDCM Implicit VR" << std::endl; + fh->SetWriteTypeToDcmImplVR(); + break; + + case 'X' : + case 'x' : + // writting a DICOM Explicit VR + // from a full gdcm readable File + std::cout << "WriteDCM Explicit VR" << std::endl; + // fh->WriteDcmExplVR(outputFileName); + // Try this one : + fh->SetWriteTypeToDcmExplVR(); + + break; + + case 'R' : + case 'r' : + // Writting a Raw File, + std::cout << "WriteRaw" << std::endl; + fh->WriteRawData(outputFileName); + break; + + case 'J' : + case 'j' : + // writting a DICOM Jpeg Lossless + // from a full gdcm readable File + std::cout << "WriteDCM Jpeg Lossless" << std::endl; + fh->SetWriteTypeToJPEG(); + break; + + case '2' : + // writting a DICOM Jpeg 2000 + // from a full gdcm readable File + std::cout << "WriteDCM Jpeg 2000" << std::endl; + fh->SetWriteTypeToJPEG2000(); + break; + + // Just for fun : + // Write a 'Video inverse' version of the file. + // *Not* described, on purpose, in the USAGE + case 'V' : + case 'v' : + if ( fh->GetFile()->GetBitsAllocated() == 8) + { + std::cout << "videoinv for 8 bits" << std::endl; + for (int i=0; iSetWriteTypeToDcmExplVR(); + break; + } + + // // user wants to keep only a part of the image (ROI, and/or some frames) // --------------------------------------------------------------------- @@ -308,7 +400,7 @@ int main(int argc, char *argv[]) } else { - roiBoundVal = new int(4); + roiBoundVal = new int[4]; roiBoundVal[0] = 0; roiBoundVal[1] = nX-1; roiBoundVal[2] = 0; @@ -321,9 +413,9 @@ int main(int argc, char *argv[]) if (roi || beg != -1 || end != -1) { if (beg == -1) - beg = 0; + beg = 0; if (end == -1) - end = nZ; + end = nZ-1; std::ostringstream str; @@ -344,15 +436,15 @@ int main(int argc, char *argv[]) int lineOffset = roiBoundVal[0]*pixelSize * numberOfScalarComponents; - for (unsigned int frameNb=beg, frameCount=0; frameNb<=end; frameNb++, frameCount++) + for (int frameNb=beg, frameCount=0; frameNb<=end; frameNb++, frameCount++) { - for (unsigned int lineNb=roiBoundVal[2], lineCount=0; lineNb<=roiBoundVal[3]; lineNb++, lineCount++) - { - /// \todo increment data pointer, don't multiply so much! + for (int lineNb=roiBoundVal[2], lineCount=0; lineNb<=roiBoundVal[3]; lineNb++, lineCount++) + { + /// \todo : increment data pointer, don't multiply so much! memcpy( (void *)(destCopy + frameCount*lgrSubFrame + lineCount*lgrSubLine), (void *)(srcCopy + frameNb*frameSize + lineNb*lineSize + lineOffset ), lgrSubLine); - } + } } // Set the image size @@ -367,77 +459,24 @@ int main(int argc, char *argv[]) str << end-beg+1; fh->InsertEntryString(str.str(),0x0028,0x0008, "IS"); // Number of Frames - fh->SetImageData(subImage,lgrSubImage); - - } - - -//----------------------------------- Write, now! --------------------------------- + //fh->SetImageData(subImage,lgrSubImage); + fh->SetUserData(subImage,lgrSubImage); // ensures the compression (if any) + } + else + { + fh->SetUserData(imageData,dataSize); // ensures the compression (if any) + } - switch (mode[0]) - { - case 'A' : - case 'a' : - // Writting an ACR file - // from a full gdcm readable File - std::cout << "WriteACR" << std::endl; - fh->WriteAcr(outputFileName); - break; - case 'D' : // Not documented in the 'usage', because the method - case 'd' : // is known to be bugged. - // Writting a DICOM Implicit VR file - // from a full gdcm readable File - std::cout << "WriteDCM Implicit VR" << std::endl; - fh->WriteDcmImplVR(outputFileName); - break; - case 'X' : - case 'x' : - // writting a DICOM Explicit VR - // from a full gdcm readable File - std::cout << "WriteDCM Explicit VR" << std::endl; - // fh->WriteDcmExplVR(outputFileName); - // Try this one : - fh->SetWriteTypeToDcmExplVR(); - fh->Write(outputFileName); - break; +//----------------------------------- Write, now! --------------------------------- - case 'R' : - case 'r' : - // Writting a Raw File, - std::cout << "WriteRaw" << std::endl; - fh->WriteRawData(outputFileName); - break; - - // Just for fun : - // Write a 'Video inverse' version of the file. - // *Not* described, on purpose, in the USAGE - case 'V' : - case 'v' : - if ( fh->GetFile()->GetBitsAllocated() == 8) - { - std::cout << "videoinv for 8 bits" << std::endl; - for (int i=0; iWriteDcmExplVR(outputFileName); - break; - } + if (mode[0] != 'R' && mode[0] != 'r') + fh->Write(outputFileName); f->Delete(); fh->Delete(); return 0; } +