[Insight-users] MetaImage: absolute path in ElementDataFile not working

Florian Pierron F.Pierron at exeter.ac.uk
Tue May 13 16:59:00 EDT 2008


Hi Luis,

Sorry to take so much of your time, but it's still not working for me 
(without spaces in the path).

The patch that I described previously by changing the condition on the 
variable 'usePath' seems to fix the problem. Are you sure MetaImage 
supports absolute path in the ElementDataFile field?

Regards,
Florian


On 13/05/2008 17:30, Luis Ibanez wrote:
>
> Hi Florian,
>
> Thanks for sending our files.
>
> I'm not sure that MetaImage can manage
> filenames that have spaces in the path....
>
>
> Your file is located at:
>
>      "C:\Program Files\Data\MyData.raw"
>
>
> Just to double check,
> Please do the following
>
>   Move your .mhd and .raw files to a directory
>   without spaces. Something like:
>
>       C:\itktest\MyData.mhd
>       C:\itktest\MyData.raw
>
>
> Try to read them from that location,
> and let us know what you find.
>
> If you can read the files then we
> should probably fill a bug report
> regarding filenames with spaces
> and the MetaImage library.
>
>
>    Thanks
>
>
>       Luis
>
>
> -----------------------
> Florian Pierron wrote:
>> Hi Luis,
>>
>> Thanks for your quick reply.
>>
>> I am using VC2005 to compile the code. I don't see anything obviously 
>> wrong with the path, it is:
>> ElementDataFile = C:\Program Files\Data\MyData.raw
>>
>> I have attached the .mha file and the .raw image. Let me know if you 
>> can load it.
>>
>> Regards,
>> Florian
>>
>> ***********************
>> ObjectType = Image
>> NDims = 2
>> DimSize = 50 50
>> ElementByteOrderMSB = False
>> ElementNumberOfChannels = 1
>> ElementType = MET_UCHAR
>> ElementDataFile = C:\Program Files\Data\MyData.raw
>> ***********************
>>
>>
>> On 12/05/2008 14:50, Luis Ibanez wrote:
>>
>>>
>>> Hi Florian,
>>>
>>> Could you please post the *exact* absolute path that you were using
>>> when you encounter this problem ?
>>>
>>> We are able to read files with absolute path without any problem.
>>> It is therefore likely that there is something special about the
>>> path that you were using.
>>>
>>> Also, please let us know what platform are you using.
>>>
>>>
>>>    Thanks
>>>
>>>
>>>       Luis
>>>
>>>
>>> ---------------------
>>> Florian Pierron wrote:
>>>
>>>> Dear ITK developer team,
>>>>
>>>> I noticed that having an absolute path in the ElementDataFile is 
>>>> not supported in ITK 3.4.0. I don't know if there is a good reason 
>>>> for that or if it's just by mistake but it seems that there is an 
>>>> easy fix to that (if I am not wrong...). I have changed the 
>>>> following lines in \Utilities\MetaIO\metaImage.cxx:
>>>>
>>>> - usePath = MET_GetFilePath(_headerName, pathName)
>>>>
>>>> by
>>>>
>>>> +  usePath = !MET_GetFilePath(elementDataFileName.c_str(), 
>>>> pathName) &&
>>>> +                 MET_GetFilePath(_headerName, pathName);
>>>>
>>>> So that usePath (which determines in fact if the path to the header 
>>>> / meta file should be append to the elementDataFileName) is used 
>>>> only if the elementDataFileName is not an absolute path and if 
>>>> there is a path for the header / meta file.
>>>>
>>>> Find attached the patch file.
>>>>
>>>> Regards,
>>>> Florian
>>>>
>>>>
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> ### Eclipse Workspace Patch 1.0
>>>> #P ITK_3_4_0
>>>> Index: Utilities/MetaIO/metaImage.cxx
>>>> ===================================================================
>>>> RCS file: /cvsroot/Insight/Insight/Utilities/MetaIO/metaImage.cxx,v
>>>> retrieving revision 1.76
>>>> diff -u -r1.76 metaImage.cxx
>>>> --- Utilities/MetaIO/metaImage.cxx    12 Sep 2007 11:46:05 -0000    
>>>> 1.76
>>>> +++ Utilities/MetaIO/metaImage.cxx    12 May 2008 10:53:09 -0000
>>>> @@ -3,7 +3,7 @@
>>>>    Program:   MetaIO
>>>>    Module:    $RCSfile: metaImage.cxx,v $
>>>>    Language:  C++
>>>> -  Date:      $Date: 2007-09-12 11:46:05 $
>>>> +  Date:      $Date: 2007/09/12 11:46:05 $
>>>>    Version:   $Revision: 1.76 $
>>>>  
>>>>    Copyright (c) Insight Software Consortium. All rights reserved.
>>>> @@ -1118,10 +1118,6 @@
>>>>      return false;
>>>>      }
>>>>  
>>>> -  bool usePath;
>>>> -  char pathName[255];
>>>> -  usePath = MET_GetFilePath(_headerName, pathName);
>>>> -
>>>>    char* buf = new char[8001];
>>>>    inputStream.read(buf,8000);
>>>>    unsigned long fileSize = inputStream.gcount();
>>>> @@ -1139,6 +1135,10 @@
>>>>  
>>>>    std::string elementDataFileName = 
>>>> M_GetTagValue(header,"ElementDataFile");
>>>>  
>>>> +  char pathName[255];
>>>> +  bool usePath = !MET_GetFilePath(elementDataFileName.c_str(), 
>>>> pathName) && +                 MET_GetFilePath(_headerName, pathName);
>>>> +
>>>>    char* fName = new char[512];
>>>>  
>>>>    if(!strcmp("Local", elementDataFileName.c_str()) || @@ -1375,10 
>>>> +1375,10 @@
>>>>        }
>>>>  
>>>>      int i, j;
>>>> -    bool usePath;
>>>>      char pathName[255];
>>>>      char fName[255];
>>>> -    usePath = MET_GetFilePath(m_FileName, pathName);
>>>> +    bool usePath = !MET_GetFilePath(m_ElementDataFileName, 
>>>> pathName) && +                   MET_GetFilePath(m_FileName, 
>>>> pathName);
>>>>  
>>>>      if(!strcmp("Local", m_ElementDataFileName) ||         
>>>> !strcmp("LOCAL", m_ElementDataFileName) ||
>>>> @@ -1620,7 +1620,8 @@
>>>>      }
>>>>  
>>>>    char pathName[255];
>>>> -  bool usePath = MET_GetFilePath(m_FileName, pathName);
>>>> +  bool usePath = !MET_GetFilePath(m_ElementDataFileName, pathName) 
>>>> && +                 MET_GetFilePath(m_FileName, pathName);
>>>>    if(usePath)
>>>>      {
>>>>      char elementPathName[255];
>>>> @@ -2240,7 +2241,8 @@
>>>>      {
>>>>      char dataFileName[255];
>>>>      char pathName[255];
>>>> -    bool usePath = MET_GetFilePath(m_FileName, pathName);
>>>> +    bool usePath = !MET_GetFilePath(m_ElementDataFileName, 
>>>> pathName) && +                   MET_GetFilePath(m_FileName, 
>>>> pathName);
>>>>      if(usePath)
>>>>        {
>>>>        sprintf(dataFileName, "%s%s", pathName, m_ElementDataFileName);
>>>> @@ -2471,10 +2473,10 @@
>>>>        m_Quantity *= (_indexMax[i] - _indexMin[i] + 1);
>>>>        }
>>>>  
>>>> -    bool usePath;
>>>>      char pathName[255];
>>>>      char fName[255];
>>>> -    usePath = MET_GetFilePath(m_FileName, pathName);
>>>> +    bool usePath = !MET_GetFilePath(m_ElementDataFileName, 
>>>> pathName) && +                   MET_GetFilePath(m_FileName, 
>>>> pathName);
>>>>  
>>>>      if(!strcmp("Local", m_ElementDataFileName) ||         
>>>> !strcmp("LOCAL", m_ElementDataFileName) ||
>>>>
>>>>
>>>> ------------------------------------------------------------------------ 
>>>>
>>>>
>>>> _______________________________________________
>>>> Insight-users mailing list
>>>> Insight-users at itk.org
>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>
>>
>> ------------------------------------------------------------------------
>>
>> ObjectType = Image
>> NDims = 2
>> DimSize = 50 50
>> ElementByteOrderMSB = False
>> ElementNumberOfChannels = 1
>> ElementType = MET_UCHAR
>> ElementDataFile = C:\Program Files\Data\MyData.raw
>


More information about the Insight-users mailing list