Program: gdcm
Module: $RCSfile: gdcmFile.cxx,v $
Language: C++
- Date: $Date: 2005/02/10 20:53:23 $
- Version: $Revision: 1.223 $
+ Date: $Date: 2005/03/22 11:37:15 $
+ Version: $Revision: 1.231 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
{
//-----------------------------------------------------------------------------
// Constructor / Destructor
+
+/**
+ * \brief Constructor used when we want to generate dicom files from scratch
+ */
+File::File():
+ Document()
+{
+ RLEInfo = new RLEFramesInfo;
+ JPEGInfo = new JPEGFragmentsInfo;
+ GrPixel = 0x7fe0;
+ NumPixel = 0x0010;
+}
+
/**
* \brief Constructor
* @param filename name of the file whose header we want to analyze
*/
File::File( std::string const &filename )
- :Document( filename )
+ :Document(filename)
{
RLEInfo = new RLEFramesInfo;
JPEGInfo = new JPEGFragmentsInfo;
// Create a new BinEntry to change the the DictEntry
// The changed DictEntry will have
// - a correct PixelVR OB or OW)
- // - a VM to "PXL"
// - the name to "Pixel Data"
BinEntry *oldEntry = dynamic_cast<BinEntry *>(entry);
if(oldEntry)
}
}
-/**
- * \brief Constructor used when we want to generate dicom files from scratch
- */
-File::File():
- Document()
-{
- RLEInfo = new RLEFramesInfo;
- JPEGInfo = new JPEGFragmentsInfo;
- InitializeDefaultFile();
-}
/**
* \brief Canonical destructor.
//-----------------------------------------------------------------------------
// Public
+
+
/**
* \brief This predicate, based on hopefully reasonable heuristics,
* decides whether or not the current File was properly parsed
*/
int File::GetImageNumber()
{
- // The function i atoi() takes the address of an area of memory as
- // parameter and converts the string stored at that location to an integer
- // using the external decimal to internal binary conversion rules. This may
- // be preferable to sscanf() since atoi() is a much smaller, simpler and
- // faster function. sscanf() can do all possible conversions whereas
- // atoi() can only do single decimal integer conversions.
- //0020 0013 IS REL Image Number
+ //0020 0013 : Image Number
std::string strImNumber = GetEntryValue(0x0020,0x0013);
if ( strImNumber != GDCM_UNFOUND )
{
*/
ModalityType File::GetModality()
{
- // 0008 0060 CS ID Modality
+ // 0008 0060 : Modality
std::string strModality = GetEntryValue(0x0008,0x0060);
if ( strModality != GDCM_UNFOUND )
{
else if ( strModality.find("PT") < strModality.length()) return PT;
else if ( strModality.find("RF") < strModality.length()) return RF;
else if ( strModality.find("RG") < strModality.length()) return RG;
- else if ( strModality.find("RTDOSE") < strModality.length()) return RTDOSE;
- else if ( strModality.find("RTIMAGE") < strModality.length()) return RTIMAGE;
- else if ( strModality.find("RTPLAN") < strModality.length()) return RTPLAN;
- else if ( strModality.find("RTSTRUCT") < strModality.length()) return RTSTRUCT;
+ else if ( strModality.find("RTDOSE")
+ < strModality.length()) return RTDOSE;
+ else if ( strModality.find("RTIMAGE")
+ < strModality.length()) return RTIMAGE;
+ else if ( strModality.find("RTPLAN")
+ < strModality.length()) return RTPLAN;
+ else if ( strModality.find("RTSTRUCT")
+ < strModality.length()) return RTSTRUCT;
else if ( strModality.find("SM") < strModality.length()) return SM;
else if ( strModality.find("ST") < strModality.length()) return ST;
else if ( strModality.find("TG") < strModality.length()) return TG;
if ( xspacing == 0.)
{
- gdcmWarningMacro("gdcmData/CT-MONO2-8-abdo.dcm problem");
+ gdcmWarningMacro("gdcmData/CT-MONO2-8-abdo.dcm-like problem");
// seems to be a bug in the header ...
nbValues = sscanf( strSpacing.c_str(), "%f\\0\\%f", &yspacing, &xspacing);
gdcmAssertMacro( nbValues == 2 );
*/
float File::GetZSpacing()
{
- // Spacing Between Slices : distance entre le milieu de chaque coupe
- // Les coupes peuvent etre :
+ // Spacing Between Slices : distance between the middle of 2 slices
+ // Slices may be :
// jointives (Spacing between Slices = Slice Thickness)
- // chevauchantes (Spacing between Slices < Slice Thickness)
+ // overlapping (Spacing between Slices < Slice Thickness)
// disjointes (Spacing between Slices > Slice Thickness)
// Slice Thickness : epaisseur de tissus sur laquelle est acquis le signal
- // ca interesse le physicien de l'IRM, pas le visualisateur de volumes ...
- // Si le Spacing Between Slices est Missing,
- // on suppose que les coupes sont jointives
+ // It only concerns the MRI guys, not people wanting to visualize volmues
+ // If Spacing Between Slices is Missing,
+ // we suppose slices joint together
const std::string &strSpacingBSlices = GetEntryValue(0x0018,0x0088);
* - 32S signed 32 bit,
* - FD floating double 64 bits (Not kosher DICOM, but so usefull!)
* \warning 12 bit images appear as 16 bit.
- * 24 bit images appear as 8 bit
+ * 24 bit images appear as 8 bit + photochromatic interp ="RGB "
* @return 0S if nothing found. NOT USABLE file. The caller has to check
*/
std::string File::GetPixelType()
}
/**
- * \brief Check whether this a monochrome picture or not by accessing
- * the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
+ * \brief Check whether this a monochrome picture (gray levels) or not,
+ * using "Photometric Interpretation" tag (0x0028,0x0004).
* @return true when "MONOCHROME1" or "MONOCHROME2". False otherwise.
*/
bool File::IsMonochrome()
return false;
}
+/**
+ * \brief Check whether this a MONOCHROME1 picture (high values = dark)
+ * or not using "Photometric Interpretation" tag (0x0028,0x0004).
+ * @return true when "MONOCHROME1" . False otherwise.
+ */
+bool File::IsMonochrome1()
+{
+ const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 );
+ if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") )
+ {
+ return true;
+ }
+ if ( PhotometricInterp == GDCM_UNFOUND )
+ {
+ gdcmWarningMacro( "Not found : Photometric Interpretation (0028,0004)");
+ }
+ return false;
+}
+
/**
* \brief Check whether this a "PALETTE COLOR" picture or not by accessing
* the "Photometric Interpretation" tag ( 0x0028, 0x0004 ).
void File::AnonymizeNoLoad()
{
std::fstream *fp = new std::fstream(Filename.c_str(),
- std::ios::in | std::ios::out | std::ios::binary);
-
- // TODO : FIXME
- // how to white out disk space if longer than 50 ?
-
-
+ std::ios::in | std::ios::out | std::ios::binary);
gdcm::DocEntry *d;
uint32_t offset;
uint32_t lgth;
* (as opposed to 'DicomDir related') entries
* then writes in a file all the (Dicom Elements) included the Pixels
* @param fileName file name to write to
- * @param filetype Type of the File to be written
+ * @param writetype Type of the File to be written
* (ACR, ExplicitVR, ImplicitVR)
*/
-bool File::Write(std::string fileName, FileType filetype)
+bool File::Write(std::string fileName, FileType writetype)
{
std::ofstream *fp = new std::ofstream(fileName.c_str(),
std::ios::out | std::ios::binary);
}
// Entry : 0002|0000 = group length -> recalculated
- ValEntry *e0002 = GetValEntry(0x0002,0x0000);
- if( e0002 )
+ ValEntry*e0000 = GetValEntry(0x0002,0x0000);
+ if( e0000 )
{
std::ostringstream sLen;
- sLen << ComputeGroup0002Length(filetype);
- e0002->SetValue(sLen.str());
+ sLen << ComputeGroup0002Length(writetype);
+ e0000->SetValue(sLen.str());
}
// Bits Allocated
}
}
- Document::WriteContent(fp, filetype);
+ Document::WriteContent(fp, writetype);
fp->close();
delete fp;
//-----------------------------------------------------------------------------
// Protected
-/**
- * \brief Initialize a default DICOM File that should contain all the
- * field require by other reader. DICOM standard does not
- * explicitely defines those fields, heuristic has been choosen.
- * This is not perfect as we are writting a CT image...
- */
-void File::InitializeDefaultFile()
-{
- std::string date = Util::GetCurrentDate();
- std::string time = Util::GetCurrentTime();
- std::string uid = Util::CreateUniqueUID();
- std::string uidMedia = uid;
- std::string uidInst = uid;
- std::string uidClass = Util::CreateUniqueUID();
- std::string uidStudy = Util::CreateUniqueUID();
- std::string uidSerie = Util::CreateUniqueUID();
-
- // Meta Element Group Length
- InsertValEntry("146 ", 0x0002, 0x0000);
- // Media Storage SOP Class UID (CT Image Storage)
- InsertValEntry("1.2.840.10008.5.1.4.1.1.2", 0x0002, 0x0002);
- // Media Storage SOP Instance UID
- InsertValEntry(uidMedia.c_str(), 0x0002, 0x0003);
- // Transfer Syntax UID (Explicit VR Little Endian)
- InsertValEntry("1.2.840.10008.1.2.1 ", 0x0002, 0x0010);
- // META Implementation Class UID
- InsertValEntry(uidClass.c_str(), 0x0002, 0x0012);
- // Source Application Entity Title
- InsertValEntry("GDCM", 0x0002, 0x0016);
-
- // Instance Creation Date
- InsertValEntry(date.c_str(), 0x0008, 0x0012);
- // Instance Creation Time
- InsertValEntry(time.c_str(), 0x0008, 0x0013);
- // SOP Class UID
- InsertValEntry("1.2.840.10008.5.1.4.1.1.2", 0x0008, 0x0016);
- // SOP Instance UID
- InsertValEntry(uidInst.c_str(), 0x0008, 0x0018);
- // Modality
- InsertValEntry("CT", 0x0008, 0x0060);
- // Manufacturer
- InsertValEntry("GDCM", 0x0008, 0x0070);
- // Institution Name
- InsertValEntry("GDCM", 0x0008, 0x0080);
- // Institution Address
- InsertValEntry("http://www-creatis.insa-lyon.fr/Public/Gdcm", 0x0008, 0x0081);
-
- // Patient's Name
- InsertValEntry("GDCM", 0x0010, 0x0010);
- // Patient ID
- InsertValEntry("GDCMID", 0x0010, 0x0020);
-
- // Study Instance UID
- InsertValEntry(uidStudy.c_str(), 0x0020, 0x000d);
- // Series Instance UID
- InsertValEntry(uidSerie.c_str(), 0x0020, 0x000e);
- // StudyID
- InsertValEntry("1", 0x0020, 0x0010);
- // SeriesNumber
- InsertValEntry("1", 0x0020, 0x0011);
-
- // Samples per pixel 1 or 3
- InsertValEntry("1", 0x0028, 0x0002);
- // photochromatic interpretation
- InsertValEntry("MONOCHROME1", 0x0028, 0x0004);
- // nbRows
- InsertValEntry("0", 0x0028, 0x0010);
- // nbCols
- InsertValEntry("0", 0x0028, 0x0011);
- // BitsAllocated 8 or 12 or 16
- InsertValEntry("8", 0x0028, 0x0100);
- // BitsStored <= BitsAllocated
- InsertValEntry("8", 0x0028, 0x0101);
- // HighBit <= BitsAllocated - 1
- InsertValEntry("7", 0x0028, 0x0102);
- // Pixel Representation 0(unsigned) or 1(signed)
- InsertValEntry("0", 0x0028, 0x0103);
-
- // default value
- // Special case this is the image (not a string)
- GrPixel = 0x7fe0;
- NumPixel = 0x0010;
- InsertBinEntry(0, 0, GrPixel, NumPixel);
-}
+
//-----------------------------------------------------------------------------
// Private