From 319d96a41c90c4bd042d8e9c510935abb958a8ad Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sat, 12 Dec 2015 02:10:20 -0500 Subject: [PATCH 1/4] BUG: Update Mesh IO factory to use static initialization. See #3393 This commit updates the Mesh IO factory to ensure it can be built as shared library so it is registered only once when linked to both a main application and application plugin dynamically loaded. In a nutshell, it updates the code so the itk::MeshIOFactory is registered only once when statically initialized. More specifically, it applies the following changes: (1) Uses of "RegisterFactoryInternal" to make sure the factory is registered once into the TransformIOFactory. See 39b4ab3 (BUG: Internal factory must use RegisterFactoryInternal method) for more details. (2) Introduces ITKIOMesh explicit instantiation where templated reader and writer are explicitly instantiated over dimensions, types and traits. This will allow templated factories to be registered in one translation unit and instantiated in an other. See http://stackoverflow.com/questions/8024010/why-do-template-class-functions-have-to-be-declared-in-the-same-translation-unit (3) Update TestDriver to explicitly register the MeshIO factories needed by QuadEdgeMeshFiltering and ITKIOMesh tests. Note that in a follow-up commit, the MeshIO library will be split into multiple modules MeshIOBase and one for (or one for each) Mesh IO factories. Open questions: (1) It is not clear why on Visual Studio 2008, the export macro need to be removed from MeshFileReader. Otherwise, it reports the following link error when building ITKIOMeshTestDriver: error C2487: 'itk::ProcessObject::SetOutput' : member of dll interface class may not be declared with dll interface C:\ath/to\ITKv4\Modules\IO\Mesh\include\itkMeshFileReader.h 77 (2) This commits introduces ITKVoronoi dependency to the ITKIOMesh module. Moving forward, this could be updated by having every module explicitly listing instantiations they expect. Change-Id: I80ea34becae742a63b5c98220b20003303188d9c --- CMake/UseITK.cmake | 51 ++++++++ CMake/itkMeshIOFactoryRegisterManager.h.in | 59 +++++++++ .../itkTestDriverIncludeRequiredIOFactories.h | 20 +++ Modules/Core/TestKernel/itk-module.cmake | 1 + Modules/IO/Mesh/include/itkMeshFileReader.h | 9 +- Modules/IO/Mesh/include/itkMeshFileReader.hxx | 7 ++ Modules/IO/Mesh/include/itkMeshFileWriter.h | 10 +- Modules/IO/Mesh/include/itkMeshIOFactory.h | 14 ++- Modules/IO/Mesh/itk-module.cmake | 10 +- Modules/IO/Mesh/src/CMakeLists.txt | 1 + Modules/IO/Mesh/src/itkMeshIOFactory.cxx | 50 ++++---- .../IO/Mesh/src/itkMeshIOInstantiation.cxx | 119 ++++++++++++++++++ 12 files changed, 314 insertions(+), 37 deletions(-) create mode 100644 CMake/itkMeshIOFactoryRegisterManager.h.in create mode 100644 Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx diff --git a/CMake/UseITK.cmake b/CMake/UseITK.cmake index 522e6743f17..c1c93ee61d3 100644 --- a/CMake/UseITK.cmake +++ b/CMake/UseITK.cmake @@ -251,6 +251,57 @@ if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER) _configure_IOFactoryRegisterManager("Image" "${LIST_OF_IMAGEIO_FORMATS}") endif() +#----------------------------------------------------------------------------- +# MeshIO +#----------------------------------------------------------------------------- + +# a list of mesh IOs to be registered when the corresponding modules are enabled +set(LIST_OF_MESHIO_FORMATS + BYU + FreeSurferAscii + FreeSurferBinary + Gifti + OBJ + OFF + VTKPolyData + ) + +# Exceptions: + +set(BYU_mesh_module_name ITKIOMesh) +set(BYU_mesh_factory_name MeshIO) + +set(FreeSurferAscii_mesh_module_name ITKIOMesh) +set(FreeSurferAscii_mesh_factory_name MeshIO) + +set(FreeSurferBinary_mesh_module_name ITKIOMesh) +set(FreeSurferBinary_mesh_factory_name MeshIO) + +set(Gifti_mesh_module_name ITKIOMesh) +set(Gifti_mesh_factory_name MeshIO) + +set(OBJ_mesh_module_name ITKIOMesh) +set(OBJ_mesh_factory_name MeshIO) + +set(OFF_mesh_module_name ITKIOMesh) +set(OFF_mesh_factory_name MeshIO) + +set(VTKPolyData_mesh_module_name ITKIOMesh) +set(VTKPolyData_mesh_factory_name MeshIO) + +foreach(MeshFormat ${LIST_OF_MESHIO_FORMATS}) + if (NOT ${MeshFormat}_mesh_module_name ) + set(${MeshFormat}_mesh_module_name ITKIOMesh${MeshFormat}) + endif() + if (NOT ${MeshFormat}_mesh_factory_name) + set(${MeshFormat}_mesh_factory_name ${MeshFormat}MeshIO) + endif() +endforeach() + +if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER) + _configure_IOFactoryRegisterManager("Mesh" "${LIST_OF_MESHIO_FORMATS}") +endif() + #----------------------------------------------------------------------------- # TransformIO #----------------------------------------------------------------------------- diff --git a/CMake/itkMeshIOFactoryRegisterManager.h.in b/CMake/itkMeshIOFactoryRegisterManager.h.in new file mode 100644 index 00000000000..28ce3c30230 --- /dev/null +++ b/CMake/itkMeshIOFactoryRegisterManager.h.in @@ -0,0 +1,59 @@ +/*========================================================================= + * + * 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. + * + *=========================================================================*/ + +#ifndef itkMeshIOFactoryRegisterManager_h +#define itkMeshIOFactoryRegisterManager_h + +namespace itk { + +class MeshIOFactoryRegisterManager +{ + public: + MeshIOFactoryRegisterManager(void (*list[])(void)) + { + for(;*list; ++list) + { + (*list)(); + } + } +}; + + +// +// The following code is intended to be expanded at the end of the +// itkMeshFileReader.h and itkMeshFileWriter.h files. +// +@LIST_OF_FACTORIES_REGISTRATION@ + +// +// The code below registers available IO helpers using static initialization in +// application translation units. Note that this code will be expanded in the +// ITK-based applications and not in ITK itself. +// +namespace { + + void (*MeshIOFactoryRegisterRegisterList[])(void) = { + @LIST_OF_FACTORY_NAMES@ + 0}; + MeshIOFactoryRegisterManager MeshIOFactoryRegisterManagerInstance(MeshIOFactoryRegisterRegisterList); + +} + +} + +#endif diff --git a/Modules/Core/TestKernel/include/itkTestDriverIncludeRequiredIOFactories.h b/Modules/Core/TestKernel/include/itkTestDriverIncludeRequiredIOFactories.h index 3728880d73e..1d0dbf8c268 100644 --- a/Modules/Core/TestKernel/include/itkTestDriverIncludeRequiredIOFactories.h +++ b/Modules/Core/TestKernel/include/itkTestDriverIncludeRequiredIOFactories.h @@ -18,6 +18,7 @@ #ifndef itkTestDriverIncludeRequiredIOFactories_h #define itkTestDriverIncludeRequiredIOFactories_h +// ImageIO #include "itkGDCMImageIOFactory.h" #include "itkMetaImageIOFactory.h" #include "itkJPEGImageIOFactory.h" @@ -28,6 +29,16 @@ #include "itkNrrdImageIOFactory.h" #include "itkGiplImageIOFactory.h" #include "itkNiftiImageIOFactory.h" + +// MeshIO +#include "itkBYUMeshIOFactory.h" +#include "itkFreeSurferAsciiMeshIOFactory.h" +#include "itkFreeSurferBinaryMeshIOFactory.h" +#include "itkGiftiMeshIOFactory.h" +#include "itkOBJMeshIOFactory.h" +#include "itkOFFMeshIOFactory.h" +#include "itkVTKPolyDataMeshIOFactory.h" + #include "itkTestDriverInclude.h" #include "itkObjectFactoryBase.h" @@ -38,6 +49,7 @@ void RegisterRequiredFactories() { + // ImageIO itk::ObjectFactoryBase::RegisterFactory( itk::MetaImageIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( itk::GDCMImageIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( itk::JPEGImageIOFactory::New() ); @@ -48,6 +60,14 @@ RegisterRequiredFactories() itk::ObjectFactoryBase::RegisterFactory( itk::NrrdImageIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( itk::GiplImageIOFactory::New() ); itk::ObjectFactoryBase::RegisterFactory( itk::NiftiImageIOFactory::New() ); + // MeshIO + itk::ObjectFactoryBase::RegisterFactory( itk::BYUMeshIOFactory::New() ); + itk::ObjectFactoryBase::RegisterFactory( itk::FreeSurferAsciiMeshIOFactory::New() ); + itk::ObjectFactoryBase::RegisterFactory( itk::FreeSurferBinaryMeshIOFactory::New() ); + itk::ObjectFactoryBase::RegisterFactory( itk::GiftiMeshIOFactory::New() ); + itk::ObjectFactoryBase::RegisterFactory( itk::OBJMeshIOFactory::New() ); + itk::ObjectFactoryBase::RegisterFactory( itk::OFFMeshIOFactory::New() ); + itk::ObjectFactoryBase::RegisterFactory( itk::VTKPolyDataMeshIOFactory::New() ); } void diff --git a/Modules/Core/TestKernel/itk-module.cmake b/Modules/Core/TestKernel/itk-module.cmake index fd220adce96..7bbf2225d5f 100644 --- a/Modules/Core/TestKernel/itk-module.cmake +++ b/Modules/Core/TestKernel/itk-module.cmake @@ -16,6 +16,7 @@ itk_module(ITKTestKernel ITKIOPNG ITKIOTIFF ITKIOVTK + ITKIOMesh PRIVATE_DEPENDS ITKCommon COMPILE_DEPENDS diff --git a/Modules/IO/Mesh/include/itkMeshFileReader.h b/Modules/IO/Mesh/include/itkMeshFileReader.h index 10cc96f39c3..c7f73207b80 100644 --- a/Modules/IO/Mesh/include/itkMeshFileReader.h +++ b/Modules/IO/Mesh/include/itkMeshFileReader.h @@ -17,7 +17,6 @@ *=========================================================================*/ #ifndef itkMeshFileReader_h #define itkMeshFileReader_h -#include "ITKIOMeshExport.h" #include "itkMeshFileReaderException.h" #include "itkMacro.h" @@ -142,7 +141,7 @@ class MeshFileReader:public MeshSource< TOutputMesh > protected: MeshFileReader(); - ~MeshFileReader(){} + virtual ~MeshFileReader(); void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; /** Convert a block of pixels from one type to another. */ @@ -174,8 +173,10 @@ class MeshFileReader:public MeshSource< TOutputMesh > }; } // namespace ITK -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkMeshFileReader.hxx" +// Note: Explicit instantiation is done in itkMeshIOInstantiation.cxx + +#ifdef ITK_IO_FACTORY_REGISTER_MANAGER +#include "itkMeshIOFactoryRegisterManager.h" #endif #endif diff --git a/Modules/IO/Mesh/include/itkMeshFileReader.hxx b/Modules/IO/Mesh/include/itkMeshFileReader.hxx index f04de762de5..1e192c0a544 100644 --- a/Modules/IO/Mesh/include/itkMeshFileReader.hxx +++ b/Modules/IO/Mesh/include/itkMeshFileReader.hxx @@ -39,6 +39,13 @@ MeshFileReader< TOutputMesh, ConvertPointPixelTraits, ConvertCellPixelTraits > m_MeshIO = ITK_NULLPTR; m_FileName = ""; m_UserSpecifiedMeshIO = false; + +} + +template< typename TOutputMesh, typename ConvertPointPixelTraits, typename ConvertCellPixelTraits > +MeshFileReader< TOutputMesh, ConvertPointPixelTraits, ConvertCellPixelTraits > +::~MeshFileReader() +{ } template< typename TOutputMesh, typename ConvertPointPixelTraits, typename ConvertCellPixelTraits > diff --git a/Modules/IO/Mesh/include/itkMeshFileWriter.h b/Modules/IO/Mesh/include/itkMeshFileWriter.h index 92ee2eec55a..1311e029549 100644 --- a/Modules/IO/Mesh/include/itkMeshFileWriter.h +++ b/Modules/IO/Mesh/include/itkMeshFileWriter.h @@ -49,7 +49,7 @@ namespace itk * \ingroup ITKIOMesh */ template< typename TInputMesh > -class ITKIOMesh_HIDDEN MeshFileWriter:public ProcessObject +class ITKIOMesh_EXPORT MeshFileWriter:public ProcessObject { public: /** Standard class typedefs. */ @@ -127,7 +127,7 @@ class ITKIOMesh_HIDDEN MeshFileWriter:public ProcessObject protected: MeshFileWriter(); - ~MeshFileWriter(); + virtual ~MeshFileWriter(); virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; template< typename Output > @@ -164,8 +164,10 @@ class ITKIOMesh_HIDDEN MeshFileWriter:public ProcessObject }; } // end namespace itk -#ifndef ITK_MANUAL_INSTANTIATION -#include "itkMeshFileWriter.hxx" +// Note: Explicit instantiation is done in itkMeshIOInstantiation.cxx + +#ifdef ITK_IO_FACTORY_REGISTER_MANAGER +#include "itkMeshIOFactoryRegisterManager.h" #endif #endif // itkMeshFileWriter_h diff --git a/Modules/IO/Mesh/include/itkMeshIOFactory.h b/Modules/IO/Mesh/include/itkMeshIOFactory.h index ca5dc2ec2d5..e64cbf8c6ec 100644 --- a/Modules/IO/Mesh/include/itkMeshIOFactory.h +++ b/Modules/IO/Mesh/include/itkMeshIOFactory.h @@ -61,9 +61,21 @@ class ITKIOMesh_EXPORT MeshIOFactory:public Object /** Create the appropriate MeshIO depending on the particulars of the file. */ static MeshIOBasePointer CreateMeshIO(const char *path, FileModeType mode); - /** Register Built-in factories */ + /** + * \sa deprecated + * This method is deprecated, MeshIO factories are registered during + * static initialization. + * \sa RegisterFactories() + */ static void RegisterBuiltInFactories(); + /** + * Register Mesh factories. + * + * This method is automatically called during static initialization. + */ + static void RegisterFactories(); + protected: MeshIOFactory(); ~MeshIOFactory(); diff --git a/Modules/IO/Mesh/itk-module.cmake b/Modules/IO/Mesh/itk-module.cmake index 53750fcfe64..50fbe4f0909 100644 --- a/Modules/IO/Mesh/itk-module.cmake +++ b/Modules/IO/Mesh/itk-module.cmake @@ -2,15 +2,17 @@ set(DOCUMENTATION "This module contains classes for reading and writing Meshes as opposed to general images.") itk_module(ITKIOMesh ENABLE_SHARED - PRIVATE_DEPENDS + DEPENDS + ITKCommon ITKIOImageBase + ITKQuadEdgeMesh + ITKMesh + ITKVoronoi + PRIVATE_DEPENDS ITKDoubleConversion ITKGIFTI - COMPILE_DEPENDS - ITKMesh TEST_DEPENDS ITKTestKernel - ITKQuadEdgeMesh DESCRIPTION "${DOCUMENTATION}" ) diff --git a/Modules/IO/Mesh/src/CMakeLists.txt b/Modules/IO/Mesh/src/CMakeLists.txt index b97b21ae3ef..de0e14a906d 100644 --- a/Modules/IO/Mesh/src/CMakeLists.txt +++ b/Modules/IO/Mesh/src/CMakeLists.txt @@ -10,6 +10,7 @@ set(ITKIOMesh_SRC itkGiftiMeshIO.cxx itkGiftiMeshIOFactory.cxx itkMeshIOBase.cxx + itkMeshIOInstantiation.cxx itkMeshIOFactory.cxx itkOBJMeshIO.cxx itkOBJMeshIOFactory.cxx diff --git a/Modules/IO/Mesh/src/itkMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkMeshIOFactory.cxx index 0b189a630b1..dd851500134 100644 --- a/Modules/IO/Mesh/src/itkMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkMeshIOFactory.cxx @@ -16,15 +16,14 @@ * *=========================================================================*/ +#include "itkMeshIOFactory.h" + #include "itkBYUMeshIOFactory.h" #include "itkFreeSurferAsciiMeshIOFactory.h" #include "itkFreeSurferBinaryMeshIOFactory.h" #include "itkGiftiMeshIOFactory.h" -#include "itkMeshIOFactory.h" #include "itkOBJMeshIOFactory.h" #include "itkOFFMeshIOFactory.h" -#include "itkMutexLock.h" -#include "itkMutexLockHolder.h" #include "itkVTKPolyDataMeshIOFactory.h" namespace itk @@ -45,8 +44,6 @@ MeshIOBase::Pointer MeshIOFactory ::CreateMeshIO(const char *path, FileModeType mode) { - RegisterBuiltInFactories(); - std::list< MeshIOBase::Pointer > possibleMeshIO; std::list< LightObject::Pointer > allobjects = ObjectFactoryBase::CreateAllInstance("itkMeshIOBase"); @@ -87,32 +84,37 @@ ::CreateMeshIO(const char *path, FileModeType mode) return ITK_NULLPTR; } - void MeshIOFactory ::RegisterBuiltInFactories() { - static SimpleMutexLock mutex; + // deprecated +} + +void +MeshIOFactory +::RegisterFactories() +{ + ObjectFactoryBase::RegisterFactoryInternal( BYUMeshIOFactory::New() ); + ObjectFactoryBase::RegisterFactoryInternal( FreeSurferAsciiMeshIOFactory::New() ); + ObjectFactoryBase::RegisterFactoryInternal( FreeSurferBinaryMeshIOFactory::New() ); + ObjectFactoryBase::RegisterFactoryInternal( GiftiMeshIOFactory::New() ); + ObjectFactoryBase::RegisterFactoryInternal( OBJMeshIOFactory::New() ); + ObjectFactoryBase::RegisterFactoryInternal( OFFMeshIOFactory::New() ); + ObjectFactoryBase::RegisterFactoryInternal( VTKPolyDataMeshIOFactory::New() ); +} + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool MeshIOFactoryHasBeenRegistered; +void ITKIOMesh_EXPORT MeshIOFactoryRegister__Private(void) +{ + if( ! MeshIOFactoryHasBeenRegistered ) { - static bool firstTime = true; - // This helper class makes sure the Mutex is unlocked - // in the event an exception is thrown. - MutexLockHolder< SimpleMutexLock > mutexHolder(mutex); - if ( firstTime ) - { - ObjectFactoryBase::RegisterFactory( BYUMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactory( FreeSurferAsciiMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactory( FreeSurferBinaryMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactory( GiftiMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactory( OBJMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactory( OFFMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactory( VTKPolyDataMeshIOFactory::New() ); - - firstTime = false; - } + MeshIOFactoryHasBeenRegistered = true; + MeshIOFactory::RegisterFactories(); } } - } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx b/Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx new file mode 100644 index 00000000000..945352413d8 --- /dev/null +++ b/Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx @@ -0,0 +1,119 @@ +/*========================================================================= + * + * 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 "ITKIOMeshExport.h" + +// Mesh Types +#include "itkMesh.h" +#include "itkQuadEdgeMesh.h" +#include "itkSimplexMesh.h" +#include "itkVoronoiDiagram2D.h" + +// Pixel Types +#include "itkCovariantVector.h" +#include "itkSymmetricSecondRankTensor.h" +#include "itkVariableLengthVector.h" + +// Traits types +#include "itkQuadEdgeMeshExtendedTraits.h" +#include "itkQuadEdgeMeshTraits.h" + +// Reader +#include "itkMeshFileReader.h" +#include "itkMeshFileReader.hxx" +#include "itkMeshSource.h" + +// Writer +#include "itkMeshFileWriter.h" +#include "itkMeshFileWriter.hxx" + +// ----------------------------------------------------------------------------- +// Reader / Writer instantiation macros + +#define ITKIOMESH_DefaultTraits_TRAITS(PIXEL_TYPE, DIMENSION) + +#define ITKIOMESH_QuadEdgeMeshTraits_TRAITS(PIXEL_TYPE, DIMENSION) \ + , QuadEdgeMeshTraits< PIXEL_TYPE, DIMENSION, bool, bool> + +#define ITKIOMESH_QuadEdgeMeshExtendedTraits_TRAITS(PIXEL_TYPE, DIMENSION) \ + , QuadEdgeMeshExtendedTraits< PIXEL_TYPE, DIMENSION, 2, CoordType, CoordType, PIXEL_TYPE, bool, bool> + +#define ITKIOMESH_INSTANTIATE_Reader(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ + template class ITKIOMesh_EXPORT MeshSource< \ + MESH_TYPE \ + >;\ + template class ITKIOMesh_EXPORT MeshFileReader< \ + MESH_TYPE, \ + MeshConvertPixelTraits< PIXEL_TYPE >, MeshConvertPixelTraits< PIXEL_TYPE > \ + >; + +#define ITKIOMESH_INSTANTIATE_Writer(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ + template class ITKIOMesh_EXPORT MeshFileWriter< \ + MESH_TYPE \ + >; + +#define ITKIOMESH_INSTANTIATE_IOS(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ + ITKIOMESH_INSTANTIATE_Reader(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ + ITKIOMESH_INSTANTIATE_Writer(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) + +#define ITKIOMESH_INSTANTIATE_IO_FOR_PIXEL_TYPES(IO_TYPE, MESH_TYPE, DIMENSION, TRAITS) \ + ITKIOMESH_INSTANTIATE_##IO_TYPE(MESH_TYPE, float, DIMENSION, TRAITS) \ + ITKIOMESH_INSTANTIATE_##IO_TYPE(MESH_TYPE, double, DIMENSION, TRAITS) + +#define ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(MESH_TYPE, DIMENSION, TRAITS) \ + ITKIOMESH_INSTANTIATE_IO_FOR_PIXEL_TYPES(Reader, MESH_TYPE, DIMENSION, TRAITS) \ + ITKIOMESH_INSTANTIATE_IO_FOR_PIXEL_TYPES(Writer, MESH_TYPE, DIMENSION, TRAITS) + +namespace itk +{ + +typedef double CoordType; + +typedef CovariantVector< float, 3 > CovariantVector_float_3; +typedef SymmetricSecondRankTensor< float, 2 > SymmetricSecondRankTensor_float_2; +typedef SymmetricSecondRankTensor< float, 3 > SymmetricSecondRankTensor_float_3; +typedef VariableLengthVector< float > VariableLengthVector_float_3; + +// ----------------------------------------------------------------------------- +// MeshFileReader / MeshFileWriter + +ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(Mesh, 2, DefaultTraits) +ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(Mesh, 3, DefaultTraits) + +ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(QuadEdgeMesh, 3, QuadEdgeMeshExtendedTraits) +ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(QuadEdgeMesh, 3, QuadEdgeMeshTraits) + +ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(SimplexMesh, 2, DefaultTraits) +ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(SimplexMesh, 3, DefaultTraits) + +// Required by ITKIOMesh itkMeshFileReadWriteVectorAttributeTest +ITKIOMESH_INSTANTIATE_IOS(Mesh, CovariantVector_float_3, 3, DefaultTraits) +ITKIOMESH_INSTANTIATE_IOS(QuadEdgeMesh, CovariantVector_float_3, 3, QuadEdgeMeshTraits) + +// Required by ITKIOMesh itkMeshFileWriteReadTensorTest +ITKIOMESH_INSTANTIATE_IOS(Mesh, SymmetricSecondRankTensor_float_2, 2, DefaultTraits) +ITKIOMESH_INSTANTIATE_IOS(Mesh, SymmetricSecondRankTensor_float_3, 3, DefaultTraits) + +// Required by ITKIOMesh itkPolylineReadWriteTest +ITKIOMESH_INSTANTIATE_IOS(Mesh, VariableLengthVector_float_3, 3, DefaultTraits) + +// Required by ITKVoronoi itkVoronoiDiagram2DTest +template class MeshFileReader< VoronoiDiagram2D< double > >; +template class ITKIOMesh_EXPORT MeshFileWriter< VoronoiDiagram2D< double > >; + +} // end namespace itk From dac02d6df13a7e778df80cbb582769c6ac4107fe Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sat, 12 Dec 2015 02:12:19 -0500 Subject: [PATCH 2/4] STYLE: MeshIO: Introduce ITKIOMeshBase module. See #3393 This change updates Mesh IO infrastructure to be consistent with the Image and Transform ones. Each Mesh factories along with the UseITK file have been updated to ensure static initialization works. "Private" function has been removed from MeshIOFactory and added to each Mesh format specific factories. Change-Id: I213e51b2a41677d3430e08cf1d81b41b3221c6ec --- CMake/UseITK.cmake | 14 ++++---- Modules/IO/Mesh/itk-module.cmake | 5 +-- Modules/IO/Mesh/src/CMakeLists.txt | 5 --- Modules/IO/Mesh/src/itkBYUMeshIOFactory.cxx | 15 ++++++++ .../src/itkFreeSurferAsciiMeshIOFactory.cxx | 15 ++++++++ .../src/itkFreeSurferBinaryMeshIOFactory.cxx | 15 ++++++++ Modules/IO/Mesh/src/itkGiftiMeshIOFactory.cxx | 15 ++++++++ Modules/IO/Mesh/src/itkOBJMeshIOFactory.cxx | 15 ++++++++ Modules/IO/Mesh/src/itkOFFMeshIOFactory.cxx | 15 ++++++++ .../Mesh/src/itkVTKPolyDataMeshIOFactory.cxx | 15 ++++++++ Modules/IO/MeshBase/CMakeLists.txt | 4 +++ .../include/itkConvertArrayPixelBuffer.h | 2 +- .../include/itkConvertArrayPixelBuffer.hxx | 0 ...tkConvertVariableLengthVectorPixelBuffer.h | 2 +- ...ConvertVariableLengthVectorPixelBuffer.hxx | 0 .../include/itkMeshConvertPixelTraits.h | 2 +- .../include/itkMeshFileReader.h | 2 +- .../include/itkMeshFileReader.hxx | 0 .../include/itkMeshFileReaderException.h | 6 ++-- .../include/itkMeshFileWriter.h | 6 ++-- .../include/itkMeshFileWriter.hxx | 0 .../include/itkMeshFileWriterException.h | 6 ++-- .../include/itkMeshIOBase.h | 8 ++--- .../include/itkMeshIOFactory.h | 13 ++----- Modules/IO/MeshBase/itk-module.cmake | 18 ++++++++++ Modules/IO/MeshBase/src/CMakeLists.txt | 11 ++++++ .../src/itkMeshFileReaderException.cxx | 0 .../src/itkMeshFileWriterException.cxx | 0 .../{Mesh => MeshBase}/src/itkMeshIOBase.cxx | 0 .../src/itkMeshIOFactory.cxx | 34 ------------------- .../src/itkMeshIOInstantiation.cxx | 10 +++--- 31 files changed, 171 insertions(+), 82 deletions(-) create mode 100644 Modules/IO/MeshBase/CMakeLists.txt rename Modules/IO/{Mesh => MeshBase}/include/itkConvertArrayPixelBuffer.h (98%) rename Modules/IO/{Mesh => MeshBase}/include/itkConvertArrayPixelBuffer.hxx (100%) rename Modules/IO/{Mesh => MeshBase}/include/itkConvertVariableLengthVectorPixelBuffer.h (98%) rename Modules/IO/{Mesh => MeshBase}/include/itkConvertVariableLengthVectorPixelBuffer.hxx (100%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshConvertPixelTraits.h (99%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshFileReader.h (99%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshFileReader.hxx (100%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshFileReaderException.h (92%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshFileWriter.h (97%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshFileWriter.hxx (100%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshFileWriterException.h (92%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshIOBase.h (99%) rename Modules/IO/{Mesh => MeshBase}/include/itkMeshIOFactory.h (90%) create mode 100644 Modules/IO/MeshBase/itk-module.cmake create mode 100644 Modules/IO/MeshBase/src/CMakeLists.txt rename Modules/IO/{Mesh => MeshBase}/src/itkMeshFileReaderException.cxx (100%) rename Modules/IO/{Mesh => MeshBase}/src/itkMeshFileWriterException.cxx (100%) rename Modules/IO/{Mesh => MeshBase}/src/itkMeshIOBase.cxx (100%) rename Modules/IO/{Mesh => MeshBase}/src/itkMeshIOFactory.cxx (63%) rename Modules/IO/{Mesh => MeshBase}/src/itkMeshIOInstantiation.cxx (94%) diff --git a/CMake/UseITK.cmake b/CMake/UseITK.cmake index c1c93ee61d3..5eec4772bdb 100644 --- a/CMake/UseITK.cmake +++ b/CMake/UseITK.cmake @@ -269,25 +269,25 @@ set(LIST_OF_MESHIO_FORMATS # Exceptions: set(BYU_mesh_module_name ITKIOMesh) -set(BYU_mesh_factory_name MeshIO) +set(BYU_mesh_factory_name BYUMeshIO) set(FreeSurferAscii_mesh_module_name ITKIOMesh) -set(FreeSurferAscii_mesh_factory_name MeshIO) +set(FreeSurferAscii_mesh_factory_name FreeSurferAsciiMeshIO) set(FreeSurferBinary_mesh_module_name ITKIOMesh) -set(FreeSurferBinary_mesh_factory_name MeshIO) +set(FreeSurferBinary_mesh_factory_name FreeSurferBinaryMeshIO) set(Gifti_mesh_module_name ITKIOMesh) -set(Gifti_mesh_factory_name MeshIO) +set(Gifti_mesh_factory_name GiftiMeshIO) set(OBJ_mesh_module_name ITKIOMesh) -set(OBJ_mesh_factory_name MeshIO) +set(OBJ_mesh_factory_name OBJMeshIO) set(OFF_mesh_module_name ITKIOMesh) -set(OFF_mesh_factory_name MeshIO) +set(OFF_mesh_factory_name OFFMeshIO) set(VTKPolyData_mesh_module_name ITKIOMesh) -set(VTKPolyData_mesh_factory_name MeshIO) +set(VTKPolyData_mesh_factory_name VTKPolyDataMeshIO) foreach(MeshFormat ${LIST_OF_MESHIO_FORMATS}) if (NOT ${MeshFormat}_mesh_module_name ) diff --git a/Modules/IO/Mesh/itk-module.cmake b/Modules/IO/Mesh/itk-module.cmake index 50fbe4f0909..d31c7c2312f 100644 --- a/Modules/IO/Mesh/itk-module.cmake +++ b/Modules/IO/Mesh/itk-module.cmake @@ -4,10 +4,7 @@ itk_module(ITKIOMesh ENABLE_SHARED DEPENDS ITKCommon - ITKIOImageBase - ITKQuadEdgeMesh - ITKMesh - ITKVoronoi + ITKIOMeshBase PRIVATE_DEPENDS ITKDoubleConversion ITKGIFTI diff --git a/Modules/IO/Mesh/src/CMakeLists.txt b/Modules/IO/Mesh/src/CMakeLists.txt index de0e14a906d..5d4522735dd 100644 --- a/Modules/IO/Mesh/src/CMakeLists.txt +++ b/Modules/IO/Mesh/src/CMakeLists.txt @@ -1,6 +1,4 @@ set(ITKIOMesh_SRC - itkMeshFileReaderException.cxx - itkMeshFileWriterException.cxx itkBYUMeshIO.cxx itkBYUMeshIOFactory.cxx itkFreeSurferAsciiMeshIO.cxx @@ -9,9 +7,6 @@ set(ITKIOMesh_SRC itkFreeSurferBinaryMeshIOFactory.cxx itkGiftiMeshIO.cxx itkGiftiMeshIOFactory.cxx - itkMeshIOBase.cxx - itkMeshIOInstantiation.cxx - itkMeshIOFactory.cxx itkOBJMeshIO.cxx itkOBJMeshIOFactory.cxx itkOFFMeshIO.cxx diff --git a/Modules/IO/Mesh/src/itkBYUMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkBYUMeshIOFactory.cxx index 20c8e763d78..f885bfcac90 100644 --- a/Modules/IO/Mesh/src/itkBYUMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkBYUMeshIOFactory.cxx @@ -15,6 +15,8 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" + #include "itkBYUMeshIOFactory.h" #include "itkBYUMeshIO.h" #include "itkVersion.h" @@ -58,5 +60,18 @@ ::GetDescription() const return "BYU Mesh IO Factory, allows the loading of BYU mesh into insight"; } +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool BYUMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT BYUMeshIOFactoryRegister__Private(void) +{ + if( ! BYUMeshIOFactoryHasBeenRegistered ) + { + BYUMeshIOFactoryHasBeenRegistered = true; + BYUMeshIOFactory::RegisterOneFactory(); + } +} + // ///////////////////////////////////////////////////////////////////// } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkFreeSurferAsciiMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkFreeSurferAsciiMeshIOFactory.cxx index ac0c7af5ad9..8793ed826b0 100644 --- a/Modules/IO/Mesh/src/itkFreeSurferAsciiMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkFreeSurferAsciiMeshIOFactory.cxx @@ -15,6 +15,7 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" #include "itkFreeSurferAsciiMeshIO.h" #include "itkFreeSurferAsciiMeshIOFactory.h" @@ -54,4 +55,18 @@ ::GetDescription() const { return "FreeSurfer ASCII Mesh IO Factory, allows the loading of FreeSurfer Ascii mesh into insight"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool FreeSurferAsciiMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT FreeSurferAsciiMeshIOFactoryRegister__Private(void) +{ + if( ! FreeSurferAsciiMeshIOFactoryHasBeenRegistered ) + { + FreeSurferAsciiMeshIOFactoryHasBeenRegistered = true; + FreeSurferAsciiMeshIOFactory::RegisterOneFactory(); + } +} + } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkFreeSurferBinaryMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkFreeSurferBinaryMeshIOFactory.cxx index 62259d23ffe..375f8282656 100644 --- a/Modules/IO/Mesh/src/itkFreeSurferBinaryMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkFreeSurferBinaryMeshIOFactory.cxx @@ -15,6 +15,7 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" #include "itkFreeSurferBinaryMeshIO.h" #include "itkFreeSurferBinaryMeshIOFactory.h" @@ -54,4 +55,18 @@ ::GetDescription() const { return "FreeSurfer BINARY Mesh IO Factory, allows the loading of FreeSurfer Binary mesh into insight"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool FreeSurferBinaryMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT FreeSurferBinaryMeshIOFactoryRegister__Private(void) +{ + if( ! FreeSurferBinaryMeshIOFactoryHasBeenRegistered ) + { + FreeSurferBinaryMeshIOFactoryHasBeenRegistered = true; + FreeSurferBinaryMeshIOFactory::RegisterOneFactory(); + } +} + } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkGiftiMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkGiftiMeshIOFactory.cxx index cd12b8d7911..051a307db22 100644 --- a/Modules/IO/Mesh/src/itkGiftiMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkGiftiMeshIOFactory.cxx @@ -15,6 +15,7 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" #include "itkGiftiMeshIO.h" #include "itkGiftiMeshIOFactory.h" @@ -54,4 +55,18 @@ ::GetDescription() const { return "Gifti MeshIO Factory, allows the loading of Gifti meshs into insight"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool GiftiMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT GiftiMeshIOFactoryRegister__Private(void) +{ + if( ! GiftiMeshIOFactoryHasBeenRegistered ) + { + GiftiMeshIOFactoryHasBeenRegistered = true; + GiftiMeshIOFactory::RegisterOneFactory(); + } +} + } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkOBJMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkOBJMeshIOFactory.cxx index 8a5b5f11619..cb0fde90a17 100644 --- a/Modules/IO/Mesh/src/itkOBJMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkOBJMeshIOFactory.cxx @@ -15,6 +15,7 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" #include "itkOBJMeshIO.h" #include "itkOBJMeshIOFactory.h" @@ -54,4 +55,18 @@ ::GetDescription() const { return "OBJ Mesh IO Factory, allows the loading of OBJ mesh into insight"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool OBJMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT OBJMeshIOFactoryRegister__Private(void) +{ + if( ! OBJMeshIOFactoryHasBeenRegistered ) + { + OBJMeshIOFactoryHasBeenRegistered = true; + OBJMeshIOFactory::RegisterOneFactory(); + } +} + } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkOFFMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkOFFMeshIOFactory.cxx index 8173236d383..b69d9bc8b9a 100644 --- a/Modules/IO/Mesh/src/itkOFFMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkOFFMeshIOFactory.cxx @@ -15,6 +15,7 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" #include "itkOFFMeshIO.h" #include "itkOFFMeshIOFactory.h" @@ -54,4 +55,18 @@ ::GetDescription() const { return "OFF Mesh IO Factory, allows the loading of OFF mesh into insight"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool OFFMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT OFFMeshIOFactoryRegister__Private(void) +{ + if( ! OFFMeshIOFactoryHasBeenRegistered ) + { + OFFMeshIOFactoryHasBeenRegistered = true; + OFFMeshIOFactory::RegisterOneFactory(); + } +} + } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkVTKPolyDataMeshIOFactory.cxx b/Modules/IO/Mesh/src/itkVTKPolyDataMeshIOFactory.cxx index 5dd2a0d3a9b..bc86c52873d 100644 --- a/Modules/IO/Mesh/src/itkVTKPolyDataMeshIOFactory.cxx +++ b/Modules/IO/Mesh/src/itkVTKPolyDataMeshIOFactory.cxx @@ -15,6 +15,7 @@ * limitations under the License. * *=========================================================================*/ +#include "ITKIOMeshExport.h" #include "itkVTKPolyDataMeshIO.h" #include "itkVTKPolyDataMeshIOFactory.h" @@ -54,4 +55,18 @@ ::GetDescription() const { return "VTK MeshIO Factory, allows the loading of VTK polydata into insight"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool VTKPolyDataMeshIOFactoryHasBeenRegistered; + +void ITKIOMesh_EXPORT VTKPolyDataMeshIOFactoryRegister__Private(void) +{ + if( ! VTKPolyDataMeshIOFactoryHasBeenRegistered ) + { + VTKPolyDataMeshIOFactoryHasBeenRegistered = true; + VTKPolyDataMeshIOFactory::RegisterOneFactory(); + } +} + } // end namespace itk diff --git a/Modules/IO/MeshBase/CMakeLists.txt b/Modules/IO/MeshBase/CMakeLists.txt new file mode 100644 index 00000000000..b815fdc1e1f --- /dev/null +++ b/Modules/IO/MeshBase/CMakeLists.txt @@ -0,0 +1,4 @@ +project(ITKIOMeshBase) + +set(ITKIOMeshBase_LIBRARIES ITKIOMeshBase) +itk_module_impl() diff --git a/Modules/IO/Mesh/include/itkConvertArrayPixelBuffer.h b/Modules/IO/MeshBase/include/itkConvertArrayPixelBuffer.h similarity index 98% rename from Modules/IO/Mesh/include/itkConvertArrayPixelBuffer.h rename to Modules/IO/MeshBase/include/itkConvertArrayPixelBuffer.h index d2d44eb830b..5ec16d08fde 100644 --- a/Modules/IO/Mesh/include/itkConvertArrayPixelBuffer.h +++ b/Modules/IO/MeshBase/include/itkConvertArrayPixelBuffer.h @@ -29,7 +29,7 @@ namespace itk * * Derived from ConvertPixelBuffer has a static method Convert(). It is used * to work with pixel type as Array type. - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ template class ConvertPixelBuffer, OutputConvertTraits> diff --git a/Modules/IO/Mesh/include/itkConvertArrayPixelBuffer.hxx b/Modules/IO/MeshBase/include/itkConvertArrayPixelBuffer.hxx similarity index 100% rename from Modules/IO/Mesh/include/itkConvertArrayPixelBuffer.hxx rename to Modules/IO/MeshBase/include/itkConvertArrayPixelBuffer.hxx diff --git a/Modules/IO/Mesh/include/itkConvertVariableLengthVectorPixelBuffer.h b/Modules/IO/MeshBase/include/itkConvertVariableLengthVectorPixelBuffer.h similarity index 98% rename from Modules/IO/Mesh/include/itkConvertVariableLengthVectorPixelBuffer.h rename to Modules/IO/MeshBase/include/itkConvertVariableLengthVectorPixelBuffer.h index 7b1cd4c9754..c5ac2fb00c4 100644 --- a/Modules/IO/Mesh/include/itkConvertVariableLengthVectorPixelBuffer.h +++ b/Modules/IO/MeshBase/include/itkConvertVariableLengthVectorPixelBuffer.h @@ -29,7 +29,7 @@ namespace itk * * Derived from ConvertPixelBuffer has a static method Convert(). It is used * to work with pixel type as VariableLengthVector type. - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ template class ConvertPixelBuffer, OutputConvertTraits> diff --git a/Modules/IO/Mesh/include/itkConvertVariableLengthVectorPixelBuffer.hxx b/Modules/IO/MeshBase/include/itkConvertVariableLengthVectorPixelBuffer.hxx similarity index 100% rename from Modules/IO/Mesh/include/itkConvertVariableLengthVectorPixelBuffer.hxx rename to Modules/IO/MeshBase/include/itkConvertVariableLengthVectorPixelBuffer.hxx diff --git a/Modules/IO/Mesh/include/itkMeshConvertPixelTraits.h b/Modules/IO/MeshBase/include/itkMeshConvertPixelTraits.h similarity index 99% rename from Modules/IO/Mesh/include/itkMeshConvertPixelTraits.h rename to Modules/IO/MeshBase/include/itkMeshConvertPixelTraits.h index d1b2abba4be..19bf381d7a5 100644 --- a/Modules/IO/Mesh/include/itkMeshConvertPixelTraits.h +++ b/Modules/IO/MeshBase/include/itkMeshConvertPixelTraits.h @@ -39,7 +39,7 @@ namespace itk * This implementaion, does a simple assignment operator, so if you are * going from from a higher bit representation to a lower bit one (int to * char), you may want to specialize and add some sort of transfer function. - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ template class MeshConvertPixelTraits diff --git a/Modules/IO/Mesh/include/itkMeshFileReader.h b/Modules/IO/MeshBase/include/itkMeshFileReader.h similarity index 99% rename from Modules/IO/Mesh/include/itkMeshFileReader.h rename to Modules/IO/MeshBase/include/itkMeshFileReader.h index c7f73207b80..a2edd2ac31b 100644 --- a/Modules/IO/Mesh/include/itkMeshFileReader.h +++ b/Modules/IO/MeshBase/include/itkMeshFileReader.h @@ -64,7 +64,7 @@ namespace itk * \sa MeshIOBase * * \ingroup IOFilters - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase * * \author Wanlin Zhu. Uviversity of New South Wales, Australia. */ diff --git a/Modules/IO/Mesh/include/itkMeshFileReader.hxx b/Modules/IO/MeshBase/include/itkMeshFileReader.hxx similarity index 100% rename from Modules/IO/Mesh/include/itkMeshFileReader.hxx rename to Modules/IO/MeshBase/include/itkMeshFileReader.hxx diff --git a/Modules/IO/Mesh/include/itkMeshFileReaderException.h b/Modules/IO/MeshBase/include/itkMeshFileReaderException.h similarity index 92% rename from Modules/IO/Mesh/include/itkMeshFileReaderException.h rename to Modules/IO/MeshBase/include/itkMeshFileReaderException.h index 7254abbf288..7f6f6ecf82a 100644 --- a/Modules/IO/Mesh/include/itkMeshFileReaderException.h +++ b/Modules/IO/MeshBase/include/itkMeshFileReaderException.h @@ -17,7 +17,7 @@ *=========================================================================*/ #ifndef itkMeshFileReaderException_h #define itkMeshFileReaderException_h -#include "ITKIOMeshExport.h" +#include "ITKIOMeshBaseExport.h" #include "itkMacro.h" #include "itkExceptionObject.h" @@ -27,9 +27,9 @@ namespace itk /** \class MeshFileReaderException * * \brief Base exception class for IO conflicts. - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ -class ITKIOMesh_EXPORT MeshFileReaderException:public ExceptionObject +class ITKIOMeshBase_EXPORT MeshFileReaderException:public ExceptionObject { public: /** Has to have empty throw(). */ diff --git a/Modules/IO/Mesh/include/itkMeshFileWriter.h b/Modules/IO/MeshBase/include/itkMeshFileWriter.h similarity index 97% rename from Modules/IO/Mesh/include/itkMeshFileWriter.h rename to Modules/IO/MeshBase/include/itkMeshFileWriter.h index 1311e029549..0b785bc827e 100644 --- a/Modules/IO/Mesh/include/itkMeshFileWriter.h +++ b/Modules/IO/MeshBase/include/itkMeshFileWriter.h @@ -17,7 +17,7 @@ *=========================================================================*/ #ifndef itkMeshFileWriter_h #define itkMeshFileWriter_h -#include "ITKIOMeshExport.h" +#include "ITKIOMeshBaseExport.h" #include "itkMeshFileWriterException.h" #include "itkProcessObject.h" @@ -46,10 +46,10 @@ namespace itk * \sa MeshIOBase * * \ingroup IOFilters - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ template< typename TInputMesh > -class ITKIOMesh_EXPORT MeshFileWriter:public ProcessObject +class ITKIOMeshBase_EXPORT MeshFileWriter:public ProcessObject { public: /** Standard class typedefs. */ diff --git a/Modules/IO/Mesh/include/itkMeshFileWriter.hxx b/Modules/IO/MeshBase/include/itkMeshFileWriter.hxx similarity index 100% rename from Modules/IO/Mesh/include/itkMeshFileWriter.hxx rename to Modules/IO/MeshBase/include/itkMeshFileWriter.hxx diff --git a/Modules/IO/Mesh/include/itkMeshFileWriterException.h b/Modules/IO/MeshBase/include/itkMeshFileWriterException.h similarity index 92% rename from Modules/IO/Mesh/include/itkMeshFileWriterException.h rename to Modules/IO/MeshBase/include/itkMeshFileWriterException.h index 2f8d837ce7e..f8d781f3f09 100644 --- a/Modules/IO/Mesh/include/itkMeshFileWriterException.h +++ b/Modules/IO/MeshBase/include/itkMeshFileWriterException.h @@ -17,7 +17,7 @@ *=========================================================================*/ #ifndef itkMeshFileWriterException_h #define itkMeshFileWriterException_h -#include "ITKIOMeshExport.h" +#include "ITKIOMeshBaseExport.h" #include "itkMacro.h" #include "itkExceptionObject.h" @@ -27,9 +27,9 @@ namespace itk /** \class MeshFileWriterException. * \brief Base exception class for IO problems during writing. * - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ -class ITKIOMesh_EXPORT MeshFileWriterException:public ExceptionObject +class ITKIOMeshBase_EXPORT MeshFileWriterException:public ExceptionObject { public: /** Has to have empty throw(). */ diff --git a/Modules/IO/Mesh/include/itkMeshIOBase.h b/Modules/IO/MeshBase/include/itkMeshIOBase.h similarity index 99% rename from Modules/IO/Mesh/include/itkMeshIOBase.h rename to Modules/IO/MeshBase/include/itkMeshIOBase.h index e1c81c26afe..271eb26cf04 100644 --- a/Modules/IO/Mesh/include/itkMeshIOBase.h +++ b/Modules/IO/MeshBase/include/itkMeshIOBase.h @@ -17,7 +17,7 @@ *=========================================================================*/ #ifndef itkMeshIOBase_h #define itkMeshIOBase_h -#include "ITKIOMeshExport.h" +#include "ITKIOMeshBaseExport.h" #include "itkByteSwapper.h" #include "itkCellInterface.h" @@ -62,11 +62,11 @@ namespace itk * \sa MeshFileReader * * \ingroup IOFilters - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase * */ -class ITKIOMesh_EXPORT MeshIOBase:public LightProcessObject +class ITKIOMeshBase_EXPORT MeshIOBase:public LightProcessObject { public: /** Standard class typedefs. */ @@ -86,7 +86,7 @@ class ITKIOMesh_EXPORT MeshIOBase:public LightProcessObject /** * \class UnknownType * Used to return information when types are unknown. - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ class UnknownType {}; diff --git a/Modules/IO/Mesh/include/itkMeshIOFactory.h b/Modules/IO/MeshBase/include/itkMeshIOFactory.h similarity index 90% rename from Modules/IO/Mesh/include/itkMeshIOFactory.h rename to Modules/IO/MeshBase/include/itkMeshIOFactory.h index e64cbf8c6ec..2c2598ff6de 100644 --- a/Modules/IO/Mesh/include/itkMeshIOFactory.h +++ b/Modules/IO/MeshBase/include/itkMeshIOFactory.h @@ -17,7 +17,7 @@ *=========================================================================*/ #ifndef itkMeshIOFactory_h #define itkMeshIOFactory_h -#include "ITKIOMeshExport.h" +#include "ITKIOMeshBaseExport.h" #include "itkObject.h" #include "itkMeshIOBase.h" @@ -35,9 +35,9 @@ namespace itk * Object file format (*.obj) * VTK legacy file format (*.vtk) * - * \ingroup ITKIOMesh + * \ingroup ITKIOMeshBase */ -class ITKIOMesh_EXPORT MeshIOFactory:public Object +class ITKIOMeshBase_EXPORT MeshIOFactory:public Object { public: /** Standard class typedefs. */ @@ -69,13 +69,6 @@ class ITKIOMesh_EXPORT MeshIOFactory:public Object */ static void RegisterBuiltInFactories(); - /** - * Register Mesh factories. - * - * This method is automatically called during static initialization. - */ - static void RegisterFactories(); - protected: MeshIOFactory(); ~MeshIOFactory(); diff --git a/Modules/IO/MeshBase/itk-module.cmake b/Modules/IO/MeshBase/itk-module.cmake new file mode 100644 index 00000000000..9530b4970ba --- /dev/null +++ b/Modules/IO/MeshBase/itk-module.cmake @@ -0,0 +1,18 @@ +set(DOCUMENTATION "This module contains base classes for IO, helper classes for +IO, and classes that function as an MeshSource in an ITK pipeline. Classes for +specific file formats, found in other modules in the IO group, should inherit +from MeshIOBase. For a mesh source or sink in the ITK +pipeline that handles all available file formats, see MeshFileReader, +or MeshFileWriter.") + +itk_module(ITKIOMeshBase + ENABLE_SHARED + DEPENDS + ITKCommon + ITKIOImageBase + ITKQuadEdgeMesh + ITKMesh + ITKVoronoi + DESCRIPTION + "${DOCUMENTATION}" +) diff --git a/Modules/IO/MeshBase/src/CMakeLists.txt b/Modules/IO/MeshBase/src/CMakeLists.txt new file mode 100644 index 00000000000..c8050a8931c --- /dev/null +++ b/Modules/IO/MeshBase/src/CMakeLists.txt @@ -0,0 +1,11 @@ +set(ITKIOMeshBase_SRC + itkMeshFileReaderException.cxx + itkMeshFileWriterException.cxx + itkMeshIOBase.cxx + itkMeshIOFactory.cxx + itkMeshIOInstantiation.cxx +) + +add_library(ITKIOMeshBase ${ITK_LIBRARY_BUILD_TYPE} ${ITKIOMeshBase_SRC}) +itk_module_link_dependencies() +itk_module_target(ITKIOMeshBase) diff --git a/Modules/IO/Mesh/src/itkMeshFileReaderException.cxx b/Modules/IO/MeshBase/src/itkMeshFileReaderException.cxx similarity index 100% rename from Modules/IO/Mesh/src/itkMeshFileReaderException.cxx rename to Modules/IO/MeshBase/src/itkMeshFileReaderException.cxx diff --git a/Modules/IO/Mesh/src/itkMeshFileWriterException.cxx b/Modules/IO/MeshBase/src/itkMeshFileWriterException.cxx similarity index 100% rename from Modules/IO/Mesh/src/itkMeshFileWriterException.cxx rename to Modules/IO/MeshBase/src/itkMeshFileWriterException.cxx diff --git a/Modules/IO/Mesh/src/itkMeshIOBase.cxx b/Modules/IO/MeshBase/src/itkMeshIOBase.cxx similarity index 100% rename from Modules/IO/Mesh/src/itkMeshIOBase.cxx rename to Modules/IO/MeshBase/src/itkMeshIOBase.cxx diff --git a/Modules/IO/Mesh/src/itkMeshIOFactory.cxx b/Modules/IO/MeshBase/src/itkMeshIOFactory.cxx similarity index 63% rename from Modules/IO/Mesh/src/itkMeshIOFactory.cxx rename to Modules/IO/MeshBase/src/itkMeshIOFactory.cxx index dd851500134..1f698a7ba06 100644 --- a/Modules/IO/Mesh/src/itkMeshIOFactory.cxx +++ b/Modules/IO/MeshBase/src/itkMeshIOFactory.cxx @@ -18,14 +18,6 @@ #include "itkMeshIOFactory.h" -#include "itkBYUMeshIOFactory.h" -#include "itkFreeSurferAsciiMeshIOFactory.h" -#include "itkFreeSurferBinaryMeshIOFactory.h" -#include "itkGiftiMeshIOFactory.h" -#include "itkOBJMeshIOFactory.h" -#include "itkOFFMeshIOFactory.h" -#include "itkVTKPolyDataMeshIOFactory.h" - namespace itk { @@ -91,30 +83,4 @@ ::RegisterBuiltInFactories() // deprecated } -void -MeshIOFactory -::RegisterFactories() -{ - ObjectFactoryBase::RegisterFactoryInternal( BYUMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactoryInternal( FreeSurferAsciiMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactoryInternal( FreeSurferBinaryMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactoryInternal( GiftiMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactoryInternal( OBJMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactoryInternal( OFFMeshIOFactory::New() ); - ObjectFactoryBase::RegisterFactoryInternal( VTKPolyDataMeshIOFactory::New() ); -} - -// Undocumented API used to register during static initialization. -// DO NOT CALL DIRECTLY. -static bool MeshIOFactoryHasBeenRegistered; - -void ITKIOMesh_EXPORT MeshIOFactoryRegister__Private(void) -{ - if( ! MeshIOFactoryHasBeenRegistered ) - { - MeshIOFactoryHasBeenRegistered = true; - MeshIOFactory::RegisterFactories(); - } -} - } // end namespace itk diff --git a/Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx b/Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx similarity index 94% rename from Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx rename to Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx index 945352413d8..621f331cf1b 100644 --- a/Modules/IO/Mesh/src/itkMeshIOInstantiation.cxx +++ b/Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx @@ -16,7 +16,7 @@ * *=========================================================================*/ -#include "ITKIOMeshExport.h" +#include "ITKIOMeshBaseExport.h" // Mesh Types #include "itkMesh.h" @@ -54,16 +54,16 @@ , QuadEdgeMeshExtendedTraits< PIXEL_TYPE, DIMENSION, 2, CoordType, CoordType, PIXEL_TYPE, bool, bool> #define ITKIOMESH_INSTANTIATE_Reader(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ - template class ITKIOMesh_EXPORT MeshSource< \ + template class ITKIOMeshBase_EXPORT MeshSource< \ MESH_TYPE \ >;\ - template class ITKIOMesh_EXPORT MeshFileReader< \ + template class ITKIOMeshBase_EXPORT MeshFileReader< \ MESH_TYPE, \ MeshConvertPixelTraits< PIXEL_TYPE >, MeshConvertPixelTraits< PIXEL_TYPE > \ >; #define ITKIOMESH_INSTANTIATE_Writer(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ - template class ITKIOMesh_EXPORT MeshFileWriter< \ + template class ITKIOMeshBase_EXPORT MeshFileWriter< \ MESH_TYPE \ >; @@ -114,6 +114,6 @@ ITKIOMESH_INSTANTIATE_IOS(Mesh, VariableLengthVector_float_3, 3, DefaultTraits) // Required by ITKVoronoi itkVoronoiDiagram2DTest template class MeshFileReader< VoronoiDiagram2D< double > >; -template class ITKIOMesh_EXPORT MeshFileWriter< VoronoiDiagram2D< double > >; +template class ITKIOMeshBase_EXPORT MeshFileWriter< VoronoiDiagram2D< double > >; } // end namespace itk From 1727635c46a4cc7de08ca2bdb49a36b7d4ead675 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Fri, 18 Dec 2015 19:53:06 -0500 Subject: [PATCH 3/4] COMP: MeshIO: Implement explicit template instantiation using "extern". This commit updates explicit instantiation to use "extern" keyword similarly to what was done in InsightSoftwareConsortium/ITK@b72726c (BUG: Explicitly instantiate common MetaDataObjects). While "extern" is only part of the c++ standard starting with c++11 (see section 14.7.2 of the standard), it is supported by Visual Studio 2008, GCC and Clang using compiler specific extension in earlier version: * Visual Studio 2008: https://msdn.microsoft.com/en-us/library/by56e477(v=vs.90).aspx * Gcc: https://gcc.gnu.org/onlinedocs/gcc-4.8.4/gcc/Template-Instantiation.html#Template-Instantiation * Clang (since v2.9): http://clang.llvm.org/cxx_status.html For completeness, initial draft of the "extern" keyword were first introduced in 2003 [1] and then revised in 2006 [2], and ultimately standardized in c++11 [3]: [1] N1448: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1448.pdf [2] N1987: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1987.htm [3] N3242: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/ See #3393 Change-Id: I74a9260e4ad9996470a54159c55cae6a7fa7f10d --- .../IO/MeshBase/include/itkMeshFileReader.h | 22 +++- .../IO/MeshBase/include/itkMeshFileWriter.h | 24 +++- .../include/itkMeshIOInstantiation.inc | 105 ++++++++++++++++ Modules/IO/MeshBase/src/CMakeLists.txt | 3 +- Modules/IO/MeshBase/src/itkMeshFileReader.cxx | 35 ++++++ Modules/IO/MeshBase/src/itkMeshFileWriter.cxx | 35 ++++++ .../MeshBase/src/itkMeshIOInstantiation.cxx | 119 ------------------ 7 files changed, 220 insertions(+), 123 deletions(-) create mode 100644 Modules/IO/MeshBase/include/itkMeshIOInstantiation.inc create mode 100644 Modules/IO/MeshBase/src/itkMeshFileReader.cxx create mode 100644 Modules/IO/MeshBase/src/itkMeshFileWriter.cxx delete mode 100644 Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx diff --git a/Modules/IO/MeshBase/include/itkMeshFileReader.h b/Modules/IO/MeshBase/include/itkMeshFileReader.h index a2edd2ac31b..16f4e875216 100644 --- a/Modules/IO/MeshBase/include/itkMeshFileReader.h +++ b/Modules/IO/MeshBase/include/itkMeshFileReader.h @@ -171,9 +171,29 @@ class MeshFileReader:public MeshSource< TOutputMesh > std::string m_ExceptionMessage; }; + } // namespace ITK -// Note: Explicit instantiation is done in itkMeshIOInstantiation.cxx +/** Explicit instantiations */ +#ifndef ITK_TEMPLATE_EXPLICIT_MeshIOInstantiation +// Explicit instantiation is required to ensure correct dynamic_cast +// behavior across shared libraries. +# if defined( ITKIOMeshBase_EXPORTS ) +// We are building this library +# define ITKIOMeshBase_EXPORT_EXPLICIT +# else +// We are using this library +# define ITKIOMeshBase_EXPORT_EXPLICIT ITKIOMeshBase_EXPORT +# endif + +# define ITKMeshIOInstantiation_IO_TYPE MeshFileReader +# include "itkMeshIOInstantiation.inc" +# undef ITKMeshIOInstantiation_IO_TYPE + +# undef ITKIOMeshBase_EXPORT_EXPLICIT +#endif + +// Note: Explicit instantiation is done in itkMeshFileReader.cxx #ifdef ITK_IO_FACTORY_REGISTER_MANAGER #include "itkMeshIOFactoryRegisterManager.h" diff --git a/Modules/IO/MeshBase/include/itkMeshFileWriter.h b/Modules/IO/MeshBase/include/itkMeshFileWriter.h index 0b785bc827e..b19b1ca67f6 100644 --- a/Modules/IO/MeshBase/include/itkMeshFileWriter.h +++ b/Modules/IO/MeshBase/include/itkMeshFileWriter.h @@ -49,7 +49,7 @@ namespace itk * \ingroup ITKIOMeshBase */ template< typename TInputMesh > -class ITKIOMeshBase_EXPORT MeshFileWriter:public ProcessObject +class MeshFileWriter:public ProcessObject { public: /** Standard class typedefs. */ @@ -162,9 +162,29 @@ class ITKIOMeshBase_EXPORT MeshFileWriter:public ProcessObject bool m_UseCompression; bool m_FileTypeIsBINARY; }; + } // end namespace itk -// Note: Explicit instantiation is done in itkMeshIOInstantiation.cxx +/** Explicit instantiations */ +#ifndef ITK_TEMPLATE_EXPLICIT_MeshIOInstantiation +// Explicit instantiation is required to ensure correct dynamic_cast +// behavior across shared libraries. +# if defined( ITKIOMeshBase_EXPORTS ) +// We are building this library +# define ITKIOMeshBase_EXPORT_EXPLICIT +# else +// We are using this library +# define ITKIOMeshBase_EXPORT_EXPLICIT ITKIOMeshBase_EXPORT +# endif + +# define ITKMeshIOInstantiation_IO_TYPE MeshFileWriter +# include "itkMeshIOInstantiation.inc" +# undef ITKMeshIOInstantiation_IO_TYPE + +# undef ITKIOMeshBase_EXPORT_EXPLICIT +#endif + +// Note: Explicit instantiation is done in itkMeshFileWriter.cxx #ifdef ITK_IO_FACTORY_REGISTER_MANAGER #include "itkMeshIOFactoryRegisterManager.h" diff --git a/Modules/IO/MeshBase/include/itkMeshIOInstantiation.inc b/Modules/IO/MeshBase/include/itkMeshIOInstantiation.inc new file mode 100644 index 00000000000..1cfc904712f --- /dev/null +++ b/Modules/IO/MeshBase/include/itkMeshIOInstantiation.inc @@ -0,0 +1,105 @@ +/*========================================================================= + * + * 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. + * + *=========================================================================*/ + +// Mesh Types +#include "itkMesh.h" +#include "itkQuadEdgeMesh.h" +#include "itkSimplexMesh.h" +#include "itkVoronoiDiagram2D.h" + +// Pixel Types +#include "itkCovariantVector.h" +#include "itkSymmetricSecondRankTensor.h" +#include "itkVariableLengthVector.h" + +// Traits types +#include "itkQuadEdgeMeshExtendedTraits.h" +#include "itkQuadEdgeMeshTraits.h" + +#ifndef ITKMeshIOInstantiation_IO_TYPE +# error "ITKMeshIOInstantiation_IO_TYPE macro is expected to set to either MeshFileReader or MeshFileWriter" +#endif + +#ifndef ITK_TEMPLATE_EXPLICIT_MeshIOInstantiation +# define MeshIO_TEMPLATE_EXPORT ITKIOMeshBase_EXPORT_EXPLICIT +# define MeshIO_TEMPLATE_EXTERN extern +#else +# define MeshIO_TEMPLATE_EXPORT ITKIOMeshBase_EXPORT +# define MeshIO_TEMPLATE_EXTERN +#endif + +#define MeshIO_DefaultTraits_TRAITS(PIXEL_TYPE, DIMENSION) + +#define MeshIO_QuadEdgeMeshTraits_TRAITS(PIXEL_TYPE, DIMENSION) \ + , QuadEdgeMeshTraits< PIXEL_TYPE, DIMENSION, bool, bool> + +#define MeshIO_QuadEdgeMeshExtendedTraits_TRAITS(PIXEL_TYPE, DIMENSION) \ + , QuadEdgeMeshExtendedTraits< PIXEL_TYPE, DIMENSION, 2, CoordType, CoordType, PIXEL_TYPE, bool, bool> + +#define MeshIO_INSTANTIATE(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ + MeshIO_TEMPLATE_EXTERN template class MeshIO_TEMPLATE_EXPORT ITKMeshIOInstantiation_IO_TYPE< \ + MESH_TYPE \ + >; + +#define MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(MESH_TYPE, DIMENSION, TRAITS) \ + MeshIO_INSTANTIATE(MESH_TYPE, float, DIMENSION, TRAITS) \ + MeshIO_INSTANTIATE(MESH_TYPE, double, DIMENSION, TRAITS) + +namespace itk +{ + +typedef double CoordType; + +typedef CovariantVector< float, 3 > CovariantVector_float_3; +typedef SymmetricSecondRankTensor< float, 2 > SymmetricSecondRankTensor_float_2; +typedef SymmetricSecondRankTensor< float, 3 > SymmetricSecondRankTensor_float_3; +typedef VariableLengthVector< float > VariableLengthVector_float_3; + +MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(Mesh, 2, DefaultTraits) +MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(Mesh, 3, DefaultTraits) + +MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(QuadEdgeMesh, 3, QuadEdgeMeshExtendedTraits) +MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(QuadEdgeMesh, 3, QuadEdgeMeshTraits) + +MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(SimplexMesh, 2, DefaultTraits) +MeshIO_INSTANTIATE_FOR_PIXEL_TYPES(SimplexMesh, 3, DefaultTraits) + +// Required by ITKIOMesh itkMeshFileReadWriteVectorAttributeTest +MeshIO_INSTANTIATE(Mesh, CovariantVector_float_3, 3, DefaultTraits) +MeshIO_INSTANTIATE(QuadEdgeMesh, CovariantVector_float_3, 3, QuadEdgeMeshTraits) + +// Required by ITKIOMesh itkMeshFileWriteReadTensorTest +MeshIO_INSTANTIATE(Mesh, SymmetricSecondRankTensor_float_2, 2, DefaultTraits) +MeshIO_INSTANTIATE(Mesh, SymmetricSecondRankTensor_float_3, 3, DefaultTraits) + +// Required by ITKIOMesh itkPolylineReadWriteTest +MeshIO_INSTANTIATE(Mesh, VariableLengthVector_float_3, 3, DefaultTraits) + +// Required by ITKVoronoi itkVoronoiDiagram2DTest +MeshIO_TEMPLATE_EXTERN template class MeshIO_TEMPLATE_EXPORT + ITKMeshIOInstantiation_IO_TYPE< VoronoiDiagram2D< double > >; + +} // end namespace itk + +#undef MeshIO_TEMPLATE_EXPORT +#undef MeshIO_TEMPLATE_EXTERN +#undef MeshIO_DefaultTraits_TRAITS +#undef MeshIO_QuadEdgeMeshTraits_TRAITS +#undef MeshIO_QuadEdgeMeshExtendedTraits_TRAITS +#undef MeshIO_INSTANTIATE +#undef MeshIO_INSTANTIATE_FOR_PIXEL_TYPES diff --git a/Modules/IO/MeshBase/src/CMakeLists.txt b/Modules/IO/MeshBase/src/CMakeLists.txt index c8050a8931c..02828c279c6 100644 --- a/Modules/IO/MeshBase/src/CMakeLists.txt +++ b/Modules/IO/MeshBase/src/CMakeLists.txt @@ -1,9 +1,10 @@ set(ITKIOMeshBase_SRC + itkMeshFileReader.cxx itkMeshFileReaderException.cxx + itkMeshFileWriter.cxx itkMeshFileWriterException.cxx itkMeshIOBase.cxx itkMeshIOFactory.cxx - itkMeshIOInstantiation.cxx ) add_library(ITKIOMeshBase ${ITK_LIBRARY_BUILD_TYPE} ${ITKIOMeshBase_SRC}) diff --git a/Modules/IO/MeshBase/src/itkMeshFileReader.cxx b/Modules/IO/MeshBase/src/itkMeshFileReader.cxx new file mode 100644 index 00000000000..00ef0360790 --- /dev/null +++ b/Modules/IO/MeshBase/src/itkMeshFileReader.cxx @@ -0,0 +1,35 @@ +/*========================================================================= + * + * 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. + * + *=========================================================================*/ + +#define ITK_TEMPLATE_EXPLICIT_MeshIOInstantiation +#include "itkMeshFileReader.h" +#include "itkMeshFileReader.hxx" + +#ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP + ITK_GCC_PRAGMA_DIAG_PUSH() +#endif +ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes") + +#define ITKMeshIOInstantiation_IO_TYPE MeshFileReader +#include "itkMeshIOInstantiation.inc" + +#ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP + ITK_GCC_PRAGMA_DIAG_POP() +#else + ITK_GCC_PRAGMA_DIAG(warning "-Wattributes") +#endif diff --git a/Modules/IO/MeshBase/src/itkMeshFileWriter.cxx b/Modules/IO/MeshBase/src/itkMeshFileWriter.cxx new file mode 100644 index 00000000000..e067071a9ba --- /dev/null +++ b/Modules/IO/MeshBase/src/itkMeshFileWriter.cxx @@ -0,0 +1,35 @@ +/*========================================================================= + * + * 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. + * + *=========================================================================*/ + +#define ITK_TEMPLATE_EXPLICIT_MeshIOInstantiation +#include "itkMeshFileWriter.h" +#include "itkMeshFileWriter.hxx" + +#ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP + ITK_GCC_PRAGMA_DIAG_PUSH() +#endif +ITK_GCC_PRAGMA_DIAG(ignored "-Wattributes") + +#define ITKMeshIOInstantiation_IO_TYPE MeshFileWriter +#include "itkMeshIOInstantiation.inc" + +#ifdef ITK_HAS_GCC_PRAGMA_DIAG_PUSHPOP + ITK_GCC_PRAGMA_DIAG_POP() +#else + ITK_GCC_PRAGMA_DIAG(warning "-Wattributes") +#endif diff --git a/Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx b/Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx deleted file mode 100644 index 621f331cf1b..00000000000 --- a/Modules/IO/MeshBase/src/itkMeshIOInstantiation.cxx +++ /dev/null @@ -1,119 +0,0 @@ -/*========================================================================= - * - * 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 "ITKIOMeshBaseExport.h" - -// Mesh Types -#include "itkMesh.h" -#include "itkQuadEdgeMesh.h" -#include "itkSimplexMesh.h" -#include "itkVoronoiDiagram2D.h" - -// Pixel Types -#include "itkCovariantVector.h" -#include "itkSymmetricSecondRankTensor.h" -#include "itkVariableLengthVector.h" - -// Traits types -#include "itkQuadEdgeMeshExtendedTraits.h" -#include "itkQuadEdgeMeshTraits.h" - -// Reader -#include "itkMeshFileReader.h" -#include "itkMeshFileReader.hxx" -#include "itkMeshSource.h" - -// Writer -#include "itkMeshFileWriter.h" -#include "itkMeshFileWriter.hxx" - -// ----------------------------------------------------------------------------- -// Reader / Writer instantiation macros - -#define ITKIOMESH_DefaultTraits_TRAITS(PIXEL_TYPE, DIMENSION) - -#define ITKIOMESH_QuadEdgeMeshTraits_TRAITS(PIXEL_TYPE, DIMENSION) \ - , QuadEdgeMeshTraits< PIXEL_TYPE, DIMENSION, bool, bool> - -#define ITKIOMESH_QuadEdgeMeshExtendedTraits_TRAITS(PIXEL_TYPE, DIMENSION) \ - , QuadEdgeMeshExtendedTraits< PIXEL_TYPE, DIMENSION, 2, CoordType, CoordType, PIXEL_TYPE, bool, bool> - -#define ITKIOMESH_INSTANTIATE_Reader(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ - template class ITKIOMeshBase_EXPORT MeshSource< \ - MESH_TYPE \ - >;\ - template class ITKIOMeshBase_EXPORT MeshFileReader< \ - MESH_TYPE, \ - MeshConvertPixelTraits< PIXEL_TYPE >, MeshConvertPixelTraits< PIXEL_TYPE > \ - >; - -#define ITKIOMESH_INSTANTIATE_Writer(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ - template class ITKIOMeshBase_EXPORT MeshFileWriter< \ - MESH_TYPE \ - >; - -#define ITKIOMESH_INSTANTIATE_IOS(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ - ITKIOMESH_INSTANTIATE_Reader(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) \ - ITKIOMESH_INSTANTIATE_Writer(MESH_TYPE, PIXEL_TYPE, DIMENSION, TRAITS) - -#define ITKIOMESH_INSTANTIATE_IO_FOR_PIXEL_TYPES(IO_TYPE, MESH_TYPE, DIMENSION, TRAITS) \ - ITKIOMESH_INSTANTIATE_##IO_TYPE(MESH_TYPE, float, DIMENSION, TRAITS) \ - ITKIOMESH_INSTANTIATE_##IO_TYPE(MESH_TYPE, double, DIMENSION, TRAITS) - -#define ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(MESH_TYPE, DIMENSION, TRAITS) \ - ITKIOMESH_INSTANTIATE_IO_FOR_PIXEL_TYPES(Reader, MESH_TYPE, DIMENSION, TRAITS) \ - ITKIOMESH_INSTANTIATE_IO_FOR_PIXEL_TYPES(Writer, MESH_TYPE, DIMENSION, TRAITS) - -namespace itk -{ - -typedef double CoordType; - -typedef CovariantVector< float, 3 > CovariantVector_float_3; -typedef SymmetricSecondRankTensor< float, 2 > SymmetricSecondRankTensor_float_2; -typedef SymmetricSecondRankTensor< float, 3 > SymmetricSecondRankTensor_float_3; -typedef VariableLengthVector< float > VariableLengthVector_float_3; - -// ----------------------------------------------------------------------------- -// MeshFileReader / MeshFileWriter - -ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(Mesh, 2, DefaultTraits) -ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(Mesh, 3, DefaultTraits) - -ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(QuadEdgeMesh, 3, QuadEdgeMeshExtendedTraits) -ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(QuadEdgeMesh, 3, QuadEdgeMeshTraits) - -ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(SimplexMesh, 2, DefaultTraits) -ITKIOMESH_INSTANTIATE_IOS_FOR_PIXEL_TYPES(SimplexMesh, 3, DefaultTraits) - -// Required by ITKIOMesh itkMeshFileReadWriteVectorAttributeTest -ITKIOMESH_INSTANTIATE_IOS(Mesh, CovariantVector_float_3, 3, DefaultTraits) -ITKIOMESH_INSTANTIATE_IOS(QuadEdgeMesh, CovariantVector_float_3, 3, QuadEdgeMeshTraits) - -// Required by ITKIOMesh itkMeshFileWriteReadTensorTest -ITKIOMESH_INSTANTIATE_IOS(Mesh, SymmetricSecondRankTensor_float_2, 2, DefaultTraits) -ITKIOMESH_INSTANTIATE_IOS(Mesh, SymmetricSecondRankTensor_float_3, 3, DefaultTraits) - -// Required by ITKIOMesh itkPolylineReadWriteTest -ITKIOMESH_INSTANTIATE_IOS(Mesh, VariableLengthVector_float_3, 3, DefaultTraits) - -// Required by ITKVoronoi itkVoronoiDiagram2DTest -template class MeshFileReader< VoronoiDiagram2D< double > >; -template class ITKIOMeshBase_EXPORT MeshFileWriter< VoronoiDiagram2D< double > >; - -} // end namespace itk From 49b931be4748e676e1786678c9b55f0aa71d098c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Fri, 11 Dec 2015 03:09:05 -0500 Subject: [PATCH 4/4] STYLE: UseITK: Simplify code adding _set_module_and_factory_names. See #3393 Change-Id: Idea55bf05e92d3266e27f711d2f29256b9f0d44b --- CMake/UseITK.cmake | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/CMake/UseITK.cmake b/CMake/UseITK.cmake index 5eec4772bdb..969cf28a91b 100644 --- a/CMake/UseITK.cmake +++ b/CMake/UseITK.cmake @@ -207,6 +207,24 @@ macro(ADD_FACTORY_REGISTRATION _registration_list_var _names_list_var _module_na endif() endmacro() +# _set_module_and_factory_names( ) +# +# Set default factory and module names associated with the formats +# while considering exceptions already set. +# +macro(_set_module_and_factory_names factory_type module_name_prefix factory_name_suffix) + string(TOUPPER ${factory_type} _qualifier_uc) + string(TOLOWER ${factory_type} _qualifier_lc) + foreach(format ${LIST_OF_${_qualifier_uc}IO_FORMATS}) + if (NOT ${format}_${_qualifier_lc}_module_name ) + set(${format}_${_qualifier_lc}_module_name ${module_name_prefix}${format}) + endif() + if (NOT ${format}_${_qualifier_lc}_factory_name) + set(${format}_${_qualifier_lc}_factory_name ${format}${factory_name_suffix}) + endif() + endforeach() +endmacro() + #----------------------------------------------------------------------------- # ImageIO #----------------------------------------------------------------------------- @@ -238,14 +256,7 @@ set(SCIFIO_image_module_name SCIFIO) set(FDF_image_module_name IOFDF) -foreach(ImageFormat ${LIST_OF_IMAGEIO_FORMATS}) - if (NOT ${ImageFormat}_image_module_name ) - set(${ImageFormat}_image_module_name ITKIO${ImageFormat}) - endif() - if (NOT ${ImageFormat}_image_factory_name) - set(${ImageFormat}_image_factory_name ${ImageFormat}ImageIO) - endif() -endforeach() +_set_module_and_factory_names("Image" "ITKIO" "ImageIO") if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER) _configure_IOFactoryRegisterManager("Image" "${LIST_OF_IMAGEIO_FORMATS}") @@ -289,14 +300,7 @@ set(OFF_mesh_factory_name OFFMeshIO) set(VTKPolyData_mesh_module_name ITKIOMesh) set(VTKPolyData_mesh_factory_name VTKPolyDataMeshIO) -foreach(MeshFormat ${LIST_OF_MESHIO_FORMATS}) - if (NOT ${MeshFormat}_mesh_module_name ) - set(${MeshFormat}_mesh_module_name ITKIOMesh${MeshFormat}) - endif() - if (NOT ${MeshFormat}_mesh_factory_name) - set(${MeshFormat}_mesh_factory_name ${MeshFormat}MeshIO) - endif() -endforeach() +_set_module_and_factory_names("Mesh" "ITKIOMesh" "MeshIO") if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER) _configure_IOFactoryRegisterManager("Mesh" "${LIST_OF_MESHIO_FORMATS}") @@ -319,14 +323,8 @@ set(LIST_OF_TRANSFORMIO_FORMATS set(Txt_transform_module_name ITKIOTransformInsightLegacy) set(Txt_transform_factory_name TxtTransformIO) -foreach(TransformFormat ${LIST_OF_TRANSFORMIO_FORMATS}) - if (NOT ${TransformFormat}_transform_module_name ) - set(${TransformFormat}_transform_module_name ITKIOTransform${TransformFormat}) - endif() - if (NOT ${TransformFormat}_transform_factory_name) - set(${TransformFormat}_transform_factory_name ${TransformFormat}TransformIO) - endif() -endforeach() + +_set_module_and_factory_names("Transform" "ITKIOTransform" "TransformIO") if(NOT ITK_NO_IO_FACTORY_REGISTER_MANAGER) _configure_IOFactoryRegisterManager("Transform" "${LIST_OF_TRANSFORMIO_FORMATS}")