DICOM @ OFFIS

Discussion Forum for OFFIS DICOM Tools - For registration, send email with desired user name to the OFFIS DICOM team
It is currently Mon, 2018-09-24, 13:07

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon, 2014-11-24, 22:58 
Offline

Joined: Mon, 2014-11-10, 11:49
Posts: 5
The dump2dcm.exe tool has a maximum line length which can be adjusted by --line. It would be much better if there is no need and the software would take each line no matter how long it is.

I've changed the implementation and I would like to know if you think that it can be made public with the next release (the changes are based on 3.6.0). I'm not familiar with the procedure but as starting point I paste the relevant snippets here:

(1) getLine() function changed to

Code:
static char * getLine(FILE *f)
{
  assert(f!= NULL);
  if (!f)
    return NULL;

  long startPos = ftell(f);
 
  size_t lineLength = 0; //without line ending
  int filePosInc = 0; //set the file position to the last line ending of this line
  int validLineConfidence = 0; //a tag must be present for a line to make it valid "(1234,1234)" so check for "(", "," and ")" and min lenght 11

  while(true)
  {
    char car = fgetc(f);
    if (car == EOF)
    {
      if (lineLength == 0)
        return NULL;
      break;
    }
    else if (car == '\n' || car == '\r')
    {
      ++filePosInc;
      char nextCar = fgetc(f);
      if (nextCar == '\n' && car == '\r' || nextCar == '\r' && car == '\n' )
        ++filePosInc;
     
      break;
    }

    if (car == '(' || car == ',' || car == ')')
      ++validLineConfidence;

    ++lineLength;
  }

  char* line= new char[lineLength + 1]; //+1 for null termination
  line[lineLength]= 0x0;

  fseek(f, startPos, SEEK_SET); //set back to position for line analysis
  size_t readBytes = fread(line, 1, lineLength, f);
  assert(readBytes == lineLength);
 
  fseek(f, filePosInc, SEEK_CUR); //read through the line endings

  /* strip any trailing white space */
  stripTrailingWhitespace(line);

  //check if line can be valid
  if (validLineConfidence< 3 || lineLength< 11)
    line[0]= 0x0;  //invalidates line

  return line;
}


(2) The file needs to be opened with
Code:
 FILE *dumpfile = fopen(opt_ifname, "rb");

to make setting the file read position correctly when the lines contain different line endings

(3) readDumpFile() must be adapted to use lineBuf as loop variable

I did a lot of automated testing for the new getLine() to make it work for the different line endings. It also now checks if the line contains a tag (prevents errors from the parser if there is garbage in the file). I could not detect a noticeable performance decrease for the additional counting part.

For me it makes no sense that, for creating a DICOM file from a dump, you have to have a fixed line size and data exceeding it is just ignored.

Could you please let me know how to proceed.


Top
 Profile  
 
PostPosted: Tue, 2014-11-25, 11:56 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1975
Location: Oldenburg, Germany
Thank you for you proposal. This feature request is already listed in our internal tracker (to-do list).
I've just added a link to your posting to this Feature #304 (number as a reference for my colleagues).


Top
 Profile  
 
PostPosted: Tue, 2014-11-25, 22:07 
Offline

Joined: Mon, 2014-11-10, 11:49
Posts: 5
Thanks for the response. Can I register to get updates from your TODO list?


Top
 Profile  
 
PostPosted: Wed, 2014-11-26, 13:38 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1975
Location: Oldenburg, Germany
Quote:
Can I register to get updates from your TODO list?

This is what we intend to provide (in the near future), but currently there is no access to this list from outside of the core DCMTK team.

We'll keep you posted...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group