[vtkusers] Localization problem with reading and writing of human readable file formats, obj, ply, ...

Hanno Hugenberg hugenberg at dornheim-medical-images.de
Mon Feb 13 04:30:00 EST 2012


Hi everyone,

we detected a minor problem today with the fileimport of obj (and 
probably all other human readable file formats).

Loading an obj file on a different localized system results in a 
failure. valid files wont get loaded on our systems.

The reason is:

the obj loader wants to read floating point values like this:

vtkOBJReader.cxx, line 183:

  if (strcmp(cmd, "v") == 0)
       {
       // this is a vertex definition, expect three floats, separated by 
whitespace:
       if (sscanf(pLine, "%f %f %f", xyz, xyz+1, xyz+2) == 3)
         {
         points->InsertNextPoint(xyz);
         }
       else
         {
           vtkErrorMacro(<<"Error reading 'v' at line " << lineNr );
         everything_ok = false;
         }
       }

Since the localisation was changed due to the application needs, the 
functions used by vtk who are influenced by this now create "wrong" results.

a german localized "sscanf" expects as float a string with comma 
seperation like:
  "7,123"

  BUT: the obj standard defines the use of point seperation like:
"7.123"

This problem is similar to a very old topic in the mailinglist archive:
http://public.kitware.com/pipermail/insight-users/2006-July/018783.html

The suggestion was to use the

setlocale (LC_NUMERIC,"C");

command from the standard c library to switch back to the general 
"7.123" reading behaviour.
But this may corrupt other parts in a program which rely on the local 
settings already done.

So the only option is to push/pop the local setting everytime there is a 
need to call one of the load/save/etc functions/classes which uses the 
standard c functions.


Is there not a way to change the loader functions to be fully file 
format compatible no matter which languages is set in an application via 
setLocal?

Any ideas regarding this?
I think we are not the only people having this problem

Best regards & thx for an awesome library.

Hanno



More information about the vtkusers mailing list