Quantcast

vtkDICOMReader read chinese character problem

classic Classic list List threaded Threaded
6 messages Options
Ang
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

vtkDICOMReader read chinese character problem

Ang
This post was updated on .
Hi all,

My IDE is vs 2015 with QT 5.6 and vtk 7.1.

My sorting dicom pipline is  QFileDialog -> QStringlist -> vtkDICOMReader.

When I set FileName with chinese character like "c://中文/dicom.dcm", I can retrieve infomation in Dicom tag, but I can't retrieve raw data correctly.

I have tried to convert utf8 to ansi (it  works well in VtkgdcmImageReader class),but  vtkDICOMFile class will give me error message in Access function.


Is there a way to read chinese character with  vtkDICOMReader  correctly?

Thanks in advance for your help.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMReader read chinese character problem

David Gobbi
Hi Ang,

The vtkDICOMReader needs the filenames to be utf8.  But I am guessing that you have already tried utf8?

What is the Transfer Syntax UID for the dicom file?

 - David


On Thu, Mar 30, 2017 at 4:17 AM, Ang <[hidden email]> wrote:
Hi all,

My IDE is vs 2015 with QT 5.6 and vtk 7.1.

My sorting dicom pipline is  QFileDialog -> QStringlist -> vtkDICOMReader.

When I set FileName with chinese character like "c://中文/dicom.dcm", I can
retrieve infomation in Dicom tag, but I can't retrieve raw data.

I have tried to convert utf8 to ansi (it  works well in VtkgdcmImageReader
class),but  vtkDICOMFile class will give me error message in Access
function.


Is there a way to read chinese character with  vtkDICOMReader  well?

Thanks in advance for your help.

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Ang
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMReader read chinese character problem

Ang
This post was updated on .
Hi David,

My character default setting is UTF-8 and the Transfer Syntax UID is "1.2.840.10008.1.2.4.91"
.

Finally, I found the solution that gdcmReader needs the filename to be ansi(I guess), I add below code in vtkDICOMReader at line 1460 to 1470.

***********************************************

  gdcm::ImageReader reader;

  int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
  wchar_t* wfilename = new wchar_t[len + 1];
  memset(wfilename, 0, len * 2 + 2);
  MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, len);
  len = WideCharToMultiByte(CP_ACP, 0, wfilename, -1, NULL, 0, NULL, NULL);
  char* szfilename = new char[len + 1];
  memset(szfilename, 0, len + 1);
  WideCharToMultiByte(CP_ACP, 0, wfilename, -1, szfilename, len, NULL, NULL);
  std::string strTemp(szfilename);
  if (wfilename) delete[] wfilename;
  if (szfilename) delete[] szfilename;


  reader.SetFileName(strTemp.c_str());

****************************************************

Is this solution better?



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMReader read chinese character problem

David Gobbi
On Thu, Mar 30, 2017 at 8:52 PM, Ang <[hidden email]> wrote:
Hi David,

My character default setting is UTF-8 and the Transfer Syntax UID is
"1.2.840.10008.1.2.4.91"
.

Finally, I found the solution that gdcmReader needs the filename to be
ansi(I guess), I add below code in vtkDICOMReader at line 1460 to 1470.

***********************************************

  gdcm::ImageReader reader;

  int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
  wchar_t* wfilename = new wchar_t[len + 1];
  memset(wfilename, 0, len * 2 + 2);
  MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, len);
  len = WideCharToMultiByte(CP_ACP, 0, wfilename, -1, NULL, 0, NULL, NULL);
  char* szfilename = new char[len + 1];
  memset(szfilename, 0, len + 1);
  WideCharToMultiByte(CP_ACP, 0, wfilename, -1, szfilename, len, NULL,
NULL);
  std::string strTemp(szfilename);
  if (wfilename) delete[] wfilename;
  if (szfilename) delete[] szfilename;
  reader.SetFileName(strTemp.c_str());

****************************************************

Is this solution better?


Yes, that is the correct solution, since your ANSI character set is Chinese.
Because vtkDICOMReader uses gdcm for decompression, it is necessary
to do this conversion if you use any compressed transfer syntax.

Most of the VTK readers use ANSI on Windows.  Personally, I think that it
would be better if they all used utf-8 (and if gdcm used utf-8, too).  Especially
since the the native character set on Windows and NTFS is Unicode.

 - David
 

_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMReader read chinese character problem

David Gobbi
I've added a similar utf8-to-ansi fix to vtk-dicom on github:

 - David

On Thu, Mar 30, 2017 at 9:41 PM, David Gobbi <[hidden email]> wrote:
On Thu, Mar 30, 2017 at 8:52 PM, Ang <[hidden email]> wrote:
Hi David,

My character default setting is UTF-8 and the Transfer Syntax UID is
"1.2.840.10008.1.2.4.91"
.

Finally, I found the solution that gdcmReader needs the filename to be
ansi(I guess), I add below code in vtkDICOMReader at line 1460 to 1470.

***********************************************

  gdcm::ImageReader reader;

  int len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
  wchar_t* wfilename = new wchar_t[len + 1];
  memset(wfilename, 0, len * 2 + 2);
  MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, len);
  len = WideCharToMultiByte(CP_ACP, 0, wfilename, -1, NULL, 0, NULL, NULL);
  char* szfilename = new char[len + 1];
  memset(szfilename, 0, len + 1);
  WideCharToMultiByte(CP_ACP, 0, wfilename, -1, szfilename, len, NULL,
NULL);
  std::string strTemp(szfilename);
  if (wfilename) delete[] wfilename;
  if (szfilename) delete[] szfilename;
  reader.SetFileName(strTemp.c_str());

****************************************************

Is this solution better?


Yes, that is the correct solution, since your ANSI character set is Chinese.
Because vtkDICOMReader uses gdcm for decompression, it is necessary
to do this conversion if you use any compressed transfer syntax.

Most of the VTK readers use ANSI on Windows.  Personally, I think that it
would be better if they all used utf-8 (and if gdcm used utf-8, too).  Especially
since the the native character set on Windows and NTFS is Unicode.

 - David
 


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Ang
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: vtkDICOMReader read chinese character problem

Ang
Hi David,

I have tried it, and it works well .

Thanks for your help!!

Loading...