Request: dump2dcm.cc: dynamic detection of line length

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
Potti
Posts: 5
Joined: Mon, 2014-11-10, 11:49

Request: dump2dcm.cc: dynamic detection of line length

#1 Post by Potti » Mon, 2014-11-24, 22:58

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: Select all

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: Select all

 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.

J. Riesmeier
DCMTK Developer
Posts: 2008
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Request: dump2dcm.cc: dynamic detection of line length

#2 Post by J. Riesmeier » Tue, 2014-11-25, 11:56

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).

Potti
Posts: 5
Joined: Mon, 2014-11-10, 11:49

Re: Request: dump2dcm.cc: dynamic detection of line length

#3 Post by Potti » Tue, 2014-11-25, 22:07

Thanks for the response. Can I register to get updates from your TODO list?

J. Riesmeier
DCMTK Developer
Posts: 2008
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: Request: dump2dcm.cc: dynamic detection of line length

#4 Post by J. Riesmeier » Wed, 2014-11-26, 13:38

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...

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest