[vtkusers] wx/vtk weirdness

Scott Johnson Scott.Johnson at neuwave.com
Mon Nov 30 10:16:01 EST 2009


Hi All,

 

I realize that the initial email that reported this problem was related to reading DICOM attributes.  However, it seems that this is really a problem with the SCU that encoded the DICOM message.  In the DICOM standard, the strings which encode numerical values have a Value Representation (VR) of DS (Decimal String).  The definition in Part 5 of the standard for a DS is:

 

A fixed point number shall contain only the characters 0-9 with an optional leading "+" or "-" and an optional "." to mark the decimal point.  A floating point number shall be conveyed as defined in ANSI X3.9, with an "E" or "e" to indicate the start of the exponent. Decimal Strings may be padded with leading or trailing spaces. Embedded spaces are not allowed.

Note: Data Elements with multiple values using this VR may not be properly encoded if Explicit-VR transfer syntax is used and the VL of this attribute exceeds 65534 bytes.

 

This does not allow for the use of a "," in the encoding of the decimal strings.

 

This isn't to say that taking care of internationalization for other reasons isn't a good thing.  I'm just pointing out that the DICOM implementation isn't the reason to do it.

 

Thanks

 

                                -- Scott

 

From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Jérôme
Sent: Friday, November 27, 2009 1:37 PM
To: Marcus D. Hanwell
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] wx/vtk weirdness

 

My 2c:
I encountered this problem with ParaView, for which I exposed the vtkDICOMImageReader. With french locales, and under linux (fedora 9-11-12), I cannot open a DICOM volume. I changed my language settings to English (UK) and that did the trick. I remember to have such a discussion about ascii writer ( http://www.mail-archive.com/paraview@paraview.org/msg04621.html ).

I will closely follow that thread!

Jerome

2009/11/27 Marcus D. Hanwell <marcus.hanwell at kitware.com>

This issue hit us on a project I worked on previously. After a quick search a
few relevant pages may help to clear up the situation. I know from an i18n
point of view, and from being a good library (where readers are often called
in separate threads so as not to lock the GUI) we should not set the global
locale.

Instead the C++ functions and classes should be used in combination with
imbue. See for example,

http://stackoverflow.com/questions/1333451/c-locale-independent-atof

This means that the C functions such as scanf cannot be used if you are
relying on the imbue functionality.

Marcus


On Friday 27 November 2009 13:29:29 Francois Bertel wrote:
> Actually, the documentation of setlocale() says that:
>
> "
> On startup of the main program, the portable "C" locale is selected as
>  default. "
> (this is probably what Markus merely remembered when he said "The C
> functions as I remember set the locale globally")
>
> It means that changing the LC_ALL environment variable in a dashboard
> script is pointless.
>
> It also means, as stated at the beginning of this discussion (but I
> haven't read it that way) that, in the combination with wx and vtk,
> the wx component is the probably the one forcing the locales to be
> something like:
>
>  setlocale(LC_ALL, ""); // Make the program portable to all locales
> (LC_NUMERIC, LC_TIME, ...)
>
>
> So we have to go back to the first approach for regression testing:
> forcing a non English locale at the beginning of the test.
>
>
> On Fri, Nov 27, 2009 at 1:09 PM, Mathieu Malaterre
>
> <mathieu.malaterre at gmail.com> wrote:
> > I do not know for Windows. But for UNIX machine if the fr_FR locale is
> > not installed , I think setlocale() is simply a no-OP. Part of the
> > test should make sure that "," is indeed the LC_NUMERIC separator.
> >
> > 2cts
> >
> > On Fri, Nov 27, 2009 at 7:05 PM, Francois Bertel
> >
> > <francois.bertel at kitware.com> wrote:
> >> Actually, forcing a non English locale in a test is probably the wrong
> >> approach because the locale might not exist on the system.
> >> Instead, it is probably better to change the environment variable on a
> >> dashboard machine.
> >>
> >> I just changed the script of arkadia on VTK to run the tests under
> >> French locales, with the following lines:
> >>
> >> # save LC_ALL
> >> set(saved_lc_all "$ENV{LC_ALL}")
> >> [...]
> >> # Change locales to make sure the text file readers and writers are
> >> locale independent:
> >> # Before writing the following line, we made sure that "fr_FR.utf8" is
> >> listed in # "locale -a", if not, install package "language-support-fr"
> >> set(ENV{LC_ALL} "fr_FR.utf8")
> >>
> >> [...]
> >> ctest_test(BUILD "${CTEST_BINARY_DIRECTORY}")
> >> [...]
> >> # restore LC_ALL
> >> set(ENV{LC_ALL} "${saved_lc_all}")
> >>
> >>
> >> We'll see how bad is it for VTK tomorrow.
> >>
> >>
> >> On Fri, Nov 27, 2009 at 12:17 PM, Francois Bertel
> >>
> >> <francois.bertel at kitware.com> wrote:
> >>> ... starting with regression tests that do the following:
> >>>
> >>> For a text reader:
> >>>
> >>> 1. switch to a locale known to be different than English regarding
> >>> numerical rules, like French where "," and "." have opposite meaning.
> >>> 2. read the file (assuming the file to read is encoded in C|POSIX
> >>> locales)
> >>>
> >>> For a text writer:
> >>> 1. switch to a non English locale
> >>> 2. write a file
> >>> 3. switch to an English locale
> >>> 4. read the file
> >>>
> >>> On Fri, Nov 27, 2009 at 12:07 PM, Bill Lorensen
<bill.lorensen at gmail.com> wrote:
> >>>> Looks like we have some work to do in both itk and vtk.
> >>>>
> >>>> Bill
> >>>>
> >>>> On Fri, Nov 27, 2009 at 12:05 PM, Francois Bertel
> >>>>
> >>>> <francois.bertel at kitware.com> wrote:
> >>>>> note: it is necessary to duplicate the return value of setlocale() as
> >>>>> it can be a pointer to a static string.
> >>>>>
> >>>>> On Fri, Nov 27, 2009 at 12:04 PM, Francois Bertel
> >>>>>
> >>>>> <francois.bertel at kitware.com> wrote:
> >>>>>> Something like that:
> >>>>>>
> >>>>>> // save the current locale
> >>>>>>  prev_locale = setlocale(LC_NUMERIC, NULL);
> >>>>>>  prev_locale = dupstring(setlocale(LC_NUMERIC, NULL));
> >>>>>> setlocale(LC_NUMERIC, "POSIX");
> >>>>>>
> >>>>>> <reader code here>
> >>>>>>
> >>>>>> // Restore locale
> >>>>>> setlocale(LC_NUMERIC, prev_locale);
> >>>>>> if(prev_locale)
> >>>>>> {
> >>>>>>  setlocale(LC_NUMERIC, prev_locale);
> >>>>>> }
> >>>>>>
> >>>>>> ref: http://www.zsh.org/mla/workers/2003/msg00210.html
> >>>>>>
> >>>>>> I don't think bug 5891 is relevant as it elimitates the use of
> >>>>>> interpretation of text into numerical values.
> >>>>>> Patch in bug 1431 was using the selocale() function (as above).
> >>>>>>
> >>>>>>
> >>>>>> On Fri, Nov 27, 2009 at 11:58 AM, Mathieu Malaterre
> >>>>>>
> >>>>>> <mathieu.malaterre at gmail.com> wrote:
> >>>>>>> On Fri, Nov 27, 2009 at 5:57 PM, Marcus D. Hanwell
> >>>>>>>
> >>>>>>> <marcus.hanwell at kitware.com> wrote:
> >>>>>>>> The C functions as I remember set the locale globally which can
> >>>>>>>> also cause unexpected bugs if a library changes this internally.
> >>>>>>>
> >>>>>>> Ah ! That answer my question :)
> >>>>>>>
> >>>>>>> Thx
> >>>>>>> --
> >>>>>>> Mathieu
> >>>>>>> _______________________________________________
> >>>>>>> Powered by www.kitware.com
> >>>>>>>
> >>>>>>> Visit other Kitware open-source projects at
> >>>>>>> http://www.kitware.com/opensource/opensource.html
> >>>>>>>
> >>>>>>> Please keep messages on-topic and check the VTK FAQ at:
> >>>>>>> http://www.vtk.org/Wiki/VTK_FAQ
> >>>>>>>
> >>>>>>> Follow this link to subscribe/unsubscribe:
> >>>>>>> http://www.vtk.org/mailman/listinfo/vtkusers
> >>>>>>
> >>>>>> --
> >>>>>> François Bertel, PhD  | Kitware Inc. Suite 204
> >>>>>> 1 (518) 371 3971 x113 | 28 Corporate Drive
> >>>>>>                      | Clifton Park NY 12065, USA
> >>>>>
> >>>>> --
> >>>>> François Bertel, PhD  | Kitware Inc. Suite 204
> >>>>> 1 (518) 371 3971 x113 | 28 Corporate Drive
> >>>>>                      | Clifton Park NY 12065, USA
> >>>>> _______________________________________________
> >>>>> Powered by www.kitware.com
> >>>>>
> >>>>> Visit other Kitware open-source projects at
> >>>>> http://www.kitware.com/opensource/opensource.html
> >>>>>
> >>>>> Please keep messages on-topic and check the VTK FAQ at:
> >>>>> http://www.vtk.org/Wiki/VTK_FAQ
> >>>>>
> >>>>> Follow this link to subscribe/unsubscribe:
> >>>>> http://www.vtk.org/mailman/listinfo/vtkusers
> >>>
> >>> --
> >>> François Bertel, PhD  | Kitware Inc. Suite 204
> >>> 1 (518) 371 3971 x113 | 28 Corporate Drive
> >>>                      | Clifton Park NY 12065, USA
> >>
> >> --
> >> François Bertel, PhD  | Kitware Inc. Suite 204
> >> 1 (518) 371 3971 x113 | 28 Corporate Drive
> >>                      | Clifton Park NY 12065, USA
> >> _______________________________________________
> >> Powered by www.kitware.com
> >>
> >> Visit other Kitware open-source projects at
> >> http://www.kitware.com/opensource/opensource.html
> >>
> >> Please keep messages on-topic and check the VTK FAQ at:
> >> http://www.vtk.org/Wiki/VTK_FAQ
> >>
> >> Follow this link to subscribe/unsubscribe:
> >> http://www.vtk.org/mailman/listinfo/vtkusers
> >
> > --
> > Mathieu
>

--

Marcus D. Hanwell, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4937
_______________________________________________

Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091130/bfc86a14/attachment.htm>


More information about the vtkusers mailing list