[ITK] ITK IO Plugin only loads after calling itk::ObjectFactoryBase::ReHash()

Bill Lorensen bill.lorensen at gmail.com
Fri May 9 16:35:50 EDT 2014


If this test does not work on your version, you may need to upgrade to
a newer ITK.


On Fri, May 9, 2014 at 4:32 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> I'm using the git HEAD, but ReHash was removed in October 2012. I've
> attached the latest version.
>
>
> On Fri, May 9, 2014 at 4:27 PM, Silvio Bauer <mail at silviobauer.de> wrote:
>> Which ITK version are you running? My itkIOPluginTest.cxx looks like this
>> (with ITK 4.2.1):
>>
>> /*=========================================================================
>>  *
>>  *  Copyright Insight Software Consortium
>>  *
>>  *  Licensed under the Apache License, Version 2.0 (the "License");
>>  *  you may not use this file except in compliance with the License.
>>  *  You may obtain a copy of the License at
>>  *
>>  *         http://www.apache.org/licenses/LICENSE-2.0.txt
>>  *
>>  *  Unless required by applicable law or agreed to in writing, software
>>  *  distributed under the License is distributed on an "AS IS" BASIS,
>>  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>  *  See the License for the specific language governing permissions and
>>  *  limitations under the License.
>>  *
>>
>> *=========================================================================*/
>>
>> #include "itkImageFileReader.h"
>> #include "itkImageFileWriter.h"
>>
>> int itkIOPluginTest(int argc, char *argv[])
>> {
>>   if (argc < 4)
>>     {
>>     std::cout << "Usage: " << argv[0] << " FactoryPath FileName Output" <<
>> std::endl;
>>     return EXIT_FAILURE;
>>     }
>>
>>   std::string myenv = std::string("ITK_AUTOLOAD_PATH=") +
>> std::string(argv[1]) + std::string("/");
>> #ifdef CMAKE_INTDIR
>>   myenv += std::string(CMAKE_INTDIR);
>> #endif
>>   std::cout << myenv << std::endl;
>>   putenv (const_cast<char *>(myenv.c_str()));
>>   itk::ObjectFactoryBase::ReHash(); // <--- there it is
>>
>>   // List all registered factories
>>   std::list<itk::ObjectFactoryBase *> factories =
>>     itk::ObjectFactoryBase::GetRegisteredFactories();
>>
>>   std::cout << "----- Registered factories -----" << std::endl;
>>   if (factories.size() > 0)
>>     {
>>     for ( std::list<itk::ObjectFactoryBase*>::iterator
>>             f = factories.begin();
>>           f != factories.end(); ++f )
>>       {
>>       std::cout << "  Factory version: "
>>                 << (*f)->GetITKSourceVersion() << std::endl
>>                 << "  Factory description: "
>>                 << (*f)->GetDescription() << std::endl;
>>
>>       std::list<std::string> overrides = (*f)->GetClassOverrideNames();
>>       std::list<std::string> names = (*f)->GetClassOverrideWithNames();
>>       std::list<std::string> descriptions =
>> (*f)->GetClassOverrideDescriptions();
>>       std::list<bool> enableflags = (*f)->GetEnableFlags();
>>       std::list<std::string>::const_iterator n = names.begin();
>>       std::list<std::string>::const_iterator d = descriptions.begin();
>>       std::list<bool>::const_iterator e = enableflags.begin();
>>       for ( std::list<std::string>::const_iterator o = overrides.begin();
>>             o != overrides.end(); ++o, ++n, ++d, e++ )
>>         {
>>         std::cout << "    Override " << *o
>>                   << " with " << *n << std::endl
>>                   << "      described as \"" << *d << "\"" << std::endl
>>                   << "      enabled " << *e << std::endl;
>>         }
>>       }
>>     std::cout << "----- -----" << std::endl;
>>     }
>>   else
>>     {
>>     std::cout << "Failed to load any factories" << std::endl;
>>     return EXIT_FAILURE;
>>     }
>>
>>   typedef itk::Image<unsigned char,2> ImageNDType;
>>   typedef itk::ImageFileReader<ImageNDType> ReaderType;
>>   typedef itk::ImageFileWriter<ImageNDType> WriterType;
>>   ReaderType::Pointer reader = ReaderType::New();
>>   WriterType::Pointer writer = WriterType::New();
>>
>>   int status = EXIT_SUCCESS;
>>   try
>>     {
>>     reader->SetFileName(argv[2]);
>>
>>     writer->SetFileName(argv[3]);
>>     writer->SetInput(reader->GetOutput());
>>     writer->Update();
>>     reader->GetOutput()->Print(std::cout);
>>   }
>>   catch (itk::ExceptionObject &ex)
>>     {
>>     std::cout << "------------------ Caught unexpected exception!" <<
>> std::endl;
>>     std::cout << ex;
>>     status = EXIT_FAILURE;
>>     }
>>
>>   try
>>     {
>>     reader->SetFileName("foo");
>>     reader->Update();
>>     }
>>   catch (itk::ExceptionObject &ex)
>>     {
>>     std::cout << "------------------ Caught expected exception!" <<
>> std::endl;
>>     std::cout << ex;
>>     status = EXIT_SUCCESS;
>>     }
>>
>>   return status;
>> }
>>
>>
>>
>>
>> 2014-05-09 14:20 GMT-06:00 Bill Lorensen <bill.lorensen at gmail.com>:
>>
>>> Really, my copy does not have ReHash
>>>
>>> On Fri, May 9, 2014 at 3:29 PM, Silvio Bauer <mail at silviobauer.de> wrote:
>>> > If you look at the source code itkIOPluginTest.cxx, it is actually
>>> > calling
>>> > ReHash() right at the beginning.
>>> >
>>> >
>>> > 2014-05-09 13:06 GMT-06:00 Bill Lorensen <bill.lorensen at gmail.com>:
>>> >
>>> >> Try running this test:
>>> >>
>>> >> ITK/Modules/IO/ImageBase/test/itkIOPluginTest
>>> >>
>>> >> it works wihtout a rehash...
>>> >>
>>> >> On Fri, May 9, 2014 at 3:02 PM, Silvio Bauer <silvio.bauer01 at gmail.com>
>>> >> wrote:
>>> >> > Hi,
>>> >> >
>>> >> > I'm working on an IO plugin for ITK to read and write in-house image
>>> >> > file
>>> >> > formats. I did everything as described in the wiki here.
>>> >> >
>>> >> > I did everything by the book, put the dynamic library in the
>>> >> > ITK_AUTOLOAD_PATH and set the ITK_AUTOLOAD_PATH environment variable.
>>> >> >
>>> >> > The library builds successfully, but when I try to read a file with
>>> >> > the
>>> >> > in-house format (with ImageReadExportVTK from the examples), I get
>>> >> > this
>>> >> > error message:
>>> >> >
>>> >> > ExceptionObject: Command not found.
>>> >> >
>>> >> > itk::ImageFileReaderException (0x7feab10f4eb8)
>>> >> > Location: "virtual void itk::ImageFileReader<itk::Image<unsigned
>>> >> > char,
>>> >> > 3>,
>>> >> > itk::DefaultConvertPixelTraits<unsigned char>
>>> >> > >::GenerateOutputInformation()
>>> >> > [TOutputImage = itk::Image<unsigned char, 3>, ConvertPixelTraits =
>>> >> > itk::DefaultConvertPixelTraits<unsigned char>]"
>>> >> > File: /people/seidel/ITK
>>> >> >
>>> >> >
>>> >> > src/InsightToolkit-4.2.1/Modules/IO/ImageBase/include/itkImageFileReader.hxx
>>> >> > Line: 143
>>> >> > Description:  Could not create IO object for file little.lat
>>> >> >
>>> >> > Tried to create one of the following:
>>> >> >
>>> >> > JPEGImageIO
>>> >> > GDCMImageIO
>>> >> > BMPImageIO
>>> >> > LSMImageIO
>>> >> > PNGImageIO
>>> >> > TIFFImageIO
>>> >> > VTKImageIO
>>> >> > StimulateImageIO
>>> >> > BioRadImageIO
>>> >> > MetaImageIO
>>> >> > NiftiImageIO
>>> >> > NrrdImageIO
>>> >> > GiplImageIO
>>> >> > HDF5ImageIO
>>> >> > You probably failed to set a file suffix, or
>>> >> > set the suffix to an unsupported type
>>> >> >
>>> >> > However, if I put
>>> >> >
>>> >> > itk::ObjectFactoryBase::ReHash();
>>> >> >
>>> >> > before the reader is instantiated, everything works fine. But after
>>> >> > that, no
>>> >> > default factories are loaded. As I understand the plugin mechanism
>>> >> > correctly, calling ReHash() shouldn't be necessary.
>>> >> >
>>> >> > Can anybody point me in the right direction?
>>> >> >
>>> >> > I'm on Mac OS 10.8.5 with ITK 4.2.1.
>>> >> >
>>> >> > Thanks in advance.
>>> >> >
>>> >> > -Silvio
>>> >> >
>>> >> >
>>> >> > _______________________________________________
>>> >> > Community mailing list
>>> >> > Community at itk.org
>>> >> > http://public.kitware.com/cgi-bin/mailman/listinfo/community
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Unpaid intern in BillsBasement at noware dot com
>>> >
>>> >
>>>
>>>
>>>
>>> --
>>> Unpaid intern in BillsBasement at noware dot com
>>
>>
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com



-- 
Unpaid intern in BillsBasement at noware dot com



More information about the Community mailing list