-
-/**
- * \brief Writes in a file (according to the requested format)
- * the value of a single gdcmDocEntry passed as argument.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written
- */
-
- // TODO : to be re -written recursively !
-
-void gdcmDocument::WriteEntryValue(gdcmDocEntry *tag, FILE *_fp,FileType type)
-{
- (void)type;
- guint16 group = tag->GetGroup();
- VRKey vr = tag->GetVR();
- guint32 lgr = tag->GetReadLength();
-
- if (vr == "SQ")
- // SeQuences have no value:
- return;
- if (group == 0xfffe)
- // Delimiters have no associated value:
- return;
-
- //--------------------------------
- //
- // FIXME :right now, both value and voidArea belong to gdcmValue
- //
- // -------------------------------
-
-// if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) ) {
- void *voidArea;
- gdcmBinEntry *BinEntry= (gdcmBinEntry *)tag;;
- voidArea = BinEntry->GetVoidArea();
- if (voidArea != NULL)
- { // there is a 'non string' LUT, overlay, etc
- fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
- return;
- }
-// }
-
- if (vr == "US" || vr == "SS")
- {
- // some 'Short integer' fields may be mulivaluated
- // each single value is separated from the next one by '\'
- // we split the string and write each value as a short int
- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (((gdcmValEntry *)tag)->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint16 val_uint16 = atoi(tokens[i].c_str());
- void *ptr = &val_uint16;
- fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- // some 'Integer' fields may be mulivaluated
- // each single value is separated from the next one by '\'
- // we split the string and write each value as an int
- if (vr == "UL" || vr == "SL")
- {
- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (((gdcmValEntry *)tag)->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint32 val_uint32 = atoi(tokens[i].c_str());
- void *ptr = &val_uint32;
- fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- fwrite (((gdcmValEntry *)tag)->GetValue().c_str(), (size_t)lgr ,(size_t)1, _fp); // Elem value
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * a single gdcmDocEntry passed as argument.
- * \sa WriteEntryValue, WriteEntryTagVRLength.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written
- */
-
-bool gdcmDocument::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type)
-{
- guint32 length = tag->GetLength();
-
- if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(tag) ) {
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
- if(length%2==1) {
- ValEntry->SetValue(ValEntry->GetValue()+"\0");
- ValEntry->SetLength(ValEntry->GetReadLength()+1);
- }
- WriteEntryTagVRLength(ValEntry, _fp, type);
- WriteEntryValue(ValEntry, _fp, type);
- return true;
- }
-
- if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) ) {
- //
- // FIXME : when voidArea belong to gdcmBinEntry only, fix voidArea length
- //
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
- /*
- if(length%2==1) {
- tag->SetValue(tag->GetValue()+"\0");
- tag->SetLength(tag->GetReadLength()+1);
- }
-*/
- WriteEntryTagVRLength(tag, _fp, type);
- WriteEntryValue(tag, _fp, type);
- return true;
- }
-}
-
-/**
- * \brief writes on disc according to the requested format
- * (ACR-NEMA, ExplicitVR, ImplicitVR) the image
- * using the Chained List
- * \warning does NOT add the missing elements in the header :
- * it's up to the user doing it !
- * (function CheckHeaderCoherence to be written)
- * \warning DON'T try, right now, to write a DICOM image
- * from an ACR Header (meta elements will be missing!)
- * @param type type of the File to be written
- * (ACR-NEMA, ExplicitVR, ImplicitVR)
- * @param _fp already open file pointer
- */
-
-bool gdcmDocument::WriteEntries(FILE *_fp,FileType type)
-{
-
-// FIXME : explore recursively the whole structure...
-
- /// \todo (?) check write failures (after *each* fwrite)
-
- std::cout << "--------------------- gdcmDocument::WriteEntries " << std::endl;
- for (TagDocEntryHT::iterator tag2=tagHT.begin();
- tag2 != tagHT.end();
- ++tag2)
- {
-
- (*tag2).second->Print();
-
- if ( type == gdcmACR ){
- if ((*tag2).second->GetGroup() < 0x0008)
- // Ignore pure DICOM V3 groups
- continue;
- if ((*tag2).second->GetGroup() %2)
- // Ignore the "shadow" groups
- continue;
- if ((*tag2).second->GetVR() == "SQ" ) // ignore Sequences
- continue;
- }
- if (! WriteEntry((*tag2).second,_fp,type) ) {
- std::cout << "Write Failure " << std::endl;
- return false;
- } else {
-
- }
- }
- return true;
-}
-