From cd34d75d207c09feb5cb48c14a24d8dac1439667 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 29 Dec 2013 22:14:30 -0500 Subject: [PATCH 01/73] ENH: First commit --- Modules/IO/IOMeshSTL/CMakeLists.txt | 3 + Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 152 ++++++++++ .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 76 +++++ Modules/IO/IOMeshSTL/itk-module.cmake | 16 ++ Modules/IO/IOMeshSTL/src/CMakeLists.txt | 18 ++ Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 270 ++++++++++++++++++ .../IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 47 +++ ...lData_MD5_2327dbe1884cbf2b58071501567400f6 | 56 ++++ ...lData_MD5_545c2293b16e250f25395dabbaa53cbb | 226 +++++++++++++++ .../IO/IOMeshSTL/test/Baseline/sphere.stl.md5 | 1 + .../IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 | 1 + Modules/IO/IOMeshSTL/test/CMakeLists.txt | 14 + .../IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 64 +++++ 13 files changed, 944 insertions(+) create mode 100644 Modules/IO/IOMeshSTL/CMakeLists.txt create mode 100644 Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h create mode 100644 Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h create mode 100644 Modules/IO/IOMeshSTL/itk-module.cmake create mode 100644 Modules/IO/IOMeshSTL/src/CMakeLists.txt create mode 100644 Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx create mode 100644 Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 create mode 100644 Modules/IO/IOMeshSTL/test/CMakeLists.txt create mode 100644 Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt new file mode 100644 index 00000000000..da161c7c69d --- /dev/null +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -0,0 +1,3 @@ +project(ITKIOSTLMesh) +set(ITKIOSTLMesh_LIBRARIES ITKIOSTLMesh) +itk_module_impl() diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h new file mode 100644 index 00000000000..78f60a237a6 --- /dev/null +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -0,0 +1,152 @@ +/*========================================================================= + * + * 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 __itkSTLMeshIO_h +#define __itkSTLMeshIO_h + +#include "itkMeshIOBase.h" + +#include + +namespace itk +{ +/** \class STLMeshIO + * \brief This class defines how to read and write STL file format. + * + * \author Luis Ibanez, Kitware Inc. + * \ingroup IOFilters + * \ingroup ITKIOMesh + */ +class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase +{ +public: + /** Standard "Self" typedef. */ + typedef STLMeshIO Self; + typedef MeshIOBase Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(STLMeshIO, MeshIOBase); + + /**-------- This part of the interfaces deals with reading data. ----- */ + + /** Determine if the file can be read with this MeshIO implementation. + * \param FileNameToRead The name of the file to test for reading. + * \post Sets classes MeshIOBase::m_FileName variable to be FileNameToWrite + * \return Returns true if this MeshIO can read the file specified. + */ + virtual bool + CanReadFile(const char * FileNameToRead); + + /** Read the content of the file into a Mesh. */ + virtual void + Read(); + + /** Set the spacing and dimension information for the set filename. */ + virtual void + ReadMeshInformation(); + + /** Reads the data from disk into the memory buffer provided. */ + virtual void + ReadPoints(void * buffer); + + virtual void + ReadCells(void * buffer); + + /** STL files do not carry information in points or cells. + * Therefore the following two methods are implemented as null + * operations. */ + virtual void + ReadPointData(void * itkNotUsed(buffer)) {}; + virtual void + ReadCellData(void * itkNotUsed(buffer)) {}; + + /*-------- This part of the interfaces deals with writing data. ----- */ + /** Determine if the file can be written with this MeshIO implementation. + * \param FileNameToWrite The name of the file to test for writing. + * \post Sets classes MeshIOBase::m_FileName variable to be FileNameToWrite + * \return Returns true if this MeshIO can write the file specified. + */ + virtual bool + CanWriteFile(const char * FileNameToWrite); + + /** Write header of the STL file */ + virtual void + WriteMeshInformation(); + + /** Write the content of the Mesh into an STL file. */ + virtual void + Write(); + + /** The STL format stores point coordinates repeatedly as part of every + * triangle. Therefore point coordinates are writen as part of the + * WriteCells() method, and not as an independent operation. + * Consequently, this method is implemented as a null operation. + */ + virtual void + WritePoints(void * itkNotUsed(buffer)) {}; + + /** The WriteCells() method does most of the work. It writes + * out every triangle in the mesh. For every triangle, it + * writes out its normal, followed by the coordinates of its + * three vertices. + * + * A typical cell looks as follows in an ASCII STL file + * + * facet normal 0.357406 0.862856 0.357406 + * outer loop + * vertex 0 1 0 + * vertex 0 0.707107 0.707107 + * vertex 0.707107 0.707107 0 + * endloop + * endfacet + * + */ + virtual void + WriteCells(void * buffer); + + /** STL files do not carry information in points or cells. + * Therefore the following two methods are implemented as null + * operations. */ + virtual void + WritePointData(void * itkNotUsed(buffer)) {}; + virtual void + WriteCellData(void * itkNotUsed(buffer)) {}; + + +protected: + STLMeshIO(); + virtual ~STLMeshIO() {} + + void + PrintSelf(std::ostream & os, Indent indent) const; + +private: + STLMeshIO(const Self &); // purposely not implemented + void + operator=(const Self &); // purposely not implemented + + std::ofstream m_OutputStream; // output file + std::ifstream m_InputStream; // input file +}; +} // end namespace itk + +#endif // __itkSTLMeshIO_h diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h new file mode 100644 index 00000000000..0e675d3c99a --- /dev/null +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -0,0 +1,76 @@ +/*========================================================================= + * + * 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 __itkSTLMeshIOFactory_h +#define __itkSTLMeshIOFactory_h +#include "ITKIOMeshExport.h" + +#include "itkObjectFactoryBase.h" +#include "itkMeshIOBase.h" + +namespace itk +{ +/** \class STLMeshIOFactory + * \brief Create instances of STLMeshIO objects using an object factory. + * \ingroup ITKIOMesh + */ +class ITKIOMesh_EXPORT STLMeshIOFactory : public ObjectFactoryBase +{ +public: + /** Standard class typedefs. */ + typedef STLMeshIOFactory Self; + typedef ObjectFactoryBase Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** Class methods used to interface with the registered factories. */ + virtual const char * + GetITKSourceVersion(void) const; + + virtual const char * + GetDescription(void) const; + + /** Method for class instantiation. */ + itkFactorylessNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(STLMeshIOFactory, ObjectFactoryBase); + + /** Register one factory of this type */ + static void + RegisterOneFactory(void) + { + STLMeshIOFactory::Pointer vtkFactory = STLMeshIOFactory::New(); + + ObjectFactoryBase::RegisterFactory(vtkFactory); + } + +protected: + STLMeshIOFactory(); + ~STLMeshIOFactory(); + + virtual void + PrintSelf(std::ostream & os, Indent indent) const; + +private: + STLMeshIOFactory(const Self &); // purposely not implemented + void + operator=(const Self &); // purposely not implemented +}; +} // end namespace itk + +#endif diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake new file mode 100644 index 00000000000..71b7119180c --- /dev/null +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -0,0 +1,16 @@ +set( + DOCUMENTATION + "This module contains classes for reading and writing +QuadEdgeMeshes using the STL file format." +) +itk_module( + ITKIOSTLMesh + ENABLE_SHARED + DEPENDS + ITKCommon + ITKIOMesh + TEST_DEPENDS + ITKTestKernel + ITKQuadEdgeMesh + DESCRIPTION "${DOCUMENTATION}" +) diff --git a/Modules/IO/IOMeshSTL/src/CMakeLists.txt b/Modules/IO/IOMeshSTL/src/CMakeLists.txt new file mode 100644 index 00000000000..f96ff34d4c9 --- /dev/null +++ b/Modules/IO/IOMeshSTL/src/CMakeLists.txt @@ -0,0 +1,18 @@ +set( + ITKIOSTLMesh_SRC + itkSTLMeshIO.cxx + itkSTLMeshIOFactory.cxx +) + +add_library( + ITKIOSTLMesh + ${ITK_LIBRARY_BUILD_TYPE} + ${ITKIOSTLMesh_SRC} +) +target_link_libraries( + ITKIOSTLMesh + ${ITKCommon_LIBRARIES} + ${ITKIOMesh_LIBRARIES} +) + +itk_module_target(ITKIOSTLMesh) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx new file mode 100644 index 00000000000..03a79cf7872 --- /dev/null +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -0,0 +1,270 @@ +/*========================================================================= + * + * 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 "itkSTLMeshIO.h" +#include "itkMetaDataObject.h" + +#include +#include + +namespace itk +{ +// Constructor +STLMeshIO ::STLMeshIO() { this->AddSupportedWriteExtension(".stl"); } + +bool +STLMeshIO ::CanReadFile(const char * fileName) +{ + if (!itksys::SystemTools::FileExists(fileName, true)) + { + return false; + } + + if (itksys::SystemTools::GetFilenameLastExtension(fileName) != ".stl") + { + return false; + } + + return true; +} + +bool +STLMeshIO ::CanWriteFile(const char * fileName) +{ + if (itksys::SystemTools::GetFilenameLastExtension(fileName) != ".stl") + { + return false; + } + + return true; +} + +void +STLMeshIO ::Read() +{} + +void +STLMeshIO ::ReadMeshInformation() +{ + + // Use default filetype + if (this->GetFileType() == ASCII) + { + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); + } + else if (GetFileType() == BINARY) + { + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); + } + + if (!this->m_InputStream.is_open()) + { + itkExceptionMacro("Unable to open file\n" + "inputFilename= " + << this->m_FileName); + return; + } + + + std::string inputLine; + + // Read STL header file(the first line) + std::getline(this->m_InputStream, inputLine, '\n'); + + // Determine file type + if (inputLine.find("solid") != std::string::npos) + { + if (this->GetFileType() != ASCII) + { + this->SetFileType(ASCII); +#ifdef _WIN32 + this->m_InputStream.close(); + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); + if (!this->m_InputStream.is_open()) + { + itkExceptionMacro("Unable to open file\n" + "inputFilename= " + << this->m_FileName); + return; + } +#endif + } + } + else if (inputLine.find("BINARY") != std::string::npos) + { + if (this->GetFileType() != BINARY) + { + this->SetFileType(BINARY); +#ifdef _WIN32 + this->m_InputStream.close(); + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); + if (!this->m_InputStream.is_open()) + { + itkExceptionMacro("Unable to open file\n" + "inputFilename= " + << this->m_FileName); + return; + } +#endif + } + } + + + this->m_InputStream.close(); +} + +void +STLMeshIO ::ReadPoints(void * itkNotUsed(buffer)) +{ + // Read input file + + if (this->GetFileType() == ASCII) + { + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); + } + else if (GetFileType() == BINARY) + { + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); + } + + // Test whether the file has been opened + if (!this->m_InputStream.is_open()) + { + itkExceptionMacro("Unable to open file\n" + "inputFilename= " + << this->m_FileName); + return; + } + + this->m_InputStream.close(); +} + +void +STLMeshIO ::ReadCells(void * itkNotUsed(buffer)) +{ + // Read input file + std::ifstream inputFile; + + if (this->GetFileType() == ASCII) + { + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); + } + else if (GetFileType() == BINARY) + { + this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); + } + + // Test whether the file has been opened + if (!this->m_InputStream.is_open()) + { + itkExceptionMacro(<< "Unable to open file\n" + "inputFilename= " + << this->m_FileName); + return; + } + + this->m_InputStream.close(); +} + + +void +STLMeshIO ::WriteMeshInformation() +{ + + // Use default filetype + if (this->GetFileType() == ASCII) + { + this->m_OutputStream.open(this->m_FileName.c_str(), std::ios::out); + } + else if (this->GetFileType() == BINARY) + { + this->m_OutputStream.open(this->m_FileName.c_str(), std::ios::out | std::ios::binary); + } + + if (!this->m_OutputStream.is_open()) + { + itkExceptionMacro("Unable to open file\n" + "inputFilename= " + << this->m_FileName); + return; + } + + if (this->GetFileType() == ASCII) + { + this->m_OutputStream << "solid ascii" << std::endl; + } +} + + +void +STLMeshIO ::Write() +{} + +void +STLMeshIO ::WriteCells(void * buffer) +{ + + IdentifierType numberOfPolygons = this->GetNumberOfCells(); + + IdentifierType * cellsBuffer = reinterpret_cast(buffer); + + SizeValueType index = 0; + + typedef MeshIOBase::CellGeometryType CellGeometryType; + + std::cout << "numberOfPolygons " << numberOfPolygons << std::endl; + + for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) + { + const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index++]); + const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index++]); + + const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); + + if (isTriangle) + { + std::cout << "POLYGON_CELL with " << numberOfVerticesInCell << " vertices " << std::endl; + this->m_OutputStream << " facet normal" << std::endl; + this->m_OutputStream << " outer loop" << std::endl; + for (unsigned int jj = 0; jj < numberOfVerticesInCell; jj++) + { + this->m_OutputStream << " vertex " << cellsBuffer[index++] << std::endl; + } + this->m_OutputStream << " endloop" << std::endl; + this->m_OutputStream << " endfacet" << std::endl; + } + else + { + index += numberOfVerticesInCell; + } + } + + if (this->GetFileType() == ASCII) + { + this->m_OutputStream << "endsolid" << std::endl; + } +} + + +void +STLMeshIO ::PrintSelf(std::ostream & os, Indent indent) const +{ + Superclass::PrintSelf(os, indent); +} + +} // end of namespace itk diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx new file mode 100644 index 00000000000..fcc8c647d99 --- /dev/null +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -0,0 +1,47 @@ +/*========================================================================= + * + * 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 "itkSTLMeshIO.h" +#include "itkSTLMeshIOFactory.h" +#include "itkVersion.h" + +namespace itk +{ +void +STLMeshIOFactory ::PrintSelf(std::ostream &, Indent) const +{} + +STLMeshIOFactory ::STLMeshIOFactory() +{ + this->RegisterOverride("itkMeshIOBase", "itkSTLMeshIO", "STL IO", 1, CreateObjectFunction::New()); +} + +STLMeshIOFactory ::~STLMeshIOFactory() {} + +const char * +STLMeshIOFactory ::GetITKSourceVersion(void) const +{ + return ITK_SOURCE_VERSION; +} + +const char * +STLMeshIOFactory ::GetDescription() const +{ + return "STL MeshIO Factory, allows the loading of STL QuadEdgeMesh data into ITK"; +} +} // end namespace itk diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 new file mode 100644 index 00000000000..38a77c65d0e --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 @@ -0,0 +1,56 @@ +# vtk DataFile Version 2.0 +File written by itkVTKPolyDataWriter +ASCII +DATASET POLYDATA +POINTS 18 float +1 0 0 +-1 0 0 +0 1 0 +0 -1 0 +0 0 1 +0 0 -1 +0 0.707107 0.707107 +0.707107 0 0.707107 +0.707107 0.707107 0 +-0.707107 0.707107 0 +-0.707107 0 0.707107 +-0.707107 -0.707107 0 +0 -0.707107 0.707107 +0.707107 -0.707107 0 +0 0.707107 -0.707107 +0.707107 0 -0.707107 +-0.707107 0 -0.707107 +0 -0.707107 -0.707107 +POLYGONS 32 128 +3 2 6 8 +3 6 4 7 +3 7 0 8 +3 6 7 8 +3 2 9 6 +3 9 1 10 +3 10 4 6 +3 9 10 6 +3 1 11 10 +3 11 3 12 +3 12 4 10 +3 11 12 10 +3 4 12 7 +3 12 3 13 +3 13 0 7 +3 12 13 7 +3 5 14 15 +3 14 2 8 +3 8 0 15 +3 14 8 15 +3 2 14 9 +3 14 5 16 +3 16 1 9 +3 14 16 9 +3 5 17 16 +3 17 3 11 +3 11 1 16 +3 17 11 16 +3 5 15 17 +3 15 0 13 +3 13 3 17 +3 15 13 17 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb new file mode 100644 index 00000000000..7af8c1d6e28 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb @@ -0,0 +1,226 @@ +solid ascii + facet normal 0.357406 0.862856 0.357406 + outer loop + vertex 0 1 0 + vertex 0 0.707107 0.707107 + vertex 0.707107 0.707107 0 + endloop + endfacet + facet normal 0.357406 0.357406 0.862856 + outer loop + vertex 0 0.707107 0.707107 + vertex 0 0 1 + vertex 0.707107 0 0.707107 + endloop + endfacet + facet normal 0.862856 0.357406 0.357406 + outer loop + vertex 0.707107 0 0.707107 + vertex 1 0 0 + vertex 0.707107 0.707107 0 + endloop + endfacet + facet normal 0.57735 0.57735 0.57735 + outer loop + vertex 0 0.707107 0.707107 + vertex 0.707107 0 0.707107 + vertex 0.707107 0.707107 0 + endloop + endfacet + facet normal -0.357406 0.862856 0.357406 + outer loop + vertex 0 1 0 + vertex -0.707107 0.707107 0 + vertex 0 0.707107 0.707107 + endloop + endfacet + facet normal -0.862856 0.357406 0.357406 + outer loop + vertex -0.707107 0.707107 0 + vertex -1 0 0 + vertex -0.707107 0 0.707107 + endloop + endfacet + facet normal -0.357406 0.357406 0.862856 + outer loop + vertex -0.707107 0 0.707107 + vertex 0 0 1 + vertex 0 0.707107 0.707107 + endloop + endfacet + facet normal -0.57735 0.57735 0.57735 + outer loop + vertex -0.707107 0.707107 0 + vertex -0.707107 0 0.707107 + vertex 0 0.707107 0.707107 + endloop + endfacet + facet normal -0.862856 -0.357406 0.357406 + outer loop + vertex -1 0 0 + vertex -0.707107 -0.707107 0 + vertex -0.707107 0 0.707107 + endloop + endfacet + facet normal -0.357406 -0.862856 0.357406 + outer loop + vertex -0.707107 -0.707107 0 + vertex 0 -1 0 + vertex 0 -0.707107 0.707107 + endloop + endfacet + facet normal -0.357406 -0.357406 0.862856 + outer loop + vertex 0 -0.707107 0.707107 + vertex 0 0 1 + vertex -0.707107 0 0.707107 + endloop + endfacet + facet normal -0.57735 -0.57735 0.57735 + outer loop + vertex -0.707107 -0.707107 0 + vertex 0 -0.707107 0.707107 + vertex -0.707107 0 0.707107 + endloop + endfacet + facet normal 0.357406 -0.357406 0.862856 + outer loop + vertex 0 0 1 + vertex 0 -0.707107 0.707107 + vertex 0.707107 0 0.707107 + endloop + endfacet + facet normal 0.357406 -0.862856 0.357406 + outer loop + vertex 0 -0.707107 0.707107 + vertex 0 -1 0 + vertex 0.707107 -0.707107 0 + endloop + endfacet + facet normal 0.862856 -0.357406 0.357406 + outer loop + vertex 0.707107 -0.707107 0 + vertex 1 0 0 + vertex 0.707107 0 0.707107 + endloop + endfacet + facet normal 0.57735 -0.57735 0.57735 + outer loop + vertex 0 -0.707107 0.707107 + vertex 0.707107 -0.707107 0 + vertex 0.707107 0 0.707107 + endloop + endfacet + facet normal 0.357406 0.357406 -0.862856 + outer loop + vertex 0 0 -1 + vertex 0 0.707107 -0.707107 + vertex 0.707107 0 -0.707107 + endloop + endfacet + facet normal 0.357406 0.862856 -0.357406 + outer loop + vertex 0 0.707107 -0.707107 + vertex 0 1 0 + vertex 0.707107 0.707107 0 + endloop + endfacet + facet normal 0.862856 0.357406 -0.357406 + outer loop + vertex 0.707107 0.707107 0 + vertex 1 0 0 + vertex 0.707107 0 -0.707107 + endloop + endfacet + facet normal 0.57735 0.57735 -0.57735 + outer loop + vertex 0 0.707107 -0.707107 + vertex 0.707107 0.707107 0 + vertex 0.707107 0 -0.707107 + endloop + endfacet + facet normal -0.357406 0.862856 -0.357406 + outer loop + vertex 0 1 0 + vertex 0 0.707107 -0.707107 + vertex -0.707107 0.707107 0 + endloop + endfacet + facet normal -0.357406 0.357406 -0.862856 + outer loop + vertex 0 0.707107 -0.707107 + vertex 0 0 -1 + vertex -0.707107 0 -0.707107 + endloop + endfacet + facet normal -0.862856 0.357406 -0.357406 + outer loop + vertex -0.707107 0 -0.707107 + vertex -1 0 0 + vertex -0.707107 0.707107 0 + endloop + endfacet + facet normal -0.57735 0.57735 -0.57735 + outer loop + vertex 0 0.707107 -0.707107 + vertex -0.707107 0 -0.707107 + vertex -0.707107 0.707107 0 + endloop + endfacet + facet normal -0.357406 -0.357406 -0.862856 + outer loop + vertex 0 0 -1 + vertex 0 -0.707107 -0.707107 + vertex -0.707107 0 -0.707107 + endloop + endfacet + facet normal -0.357406 -0.862856 -0.357406 + outer loop + vertex 0 -0.707107 -0.707107 + vertex 0 -1 0 + vertex -0.707107 -0.707107 0 + endloop + endfacet + facet normal -0.862856 -0.357406 -0.357406 + outer loop + vertex -0.707107 -0.707107 0 + vertex -1 0 0 + vertex -0.707107 0 -0.707107 + endloop + endfacet + facet normal -0.57735 -0.57735 -0.57735 + outer loop + vertex 0 -0.707107 -0.707107 + vertex -0.707107 -0.707107 0 + vertex -0.707107 0 -0.707107 + endloop + endfacet + facet normal 0.357406 -0.357406 -0.862856 + outer loop + vertex 0 0 -1 + vertex 0.707107 0 -0.707107 + vertex 0 -0.707107 -0.707107 + endloop + endfacet + facet normal 0.862856 -0.357406 -0.357406 + outer loop + vertex 0.707107 0 -0.707107 + vertex 1 0 0 + vertex 0.707107 -0.707107 0 + endloop + endfacet + facet normal 0.357406 -0.862856 -0.357406 + outer loop + vertex 0.707107 -0.707107 0 + vertex 0 -1 0 + vertex 0 -0.707107 -0.707107 + endloop + endfacet + facet normal 0.57735 -0.57735 -0.57735 + outer loop + vertex 0.707107 0 -0.707107 + vertex 0.707107 -0.707107 0 + vertex 0 -0.707107 -0.707107 + endloop + endfacet +endsolid diff --git a/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 b/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 new file mode 100644 index 00000000000..3e9f76652ae --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 @@ -0,0 +1 @@ +545c2293b16e250f25395dabbaa53cbb diff --git a/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 b/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 new file mode 100644 index 00000000000..44f4f16d7bd --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 @@ -0,0 +1 @@ +2327dbe1884cbf2b58071501567400f6 diff --git a/Modules/IO/IOMeshSTL/test/CMakeLists.txt b/Modules/IO/IOMeshSTL/test/CMakeLists.txt new file mode 100644 index 00000000000..a05deb71c1a --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/CMakeLists.txt @@ -0,0 +1,14 @@ +itk_module_test() + +set(ITKIOSTLMeshTests itkSTLMeshIOTest.cxx) + +createtestdriver(ITKIOSTLMesh "${ITKIOSTLMesh-Test_LIBRARIES}" "${ITKIOSTLMeshTests}") + +itk_add_test( + NAME itkSTLMeshIOTest00 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/sphere.vtk} + ${ITK_TEST_OUTPUT_DIR}/sphere00.stl +) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx new file mode 100644 index 00000000000..1618f95e0c8 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -0,0 +1,64 @@ +/*========================================================================= + * + * 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 "itkQuadEdgeMesh.h" +#include "itkSTLMeshIOFactory.h" +#include "itkMeshFileReader.h" +#include "itkMeshFileWriter.h" + +int +itkSTLMeshIOTest(int argc, char * argv[]) +{ + if (argc < 3) + { + std::cerr << "Invalid commands, You need input and output mesh file name " << std::endl; + return EXIT_FAILURE; + } + + const unsigned int Dimension = 3; + typedef float PixelType; + + typedef itk::QuadEdgeMesh QEMeshType; + + itk::STLMeshIOFactory::RegisterOneFactory(); + + typedef itk::MeshFileReader ReaderType; + typedef itk::MeshFileWriter WriterType; + + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + reader->SetFileName(argv[1]); + writer->SetFileName(argv[2]); + + writer->SetInput(reader->GetOutput()); + + int result = EXIT_SUCCESS; + + try + { + writer->Update(); + } + catch (itk::ExceptionObject & excp) + { + std::cerr << excp << std::endl; + result = EXIT_FAILURE; + } + + return result; +} From 6ba7e6d9e6dac17c7a806bdfa906d5d71fa42281 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Mon, 30 Dec 2013 12:24:15 -0500 Subject: [PATCH 02/73] DOC: Added the Apache 2.0 License file. --- Modules/IO/IOMeshSTL/LICENSE | 202 +++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 Modules/IO/IOMeshSTL/LICENSE diff --git a/Modules/IO/IOMeshSTL/LICENSE b/Modules/IO/IOMeshSTL/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/Modules/IO/IOMeshSTL/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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 + + 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. From 3f1e6dfa312cc3c06a7ecfd03c380a3a978e705b Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Mon, 30 Dec 2013 13:47:38 -0500 Subject: [PATCH 03/73] ENH: First working version. Added internal copy of points in WritePoints(). Added computation of normal and print out of point coordinates in WriteCells(). Produced first successful write out of the sphere.stl file, and was able to open it with meshlab. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 15 +++++- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 55 +++++++++++++++++---- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 78f60a237a6..99477e3d589 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -99,10 +99,11 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase /** The STL format stores point coordinates repeatedly as part of every * triangle. Therefore point coordinates are writen as part of the * WriteCells() method, and not as an independent operation. - * Consequently, this method is implemented as a null operation. + * Consequently, this method only performs an internal copy of the Point + * coordinates data, than then is used in the WriteCells() method. */ virtual void - WritePoints(void * itkNotUsed(buffer)) {}; + WritePoints(void * buffer); /** The WriteCells() method does most of the work. It writes * out every triangle in the mesh. For every triangle, it @@ -146,6 +147,16 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase std::ofstream m_OutputStream; // output file std::ifstream m_InputStream; // input file + + typedef float PointValueType; // type to represent point coordinates + + typedef Point PointType; + typedef Vector VectorType; + typedef CovariantVector NormalType; + + typedef std::vector PointContainerType; + + PointContainerType m_Points; }; } // end namespace itk diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 03a79cf7872..7c404652d39 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -215,19 +215,45 @@ void STLMeshIO ::Write() {} +void +STLMeshIO ::WritePoints(void * buffer) +{ + const IdentifierType numberOfPoints = this->GetNumberOfPoints(); + + // Revisit this choice. Although.. STL will only manage 3D. + // This probably should throw and exception if the input Mesh is not in 3D space. + const unsigned int PointDimension = 3; + + typedef float PointValueType; // FIXME Revisit this choice. It should be read from the MetaData. + + const PointValueType * pointCoordinates = reinterpret_cast(buffer); + + this->m_Points.clear(); + + this->m_Points.resize(numberOfPoints); + + for (IdentifierType pi = 0; pi < numberOfPoints; ++pi) + { + for (unsigned int i = 0; i < PointDimension; ++i) + { + m_Points[pi][i] = *pointCoordinates++; + } + } +} + void STLMeshIO ::WriteCells(void * buffer) { - IdentifierType numberOfPolygons = this->GetNumberOfCells(); + const IdentifierType numberOfPolygons = this->GetNumberOfCells(); - IdentifierType * cellsBuffer = reinterpret_cast(buffer); + const IdentifierType * cellsBuffer = reinterpret_cast(buffer); SizeValueType index = 0; typedef MeshIOBase::CellGeometryType CellGeometryType; - std::cout << "numberOfPolygons " << numberOfPolygons << std::endl; + NormalType normal; for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { @@ -238,13 +264,24 @@ STLMeshIO ::WriteCells(void * buffer) if (isTriangle) { - std::cout << "POLYGON_CELL with " << numberOfVerticesInCell << " vertices " << std::endl; - this->m_OutputStream << " facet normal" << std::endl; + const PointType & p0 = m_Points[cellsBuffer[index++]]; + const PointType & p1 = m_Points[cellsBuffer[index++]]; + const PointType & p2 = m_Points[cellsBuffer[index++]]; + + const VectorType v10(p0 - p1); + const VectorType v12(p2 - p1); + + CrossProduct(normal, v10, v12); + + this->m_OutputStream << " facet normal "; + this->m_OutputStream << normal[0] << " " << normal[1] << " " << normal[2] << std::endl; + this->m_OutputStream << " outer loop" << std::endl; - for (unsigned int jj = 0; jj < numberOfVerticesInCell; jj++) - { - this->m_OutputStream << " vertex " << cellsBuffer[index++] << std::endl; - } + + this->m_OutputStream << " vertex " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; + this->m_OutputStream << " vertex " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; + this->m_OutputStream << " vertex " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; + this->m_OutputStream << " endloop" << std::endl; this->m_OutputStream << " endfacet" << std::endl; } From de9dea291d012c7dc86a6fed386d7ef6c1f10a68 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 11:04:26 -0500 Subject: [PATCH 04/73] ENH: WritePoints now templated on coordinate type. Introduced a templated function to manage the multiple cases of point coordinate types. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 32 +++++++++ Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 78 +++++++++++++++------ 2 files changed, 90 insertions(+), 20 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 99477e3d589..69e34abcf23 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -140,6 +140,38 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase void PrintSelf(std::ostream & os, Indent indent) const; + /** Templated version of write points method, that is aware of the specific + * type used to represent the point coordinates. */ + template + void + WritePointsTyped(const PointValueType * buffer) + { + + const unsigned int pointDimension = this->GetPointDimension(); + + if (pointDimension != 3) + { + itkExceptionMacro("STL only supports 3D points"); + } + + const PointValueType * pointCoordinates = buffer; + + this->m_Points.clear(); + + const IdentifierType numberOfPoints = this->GetNumberOfPoints(); + + this->m_Points.resize(numberOfPoints); + + for (IdentifierType pi = 0; pi < numberOfPoints; ++pi) + { + for (unsigned int i = 0; i < pointDimension; ++i) + { + m_Points[pi][i] = *pointCoordinates++; + } + } + } + + private: STLMeshIO(const Self &); // purposely not implemented void diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 7c404652d39..b2a290aa45c 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -25,7 +25,11 @@ namespace itk { // Constructor -STLMeshIO ::STLMeshIO() { this->AddSupportedWriteExtension(".stl"); } +STLMeshIO ::STLMeshIO() +{ + this->AddSupportedWriteExtension(".stl"); + this->AddSupportedWriteExtension(".STL"); +} bool STLMeshIO ::CanReadFile(const char * fileName) @@ -35,7 +39,9 @@ STLMeshIO ::CanReadFile(const char * fileName) return false; } - if (itksys::SystemTools::GetFilenameLastExtension(fileName) != ".stl") + const std::string extension = itksys::SystemTools::GetFilenameLastExtension(fileName); + + if (extension != ".stl" && extension != ".STL") { return false; } @@ -213,34 +219,66 @@ STLMeshIO ::WriteMeshInformation() void STLMeshIO ::Write() -{} +{ + // All has been done in the WriteCells() method. + + // Here we only need to close the output stream. + m_OutputStream.close(); +} void STLMeshIO ::WritePoints(void * buffer) { - const IdentifierType numberOfPoints = this->GetNumberOfPoints(); - // Revisit this choice. Although.. STL will only manage 3D. - // This probably should throw and exception if the input Mesh is not in 3D space. - const unsigned int PointDimension = 3; + const IOComponentType pointValueType = this->GetPointComponentType(); - typedef float PointValueType; // FIXME Revisit this choice. It should be read from the MetaData. - - const PointValueType * pointCoordinates = reinterpret_cast(buffer); - - this->m_Points.clear(); - - this->m_Points.resize(numberOfPoints); - - for (IdentifierType pi = 0; pi < numberOfPoints; ++pi) + switch (pointValueType) { - for (unsigned int i = 0; i < PointDimension; ++i) - { - m_Points[pi][i] = *pointCoordinates++; - } + case UCHAR: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case CHAR: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case USHORT: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case SHORT: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case UINT: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case INT: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case ULONG: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case LONG: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case ULONGLONG: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case LONGLONG: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case FLOAT: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case DOUBLE: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + case LDOUBLE: + this->WritePointsTyped(reinterpret_cast(buffer)); + break; + default: + itkExceptionMacro(<< "Unknonwn point component type"); } } + void STLMeshIO ::WriteCells(void * buffer) { From 1541c87f6ca390d77820dcbd02d875ddbaa45696 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 11:06:28 -0500 Subject: [PATCH 05/73] BUG: Fixed direction of normals. Still assuming that points are provided in a right handed order. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index b2a290aa45c..1b557875640 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -309,7 +309,7 @@ STLMeshIO ::WriteCells(void * buffer) const VectorType v10(p0 - p1); const VectorType v12(p2 - p1); - CrossProduct(normal, v10, v12); + CrossProduct(normal, v12, v10); this->m_OutputStream << " facet normal "; this->m_OutputStream << normal[0] << " " << normal[1] << " " << normal[2] << std::endl; From 16fee790e9c0d4bc19f924340ca7b4f26afb09d0 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 11:14:07 -0500 Subject: [PATCH 06/73] ENH: Now supporting .STL extension too. The .STL (in capitals) extension is now supported too in the filename. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 1b557875640..1e241c7c13c 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -52,7 +52,9 @@ STLMeshIO ::CanReadFile(const char * fileName) bool STLMeshIO ::CanWriteFile(const char * fileName) { - if (itksys::SystemTools::GetFilenameLastExtension(fileName) != ".stl") + const std::string extension = itksys::SystemTools::GetFilenameLastExtension(fileName); + + if (extension != ".stl" && extension != ".STL") { return false; } From a36cca87e2f7047ea248069d5bac259f744f0e44 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 14:00:25 -0500 Subject: [PATCH 07/73] ENH: Added support for BINARY writing. And corresponding test. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 10 ++ Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 121 ++++++++++++++++-- Modules/IO/IOMeshSTL/test/CMakeLists.txt | 11 ++ .../IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 17 ++- 4 files changed, 146 insertions(+), 13 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 69e34abcf23..999688c53ad 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -188,6 +188,16 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase typedef std::vector PointContainerType; + /** Helper functions to write elements to binary file */ + void + WriteInt32AsBinary(int32_t value); + void + WriteInt16AsBinary(int16_t value); + void + WriteNormalAsBinary(const NormalType & normal); + void + WritePointAsBinary(const PointType & point); + PointContainerType m_Points; }; } // end namespace itk diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 1e241c7c13c..59762013843 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -21,6 +21,7 @@ #include #include +#include namespace itk { @@ -75,7 +76,7 @@ STLMeshIO ::ReadMeshInformation() { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); } - else if (GetFileType() == BINARY) + else if (this->GetFileType() == BINARY) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); } @@ -145,7 +146,7 @@ STLMeshIO ::ReadPoints(void * itkNotUsed(buffer)) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); } - else if (GetFileType() == BINARY) + else if (this->GetFileType() == BINARY) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); } @@ -172,7 +173,7 @@ STLMeshIO ::ReadCells(void * itkNotUsed(buffer)) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); } - else if (GetFileType() == BINARY) + else if (this->GetFileType() == BINARY) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); } @@ -216,6 +217,15 @@ STLMeshIO ::WriteMeshInformation() { this->m_OutputStream << "solid ascii" << std::endl; } + else if (this->GetFileType() == BINARY) + { + // + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + // UINT8[80] header + // + this->m_OutputStream << std::setfill(' ') << std::setw(80) << "binary STL generated from ITK"; + } } @@ -295,6 +305,35 @@ STLMeshIO ::WriteCells(void * buffer) NormalType normal; + if (this->GetFileType() == BINARY) + { + // + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + // UINT32 -- Number of Triangles + // + int32_t numberOfTriangles = 0; + + SizeValueType index2 = 0; + + for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) + { + const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index2++]); + const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index2++]); + + const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); + + if (isTriangle) + { + numberOfTriangles++; + } + + index2 += numberOfVerticesInCell; + } + + this->WriteInt32AsBinary(numberOfTriangles); + } + for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index++]); @@ -313,17 +352,38 @@ STLMeshIO ::WriteCells(void * buffer) CrossProduct(normal, v12, v10); - this->m_OutputStream << " facet normal "; - this->m_OutputStream << normal[0] << " " << normal[1] << " " << normal[2] << std::endl; + if (this->GetFileType() == ASCII) + { + this->m_OutputStream << " facet normal "; + this->m_OutputStream << normal[0] << " " << normal[1] << " " << normal[2] << std::endl; - this->m_OutputStream << " outer loop" << std::endl; + this->m_OutputStream << " outer loop" << std::endl; - this->m_OutputStream << " vertex " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; - this->m_OutputStream << " vertex " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; - this->m_OutputStream << " vertex " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; + this->m_OutputStream << " vertex " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; + this->m_OutputStream << " vertex " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; + this->m_OutputStream << " vertex " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; - this->m_OutputStream << " endloop" << std::endl; - this->m_OutputStream << " endfacet" << std::endl; + this->m_OutputStream << " endloop" << std::endl; + this->m_OutputStream << " endfacet" << std::endl; + } + else if (this->GetFileType() == BINARY) + { + // + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + // foreach triangle + // REAL32[3] – Normal vector + // REAL32[3] – Vertex 1 + // REAL32[3] – Vertex 2 + // REAL32[3] – Vertex 3 + // UINT16 – Attribute byte count + // + this->WriteNormalAsBinary(normal); + this->WritePointAsBinary(p0); + this->WritePointAsBinary(p1); + this->WritePointAsBinary(p2); + this->WriteInt16AsBinary(0); + } } else { @@ -335,6 +395,45 @@ STLMeshIO ::WriteCells(void * buffer) { this->m_OutputStream << "endsolid" << std::endl; } + // + // There is no ending section when doing BINARY + // +} + + +void +STLMeshIO ::WriteInt32AsBinary(int32_t value) +{ + this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); +} + + +void +STLMeshIO ::WriteInt16AsBinary(int16_t value) +{ + this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); +} + + +void +STLMeshIO ::WriteNormalAsBinary(const NormalType & normal) +{ + for (unsigned int i = 0; i < 3; ++i) + { + const float value = normal[i]; + this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); + } +} + + +void +STLMeshIO ::WritePointAsBinary(const PointType & point) +{ + for (unsigned int i = 0; i < 3; ++i) + { + const float value = point[i]; + this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); + } } diff --git a/Modules/IO/IOMeshSTL/test/CMakeLists.txt b/Modules/IO/IOMeshSTL/test/CMakeLists.txt index a05deb71c1a..3255ce93f9c 100644 --- a/Modules/IO/IOMeshSTL/test/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/test/CMakeLists.txt @@ -11,4 +11,15 @@ itk_add_test( itkSTLMeshIOTest DATA{Baseline/sphere.vtk} ${ITK_TEST_OUTPUT_DIR}/sphere00.stl + 0 # write in ASCII +) + +itk_add_test( + NAME itkSTLMeshIOTest01 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/sphere.vtk} + ${ITK_TEST_OUTPUT_DIR}/sphere01.stl + 1 # write in BINARY ) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 1618f95e0c8..366bd9a75ae 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -24,9 +24,11 @@ int itkSTLMeshIOTest(int argc, char * argv[]) { - if (argc < 3) + if (argc < 4) { - std::cerr << "Invalid commands, You need input and output mesh file name " << std::endl; + std::cerr << "Missing Arguments." << std::endl; + std::cerr << "Usage: " << std::endl; + std::cerr << "inputMesh outputMesh (0:ASCII/1:BINARY) " << std::endl; return EXIT_FAILURE; } @@ -46,6 +48,17 @@ itkSTLMeshIOTest(int argc, char * argv[]) reader->SetFileName(argv[1]); writer->SetFileName(argv[2]); + int fileMode = atoi(argv[3]); + + if (fileMode == 0) + { + writer->SetFileTypeAsASCII(); + } + else if (fileMode == 1) + { + writer->SetFileTypeAsBINARY(); + } + writer->SetInput(reader->GetOutput()); int result = EXIT_SUCCESS; From 083f42d7b0f6e9bb14f73d908141bf80b46ee0d9 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 18:41:37 -0500 Subject: [PATCH 08/73] ENH: Improved code coverage. --- Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 366bd9a75ae..83b0d8a5d7a 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -18,6 +18,7 @@ #include "itkQuadEdgeMesh.h" #include "itkSTLMeshIOFactory.h" +#include "itkSTLMeshIO.h" #include "itkMeshFileReader.h" #include "itkMeshFileWriter.h" @@ -73,5 +74,12 @@ itkSTLMeshIOTest(int argc, char * argv[]) result = EXIT_FAILURE; } + // + // Exercising additional methods + // + itk::STLMeshIO::Pointer meshIO = itk::STLMeshIO::New(); + + meshIO->Print(std::cout); + return result; } From 3d51c322a7089d788a6f43925dc626821c7ce4e6 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 21:37:05 -0500 Subject: [PATCH 09/73] ENH: Started to do parsing on Read. Parsed input file both in ASCII and BINARY, stored points into an std::set. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 59 ++++++ Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 212 +++++++++++++++++++- Modules/IO/IOMeshSTL/test/CMakeLists.txt | 20 ++ 3 files changed, 290 insertions(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 999688c53ad..4810c0d2a78 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -21,6 +21,7 @@ #include "itkMeshIOBase.h" #include +#include namespace itk { @@ -180,6 +181,8 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase std::ofstream m_OutputStream; // output file std::ifstream m_InputStream; // input file + std::string m_InputLine; // helper during reading + typedef float PointValueType; // type to represent point coordinates typedef Point PointType; @@ -198,7 +201,63 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase void WritePointAsBinary(const PointType & point); + /** Helper functions to read elements from ASCII and BINARY files. */ + void + ReadMeshInternalFromAscii(); + void + ReadMeshInternalFromBinary(); + + /** Helper functions to read elements from binary file */ + void + ReadInt32AsBinary(int32_t & value); + void + ReadInt16AsBinary(int16_t & value); + void + ReadNormalAsBinary(NormalType & normal); + void + ReadPointAsBinary(PointType & point); + + /** Helper functions to read elements from ASCII files. */ + void + ReadStringFromAscii(const std::string & keyword); + void + ReadPointAsAscii(PointType & point); + bool + CheckStringFromAscii(const std::string & expected); + + /** Functions to create set of points and disambiguate them. */ + void + InsertPointIntoSet(const PointType & point); + PointContainerType m_Points; + + unsigned int m_InputLineNumber; + + static double + PointHash(const PointType & point) + { + double hash = 0; + double factor = 1e10; + hash = static_cast(point[0]); + hash *= factor; + hash += static_cast(point[1]); + hash *= factor; + hash += static_cast(point[2]); + return hash; + } + + struct PointCompare + { + bool + operator()(const PointType & p1, const PointType & p2) const + { + return PointHash(p1) < PointHash(p2); + } + }; + + typedef std::set PointSetType; + + PointSetType m_PointsSet; }; } // end namespace itk diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 59762013843..d5b55f4ecb9 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -113,8 +113,10 @@ STLMeshIO ::ReadMeshInformation() } #endif } + + this->ReadMeshInternalFromAscii(); } - else if (inputLine.find("BINARY") != std::string::npos) + else { if (this->GetFileType() != BINARY) { @@ -131,12 +133,131 @@ STLMeshIO ::ReadMeshInformation() } #endif } + + this->ReadMeshInternalFromBinary(); } this->m_InputStream.close(); } + +void +STLMeshIO ::ReadMeshInternalFromAscii() +{ + // Read all the points, and reduce them to unique ones + std::string inputLine; + PointType p0; + PointType p1; + PointType p2; + + this->m_InputLineNumber = 2; + + while (!this->CheckStringFromAscii("endsolid")) + { + // + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + // facet normal ni nj nk + // outer loop + // vertex v1x v1y v1z + // vertex v2x v2y v2z + // vertex v3x v3y v3z + // endloop + // endfacet + // + this->ReadStringFromAscii("facet normal"); + this->ReadStringFromAscii("outer loop"); + this->ReadPointAsAscii(p0); + this->ReadPointAsAscii(p1); + this->ReadPointAsAscii(p2); + this->ReadStringFromAscii("endloop"); + this->ReadStringFromAscii("endfacet"); + } +} + + +void +STLMeshIO ::ReadStringFromAscii(const std::string & expected) +{ + if (this->m_InputLine.empty()) + { + std::getline(this->m_InputStream, this->m_InputLine, '\n'); + } + + if (this->m_InputLine.find(expected) == std::string::npos) + { + itkExceptionMacro("Parsing error: missed " << expected << " in line " << this->m_InputLineNumber + << " found: " << this->m_InputLine); + } + + this->m_InputLine.clear(); + + this->m_InputLineNumber++; +} + + +bool +STLMeshIO ::CheckStringFromAscii(const std::string & expected) +{ + std::getline(this->m_InputStream, this->m_InputLine, '\n'); + + if (this->m_InputLine.find(expected) != std::string::npos) + { + this->m_InputLineNumber++; + return true; + } + + return false; +} + + +void +STLMeshIO ::ReadMeshInternalFromBinary() +{ + // + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + // UINT8[80] header + // + char header[80]; + this->m_InputStream.read(header, 80); + + // + // UINT32 -- Number of Triangles + // + int32_t numberOfTriangles; + this->m_InputStream.read(reinterpret_cast(&numberOfTriangles), sizeof(numberOfTriangles)); + + this->SetNumberOfCells(numberOfTriangles); + + // + // foreach triangle + // + NormalType normal; + PointType p0; + PointType p1; + PointType p2; + int16_t bytecount; + + while (numberOfTriangles--) + { + // + // REAL32[3] – Normal vector + // REAL32[3] – Vertex 1 + // REAL32[3] – Vertex 2 + // REAL32[3] – Vertex 3 + // UINT16 – Attribute byte count + // + this->ReadNormalAsBinary(normal); + this->ReadPointAsBinary(p0); + this->ReadPointAsBinary(p1); + this->ReadPointAsBinary(p2); + this->ReadInt16AsBinary(bytecount); + } +} + + void STLMeshIO ::ReadPoints(void * itkNotUsed(buffer)) { @@ -437,6 +558,95 @@ STLMeshIO ::WritePointAsBinary(const PointType & point) } +void +STLMeshIO ::ReadNormalAsBinary(NormalType & normal) +{ + float value; + for (unsigned int i = 0; i < 3; ++i) + { + this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + normal[i] = value; + } +} + + +void +STLMeshIO ::ReadInt32AsBinary(int32_t & value) +{ + this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); +} + + +void +STLMeshIO ::ReadInt16AsBinary(int16_t & value) +{ + this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); +} + + +void +STLMeshIO ::ReadPointAsBinary(PointType & point) +{ + float value; + for (unsigned int i = 0; i < 3; ++i) + { + this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + point[i] = value; + } +} + + +void +STLMeshIO ::ReadPointAsAscii(PointType & point) +{ + std::string keywword; + this->m_InputStream >> keywword; + + if (keywword.find("vertex") == std::string::npos) + { + itkExceptionMacro("Parsing error: missed 'vertex' in line " << this->m_InputLineNumber); + } + + this->m_InputStream >> point; + + this->InsertPointIntoSet(point); + + // read remaining of the line, most often just the end of line. + std::string restOfLine; + std::getline(this->m_InputStream, restOfLine, '\n'); + + this->m_InputLineNumber++; +} + + +void +STLMeshIO ::InsertPointIntoSet(const PointType & point) +{ + // + // combines the FLOAT32 bits components of points into a hash + // + const unsigned int size = sizeof(float); + + char pointHash[3 * size]; + + float valueX = point[0]; + float valueY = point[1]; + float valueZ = point[2]; + + char * destination = pointHash; + + strncpy(destination, reinterpret_cast(&valueX), size); + destination += size; + + strncpy(destination, reinterpret_cast(&valueY), size); + destination += size; + + strncpy(destination, reinterpret_cast(&valueZ), size); + + this->m_PointsSet.insert(point); +} + + void STLMeshIO ::PrintSelf(std::ostream & os, Indent indent) const { diff --git a/Modules/IO/IOMeshSTL/test/CMakeLists.txt b/Modules/IO/IOMeshSTL/test/CMakeLists.txt index 3255ce93f9c..5af678e7718 100644 --- a/Modules/IO/IOMeshSTL/test/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/test/CMakeLists.txt @@ -23,3 +23,23 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/sphere01.stl 1 # write in BINARY ) + +itk_add_test( + NAME itkSTLMeshIOTest02 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/sphere.stl} + ${ITK_TEST_OUTPUT_DIR}/sphere02.stl + 0 # write in ASCII +) + +itk_add_test( + NAME itkSTLMeshIOTest03 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/sphere.stl} + ${ITK_TEST_OUTPUT_DIR}/sphere03.stl + 1 # write in BINARY +) From 3931da9bbf3e72ea6ee4c6962f34886a317bdf64 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Tue, 31 Dec 2013 22:18:36 -0500 Subject: [PATCH 10/73] ENH: Added structure for list of Cells and point Ids. Added an std::vector to hold, for each cell, the triplet of point Ids corresponding to the vertices of that particular triangle. Related the pointIds to positions in the std::set that de-duplicates points. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 17 +++++++++++++- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 25 +++++++++++++++++---- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 4810c0d2a78..bd19924876a 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -256,8 +256,23 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase }; typedef std::set PointSetType; + typedef PointSetType::iterator PointSetIterator; + typedef std::pair PointSetResultType; + typedef std::vector PointsVectorType; - PointSetType m_PointsSet; + PointSetType m_PointsSet; + PointsVectorType m_PointsVector; + + // Helper variable to put Ids in points as they are read + IdentifierType m_LatestPointId; + + // Triplet to hold the Ids of points in a triagle as they are being read + typedef IdentifierType TripletType[3]; + TripletType m_TrianglePointIds; + unsigned int m_PointInTriangleCounter; + + typedef std::vector CellsVectorType; + CellsVectorType m_CellsVector; }; } // end namespace itk diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index d5b55f4ecb9..8eb7fa504e3 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -166,6 +166,8 @@ STLMeshIO ::ReadMeshInternalFromAscii() // endloop // endfacet // + this->m_PointInTriangleCounter = 0; + this->ReadStringFromAscii("facet normal"); this->ReadStringFromAscii("outer loop"); this->ReadPointAsAscii(p0); @@ -173,6 +175,8 @@ STLMeshIO ::ReadMeshInternalFromAscii() this->ReadPointAsAscii(p2); this->ReadStringFromAscii("endloop"); this->ReadStringFromAscii("endfacet"); + + // this->m_CellsVector.push_back( this->m_TrianglePointIds ); } } @@ -249,11 +253,15 @@ STLMeshIO ::ReadMeshInternalFromBinary() // REAL32[3] – Vertex 3 // UINT16 – Attribute byte count // + this->m_PointInTriangleCounter = 0; + this->ReadNormalAsBinary(normal); this->ReadPointAsBinary(p0); this->ReadPointAsBinary(p1); this->ReadPointAsBinary(p2); this->ReadInt16AsBinary(bytecount); + + // this->m_CellsVector.push_back( this->m_TrianglePointIds ); } } @@ -593,16 +601,18 @@ STLMeshIO ::ReadPointAsBinary(PointType & point) this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); point[i] = value; } + + this->InsertPointIntoSet(point); } void STLMeshIO ::ReadPointAsAscii(PointType & point) { - std::string keywword; - this->m_InputStream >> keywword; + std::string keyword; + this->m_InputStream >> keyword; - if (keywword.find("vertex") == std::string::npos) + if (keyword.find("vertex") == std::string::npos) { itkExceptionMacro("Parsing error: missed 'vertex' in line " << this->m_InputLineNumber); } @@ -643,7 +653,14 @@ STLMeshIO ::InsertPointIntoSet(const PointType & point) strncpy(destination, reinterpret_cast(&valueZ), size); - this->m_PointsSet.insert(point); + PointSetResultType result = this->m_PointsSet.insert(point); + + if (result.second) + { + this->m_PointsVector.push_back(result.first); + this->m_LatestPointId = this->m_PointsVector.size(); + this->m_TrianglePointIds[this->m_PointInTriangleCounter++] = this->m_LatestPointId; + } } From 07370d20a647b657a3d700f79f9ccf9e76ce9822 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Wed, 1 Jan 2014 11:42:16 -0500 Subject: [PATCH 11/73] ENH: Implemented ReadPoints(buffer). Now package the information about point coordinates into a buffer that is passed back to the MeshFileReader. Adjusted the helper data structures that hold the pointIds and the iterators to unique points in the a point set. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 27 ++++- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 115 +++++++++++++------- 2 files changed, 95 insertions(+), 47 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index bd19924876a..a33b8fc565f 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -65,13 +65,22 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase virtual void ReadMeshInformation(); - /** Reads the data from disk into the memory buffer provided. */ + /** Stores the point data into the memory buffer provided. */ virtual void ReadPoints(void * buffer); + /** Stores the cell data into the memory buffer provided. */ virtual void ReadCells(void * buffer); + /** Indicates whether ReadPoints() should be called. */ + virtual bool + GetUpdatePoints() const; + + /** Indicates whether ReadCells() should be called. */ + virtual bool + GetUpdateCells() const; + /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ @@ -133,7 +142,6 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase virtual void WriteCellData(void * itkNotUsed(buffer)) {}; - protected: STLMeshIO(); virtual ~STLMeshIO() {} @@ -237,7 +245,7 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase PointHash(const PointType & point) { double hash = 0; - double factor = 1e10; + double factor = 1e5; // one third of the range of the double mantissa hash = static_cast(point[0]); hash *= factor; hash += static_cast(point[1]); @@ -267,9 +275,16 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase IdentifierType m_LatestPointId; // Triplet to hold the Ids of points in a triagle as they are being read - typedef IdentifierType TripletType[3]; - TripletType m_TrianglePointIds; - unsigned int m_PointInTriangleCounter; + class TripletType + { + public: + IdentifierType p0; + IdentifierType p1; + IdentifierType p2; + }; + + TripletType m_TrianglePointIds; + unsigned int m_PointInTriangleCounter; typedef std::vector CellsVectorType; CellsVectorType m_CellsVector; diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 8eb7fa504e3..877eef97643 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -30,6 +30,13 @@ STLMeshIO ::STLMeshIO() { this->AddSupportedWriteExtension(".stl"); this->AddSupportedWriteExtension(".STL"); + + // STL uses float type by default to store point data + this->SetPointComponentType(FLOAT); + + // STL uses UINT32 to store the number of points, + // hence the point Ids are of the same UINT32 type. + this->SetCellComponentType(UINT); } bool @@ -176,8 +183,10 @@ STLMeshIO ::ReadMeshInternalFromAscii() this->ReadStringFromAscii("endloop"); this->ReadStringFromAscii("endfacet"); - // this->m_CellsVector.push_back( this->m_TrianglePointIds ); + this->m_CellsVector.push_back(this->m_TrianglePointIds); } + + this->SetNumberOfPoints(this->m_PointsVector.size()); } @@ -261,37 +270,46 @@ STLMeshIO ::ReadMeshInternalFromBinary() this->ReadPointAsBinary(p2); this->ReadInt16AsBinary(bytecount); - // this->m_CellsVector.push_back( this->m_TrianglePointIds ); + this->m_CellsVector.push_back(this->m_TrianglePointIds); } + + this->SetNumberOfPoints(this->m_PointsVector.size()); } void -STLMeshIO ::ReadPoints(void * itkNotUsed(buffer)) +STLMeshIO ::ReadPoints(void * buffer) { - // Read input file + // + // The Point and Cell data were read in the ReadMeshInformation() method. + // Here, we can focus on packaging the point data into the return buffer. + // + std::cout << "Number of Unique Points = " << this->m_PointsVector.size() << std::endl; + PointsVectorType::const_iterator pointItr = this->m_PointsVector.begin(); + PointsVectorType::const_iterator pointEnd = this->m_PointsVector.end(); - if (this->GetFileType() == ASCII) - { - this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); - } - else if (this->GetFileType() == BINARY) - { - this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); - } + float * pointCoordinates = reinterpret_cast(buffer); - // Test whether the file has been opened - if (!this->m_InputStream.is_open()) + while (pointItr != pointEnd) { - itkExceptionMacro("Unable to open file\n" - "inputFilename= " - << this->m_FileName); - return; - } + // get the iterator to the Set, pointing to a unique Point. + PointSetIterator uniquePointItr = *pointItr; - this->m_InputStream.close(); + // Get the reference to that PointType object. + const PointType & point = *uniquePointItr; + + // + // Store the Point coordintes in the buffer. + // + *pointCoordinates++ = point[0]; + *pointCoordinates++ = point[1]; + *pointCoordinates++ = point[2]; + + ++pointItr; + } } + void STLMeshIO ::ReadCells(void * itkNotUsed(buffer)) { @@ -632,38 +650,53 @@ STLMeshIO ::ReadPointAsAscii(PointType & point) void STLMeshIO ::InsertPointIntoSet(const PointType & point) { - // - // combines the FLOAT32 bits components of points into a hash - // - const unsigned int size = sizeof(float); - - char pointHash[3 * size]; - - float valueX = point[0]; - float valueY = point[1]; - float valueZ = point[2]; - - char * destination = pointHash; - - strncpy(destination, reinterpret_cast(&valueX), size); - destination += size; - - strncpy(destination, reinterpret_cast(&valueY), size); - destination += size; - - strncpy(destination, reinterpret_cast(&valueZ), size); PointSetResultType result = this->m_PointsSet.insert(point); if (result.second) { this->m_PointsVector.push_back(result.first); + this->m_LatestPointId = this->m_PointsVector.size(); - this->m_TrianglePointIds[this->m_PointInTriangleCounter++] = this->m_LatestPointId; + switch (this->m_PointInTriangleCounter) + { + case 0: + this->m_TrianglePointIds.p0 = this->m_LatestPointId; + break; + case 1: + this->m_TrianglePointIds.p1 = this->m_LatestPointId; + break; + case 2: + this->m_TrianglePointIds.p2 = this->m_LatestPointId; + break; + default: + itkExceptionMacro("Point counter went beyond value 2"); + } + this->m_PointInTriangleCounter++; } } +bool +STLMeshIO ::GetUpdatePoints() const +{ + // Always true, since we are reading the point information + // in ReadMeshInformation(), and we need ReadPoints() to be + // called in order to store the point data into the buffer. + return true; +} + + +bool +STLMeshIO ::GetUpdateCells() const +{ + // Always true, since we are reading the cell information + // in ReadMeshInformation(), and we need ReadCells() to be + // called in order to store the cell data into the buffer. + return true; +} + + void STLMeshIO ::PrintSelf(std::ostream & os, Indent indent) const { From 3abcb31b25f2deeb2ee2ff76551f2c82ab7d7eea Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Wed, 1 Jan 2014 20:08:29 -0500 Subject: [PATCH 12/73] ENH: Implemented ReadCells() method. Now recomposing the cells information in the buffer that goes back to the MeshFileReader. Still have debugging issues with reading enough cells, and confounding the input points. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 70 ++++++++++++++++------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 877eef97643..d4ff372da3a 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -144,7 +144,6 @@ STLMeshIO ::ReadMeshInformation() this->ReadMeshInternalFromBinary(); } - this->m_InputStream.close(); } @@ -187,6 +186,16 @@ STLMeshIO ::ReadMeshInternalFromAscii() } this->SetNumberOfPoints(this->m_PointsVector.size()); + + // + // The factor 5 accounts for five integers + // 1. cell type id + // 2. number of points in cell + // 3. point id of point 0 + // 4. point id of point 1 + // 5. point id of point 2 + // + this->SetCellBufferSize(5 * this->m_CellsVector.size()); } @@ -273,7 +282,19 @@ STLMeshIO ::ReadMeshInternalFromBinary() this->m_CellsVector.push_back(this->m_TrianglePointIds); } + std::cout << "Number of Unique Points = " << this->m_PointsVector.size() << std::endl; + this->SetNumberOfPoints(this->m_PointsVector.size()); + + // + // The factor 5 accounts for five integers + // 1. cell type id + // 2. number of points in cell + // 3. point id of point 0 + // 4. point id of point 1 + // 5. point id of point 2 + // + this->SetCellBufferSize(5 * this->m_CellsVector.size()); } @@ -284,7 +305,6 @@ STLMeshIO ::ReadPoints(void * buffer) // The Point and Cell data were read in the ReadMeshInformation() method. // Here, we can focus on packaging the point data into the return buffer. // - std::cout << "Number of Unique Points = " << this->m_PointsVector.size() << std::endl; PointsVectorType::const_iterator pointItr = this->m_PointsVector.begin(); PointsVectorType::const_iterator pointEnd = this->m_PointsVector.end(); @@ -311,30 +331,36 @@ STLMeshIO ::ReadPoints(void * buffer) void -STLMeshIO ::ReadCells(void * itkNotUsed(buffer)) +STLMeshIO ::ReadCells(void * buffer) { - // Read input file - std::ifstream inputFile; + // + // The Point and Cell data were read in the ReadMeshInformation() method. + // Here, we can focus on packaging the cell data into the return buffer. + // + CellsVectorType::const_iterator cellItr = this->m_CellsVector.begin(); + CellsVectorType::const_iterator cellEnd = this->m_CellsVector.end(); - if (this->GetFileType() == ASCII) - { - this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); - } - else if (this->GetFileType() == BINARY) - { - this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); - } + unsigned int * cellPointIds = reinterpret_cast(buffer); - // Test whether the file has been opened - if (!this->m_InputStream.is_open()) + const unsigned int numberOfPointsInCell = 3; + + while (cellItr != cellEnd) { - itkExceptionMacro(<< "Unable to open file\n" - "inputFilename= " - << this->m_FileName); - return; - } - this->m_InputStream.close(); + *cellPointIds++ = MeshIOBase::TRIANGLE_CELL; + *cellPointIds++ = numberOfPointsInCell; + + // + // Store the Point Ids for this cell, in the buffer. + // + *cellPointIds++ = cellItr->p0; + *cellPointIds++ = cellItr->p1; + *cellPointIds++ = cellItr->p2; + + std::cout << "points " << cellItr->p0 << " " << cellItr->p1 << " " << cellItr->p2 << std::endl; + + ++cellItr; + } } @@ -657,7 +683,7 @@ STLMeshIO ::InsertPointIntoSet(const PointType & point) { this->m_PointsVector.push_back(result.first); - this->m_LatestPointId = this->m_PointsVector.size(); + this->m_LatestPointId = this->m_PointsVector.size() - 1; switch (this->m_PointInTriangleCounter) { case 0: From d7231a2650c8504a634f90d9ad59d5959da85748 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Fri, 3 Jan 2014 22:09:45 -0500 Subject: [PATCH 13/73] BUG: Fixed STL reading. Added tetrahedron test. After adding a tetrahedron test, debugged the process of reading and consolidating incoming vertices. Fixed the reading of STL files. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 8 +-- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 68 ++++++++++--------- ...lData_MD5_4cd09d26436a53a5adedb33d822cabcd | 14 ++++ ...lData_MD5_70a19e48a4393776cfe02f852f25cbe1 | 30 ++++++++ .../test/Baseline/tetrahedron.stl.md5 | 1 + .../test/Baseline/tetrahedron.vtk.md5 | 1 + Modules/IO/IOMeshSTL/test/CMakeLists.txt | 40 +++++++++++ .../IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 6 ++ 8 files changed, 131 insertions(+), 37 deletions(-) create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index a33b8fc565f..37a69b8cf72 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -263,13 +263,9 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase } }; - typedef std::set PointSetType; - typedef PointSetType::iterator PointSetIterator; - typedef std::pair PointSetResultType; - typedef std::vector PointsVectorType; + typedef std::map PointsMapType; - PointSetType m_PointsSet; - PointsVectorType m_PointsVector; + PointsMapType m_PointsMap; // Helper variable to put Ids in points as they are read IdentifierType m_LatestPointId; diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index d4ff372da3a..9d3ff7dfd5a 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -159,6 +159,8 @@ STLMeshIO ::ReadMeshInternalFromAscii() this->m_InputLineNumber = 2; + this->m_LatestPointId = NumericTraits::Zero; + while (!this->CheckStringFromAscii("endsolid")) { // @@ -185,7 +187,7 @@ STLMeshIO ::ReadMeshInternalFromAscii() this->m_CellsVector.push_back(this->m_TrianglePointIds); } - this->SetNumberOfPoints(this->m_PointsVector.size()); + this->SetNumberOfPoints(this->m_PointsMap.size()); // // The factor 5 accounts for five integers @@ -245,6 +247,8 @@ STLMeshIO ::ReadMeshInternalFromBinary() char header[80]; this->m_InputStream.read(header, 80); + this->m_LatestPointId = NumericTraits::Zero; + // // UINT32 -- Number of Triangles // @@ -282,9 +286,7 @@ STLMeshIO ::ReadMeshInternalFromBinary() this->m_CellsVector.push_back(this->m_TrianglePointIds); } - std::cout << "Number of Unique Points = " << this->m_PointsVector.size() << std::endl; - - this->SetNumberOfPoints(this->m_PointsVector.size()); + this->SetNumberOfPoints(this->m_PointsMap.size()); // // The factor 5 accounts for five integers @@ -305,18 +307,15 @@ STLMeshIO ::ReadPoints(void * buffer) // The Point and Cell data were read in the ReadMeshInformation() method. // Here, we can focus on packaging the point data into the return buffer. // - PointsVectorType::const_iterator pointItr = this->m_PointsVector.begin(); - PointsVectorType::const_iterator pointEnd = this->m_PointsVector.end(); + PointsMapType::const_iterator pointItr = this->m_PointsMap.begin(); + PointsMapType::const_iterator pointEnd = this->m_PointsMap.end(); float * pointCoordinates = reinterpret_cast(buffer); while (pointItr != pointEnd) { - // get the iterator to the Set, pointing to a unique Point. - PointSetIterator uniquePointItr = *pointItr; - // Get the reference to that PointType object. - const PointType & point = *uniquePointItr; + const PointType & point = pointItr->first; // // Store the Point coordintes in the buffer. @@ -357,8 +356,6 @@ STLMeshIO ::ReadCells(void * buffer) *cellPointIds++ = cellItr->p1; *cellPointIds++ = cellItr->p2; - std::cout << "points " << cellItr->p0 << " " << cellItr->p1 << " " << cellItr->p2 << std::endl; - ++cellItr; } } @@ -677,28 +674,37 @@ void STLMeshIO ::InsertPointIntoSet(const PointType & point) { - PointSetResultType result = this->m_PointsSet.insert(point); + PointsMapType::const_iterator pointMapItr = this->m_PointsMap.find(point); - if (result.second) + IdentifierType pointId = pointMapItr->second; + + if (pointMapItr == this->m_PointsMap.end()) { - this->m_PointsVector.push_back(result.first); + this->m_PointsMap[point] = this->m_LatestPointId; + pointId = this->m_LatestPointId; + this->m_LatestPointId++; + } - this->m_LatestPointId = this->m_PointsVector.size() - 1; - switch (this->m_PointInTriangleCounter) - { - case 0: - this->m_TrianglePointIds.p0 = this->m_LatestPointId; - break; - case 1: - this->m_TrianglePointIds.p1 = this->m_LatestPointId; - break; - case 2: - this->m_TrianglePointIds.p2 = this->m_LatestPointId; - break; - default: - itkExceptionMacro("Point counter went beyond value 2"); - } - this->m_PointInTriangleCounter++; + switch (this->m_PointInTriangleCounter) + { + case 0: + this->m_TrianglePointIds.p0 = pointId; + break; + case 1: + this->m_TrianglePointIds.p1 = pointId; + break; + case 2: + this->m_TrianglePointIds.p2 = pointId; + break; + default: + itkExceptionMacro("Point counter went beyond value 2"); + } + + this->m_PointInTriangleCounter++; + + if (this->m_PointInTriangleCounter == 3) + { + this->m_PointInTriangleCounter = 0; } } diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd new file mode 100644 index 00000000000..9339517655d --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd @@ -0,0 +1,14 @@ +# vtk DataFile Version 2.0 +File written by itkVTKPolyDataWriter +ASCII +DATASET POLYDATA +POINTS 4 float +0 0 0 +1 0 0 +0 1 0 +0 0 1 +POLYGONS 4 16 +3 0 2 1 +3 0 1 3 +3 0 3 2 +3 1 2 3 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 new file mode 100644 index 00000000000..be14d23b637 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 @@ -0,0 +1,30 @@ +solid ascii + facet normal 0 0 -1 + outer loop + vertex 0 0 0 + vertex 0 1 0 + vertex 1 0 0 + endloop + endfacet + facet normal 0 -1 0 + outer loop + vertex 0 0 0 + vertex 1 0 0 + vertex 0 0 1 + endloop + endfacet + facet normal -1 0 0 + outer loop + vertex 0 0 0 + vertex 0 0 1 + vertex 0 1 0 + endloop + endfacet + facet normal 1 1 1 + outer loop + vertex 1 0 0 + vertex 0 1 0 + vertex 0 0 1 + endloop + endfacet +endsolid diff --git a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 new file mode 100644 index 00000000000..78055773cfb --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 @@ -0,0 +1 @@ +70a19e48a4393776cfe02f852f25cbe1 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 new file mode 100644 index 00000000000..eea81ea180b --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 @@ -0,0 +1 @@ +4cd09d26436a53a5adedb33d822cabcd diff --git a/Modules/IO/IOMeshSTL/test/CMakeLists.txt b/Modules/IO/IOMeshSTL/test/CMakeLists.txt index 5af678e7718..c61d211d72c 100644 --- a/Modules/IO/IOMeshSTL/test/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/test/CMakeLists.txt @@ -43,3 +43,43 @@ itk_add_test( ${ITK_TEST_OUTPUT_DIR}/sphere03.stl 1 # write in BINARY ) + +itk_add_test( + NAME itkSTLMeshIOTest04 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/tetrahedron.vtk} + ${ITK_TEST_OUTPUT_DIR}/tetrahedron01.stl + 0 # write in ASCII +) + +itk_add_test( + NAME itkSTLMeshIOTest05 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/tetrahedron.vtk} + ${ITK_TEST_OUTPUT_DIR}/tetrahedron02.stl + 1 # write in BINARY +) + +itk_add_test( + NAME itkSTLMeshIOTest06 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/tetrahedron.stl} + ${ITK_TEST_OUTPUT_DIR}/tetrahedron03.stl + 0 # write in ASCII +) + +itk_add_test( + NAME itkSTLMeshIOTest07 + COMMAND + ITKIOSTLMeshTestDriver + itkSTLMeshIOTest + DATA{Baseline/tetrahedron.stl} + ${ITK_TEST_OUTPUT_DIR}/tetrahedron04.stl + 1 # write in BINARY +) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 83b0d8a5d7a..7f12f84bfb6 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -60,6 +60,12 @@ itkSTLMeshIOTest(int argc, char * argv[]) writer->SetFileTypeAsBINARY(); } + reader->Update(); + QEMeshType * mesh = reader->GetOutput(); + + mesh->Print(std::cout); + + writer->SetInput(reader->GetOutput()); int result = EXIT_SUCCESS; From 0ad86235b25aa42f10fb4df55e983eeeaf7b2e0a Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Fri, 3 Jan 2014 23:02:30 -0500 Subject: [PATCH 14/73] ENH: Better Point compare method. Replaced previous hash, with a more consistent compare method. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 37a69b8cf72..1a947c00cb1 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -241,25 +241,24 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase unsigned int m_InputLineNumber; - static double - PointHash(const PointType & point) - { - double hash = 0; - double factor = 1e5; // one third of the range of the double mantissa - hash = static_cast(point[0]); - hash *= factor; - hash += static_cast(point[1]); - hash *= factor; - hash += static_cast(point[2]); - return hash; - } - struct PointCompare { bool operator()(const PointType & p1, const PointType & p2) const { - return PointHash(p1) < PointHash(p2); + if (p1[0] != p2[0]) + { + return p1[0] < p2[0]; + } + else + { + if (p1[1] != p2[1]) + { + return p1[1] < p2[1]; + } + } + + return p1[2] < p2[2]; } }; From 2eb008932416f6f6b42e3a502c8b5f6a133286bc Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Fri, 3 Jan 2014 23:03:36 -0500 Subject: [PATCH 15/73] BUG: Fixed bug. Points must be passed in order. When transferring points from the Point Map to the points buffer, the points must be stored in the location indicated by the second element of the map pairs. Those are the ordered locations of the points, to which the cell point ids are referring. Now manage to read and write the sphere.stl file. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 9d3ff7dfd5a..86e26b0c54e 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -310,15 +310,18 @@ STLMeshIO ::ReadPoints(void * buffer) PointsMapType::const_iterator pointItr = this->m_PointsMap.begin(); PointsMapType::const_iterator pointEnd = this->m_PointsMap.end(); - float * pointCoordinates = reinterpret_cast(buffer); + float * pointsBuffer = reinterpret_cast(buffer); while (pointItr != pointEnd) { // Get the reference to that PointType object. const PointType & point = pointItr->first; + // Get the location in the buffer where the point should be stored + float * pointCoordinates = pointsBuffer + 3 * pointItr->second; + // - // Store the Point coordintes in the buffer. + // Store the Point coordinates in the buffer. // *pointCoordinates++ = point[0]; *pointCoordinates++ = point[1]; From 4aeac59caefb40c396abcf2dc8c72d3ce3b045eb Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 5 Jan 2014 15:15:07 -0500 Subject: [PATCH 16/73] BUG: Fixed BINARY read. It was off due to the initial read of the header used to determine whether the input file is ASCII or BINARY. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 32 +++++++++++++++++------ 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 86e26b0c54e..a8e9649e953 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -97,13 +97,24 @@ STLMeshIO ::ReadMeshInformation() } - std::string inputLine; - // Read STL header file(the first line) - std::getline(this->m_InputStream, inputLine, '\n'); + char headerBuffer[6]; + this->m_InputStream.read(headerBuffer, 6); + this->m_InputStream.seekg(0); // Reset to the beginning of the file. + + headerBuffer[5] = '\0'; + std::string header(headerBuffer); + + bool inputFileIsASCII = false; + + // Based on the header line define whether the file is ASCII or BINARY + if (header.find("solid") != std::string::npos) + { + inputFileIsASCII = true; + } // Determine file type - if (inputLine.find("solid") != std::string::npos) + if (inputFileIsASCII) { if (this->GetFileType() != ASCII) { @@ -152,15 +163,17 @@ void STLMeshIO ::ReadMeshInternalFromAscii() { // Read all the points, and reduce them to unique ones - std::string inputLine; - PointType p0; - PointType p1; - PointType p2; + PointType p0; + PointType p1; + PointType p2; this->m_InputLineNumber = 2; this->m_LatestPointId = NumericTraits::Zero; + // read header line + std::getline(this->m_InputStream, this->m_InputLine, '\n'); + while (!this->CheckStringFromAscii("endsolid")) { // @@ -247,6 +260,9 @@ STLMeshIO ::ReadMeshInternalFromBinary() char header[80]; this->m_InputStream.read(header, 80); + header[79] = '\0'; // insert string terminator + + this->m_LatestPointId = NumericTraits::Zero; // From 1fe73e6b19185830f603ed410109394a8b6e3ff2 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 12 Jan 2014 09:33:14 -0500 Subject: [PATCH 17/73] DOC: Fixing Doxygen groups. Added these two classes to the STLMeshIO group. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 1 + Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 1 + 2 files changed, 2 insertions(+) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 1a947c00cb1..471e4777dbc 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -31,6 +31,7 @@ namespace itk * \author Luis Ibanez, Kitware Inc. * \ingroup IOFilters * \ingroup ITKIOMesh + * \ingroup ITKIOSTLMesh */ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase { diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 0e675d3c99a..bc44447448b 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -27,6 +27,7 @@ namespace itk /** \class STLMeshIOFactory * \brief Create instances of STLMeshIO objects using an object factory. * \ingroup ITKIOMesh + * \ingroup ITKIOSTLMesh */ class ITKIOMesh_EXPORT STLMeshIOFactory : public ObjectFactoryBase { From 6fd22dbdd9fc1e8e2897a1292c01850fadefeb3f Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 12 Jan 2014 09:34:00 -0500 Subject: [PATCH 18/73] BUG: Now managing Endianness. The STL format assumes little endianness in the files: http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL Here we introduce conversions between System endianness, and little endianness when reading and writing in BINARY format. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 51 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index a8e9649e953..3297784b211 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -18,6 +18,7 @@ #include "itkSTLMeshIO.h" #include "itkMetaDataObject.h" +#include "itkByteSwapper.h" #include #include @@ -271,6 +272,12 @@ STLMeshIO ::ReadMeshInternalFromBinary() int32_t numberOfTriangles; this->m_InputStream.read(reinterpret_cast(&numberOfTriangles), sizeof(numberOfTriangles)); + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&numberOfTriangles); + this->SetNumberOfCells(numberOfTriangles); // @@ -593,6 +600,11 @@ STLMeshIO ::WriteCells(void * buffer) void STLMeshIO ::WriteInt32AsBinary(int32_t value) { + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); } @@ -600,6 +612,11 @@ STLMeshIO ::WriteInt32AsBinary(int32_t value) void STLMeshIO ::WriteInt16AsBinary(int16_t value) { + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); } @@ -609,7 +626,12 @@ STLMeshIO ::WriteNormalAsBinary(const NormalType & normal) { for (unsigned int i = 0; i < 3; ++i) { - const float value = normal[i]; + float value = normal[i]; + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); } } @@ -620,7 +642,12 @@ STLMeshIO ::WritePointAsBinary(const PointType & point) { for (unsigned int i = 0; i < 3; ++i) { - const float value = point[i]; + float value = point[i]; + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); } } @@ -633,6 +660,11 @@ STLMeshIO ::ReadNormalAsBinary(NormalType & normal) for (unsigned int i = 0; i < 3; ++i) { this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); normal[i] = value; } } @@ -642,6 +674,11 @@ void STLMeshIO ::ReadInt32AsBinary(int32_t & value) { this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); } @@ -649,6 +686,11 @@ void STLMeshIO ::ReadInt16AsBinary(int16_t & value) { this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); } @@ -659,6 +701,11 @@ STLMeshIO ::ReadPointAsBinary(PointType & point) for (unsigned int i = 0; i < 3; ++i) { this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + // + // Binary values in STL files are expected to be in little endian + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + ByteSwapper::SwapFromSystemToLittleEndian(&value); point[i] = value; } From 7bf583057972b51228e01e5eed2cf89c204ce9af Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 12 Jan 2014 09:45:47 -0500 Subject: [PATCH 19/73] ENH: Report the system endianness. At the end of the test, we now print out the Endianness of the system. This should be helpful when verifying STL files in BINARY format. --- Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 7f12f84bfb6..76c922be424 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -87,5 +87,18 @@ itkSTLMeshIOTest(int argc, char * argv[]) meshIO->Print(std::cout); + // + // Report the System Endianness + // + std::cout << std::endl; + if (itk::ByteSwapper::SystemIsLittleEndian()) + { + std::cout << "This system is Little Endian" << std::endl; + } + else + { + std::cout << "This system is Big Endian" << std::endl; + } + return result; } From 11fcf749c4c2564a6a30de092ed4a79ebf247435 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 12 Jan 2014 10:26:48 -0500 Subject: [PATCH 20/73] ENH: Throwing exception for non-triangle cells. Suggested in code review by Arnaud Gelas. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 3297784b211..037acbe8d0a 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -523,6 +523,10 @@ STLMeshIO ::WriteCells(void * buffer) { numberOfTriangles++; } + else + { + itkExceptionMacro("Found Non-Triangular Cell."); + } index2 += numberOfVerticesInCell; } From 1cee9a21fdebf9da9a24fbf9a5d664a4a5528c73 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Sun, 12 Jan 2014 10:46:57 -0500 Subject: [PATCH 21/73] ENH: Splitted WriteCells() into BINARY and ASCII. Splitted the WriteCells() method into BINARY and ASCII cases, as suggested by Arnaud Gelas in code review. It makes easier to follow the logic of each individual case. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 6 + Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 170 ++++++++++++-------- 2 files changed, 106 insertions(+), 70 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 471e4777dbc..7f76600cdb6 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -234,6 +234,12 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase bool CheckStringFromAscii(const std::string & expected); + /** Helper function to write cells as ASCII or BINARY. */ + virtual void + WriteCellsAsAscii(void * buffer); + virtual void + WriteCellsAsBinary(void * buffer); + /** Functions to create set of points and disambiguate them. */ void InsertPointIntoSet(const PointType & point); diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 037acbe8d0a..78c16c7beb9 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -489,6 +489,19 @@ STLMeshIO ::WritePoints(void * buffer) void STLMeshIO ::WriteCells(void * buffer) +{ + if (this->GetFileType() == BINARY) + { + this->WriteCellsAsBinary(buffer); + } + else + { + this->WriteCellsAsAscii(buffer); + } +} + +void +STLMeshIO ::WriteCellsAsBinary(void * buffer) { const IdentifierType numberOfPolygons = this->GetNumberOfCells(); @@ -501,38 +514,85 @@ STLMeshIO ::WriteCells(void * buffer) NormalType normal; - if (this->GetFileType() == BINARY) + // + // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // + // UINT32 -- Number of Triangles + // + int32_t numberOfTriangles = 0; + + SizeValueType index2 = 0; + + for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) + { + const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index2++]); + const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index2++]); + + const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); + + if (isTriangle) + { + numberOfTriangles++; + } + else + { + itkExceptionMacro("Found Non-Triangular Cell."); + } + + index2 += numberOfVerticesInCell; + } + + this->WriteInt32AsBinary(numberOfTriangles); + + for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { + const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index++]); + const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index++]); + + const PointType & p0 = m_Points[cellsBuffer[index++]]; + const PointType & p1 = m_Points[cellsBuffer[index++]]; + const PointType & p2 = m_Points[cellsBuffer[index++]]; + + const VectorType v10(p0 - p1); + const VectorType v12(p2 - p1); + + CrossProduct(normal, v12, v10); + // // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // - // UINT32 -- Number of Triangles + // foreach triangle + // REAL32[3] – Normal vector + // REAL32[3] – Vertex 1 + // REAL32[3] – Vertex 2 + // REAL32[3] – Vertex 3 + // UINT16 – Attribute byte count // - int32_t numberOfTriangles = 0; + this->WriteNormalAsBinary(normal); + this->WritePointAsBinary(p0); + this->WritePointAsBinary(p1); + this->WritePointAsBinary(p2); + this->WriteInt16AsBinary(0); + } - SizeValueType index2 = 0; + // + // There is no ending section when doing BINARY + // +} - for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) - { - const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index2++]); - const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index2++]); +void +STLMeshIO ::WriteCellsAsAscii(void * buffer) +{ - const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); + const IdentifierType numberOfPolygons = this->GetNumberOfCells(); - if (isTriangle) - { - numberOfTriangles++; - } - else - { - itkExceptionMacro("Found Non-Triangular Cell."); - } + const IdentifierType * cellsBuffer = reinterpret_cast(buffer); - index2 += numberOfVerticesInCell; - } + SizeValueType index = 0; - this->WriteInt32AsBinary(numberOfTriangles); - } + typedef MeshIOBase::CellGeometryType CellGeometryType; + + NormalType normal; for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { @@ -541,65 +601,35 @@ STLMeshIO ::WriteCells(void * buffer) const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); - if (isTriangle) + if (!isTriangle) { - const PointType & p0 = m_Points[cellsBuffer[index++]]; - const PointType & p1 = m_Points[cellsBuffer[index++]]; - const PointType & p2 = m_Points[cellsBuffer[index++]]; + itkExceptionMacro("Found Non-Triangular Cell."); + } - const VectorType v10(p0 - p1); - const VectorType v12(p2 - p1); + const PointType & p0 = m_Points[cellsBuffer[index++]]; + const PointType & p1 = m_Points[cellsBuffer[index++]]; + const PointType & p2 = m_Points[cellsBuffer[index++]]; - CrossProduct(normal, v12, v10); + const VectorType v10(p0 - p1); + const VectorType v12(p2 - p1); - if (this->GetFileType() == ASCII) - { - this->m_OutputStream << " facet normal "; - this->m_OutputStream << normal[0] << " " << normal[1] << " " << normal[2] << std::endl; + CrossProduct(normal, v12, v10); - this->m_OutputStream << " outer loop" << std::endl; + this->m_OutputStream << " facet normal "; + this->m_OutputStream << normal[0] << " " << normal[1] << " " << normal[2] << std::endl; - this->m_OutputStream << " vertex " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; - this->m_OutputStream << " vertex " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; - this->m_OutputStream << " vertex " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; + this->m_OutputStream << " outer loop" << std::endl; - this->m_OutputStream << " endloop" << std::endl; - this->m_OutputStream << " endfacet" << std::endl; - } - else if (this->GetFileType() == BINARY) - { - // - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL - // - // foreach triangle - // REAL32[3] – Normal vector - // REAL32[3] – Vertex 1 - // REAL32[3] – Vertex 2 - // REAL32[3] – Vertex 3 - // UINT16 – Attribute byte count - // - this->WriteNormalAsBinary(normal); - this->WritePointAsBinary(p0); - this->WritePointAsBinary(p1); - this->WritePointAsBinary(p2); - this->WriteInt16AsBinary(0); - } - } - else - { - index += numberOfVerticesInCell; - } - } + this->m_OutputStream << " vertex " << p0[0] << " " << p0[1] << " " << p0[2] << std::endl; + this->m_OutputStream << " vertex " << p1[0] << " " << p1[1] << " " << p1[2] << std::endl; + this->m_OutputStream << " vertex " << p2[0] << " " << p2[1] << " " << p2[2] << std::endl; - if (this->GetFileType() == ASCII) - { - this->m_OutputStream << "endsolid" << std::endl; + this->m_OutputStream << " endloop" << std::endl; + this->m_OutputStream << " endfacet" << std::endl; } - // - // There is no ending section when doing BINARY - // -} + this->m_OutputStream << "endsolid" << std::endl; +} void STLMeshIO ::WriteInt32AsBinary(int32_t value) From 4ab31f249d5cc67b209b8bb6caf5dec3c17d0109 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Thu, 16 Jan 2014 17:14:47 -0500 Subject: [PATCH 22/73] STYLE: Rename module to match ITK standards. --- Modules/IO/IOMeshSTL/itk-module.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake index 71b7119180c..4010b6ecafa 100644 --- a/Modules/IO/IOMeshSTL/itk-module.cmake +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -4,7 +4,7 @@ set( QuadEdgeMeshes using the STL file format." ) itk_module( - ITKIOSTLMesh + IOSTL ENABLE_SHARED DEPENDS ITKCommon From 3e42b36c4c44998c75e749c2ef77ec2298027085 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Thu, 16 Jan 2014 17:48:44 -0500 Subject: [PATCH 23/73] ENH: Propagated Module name changes. To make it consistent in all the CMake infrastructure. --- Modules/IO/IOMeshSTL/CMakeLists.txt | 4 ++-- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 2 +- .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 2 +- Modules/IO/IOMeshSTL/src/CMakeLists.txt | 10 +++++----- Modules/IO/IOMeshSTL/test/CMakeLists.txt | 20 +++++++++---------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index da161c7c69d..031563575c4 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,3 +1,3 @@ -project(ITKIOSTLMesh) -set(ITKIOSTLMesh_LIBRARIES ITKIOSTLMesh) +project(IOSTL) +set(IOSTL_LIBRARIES IOSTL) itk_module_impl() diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 7f76600cdb6..085735640df 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -31,7 +31,7 @@ namespace itk * \author Luis Ibanez, Kitware Inc. * \ingroup IOFilters * \ingroup ITKIOMesh - * \ingroup ITKIOSTLMesh + * \ingroup IOSTL */ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase { diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index bc44447448b..e55cad44334 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -27,7 +27,7 @@ namespace itk /** \class STLMeshIOFactory * \brief Create instances of STLMeshIO objects using an object factory. * \ingroup ITKIOMesh - * \ingroup ITKIOSTLMesh + * \ingroup IOSTL */ class ITKIOMesh_EXPORT STLMeshIOFactory : public ObjectFactoryBase { diff --git a/Modules/IO/IOMeshSTL/src/CMakeLists.txt b/Modules/IO/IOMeshSTL/src/CMakeLists.txt index f96ff34d4c9..685a7312de8 100644 --- a/Modules/IO/IOMeshSTL/src/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/src/CMakeLists.txt @@ -1,18 +1,18 @@ set( - ITKIOSTLMesh_SRC + IOSTL_SRC itkSTLMeshIO.cxx itkSTLMeshIOFactory.cxx ) add_library( - ITKIOSTLMesh + IOSTL ${ITK_LIBRARY_BUILD_TYPE} - ${ITKIOSTLMesh_SRC} + ${IOSTL_SRC} ) target_link_libraries( - ITKIOSTLMesh + IOSTL ${ITKCommon_LIBRARIES} ${ITKIOMesh_LIBRARIES} ) -itk_module_target(ITKIOSTLMesh) +itk_module_target(IOSTL) diff --git a/Modules/IO/IOMeshSTL/test/CMakeLists.txt b/Modules/IO/IOMeshSTL/test/CMakeLists.txt index c61d211d72c..fc19533b77c 100644 --- a/Modules/IO/IOMeshSTL/test/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/test/CMakeLists.txt @@ -1,13 +1,13 @@ itk_module_test() -set(ITKIOSTLMeshTests itkSTLMeshIOTest.cxx) +set(IOSTLTests itkSTLMeshIOTest.cxx) -createtestdriver(ITKIOSTLMesh "${ITKIOSTLMesh-Test_LIBRARIES}" "${ITKIOSTLMeshTests}") +createtestdriver(IOSTL "${IOSTL-Test_LIBRARIES}" "${IOSTLTests}" ) itk_add_test( NAME itkSTLMeshIOTest00 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.vtk} ${ITK_TEST_OUTPUT_DIR}/sphere00.stl @@ -17,7 +17,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest01 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.vtk} ${ITK_TEST_OUTPUT_DIR}/sphere01.stl @@ -27,7 +27,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest02 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.stl} ${ITK_TEST_OUTPUT_DIR}/sphere02.stl @@ -37,7 +37,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest03 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.stl} ${ITK_TEST_OUTPUT_DIR}/sphere03.stl @@ -47,7 +47,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest04 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.vtk} ${ITK_TEST_OUTPUT_DIR}/tetrahedron01.stl @@ -57,7 +57,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest05 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.vtk} ${ITK_TEST_OUTPUT_DIR}/tetrahedron02.stl @@ -67,7 +67,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest06 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.stl} ${ITK_TEST_OUTPUT_DIR}/tetrahedron03.stl @@ -77,7 +77,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest07 COMMAND - ITKIOSTLMeshTestDriver + IOSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.stl} ${ITK_TEST_OUTPUT_DIR}/tetrahedron04.stl From ec2853609884c07ba152639dc4d0c8de2368ff5c Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Thu, 16 Jan 2014 17:53:17 -0500 Subject: [PATCH 24/73] ENH: Removing unused variables. That before were used to verify that all cells were triangles. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 3 --- 1 file changed, 3 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 78c16c7beb9..4a44dc0031b 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -546,9 +546,6 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { - const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index++]); - const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index++]); - const PointType & p0 = m_Points[cellsBuffer[index++]]; const PointType & p1 = m_Points[cellsBuffer[index++]]; const PointType & p2 = m_Points[cellsBuffer[index++]]; From b9b41ef70965f14c01224ec76aace21245e9cda2 Mon Sep 17 00:00:00 2001 From: Luis Ibanez Date: Fri, 17 Jan 2014 22:30:16 -0500 Subject: [PATCH 25/73] COMP: Fixing instantiation of templated functions. To address compilation errors from MacOSX-gcc4.2-Release-IOSTL. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 69 +++++++++++++++++------ 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 4a44dc0031b..3d1f3300b8c 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -443,44 +443,83 @@ STLMeshIO ::WritePoints(void * buffer) switch (pointValueType) { case UCHAR: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef unsigned char CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case CHAR: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef char CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case USHORT: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef unsigned short CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case SHORT: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef short CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case UINT: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef unsigned int CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case INT: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef int CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case ULONG: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef unsigned long CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case LONG: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef long CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case ULONGLONG: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef unsigned long long CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case LONGLONG: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef long long CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case FLOAT: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef float CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case DOUBLE: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef double CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } case LDOUBLE: - this->WritePointsTyped(reinterpret_cast(buffer)); + { + typedef long double CoordType; + this->WritePointsTyped(reinterpret_cast(buffer)); break; + } default: itkExceptionMacro(<< "Unknonwn point component type"); } @@ -510,8 +549,6 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) SizeValueType index = 0; - typedef MeshIOBase::CellGeometryType CellGeometryType; - NormalType normal; // @@ -587,8 +624,6 @@ STLMeshIO ::WriteCellsAsAscii(void * buffer) SizeValueType index = 0; - typedef MeshIOBase::CellGeometryType CellGeometryType; - NormalType normal; for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) From 038aafb56fc01219c5bccfea141e609a833ab1e5 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 1 Feb 2014 13:16:07 -0500 Subject: [PATCH 26/73] BUG: Add EXCLUDE_FROM_DEFAULT. As a Remote Module, EXCLUDE_FROM_DEFAULT needs to be added from the module being inadvertently turned on in a fresh build after it was downloaded in a previous build. --- Modules/IO/IOMeshSTL/itk-module.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake index 4010b6ecafa..1c08828db85 100644 --- a/Modules/IO/IOMeshSTL/itk-module.cmake +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -13,4 +13,5 @@ itk_module( ITKTestKernel ITKQuadEdgeMesh DESCRIPTION "${DOCUMENTATION}" + EXCLUDE_FROM_DEFAULT ) From c34e0436dc7188885e167513a8ef4c68e0163c71 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Sat, 1 Feb 2014 17:36:03 -0500 Subject: [PATCH 27/73] BUG: Fix WritePointsTyped() to no longer use conflicting typenames "PointValueType" was both the template parmeter of WritePointsTyped() and a typedef of the enclosing class. This was generating errors with GCC on OSX. Renamed the template parameter to "TPointsBuffer" to fix this error. Also added a static_cast to make the conversion to the internal value type explicit. Also made the parameter for WritePointsTyped() a const pointer to const values, to clarify its intended use as an input buffer. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 085735640df..9dd7779d65e 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -152,9 +152,9 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase /** Templated version of write points method, that is aware of the specific * type used to represent the point coordinates. */ - template + template void - WritePointsTyped(const PointValueType * buffer) + WritePointsTyped(const TPointsBuffer * const buffer) { const unsigned int pointDimension = this->GetPointDimension(); @@ -164,7 +164,7 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase itkExceptionMacro("STL only supports 3D points"); } - const PointValueType * pointCoordinates = buffer; + const TPointsBuffer * pointCoordinates = buffer; this->m_Points.clear(); @@ -176,7 +176,7 @@ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase { for (unsigned int i = 0; i < pointDimension; ++i) { - m_Points[pi][i] = *pointCoordinates++; + m_Points[pi][i] = static_cast(*pointCoordinates++); } } } From 1e52de56536a4e70d0cd1a269231d51568e2a161 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Jun 2014 14:42:36 -0400 Subject: [PATCH 28/73] COMP: Remove duplicate group entry in ITKIOMesh. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 2 +- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 9dd7779d65e..3a5f25e8716 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -29,8 +29,8 @@ namespace itk * \brief This class defines how to read and write STL file format. * * \author Luis Ibanez, Kitware Inc. + * * \ingroup IOFilters - * \ingroup ITKIOMesh * \ingroup IOSTL */ class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index e55cad44334..984d2bf2a77 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -26,7 +26,7 @@ namespace itk { /** \class STLMeshIOFactory * \brief Create instances of STLMeshIO objects using an object factory. - * \ingroup ITKIOMesh + * * \ingroup IOSTL */ class ITKIOMesh_EXPORT STLMeshIOFactory : public ObjectFactoryBase From 5bac1afd314e3ef14cf291e8f45a4c31e02ce497 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 29 Jun 2014 17:42:28 -0400 Subject: [PATCH 29/73] COMP: Add export definitions to build on Windows with shared libs. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 4 +++- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 9dd7779d65e..5afa7829c62 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -18,6 +18,8 @@ #ifndef __itkSTLMeshIO_h #define __itkSTLMeshIO_h +#include "IOSTLExport.h" + #include "itkMeshIOBase.h" #include @@ -33,7 +35,7 @@ namespace itk * \ingroup ITKIOMesh * \ingroup IOSTL */ -class ITKIOMesh_EXPORT STLMeshIO : public MeshIOBase +class IOSTL_EXPORT STLMeshIO : public MeshIOBase { public: /** Standard "Self" typedef. */ diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index e55cad44334..2bca963f2c6 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -17,7 +17,8 @@ *=========================================================================*/ #ifndef __itkSTLMeshIOFactory_h #define __itkSTLMeshIOFactory_h -#include "ITKIOMeshExport.h" + +#include "IOSTLExport.h" #include "itkObjectFactoryBase.h" #include "itkMeshIOBase.h" @@ -29,7 +30,7 @@ namespace itk * \ingroup ITKIOMesh * \ingroup IOSTL */ -class ITKIOMesh_EXPORT STLMeshIOFactory : public ObjectFactoryBase +class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase { public: /** Standard class typedefs. */ From 8468275e8205d165abd274c7799ca2ab9cf0404d Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 3 Apr 2015 10:53:32 -0400 Subject: [PATCH 30/73] STYLE: Remove __ in header inclusion guards. These are reserved for compilers. This addresses the KWStyle failing test. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 6 +++--- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 5fa373c0a38..eefb8b08eb6 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -15,8 +15,8 @@ * limitations under the License. * *=========================================================================*/ -#ifndef __itkSTLMeshIO_h -#define __itkSTLMeshIO_h +#ifndef itkSTLMeshIO_h +#define itkSTLMeshIO_h #include "IOSTLExport.h" @@ -295,4 +295,4 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase }; } // end namespace itk -#endif // __itkSTLMeshIO_h +#endif // itkSTLMeshIO_h diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index e90adaa9df5..a0786d7c8f0 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -15,8 +15,8 @@ * limitations under the License. * *=========================================================================*/ -#ifndef __itkSTLMeshIOFactory_h -#define __itkSTLMeshIOFactory_h +#ifndef itkSTLMeshIOFactory_h +#define itkSTLMeshIOFactory_h #include "IOSTLExport.h" From 77e5f531dcbb97c39c9665089f6845c2a9f009ae Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Mon, 22 Jun 2015 14:08:00 -0400 Subject: [PATCH 31/73] BUG: Fix incorrect output, and invalid memory access The m_Points array was incorrectly traversed. It's a mix of cellType, numberOfVerticiesInCells, followed by index into points. The first two are not correctly being skipped. This issue was detected by valgrind defects. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 3d1f3300b8c..842a17232a8 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -583,6 +583,9 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { + // skip cell type and number of vertices in cell + index += 2; + const PointType & p0 = m_Points[cellsBuffer[index++]]; const PointType & p1 = m_Points[cellsBuffer[index++]]; const PointType & p2 = m_Points[cellsBuffer[index++]]; From 3c52d2174380d809ce1ccff737d7dacb5d6f91d6 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 4 Nov 2015 21:44:49 -0500 Subject: [PATCH 32/73] ENH: Add external build support. --- Modules/IO/IOMeshSTL/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 031563575c4..13a02c5aed0 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,3 +1,11 @@ +cmake_minimum_required(VERSION 2.9) project(IOSTL) set(IOSTL_LIBRARIES IOSTL) -itk_module_impl() + +if(NOT ITK_SOURCE_DIR) + find_package(ITK REQUIRED) + list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR}) + include(ITKModuleExternal) +else() + itk_module_impl() +endif() From 273e537aaf9ddff8e38bddb1588e0671954877c1 Mon Sep 17 00:00:00 2001 From: Davis Vigneault Date: Fri, 3 Jun 2016 15:11:11 +0100 Subject: [PATCH 33/73] COMP: Address override warnings. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 32 ++++++++++----------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index eefb8b08eb6..93dfdc1385b 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -58,7 +58,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * \return Returns true if this MeshIO can read the file specified. */ virtual bool - CanReadFile(const char * FileNameToRead); + CanReadFile(const char * FileNameToRead) ITK_OVERRIDE; /** Read the content of the file into a Mesh. */ virtual void @@ -66,31 +66,31 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase /** Set the spacing and dimension information for the set filename. */ virtual void - ReadMeshInformation(); + ReadMeshInformation() ITK_OVERRIDE; /** Stores the point data into the memory buffer provided. */ virtual void - ReadPoints(void * buffer); + ReadPoints(void * buffer) ITK_OVERRIDE; /** Stores the cell data into the memory buffer provided. */ virtual void - ReadCells(void * buffer); + ReadCells(void * buffer) ITK_OVERRIDE; /** Indicates whether ReadPoints() should be called. */ virtual bool - GetUpdatePoints() const; + GetUpdatePoints() const ITK_OVERRIDE; /** Indicates whether ReadCells() should be called. */ virtual bool - GetUpdateCells() const; + GetUpdateCells() const ITK_OVERRIDE; /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ virtual void - ReadPointData(void * itkNotUsed(buffer)) {}; + ReadPointData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; virtual void - ReadCellData(void * itkNotUsed(buffer)) {}; + ReadCellData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; /*-------- This part of the interfaces deals with writing data. ----- */ /** Determine if the file can be written with this MeshIO implementation. @@ -99,15 +99,15 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * \return Returns true if this MeshIO can write the file specified. */ virtual bool - CanWriteFile(const char * FileNameToWrite); + CanWriteFile(const char * FileNameToWrite) ITK_OVERRIDE; /** Write header of the STL file */ virtual void - WriteMeshInformation(); + WriteMeshInformation() ITK_OVERRIDE; /** Write the content of the Mesh into an STL file. */ virtual void - Write(); + Write() ITK_OVERRIDE; /** The STL format stores point coordinates repeatedly as part of every * triangle. Therefore point coordinates are writen as part of the @@ -116,7 +116,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * coordinates data, than then is used in the WriteCells() method. */ virtual void - WritePoints(void * buffer); + WritePoints(void * buffer) ITK_OVERRIDE; /** The WriteCells() method does most of the work. It writes * out every triangle in the mesh. For every triangle, it @@ -135,22 +135,22 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * */ virtual void - WriteCells(void * buffer); + WriteCells(void * buffer) ITK_OVERRIDE; /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ virtual void - WritePointData(void * itkNotUsed(buffer)) {}; + WritePointData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; virtual void - WriteCellData(void * itkNotUsed(buffer)) {}; + WriteCellData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; protected: STLMeshIO(); virtual ~STLMeshIO() {} void - PrintSelf(std::ostream & os, Indent indent) const; + PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; /** Templated version of write points method, that is aware of the specific * type used to represent the point coordinates. */ From f5ed3ed7ec70a78567aa3faf4ed4bce2c9296d1e Mon Sep 17 00:00:00 2001 From: Zach Williamson Date: Thu, 23 Jun 2016 11:27:02 -0500 Subject: [PATCH 34/73] COMP: Use override annotations on overridden functions --- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index a0786d7c8f0..6baab46258a 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -41,10 +41,10 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase /** Class methods used to interface with the registered factories. */ virtual const char * - GetITKSourceVersion(void) const; + GetITKSourceVersion(void) const ITK_OVERRIDE; virtual const char * - GetDescription(void) const; + GetDescription(void) const ITK_OVERRIDE; /** Method for class instantiation. */ itkFactorylessNewMacro(Self); @@ -66,7 +66,7 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase ~STLMeshIOFactory(); virtual void - PrintSelf(std::ostream & os, Indent indent) const; + PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; private: STLMeshIOFactory(const Self &); // purposely not implemented From 24ebcffc15f26c706ebd274ab3a82c1f522c8a33 Mon Sep 17 00:00:00 2001 From: Zach Williamson Date: Wed, 29 Jun 2016 09:59:17 -0500 Subject: [PATCH 35/73] STYLE: Use Macro for Function Deletion --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 4 +--- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 93dfdc1385b..b24a14ec29b 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -185,9 +185,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase private: - STLMeshIO(const Self &); // purposely not implemented - void - operator=(const Self &); // purposely not implemented + ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIO); std::ofstream m_OutputStream; // output file std::ifstream m_InputStream; // input file diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 6baab46258a..f9a3406fab6 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -69,9 +69,7 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; private: - STLMeshIOFactory(const Self &); // purposely not implemented - void - operator=(const Self &); // purposely not implemented + ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIOFactory); }; } // end namespace itk From c58a7ab679f97f7b991d89dc9c4f67c140d57bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Sun, 5 Nov 2017 10:19:01 -0500 Subject: [PATCH 36/73] BUG: Fixing reading --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 842a17232a8..8df7672f66b 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -811,7 +811,7 @@ STLMeshIO ::InsertPointIntoSet(const PointType & point) PointsMapType::const_iterator pointMapItr = this->m_PointsMap.find(point); - IdentifierType pointId = pointMapItr->second; + IdentifierType pointId; if (pointMapItr == this->m_PointsMap.end()) { @@ -819,6 +819,10 @@ STLMeshIO ::InsertPointIntoSet(const PointType & point) pointId = this->m_LatestPointId; this->m_LatestPointId++; } + else + { + pointId = pointMapItr->second; + } switch (this->m_PointInTriangleCounter) { From 0a409b96df58a550d8b98061fd5f72fe47bc45a2 Mon Sep 17 00:00:00 2001 From: Jon Haitz Legarreta Date: Wed, 17 Jan 2018 17:54:44 +0100 Subject: [PATCH 37/73] ENH: Require cmake minimum version to be 3.9.5. Require CMake minimum version to be 3.9.5 following ITKv5 requiring C++11: https://discourse.itk.org/t/minimum-cmake-version-update/585 --- Modules/IO/IOMeshSTL/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 13a02c5aed0..317be8e06e9 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.9) +cmake_minimum_required(VERSION 3.9.5) project(IOSTL) set(IOSTL_LIBRARIES IOSTL) From 6f5c2c6f209f7ecb413e29da0c5b40f64dd4d3f4 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sat, 16 Dec 2017 19:17:00 -0600 Subject: [PATCH 38/73] ENH: ITKv5 override consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Provide remove virtual and override Use clang-tidy to add ITK_OVERRIDE, and to remove redundant virtual on functions. cd ../ITK; clang-tidy -p ITK-clangtidy $find Modules/[A-J]* -name *.cxx |fgrep -v ThirdParty) -checks=-*,modernize-use-override -header-filter=.* -fix clang-tidy -p ITK-clangtidy $(find Modules/[K-Z]* -name *.cxx |fgrep -v ThirdParty) -checks=-*,modernize-use-override -header-filter=.* -fix https://stackoverflow.com/questions/39932391/virtual-override-or-both-c When you override a function you don't technically need to write either virtual or override. The original base class declaration needs the keyword virtual to mark it as virtual. In the derived class the function is virtual by way of having the ¹same type as the base class function. However, an override can help avoid bugs by producing a compilation error when the intended override isn't technically an override. E.g. that the function type isn't exactly like the base class function. Or that a maintenance of the base class changes that function's type, e.g. adding a defaulted argument. In the same way, a virtual keyword in the derived class can make such a bug more subtle, by ensuring that the function is still is virtual in further derived classes. So the general advice is, virtual for the base class function declaration. This is technically necessary. Use override (only) for a derived class' override. This helps with maintenance. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 32 +++++++++---------- .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 8 ++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index b24a14ec29b..cf539d0da25 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -57,7 +57,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * \post Sets classes MeshIOBase::m_FileName variable to be FileNameToWrite * \return Returns true if this MeshIO can read the file specified. */ - virtual bool + bool CanReadFile(const char * FileNameToRead) ITK_OVERRIDE; /** Read the content of the file into a Mesh. */ @@ -65,31 +65,31 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase Read(); /** Set the spacing and dimension information for the set filename. */ - virtual void + void ReadMeshInformation() ITK_OVERRIDE; /** Stores the point data into the memory buffer provided. */ - virtual void + void ReadPoints(void * buffer) ITK_OVERRIDE; /** Stores the cell data into the memory buffer provided. */ - virtual void + void ReadCells(void * buffer) ITK_OVERRIDE; /** Indicates whether ReadPoints() should be called. */ - virtual bool + bool GetUpdatePoints() const ITK_OVERRIDE; /** Indicates whether ReadCells() should be called. */ - virtual bool + bool GetUpdateCells() const ITK_OVERRIDE; /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ - virtual void + void ReadPointData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; - virtual void + void ReadCellData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; /*-------- This part of the interfaces deals with writing data. ----- */ @@ -98,15 +98,15 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * \post Sets classes MeshIOBase::m_FileName variable to be FileNameToWrite * \return Returns true if this MeshIO can write the file specified. */ - virtual bool + bool CanWriteFile(const char * FileNameToWrite) ITK_OVERRIDE; /** Write header of the STL file */ - virtual void + void WriteMeshInformation() ITK_OVERRIDE; /** Write the content of the Mesh into an STL file. */ - virtual void + void Write() ITK_OVERRIDE; /** The STL format stores point coordinates repeatedly as part of every @@ -115,7 +115,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * Consequently, this method only performs an internal copy of the Point * coordinates data, than then is used in the WriteCells() method. */ - virtual void + void WritePoints(void * buffer) ITK_OVERRIDE; /** The WriteCells() method does most of the work. It writes @@ -134,20 +134,20 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * endfacet * */ - virtual void + void WriteCells(void * buffer) ITK_OVERRIDE; /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ - virtual void + void WritePointData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; - virtual void + void WriteCellData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; protected: STLMeshIO(); - virtual ~STLMeshIO() {} + ~STLMeshIO() ITK_OVERRIDE {} void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index f9a3406fab6..6c757cd0e8e 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -40,10 +40,10 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase typedef SmartPointer ConstPointer; /** Class methods used to interface with the registered factories. */ - virtual const char * + const char * GetITKSourceVersion(void) const ITK_OVERRIDE; - virtual const char * + const char * GetDescription(void) const ITK_OVERRIDE; /** Method for class instantiation. */ @@ -63,9 +63,9 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase protected: STLMeshIOFactory(); - ~STLMeshIOFactory(); + ~STLMeshIOFactory() ITK_OVERRIDE; - virtual void + void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; private: From 86006af4cd00e0825900f22d07e660d82e980e8f Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sat, 16 Dec 2017 19:36:25 -0600 Subject: [PATCH 39/73] COMP: Use C++11 override directly git grep -l "ITK_OVERRIDE" | fgrep -v itk_compiler_detection.h | fgrep -v CMakeLists.txt |fgrep -v .cmake | xargs sed -i '' -e "s/ITK_OVERRIDE/override/g" --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 34 +++++++++---------- .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 8 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index cf539d0da25..2d5d30ea3a3 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -58,7 +58,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * \return Returns true if this MeshIO can read the file specified. */ bool - CanReadFile(const char * FileNameToRead) ITK_OVERRIDE; + CanReadFile(const char * FileNameToRead) override; /** Read the content of the file into a Mesh. */ virtual void @@ -66,31 +66,31 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase /** Set the spacing and dimension information for the set filename. */ void - ReadMeshInformation() ITK_OVERRIDE; + ReadMeshInformation() override; /** Stores the point data into the memory buffer provided. */ void - ReadPoints(void * buffer) ITK_OVERRIDE; + ReadPoints(void * buffer) override; /** Stores the cell data into the memory buffer provided. */ void - ReadCells(void * buffer) ITK_OVERRIDE; + ReadCells(void * buffer) override; /** Indicates whether ReadPoints() should be called. */ bool - GetUpdatePoints() const ITK_OVERRIDE; + GetUpdatePoints() const override; /** Indicates whether ReadCells() should be called. */ bool - GetUpdateCells() const ITK_OVERRIDE; + GetUpdateCells() const override; /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ void - ReadPointData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; + ReadPointData(void * itkNotUsed(buffer)) override {}; void - ReadCellData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; + ReadCellData(void * itkNotUsed(buffer)) override {}; /*-------- This part of the interfaces deals with writing data. ----- */ /** Determine if the file can be written with this MeshIO implementation. @@ -99,15 +99,15 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * \return Returns true if this MeshIO can write the file specified. */ bool - CanWriteFile(const char * FileNameToWrite) ITK_OVERRIDE; + CanWriteFile(const char * FileNameToWrite) override; /** Write header of the STL file */ void - WriteMeshInformation() ITK_OVERRIDE; + WriteMeshInformation() override; /** Write the content of the Mesh into an STL file. */ void - Write() ITK_OVERRIDE; + Write() override; /** The STL format stores point coordinates repeatedly as part of every * triangle. Therefore point coordinates are writen as part of the @@ -116,7 +116,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * coordinates data, than then is used in the WriteCells() method. */ void - WritePoints(void * buffer) ITK_OVERRIDE; + WritePoints(void * buffer) override; /** The WriteCells() method does most of the work. It writes * out every triangle in the mesh. For every triangle, it @@ -135,22 +135,22 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase * */ void - WriteCells(void * buffer) ITK_OVERRIDE; + WriteCells(void * buffer) override; /** STL files do not carry information in points or cells. * Therefore the following two methods are implemented as null * operations. */ void - WritePointData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; + WritePointData(void * itkNotUsed(buffer)) override {}; void - WriteCellData(void * itkNotUsed(buffer)) ITK_OVERRIDE {}; + WriteCellData(void * itkNotUsed(buffer)) override {}; protected: STLMeshIO(); - ~STLMeshIO() ITK_OVERRIDE {} + ~STLMeshIO() override {} void - PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; + PrintSelf(std::ostream & os, Indent indent) const override; /** Templated version of write points method, that is aware of the specific * type used to represent the point coordinates. */ diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 6c757cd0e8e..84ce378c299 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -41,10 +41,10 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase /** Class methods used to interface with the registered factories. */ const char * - GetITKSourceVersion(void) const ITK_OVERRIDE; + GetITKSourceVersion(void) const override; const char * - GetDescription(void) const ITK_OVERRIDE; + GetDescription(void) const override; /** Method for class instantiation. */ itkFactorylessNewMacro(Self); @@ -63,10 +63,10 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase protected: STLMeshIOFactory(); - ~STLMeshIOFactory() ITK_OVERRIDE; + ~STLMeshIOFactory() override; void - PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE; + PrintSelf(std::ostream & os, Indent indent) const override; private: ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIOFactory); From c765210293889a9045b7ceb6fa3144e2ce1a342f Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 12 Feb 2018 15:21:08 -0600 Subject: [PATCH 40/73] STYLE: Modernize to C++11 conventions STYLE: Use auto for variable creation This check is responsible for using the auto type specifier for variable declarations to improve code readability and maintainability. The auto type specifier will only be introduced in situations where the variable type matches the type of the initializer expression. In other words auto should deduce the same type that was originally spelled in the source cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-use-auto -header-filter=.* -fix use auto when declaring iterators use auto when initializing with a cast to avoid duplicating the type name use auto when initializing with a template cast to avoid duplicating the type name use auto when initializing with new to avoid duplicating the type name SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD PERF: Replace explicit return calls of constructor Replaces explicit calls to the constructor in a return with a braced initializer list. This way the return type is not needlessly duplicated in the function definition and the return statement. SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-return-braced-init-list -header-filter=.* -fix PERF: Allow compiler to choose best way to construct a copy With move semantics added to the language and the standard library updated with move constructors added for many types it is now interesting to take an argument directly by value, instead of by const-reference, and then copy. This check allows the compiler to take care of choosing the best way to construct the copy. The transformation is usually beneficial when the calling code passes an rvalue and assumes the move construction is a cheap operation. This short example illustrates how the construction of the value happens: class Foo { public: - Foo(const std::string &Copied, const std::string &ReadOnly) - : Copied(Copied), ReadOnly(ReadOnly) {} + Foo(std::string Moved, const std::string &ReadOnly) + : Copied(std::move(Moved)), ReadOnly(ReadOnly) {} private: private: std::string Copied; const std::string &ReadOnly; }; SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-pass-by-value -header-filter=.* -fix STYLE: Use range-based loops from C++11 Used as a more readable equivalent to the traditional for loop operating over a range of values, such as all elements in a container, in the forward direction. ==== Range based loopes are more explicit for only computing the end location once for containers. for ( ImageIORegion::IndexType::const_iterator i = this->GetIndex().begin(); i != this->GetIndex().end(); //<- NOTE: Compute end every loop iteration ++i ) for (long i : this->GetIndex()) //<- NOTE: Implicitly only compute end once ==== Explicitly reduce the amount of index computations: (The compiler probably does this too) for(int i = 0; i < 11; i++) { pos[0] = testPoints[i][0]; pos[1] = testPoints[i][1]; ^^^^ for(auto & testPoint : testPoints) { pos[0] = testPoint[0]; pos[1] = testPoint[1]; ==== SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/ run-clang-tidy.py -checks=-*,modernize-loop-convert -header-filter=.* -fix --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 8df7672f66b..70b5f639ca8 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -333,7 +333,7 @@ STLMeshIO ::ReadPoints(void * buffer) PointsMapType::const_iterator pointItr = this->m_PointsMap.begin(); PointsMapType::const_iterator pointEnd = this->m_PointsMap.end(); - float * pointsBuffer = reinterpret_cast(buffer); + auto * pointsBuffer = reinterpret_cast(buffer); while (pointItr != pointEnd) { @@ -365,7 +365,7 @@ STLMeshIO ::ReadCells(void * buffer) CellsVectorType::const_iterator cellItr = this->m_CellsVector.begin(); CellsVectorType::const_iterator cellEnd = this->m_CellsVector.end(); - unsigned int * cellPointIds = reinterpret_cast(buffer); + auto * cellPointIds = reinterpret_cast(buffer); const unsigned int numberOfPointsInCell = 3; @@ -545,7 +545,7 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) const IdentifierType numberOfPolygons = this->GetNumberOfCells(); - const IdentifierType * cellsBuffer = reinterpret_cast(buffer); + const auto * cellsBuffer = reinterpret_cast(buffer); SizeValueType index = 0; @@ -562,8 +562,8 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { - const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index2++]); - const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index2++]); + const auto cellType = static_cast(cellsBuffer[index2++]); + const auto numberOfVerticesInCell = static_cast(cellsBuffer[index2++]); const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); @@ -623,7 +623,7 @@ STLMeshIO ::WriteCellsAsAscii(void * buffer) const IdentifierType numberOfPolygons = this->GetNumberOfCells(); - const IdentifierType * cellsBuffer = reinterpret_cast(buffer); + const auto * cellsBuffer = reinterpret_cast(buffer); SizeValueType index = 0; @@ -631,8 +631,8 @@ STLMeshIO ::WriteCellsAsAscii(void * buffer) for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { - const MeshIOBase::CellGeometryType cellType = static_cast(cellsBuffer[index++]); - const IdentifierType numberOfVerticesInCell = static_cast(cellsBuffer[index++]); + const auto cellType = static_cast(cellsBuffer[index++]); + const auto numberOfVerticesInCell = static_cast(cellsBuffer[index++]); const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); From 05a3eb53bd1da38c78b546048f4dc7092963c789 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 12 Feb 2018 23:29:57 -0600 Subject: [PATCH 41/73] STYLE: Prefer C++11 type alias over typedef == http://en.cppreference.com/w/cpp/language/type_alias == Type alias is a name that refers to a previously defined type (similar to typedef). A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id. It does not introduce a new type and it cannot change the meaning of an existing type name. There is no difference between a type alias declaration and typedef declaration. This declaration may appear in block scope, class scope, or namespace scope. == https://www.quora.com/Is-using-typedef-in-C++-considered-a-bad-practice == While typedef is still available for backward compatibility, the new Type Alias syntax 'using Alias = ExistingLongName;' is more consistent with the flow of C++ than the old typedef syntax 'typedef ExistingLongName Alias;', and it also works for templates (Type alias, alias template (since C++11)), so leftover 'typedef' aliases will differ in style from any alias templates. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 26 +++++++++---------- .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 10 +++---- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 26 +++++++++---------- .../IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 8 +++--- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 2d5d30ea3a3..aeb997cde7a 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -38,11 +38,11 @@ namespace itk class IOSTL_EXPORT STLMeshIO : public MeshIOBase { public: - /** Standard "Self" typedef. */ - typedef STLMeshIO Self; - typedef MeshIOBase Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; + /** Standard "Self" type alias. */ + using Self = STLMeshIO; + using Superclass = MeshIOBase; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; /** Method for creation through the object factory. */ itkNewMacro(Self); @@ -192,13 +192,13 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase std::string m_InputLine; // helper during reading - typedef float PointValueType; // type to represent point coordinates + using PointValueType = float; // type to represent point coordinates - typedef Point PointType; - typedef Vector VectorType; - typedef CovariantVector NormalType; + using PointType = Point; + using VectorType = Vector; + using NormalType = CovariantVector; - typedef std::vector PointContainerType; + using PointContainerType = std::vector; /** Helper functions to write elements to binary file */ void @@ -269,7 +269,7 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase } }; - typedef std::map PointsMapType; + using PointsMapType = std::map; PointsMapType m_PointsMap; @@ -288,8 +288,8 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase TripletType m_TrianglePointIds; unsigned int m_PointInTriangleCounter; - typedef std::vector CellsVectorType; - CellsVectorType m_CellsVector; + using CellsVectorType = std::vector; + CellsVectorType m_CellsVector; }; } // end namespace itk diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 84ce378c299..d0939237434 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -33,11 +33,11 @@ namespace itk class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase { public: - /** Standard class typedefs. */ - typedef STLMeshIOFactory Self; - typedef ObjectFactoryBase Superclass; - typedef SmartPointer Pointer; - typedef SmartPointer ConstPointer; + /** Standard class type alias. */ + using Self = STLMeshIOFactory; + using Superclass = ObjectFactoryBase; + using Pointer = SmartPointer; + using ConstPointer = SmartPointer; /** Class methods used to interface with the registered factories. */ const char * diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 70b5f639ca8..ef08e6d9ec4 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -444,79 +444,79 @@ STLMeshIO ::WritePoints(void * buffer) { case UCHAR: { - typedef unsigned char CoordType; + using CoordType = unsigned char; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case CHAR: { - typedef char CoordType; + using CoordType = char; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case USHORT: { - typedef unsigned short CoordType; + using CoordType = unsigned short; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case SHORT: { - typedef short CoordType; + using CoordType = short; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case UINT: { - typedef unsigned int CoordType; + using CoordType = unsigned int; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case INT: { - typedef int CoordType; + using CoordType = int; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case ULONG: { - typedef unsigned long CoordType; + using CoordType = unsigned long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case LONG: { - typedef long CoordType; + using CoordType = long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case ULONGLONG: { - typedef unsigned long long CoordType; + using CoordType = unsigned long long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case LONGLONG: { - typedef long long CoordType; + using CoordType = long long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case FLOAT: { - typedef float CoordType; + using CoordType = float; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case DOUBLE: { - typedef double CoordType; + using CoordType = double; this->WritePointsTyped(reinterpret_cast(buffer)); break; } case LDOUBLE: { - typedef long double CoordType; + using CoordType = long double; this->WritePointsTyped(reinterpret_cast(buffer)); break; } diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 76c922be424..ad1da619f69 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -34,14 +34,14 @@ itkSTLMeshIOTest(int argc, char * argv[]) } const unsigned int Dimension = 3; - typedef float PixelType; + using PixelType = float; - typedef itk::QuadEdgeMesh QEMeshType; + using QEMeshType = itk::QuadEdgeMesh; itk::STLMeshIOFactory::RegisterOneFactory(); - typedef itk::MeshFileReader ReaderType; - typedef itk::MeshFileWriter WriterType; + using ReaderType = itk::MeshFileReader; + using WriterType = itk::MeshFileWriter; ReaderType::Pointer reader = ReaderType::New(); WriterType::Pointer writer = WriterType::New(); From e08b4b4fc500ec450654753307b363bc30736e98 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Tue, 13 Feb 2018 08:24:24 -0600 Subject: [PATCH 42/73] STYLE: Prefer constexpr for const numeric literals Use constexpr for constant numeric literals. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 2 +- Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index ef08e6d9ec4..753962d7156 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -367,7 +367,7 @@ STLMeshIO ::ReadCells(void * buffer) auto * cellPointIds = reinterpret_cast(buffer); - const unsigned int numberOfPointsInCell = 3; + constexpr unsigned int numberOfPointsInCell = 3; while (cellItr != cellEnd) { diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index ad1da619f69..95f40791e5c 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -33,7 +33,7 @@ itkSTLMeshIOTest(int argc, char * argv[]) return EXIT_FAILURE; } - const unsigned int Dimension = 3; + constexpr unsigned int Dimension = 3; using PixelType = float; using QEMeshType = itk::QuadEdgeMesh; From 76530e4f518dc3ae4c8910e99ee18178e6566fdd Mon Sep 17 00:00:00 2001 From: Jon Haitz Legarreta Date: Sat, 14 Apr 2018 19:13:54 +0200 Subject: [PATCH 43/73] COMP: Move ITK_DISALLOW_COPY_AND_ASSIGN calls to public section. Move `ITK_DISALLOW_COPY_AND_ASSIGN` calls to public section following the discussion in https://discourse.itk.org/t/noncopyable If legacy (pre-macro) copy and assing methods existed, subsitute them for the `ITK_DISALLOW_COPY_AND_ASSIGN` macro. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 4 ++-- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index aeb997cde7a..1ceb8d0b53f 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -38,6 +38,8 @@ namespace itk class IOSTL_EXPORT STLMeshIO : public MeshIOBase { public: + ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIO); + /** Standard "Self" type alias. */ using Self = STLMeshIO; using Superclass = MeshIOBase; @@ -185,8 +187,6 @@ class IOSTL_EXPORT STLMeshIO : public MeshIOBase private: - ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIO); - std::ofstream m_OutputStream; // output file std::ifstream m_InputStream; // input file diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index d0939237434..269358a0175 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -33,6 +33,8 @@ namespace itk class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase { public: + ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIOFactory); + /** Standard class type alias. */ using Self = STLMeshIOFactory; using Superclass = ObjectFactoryBase; @@ -67,9 +69,6 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase void PrintSelf(std::ostream & os, Indent indent) const override; - -private: - ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIOFactory); }; } // end namespace itk From c9fe725efd0658a251fd795298cb46f1b59a29e2 Mon Sep 17 00:00:00 2001 From: Jon Haitz Legarreta Date: Sat, 5 May 2018 12:43:32 +0200 Subject: [PATCH 44/73] COMP: Set the minimum required CMake version to 3.10.2. As agreed in: https://discourse.itk.org/t/cmake-update/870/ Set the `cmake_minimum_required` to version **3.10.2**. --- Modules/IO/IOMeshSTL/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 317be8e06e9..52a47f829d4 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9.5) +cmake_minimum_required(VERSION 3.10.2) project(IOSTL) set(IOSTL_LIBRARIES IOSTL) From 93f817a6faffbbc9191901efcf28ab2ed731f091 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 20 Dec 2018 23:28:49 -0500 Subject: [PATCH 45/73] ENH: Enable mesh module factory registration Also address a few minor style issues. --- .../IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 10 +++++----- Modules/IO/IOMeshSTL/itk-module.cmake | 2 ++ .../IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 269358a0175..95ad6fec9e6 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -43,10 +43,10 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase /** Class methods used to interface with the registered factories. */ const char * - GetITKSourceVersion(void) const override; + GetITKSourceVersion() const override; const char * - GetDescription(void) const override; + GetDescription() const override; /** Method for class instantiation. */ itkFactorylessNewMacro(Self); @@ -56,11 +56,11 @@ class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase /** Register one factory of this type */ static void - RegisterOneFactory(void) + RegisterOneFactory() { - STLMeshIOFactory::Pointer vtkFactory = STLMeshIOFactory::New(); + STLMeshIOFactory::Pointer meshFactory = STLMeshIOFactory::New(); - ObjectFactoryBase::RegisterFactory(vtkFactory); + ObjectFactoryBase::RegisterFactory(meshFactory); } protected: diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake index 1c08828db85..440dd6d9f81 100644 --- a/Modules/IO/IOMeshSTL/itk-module.cmake +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -12,6 +12,8 @@ itk_module( TEST_DEPENDS ITKTestKernel ITKQuadEdgeMesh + FACTORY_NAMES + MeshIO::STL DESCRIPTION "${DOCUMENTATION}" EXCLUDE_FROM_DEFAULT ) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx index fcc8c647d99..e6c880c9f3d 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -16,6 +16,7 @@ * *=========================================================================*/ +#include "IOSTLExport.h" #include "itkSTLMeshIO.h" #include "itkSTLMeshIOFactory.h" #include "itkVersion.h" @@ -34,7 +35,7 @@ STLMeshIOFactory ::STLMeshIOFactory() STLMeshIOFactory ::~STLMeshIOFactory() {} const char * -STLMeshIOFactory ::GetITKSourceVersion(void) const +STLMeshIOFactory ::GetITKSourceVersion() const { return ITK_SOURCE_VERSION; } @@ -44,4 +45,18 @@ STLMeshIOFactory ::GetDescription() const { return "STL MeshIO Factory, allows the loading of STL QuadEdgeMesh data into ITK"; } + +// Undocumented API used to register during static initialization. +// DO NOT CALL DIRECTLY. +static bool STLMeshIOFactoryHasBeenRegistered; + +void IOSTL_EXPORT +STLMeshIOFactoryRegister__Private() +{ + if (!STLMeshIOFactoryHasBeenRegistered) + { + STLMeshIOFactoryHasBeenRegistered = true; + STLMeshIOFactory::RegisterOneFactory(); + } +} } // end namespace itk From c08e845b76db5691814d9a97033a9326140784dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Fri, 21 Dec 2018 17:29:01 -0500 Subject: [PATCH 46/73] ENH: Add CI. Add CI: - Add `*.yml` configuration files for CI. - Add the `setup.py` Python setup file. - Add Python wrapping files. - Add the `CTestConfig.cmake` file to make the build results be sent to the **Insight** project in **open.cdash.org**. --- Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt | 3 +++ Modules/IO/IOMeshSTL/wrapping/itkSTLMeshIO.wrap | 2 ++ 2 files changed, 5 insertions(+) create mode 100644 Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt create mode 100644 Modules/IO/IOMeshSTL/wrapping/itkSTLMeshIO.wrap diff --git a/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt b/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt new file mode 100644 index 00000000000..5bb5423f673 --- /dev/null +++ b/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt @@ -0,0 +1,3 @@ +itk_wrap_module(SkullStrip) +itk_auto_load_submodules() +itk_end_wrap_module() diff --git a/Modules/IO/IOMeshSTL/wrapping/itkSTLMeshIO.wrap b/Modules/IO/IOMeshSTL/wrapping/itkSTLMeshIO.wrap new file mode 100644 index 00000000000..96be3782361 --- /dev/null +++ b/Modules/IO/IOMeshSTL/wrapping/itkSTLMeshIO.wrap @@ -0,0 +1,2 @@ +itk_wrap_simple_class("itk::STLMeshIO" POINTER) +itk_wrap_simple_class("itk::STLMeshIOFactory" POINTER) From 53453d60ca9b0d09d56f236571e401f6fb0ea939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Fri, 21 Dec 2018 20:44:41 -0500 Subject: [PATCH 47/73] DOC: Re-use `README.rst` info in `itk-module.cmake`. Re-use `README.rst` info in `itk-module.cmake`. Helps avoiding duplications/diverging versions of the documentation. --- Modules/IO/IOMeshSTL/itk-module.cmake | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake index 1c08828db85..8af93ebaa05 100644 --- a/Modules/IO/IOMeshSTL/itk-module.cmake +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -1,8 +1,14 @@ -set( - DOCUMENTATION - "This module contains classes for reading and writing -QuadEdgeMeshes using the STL file format." -) +# the top-level README is used for describing this module, just +# re-used it for documentation here +get_filename_component(MY_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +file(READ "${MY_CURRENT_DIR}/README.md" DOCUMENTATION) + +# itk_module() defines the module dependencies in IOSTL +# The testing module in IOSTL depends on ITKTestKernel +# By convention those modules outside of ITK are not prefixed with +# ITK. + +# define the dependencies of the include module and the tests itk_module( IOSTL ENABLE_SHARED From 6183f4a07656af7a12f37d893c39d3b144aa32f7 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 19 Jan 2019 17:45:00 -0500 Subject: [PATCH 48/73] BUG: Set PointDimension to 3 STL meshes are always 3D. The default is 0. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 753962d7156..cd42f4d41c0 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -38,6 +38,8 @@ STLMeshIO ::STLMeshIO() // STL uses UINT32 to store the number of points, // hence the point Ids are of the same UINT32 type. this->SetCellComponentType(UINT); + + this->SetPointDimension(3); } bool From e216d8f8501f824bdbaf3f9758b902b966272915 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 19 Jan 2019 17:47:39 -0500 Subject: [PATCH 49/73] BUG: Fix wrapping module name --- Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt b/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt index 5bb5423f673..22ecdf90abd 100644 --- a/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt @@ -1,3 +1,3 @@ -itk_wrap_module(SkullStrip) +itk_wrap_module(IOSTL) itk_auto_load_submodules() itk_end_wrap_module() From a2045b0d093926ef212b837dc01ca1dadd3f1b2b Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sun, 20 Jan 2019 20:52:19 -0500 Subject: [PATCH 50/73] ENH: Make module name consistent with conventions Since the repository name is ITKIOMeshSTL and it is an external/remote module, name the module IOMeshSTL according to our naming convention. --- Modules/IO/IOMeshSTL/CMakeLists.txt | 4 ++-- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 6 +++--- .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 6 +++--- Modules/IO/IOMeshSTL/itk-module.cmake | 6 +++--- Modules/IO/IOMeshSTL/src/CMakeLists.txt | 10 +++++----- .../IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 4 ++-- Modules/IO/IOMeshSTL/test/CMakeLists.txt | 20 +++++++++---------- Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt | 2 +- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 52a47f829d4..90a56f1297b 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.10.2) -project(IOSTL) -set(IOSTL_LIBRARIES IOSTL) +project(IOMeshSTL) +set(IOMeshSTL_LIBRARIES IOMeshSTL) if(NOT ITK_SOURCE_DIR) find_package(ITK REQUIRED) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 1ceb8d0b53f..23b6a3f8b30 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -18,7 +18,7 @@ #ifndef itkSTLMeshIO_h #define itkSTLMeshIO_h -#include "IOSTLExport.h" +#include "IOMeshSTLExport.h" #include "itkMeshIOBase.h" @@ -33,9 +33,9 @@ namespace itk * \author Luis Ibanez, Kitware Inc. * * \ingroup IOFilters - * \ingroup IOSTL + * \ingroup IOMeshSTL */ -class IOSTL_EXPORT STLMeshIO : public MeshIOBase +class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase { public: ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIO); diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 95ad6fec9e6..bc06fffed3f 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -18,7 +18,7 @@ #ifndef itkSTLMeshIOFactory_h #define itkSTLMeshIOFactory_h -#include "IOSTLExport.h" +#include "IOMeshSTLExport.h" #include "itkObjectFactoryBase.h" #include "itkMeshIOBase.h" @@ -28,9 +28,9 @@ namespace itk /** \class STLMeshIOFactory * \brief Create instances of STLMeshIO objects using an object factory. * - * \ingroup IOSTL + * \ingroup IOMeshSTL */ -class IOSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase +class IOMeshSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase { public: ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIOFactory); diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake index 4ca6afe720e..13439b52a2c 100644 --- a/Modules/IO/IOMeshSTL/itk-module.cmake +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -3,14 +3,14 @@ get_filename_component(MY_CURRENT_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) file(READ "${MY_CURRENT_DIR}/README.md" DOCUMENTATION) -# itk_module() defines the module dependencies in IOSTL -# The testing module in IOSTL depends on ITKTestKernel +# itk_module() defines the module dependencies in IOMeshSTL +# The testing module in IOMeshSTL depends on ITKTestKernel # By convention those modules outside of ITK are not prefixed with # ITK. # define the dependencies of the include module and the tests itk_module( - IOSTL + IOMeshSTL ENABLE_SHARED DEPENDS ITKCommon diff --git a/Modules/IO/IOMeshSTL/src/CMakeLists.txt b/Modules/IO/IOMeshSTL/src/CMakeLists.txt index 685a7312de8..4ed281d28d6 100644 --- a/Modules/IO/IOMeshSTL/src/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/src/CMakeLists.txt @@ -1,18 +1,18 @@ set( - IOSTL_SRC + IOMeshSTL_SRC itkSTLMeshIO.cxx itkSTLMeshIOFactory.cxx ) add_library( - IOSTL + IOMeshSTL ${ITK_LIBRARY_BUILD_TYPE} - ${IOSTL_SRC} + ${IOMeshSTL_SRC} ) target_link_libraries( - IOSTL + IOMeshSTL ${ITKCommon_LIBRARIES} ${ITKIOMesh_LIBRARIES} ) -itk_module_target(IOSTL) +itk_module_target(IOMeshSTL) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx index e6c880c9f3d..65ae5f76209 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -16,7 +16,7 @@ * *=========================================================================*/ -#include "IOSTLExport.h" +#include "IOMeshSTLExport.h" #include "itkSTLMeshIO.h" #include "itkSTLMeshIOFactory.h" #include "itkVersion.h" @@ -50,7 +50,7 @@ STLMeshIOFactory ::GetDescription() const // DO NOT CALL DIRECTLY. static bool STLMeshIOFactoryHasBeenRegistered; -void IOSTL_EXPORT +void IOMeshSTL_EXPORT STLMeshIOFactoryRegister__Private() { if (!STLMeshIOFactoryHasBeenRegistered) diff --git a/Modules/IO/IOMeshSTL/test/CMakeLists.txt b/Modules/IO/IOMeshSTL/test/CMakeLists.txt index fc19533b77c..d667e49bfcb 100644 --- a/Modules/IO/IOMeshSTL/test/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/test/CMakeLists.txt @@ -1,13 +1,13 @@ itk_module_test() -set(IOSTLTests itkSTLMeshIOTest.cxx) +set(IOMeshSTLTests itkSTLMeshIOTest.cxx) -createtestdriver(IOSTL "${IOSTL-Test_LIBRARIES}" "${IOSTLTests}" ) +createtestdriver(IOMeshSTL "${IOMeshSTL-Test_LIBRARIES}" "${IOMeshSTLTests}" ) itk_add_test( NAME itkSTLMeshIOTest00 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.vtk} ${ITK_TEST_OUTPUT_DIR}/sphere00.stl @@ -17,7 +17,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest01 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.vtk} ${ITK_TEST_OUTPUT_DIR}/sphere01.stl @@ -27,7 +27,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest02 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.stl} ${ITK_TEST_OUTPUT_DIR}/sphere02.stl @@ -37,7 +37,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest03 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/sphere.stl} ${ITK_TEST_OUTPUT_DIR}/sphere03.stl @@ -47,7 +47,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest04 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.vtk} ${ITK_TEST_OUTPUT_DIR}/tetrahedron01.stl @@ -57,7 +57,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest05 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.vtk} ${ITK_TEST_OUTPUT_DIR}/tetrahedron02.stl @@ -67,7 +67,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest06 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.stl} ${ITK_TEST_OUTPUT_DIR}/tetrahedron03.stl @@ -77,7 +77,7 @@ itk_add_test( itk_add_test( NAME itkSTLMeshIOTest07 COMMAND - IOSTLTestDriver + IOMeshSTLTestDriver itkSTLMeshIOTest DATA{Baseline/tetrahedron.stl} ${ITK_TEST_OUTPUT_DIR}/tetrahedron04.stl diff --git a/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt b/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt index 22ecdf90abd..acc04954e53 100644 --- a/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/wrapping/CMakeLists.txt @@ -1,3 +1,3 @@ -itk_wrap_module(IOSTL) +itk_wrap_module(IOMeshSTL) itk_auto_load_submodules() itk_end_wrap_module() From efcab1b7acae8b4235eadc42f122e8ad4dacafde Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Thu, 24 Jan 2019 16:19:06 -0500 Subject: [PATCH 51/73] BUG: Set NumberOfCells for ASCII files --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 1 + Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index cd42f4d41c0..0d8f6ad8759 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -204,6 +204,7 @@ STLMeshIO ::ReadMeshInternalFromAscii() } this->SetNumberOfPoints(this->m_PointsMap.size()); + this->SetNumberOfCells(this->m_CellsVector.size()); // // The factor 5 accounts for five integers diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 95f40791e5c..508f075262f 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -63,9 +63,6 @@ itkSTLMeshIOTest(int argc, char * argv[]) reader->Update(); QEMeshType * mesh = reader->GetOutput(); - mesh->Print(std::cout); - - writer->SetInput(reader->GetOutput()); int result = EXIT_SUCCESS; @@ -85,7 +82,9 @@ itkSTLMeshIOTest(int argc, char * argv[]) // itk::STLMeshIO::Pointer meshIO = itk::STLMeshIO::New(); - meshIO->Print(std::cout); + mesh->Print(std::cout); + reader->GetMeshIO()->Print(std::cout); + writer->GetMeshIO()->Print(std::cout); // // Report the System Endianness From 30c6d8775ebfbe29325d85e85348ce5cbeb90a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sat, 26 Jan 2019 18:20:27 -0500 Subject: [PATCH 52/73] STYLE: Improve test style. Improve test style: - Use the `TRY_EXPECT_NO_EXCEPTION` macro to avoid boilerplate code. - Add a test ending message as recommened by the ITK SW Guide. Take advantage to call the `EXERCISE_BASIC_OBJECT_METHODS` macro to improve coverage. --- Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 508f075262f..c7f669adeb5 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -21,6 +21,7 @@ #include "itkSTLMeshIO.h" #include "itkMeshFileReader.h" #include "itkMeshFileWriter.h" +#include "itkTestingMacros.h" int itkSTLMeshIOTest(int argc, char * argv[]) @@ -65,23 +66,16 @@ itkSTLMeshIOTest(int argc, char * argv[]) writer->SetInput(reader->GetOutput()); - int result = EXIT_SUCCESS; + TRY_EXPECT_NO_EXCEPTION(writer->Update()); - try - { - writer->Update(); - } - catch (itk::ExceptionObject & excp) - { - std::cerr << excp << std::endl; - result = EXIT_FAILURE; - } // // Exercising additional methods // itk::STLMeshIO::Pointer meshIO = itk::STLMeshIO::New(); + EXERCISE_BASIC_OBJECT_METHODS(meshIO, STLMeshIO, MeshIOBase); + mesh->Print(std::cout); reader->GetMeshIO()->Print(std::cout); writer->GetMeshIO()->Print(std::cout); @@ -99,5 +93,7 @@ itkSTLMeshIOTest(int argc, char * argv[]) std::cout << "This system is Big Endian" << std::endl; } - return result; + + std::cout << "Test finished." << std::endl; + return EXIT_SUCCESS; } From cd85e79f3b5d0ad64f98308f6f6e91679bebb13f Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 15 Feb 2019 14:15:04 -0500 Subject: [PATCH 53/73] BUG: Dependency is on ITKIOMeshBase vs ITKIOMesh --- Modules/IO/IOMeshSTL/itk-module.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/itk-module.cmake b/Modules/IO/IOMeshSTL/itk-module.cmake index 13439b52a2c..7d1208b98d2 100644 --- a/Modules/IO/IOMeshSTL/itk-module.cmake +++ b/Modules/IO/IOMeshSTL/itk-module.cmake @@ -14,7 +14,7 @@ itk_module( ENABLE_SHARED DEPENDS ITKCommon - ITKIOMesh + ITKIOMeshBase TEST_DEPENDS ITKTestKernel ITKQuadEdgeMesh From 9eff1236e503b3e33cef29c45058f1f0728eddbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Fri, 14 Jun 2019 20:27:38 -0400 Subject: [PATCH 54/73] STYLE: Add ITK prefix to testing macros --- Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index c7f669adeb5..9ca0b97a9d7 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -66,7 +66,7 @@ itkSTLMeshIOTest(int argc, char * argv[]) writer->SetInput(reader->GetOutput()); - TRY_EXPECT_NO_EXCEPTION(writer->Update()); + ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update()); // @@ -74,7 +74,7 @@ itkSTLMeshIOTest(int argc, char * argv[]) // itk::STLMeshIO::Pointer meshIO = itk::STLMeshIO::New(); - EXERCISE_BASIC_OBJECT_METHODS(meshIO, STLMeshIO, MeshIOBase); + ITK_EXERCISE_BASIC_OBJECT_METHODS(meshIO, STLMeshIO, MeshIOBase); mesh->Print(std::cout); reader->GetMeshIO()->Print(std::cout); From 5d9171ceeeec2dffe954a5d3a39139a7020b8ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Fri, 16 Aug 2019 14:18:10 -0400 Subject: [PATCH 55/73] COMP: fix link errors Creating library C:/Libs/ITK-5.0.1-vs2015/lib/Debug/itkIOMeshSTL-5.0.lib and object C:/Libs/ITK-5.0.1-vs2015/lib/Debug/itkIOMeshSTL-5.0.exp itkSTLMeshIO.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __cdecl itk::MeshIOBase::SetPointComponentType(enum itk::MeshIOBase::IOComponentType)" (__imp_?SetPointComponentType@MeshIOBase@itk@@UEAAXW4IOComponentType@12@@Z) referenced in function "protected: __cdecl itk::STLMeshIO::STLMeshIO(void)" (??0STLMeshIO@itk@@IEAA@XZ) --- Modules/IO/IOMeshSTL/src/CMakeLists.txt | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/CMakeLists.txt b/Modules/IO/IOMeshSTL/src/CMakeLists.txt index 4ed281d28d6..e2e927802e4 100644 --- a/Modules/IO/IOMeshSTL/src/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/src/CMakeLists.txt @@ -1,18 +1,6 @@ -set( - IOMeshSTL_SRC +set(IOMeshSTL_SRC itkSTLMeshIO.cxx itkSTLMeshIOFactory.cxx ) -add_library( - IOMeshSTL - ${ITK_LIBRARY_BUILD_TYPE} - ${IOMeshSTL_SRC} -) -target_link_libraries( - IOMeshSTL - ${ITKCommon_LIBRARIES} - ${ITKIOMesh_LIBRARIES} -) - -itk_module_target(IOMeshSTL) +itk_module_add_library(IOMeshSTL ${ITK_LIBRARY_BUILD_TYPE} ${IOMeshSTL_SRC}) From 9c2f1cee322b11499ba908c8dc7d86868f4cdccc Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 16 Feb 2020 12:09:47 -0600 Subject: [PATCH 56/73] COMP: Enumeration type to store as unsigned int Explicit static cast needed to convert enumerations. --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 0d8f6ad8759..6e07d9014ec 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -368,14 +368,15 @@ STLMeshIO ::ReadCells(void * buffer) CellsVectorType::const_iterator cellItr = this->m_CellsVector.begin(); CellsVectorType::const_iterator cellEnd = this->m_CellsVector.end(); - auto * cellPointIds = reinterpret_cast(buffer); + using CellIDType = unsigned int; + auto * cellPointIds = reinterpret_cast(buffer); constexpr unsigned int numberOfPointsInCell = 3; while (cellItr != cellEnd) { - *cellPointIds++ = MeshIOBase::TRIANGLE_CELL; + *cellPointIds++ = static_cast(MeshIOBase::TRIANGLE_CELL); *cellPointIds++ = numberOfPointsInCell; // From e85d651b08057f281f72a53a3ca1cb95bd6890ce Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 16 Feb 2020 19:08:58 -0600 Subject: [PATCH 57/73] STYLE: Make prototype match definition names Enforce consistency in large projects, where it often happens that a definition of function is refactored, changing the parameter names, but its declaration in header file is not updated. With this check, we can easily find and correct such inconsistencies, keeping declaration and definition always in sync. Unnamed parameters are allowed and are not taken into account when comparing function declarations --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 23b6a3f8b30..9f6529bc5c7 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -60,7 +60,7 @@ class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase * \return Returns true if this MeshIO can read the file specified. */ bool - CanReadFile(const char * FileNameToRead) override; + CanReadFile(const char * fileName) override; /** Read the content of the file into a Mesh. */ virtual void @@ -101,7 +101,7 @@ class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase * \return Returns true if this MeshIO can write the file specified. */ bool - CanWriteFile(const char * FileNameToWrite) override; + CanWriteFile(const char * fileName) override; /** Write header of the STL file */ void @@ -228,7 +228,7 @@ class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase /** Helper functions to read elements from ASCII files. */ void - ReadStringFromAscii(const std::string & keyword); + ReadStringFromAscii(const std::string & expected); void ReadPointAsAscii(PointType & point); bool From 8505e7c05324ee28851d37fb9478e8ff58647394 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Sun, 16 Feb 2020 22:07:45 -0600 Subject: [PATCH 58/73] STYLE: Replace integer literals which are cast to bool. Finds and replaces integer literals which are cast to bool. SRCDIR= #My local SRC BLDDIR= #My local BLD cd run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-bool-literals -header-filter=.* -fix --- Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx index 65ae5f76209..21951f5cc38 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -29,7 +29,7 @@ STLMeshIOFactory ::PrintSelf(std::ostream &, Indent) const STLMeshIOFactory ::STLMeshIOFactory() { - this->RegisterOverride("itkMeshIOBase", "itkSTLMeshIO", "STL IO", 1, CreateObjectFunction::New()); + this->RegisterOverride("itkMeshIOBase", "itkSTLMeshIO", "STL IO", true, CreateObjectFunction::New()); } STLMeshIOFactory ::~STLMeshIOFactory() {} From 0c7f3a378e766ab5cc1d0ca769a31f2699777ae7 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Mon, 17 Feb 2020 11:58:48 -0600 Subject: [PATCH 59/73] STYLE: Pefer = default to explicitly trivial implementations This check replaces default bodies of special member functions with = default;. The explicitly defaulted function declarations enable more opportunities in optimization, because the compiler might treat explicitly defaulted functions as trivial. Additionally, the C++11 use of = default more clearly expreses the intent for the special member functions. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 2 +- Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 9f6529bc5c7..26113bb7bf1 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -149,7 +149,7 @@ class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase protected: STLMeshIO(); - ~STLMeshIO() override {} + ~STLMeshIO() override = default; void PrintSelf(std::ostream & os, Indent indent) const override; diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx index 21951f5cc38..13584b23e11 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -32,7 +32,7 @@ STLMeshIOFactory ::STLMeshIOFactory() this->RegisterOverride("itkMeshIOBase", "itkSTLMeshIO", "STL IO", true, CreateObjectFunction::New()); } -STLMeshIOFactory ::~STLMeshIOFactory() {} +STLMeshIOFactory ::~STLMeshIOFactory() = default; const char * STLMeshIOFactory ::GetITKSourceVersion() const From f00a465a17cd3ada3a224f042ff38bcf301af482 Mon Sep 17 00:00:00 2001 From: Mathew Seng Date: Tue, 18 Feb 2020 09:02:19 -0600 Subject: [PATCH 60/73] ENH: Update enums from recent enum changes in ITK --- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 66 ++++++++++++----------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 6e07d9014ec..144fd90e32f 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -33,11 +33,11 @@ STLMeshIO ::STLMeshIO() this->AddSupportedWriteExtension(".STL"); // STL uses float type by default to store point data - this->SetPointComponentType(FLOAT); + this->SetPointComponentType(IOComponentEnum::FLOAT); // STL uses UINT32 to store the number of points, // hence the point Ids are of the same UINT32 type. - this->SetCellComponentType(UINT); + this->SetCellComponentType(IOComponentEnum::UINT); this->SetPointDimension(3); } @@ -82,11 +82,11 @@ STLMeshIO ::ReadMeshInformation() { // Use default filetype - if (this->GetFileType() == ASCII) + if (this->GetFileType() == IOFileEnum::ASCII) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); } - else if (this->GetFileType() == BINARY) + else if (this->GetFileType() == IOFileEnum::BINARY) { this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); } @@ -119,9 +119,9 @@ STLMeshIO ::ReadMeshInformation() // Determine file type if (inputFileIsASCII) { - if (this->GetFileType() != ASCII) + if (this->GetFileType() != IOFileEnum::ASCII) { - this->SetFileType(ASCII); + this->SetFileType(IOFileEnum::ASCII); #ifdef _WIN32 this->m_InputStream.close(); this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in); @@ -139,9 +139,9 @@ STLMeshIO ::ReadMeshInformation() } else { - if (this->GetFileType() != BINARY) + if (this->GetFileType() != IOFileEnum::BINARY) { - this->SetFileType(BINARY); + this->SetFileType(IOFileEnum::BINARY); #ifdef _WIN32 this->m_InputStream.close(); this->m_InputStream.open(this->m_FileName.c_str(), std::ios::in | std::ios::binary); @@ -376,7 +376,7 @@ STLMeshIO ::ReadCells(void * buffer) while (cellItr != cellEnd) { - *cellPointIds++ = static_cast(MeshIOBase::TRIANGLE_CELL); + *cellPointIds++ = static_cast(CellGeometryEnum::TRIANGLE_CELL); *cellPointIds++ = numberOfPointsInCell; // @@ -396,11 +396,11 @@ STLMeshIO ::WriteMeshInformation() { // Use default filetype - if (this->GetFileType() == ASCII) + if (this->GetFileType() == IOFileEnum::ASCII) { this->m_OutputStream.open(this->m_FileName.c_str(), std::ios::out); } - else if (this->GetFileType() == BINARY) + else if (this->GetFileType() == IOFileEnum::BINARY) { this->m_OutputStream.open(this->m_FileName.c_str(), std::ios::out | std::ios::binary); } @@ -413,11 +413,11 @@ STLMeshIO ::WriteMeshInformation() return; } - if (this->GetFileType() == ASCII) + if (this->GetFileType() == IOFileEnum::ASCII) { this->m_OutputStream << "solid ascii" << std::endl; } - else if (this->GetFileType() == BINARY) + else if (this->GetFileType() == IOFileEnum::BINARY) { // // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL @@ -442,83 +442,83 @@ void STLMeshIO ::WritePoints(void * buffer) { - const IOComponentType pointValueType = this->GetPointComponentType(); + const IOComponentEnum pointValueType = this->GetPointComponentType(); switch (pointValueType) { - case UCHAR: + case IOComponentEnum::UCHAR: { using CoordType = unsigned char; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case CHAR: + case IOComponentEnum::CHAR: { using CoordType = char; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case USHORT: + case IOComponentEnum::USHORT: { using CoordType = unsigned short; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case SHORT: + case IOComponentEnum::SHORT: { using CoordType = short; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case UINT: + case IOComponentEnum::UINT: { using CoordType = unsigned int; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case INT: + case IOComponentEnum::INT: { using CoordType = int; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case ULONG: + case IOComponentEnum::ULONG: { using CoordType = unsigned long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case LONG: + case IOComponentEnum::LONG: { using CoordType = long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case ULONGLONG: + case IOComponentEnum::ULONGLONG: { using CoordType = unsigned long long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case LONGLONG: + case IOComponentEnum::LONGLONG: { using CoordType = long long; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case FLOAT: + case IOComponentEnum::FLOAT: { using CoordType = float; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case DOUBLE: + case IOComponentEnum::DOUBLE: { using CoordType = double; this->WritePointsTyped(reinterpret_cast(buffer)); break; } - case LDOUBLE: + case IOComponentEnum::LDOUBLE: { using CoordType = long double; this->WritePointsTyped(reinterpret_cast(buffer)); @@ -533,7 +533,7 @@ STLMeshIO ::WritePoints(void * buffer) void STLMeshIO ::WriteCells(void * buffer) { - if (this->GetFileType() == BINARY) + if (this->GetFileType() == IOFileEnum::BINARY) { this->WriteCellsAsBinary(buffer); } @@ -566,10 +566,11 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { - const auto cellType = static_cast(cellsBuffer[index2++]); + const auto cellType = static_cast(cellsBuffer[index2++]); const auto numberOfVerticesInCell = static_cast(cellsBuffer[index2++]); - const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); + const bool isTriangle = (cellType == CellGeometryEnum::TRIANGLE_CELL) || + (cellType == CellGeometryEnum::POLYGON_CELL && numberOfVerticesInCell == 3); if (isTriangle) { @@ -635,10 +636,11 @@ STLMeshIO ::WriteCellsAsAscii(void * buffer) for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { - const auto cellType = static_cast(cellsBuffer[index++]); + const auto cellType = static_cast(cellsBuffer[index++]); const auto numberOfVerticesInCell = static_cast(cellsBuffer[index++]); - const bool isTriangle = (cellType == TRIANGLE_CELL) || (cellType == POLYGON_CELL && numberOfVerticesInCell == 3); + const bool isTriangle = (cellType == CellGeometryEnum::TRIANGLE_CELL) || + (cellType == CellGeometryEnum::POLYGON_CELL && numberOfVerticesInCell == 3); if (!isTriangle) { From 4f236e04f67ed6ad21c5fd0130b0ad2d9393e598 Mon Sep 17 00:00:00 2001 From: Hans Johnson Date: Wed, 19 Feb 2020 10:45:25 -0600 Subject: [PATCH 61/73] DOC: Update copyright assignment to NumFOCUS The mission of NumFOCUS is to promote open practices in research, data, and scientific computing. https://numfocus.org --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 2 +- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 2 +- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 2 +- Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 2 +- Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 26113bb7bf1..099f5cc5b70 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index bc06fffed3f..5a3b38077ce 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 144fd90e32f..455ce1d1608 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx index 13584b23e11..e77b333688a 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 9ca0b97a9d7..1e584f3f0c5 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -1,6 +1,6 @@ /*========================================================================= * - * Copyright Insight Software Consortium + * Copyright NumFOCUS * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From b09fb2656c63cb768fccd6869f31b0f707fb1191 Mon Sep 17 00:00:00 2001 From: Mathew Seng Date: Wed, 14 Oct 2020 11:19:21 -0500 Subject: [PATCH 62/73] STYLE: Rename ITK_DISALLOW_COPY_AND_ASSIGN to ITK_DISALLOW_COPY_AND_MOVE Fixes changes made in #2053. ITK_DISALLOW_COPY_AND_ASSIGN will be used if ITK_FUTURE_LEGACY_REMOVE=OFF. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 2 +- Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 099f5cc5b70..04d53fff838 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -38,7 +38,7 @@ namespace itk class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase { public: - ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIO); + ITK_DISALLOW_COPY_AND_MOVE(STLMeshIO); /** Standard "Self" type alias. */ using Self = STLMeshIO; diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 5a3b38077ce..9c3db7a7fb5 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -33,7 +33,7 @@ namespace itk class IOMeshSTL_EXPORT STLMeshIOFactory : public ObjectFactoryBase { public: - ITK_DISALLOW_COPY_AND_ASSIGN(STLMeshIOFactory); + ITK_DISALLOW_COPY_AND_MOVE(STLMeshIOFactory); /** Standard class type alias. */ using Self = STLMeshIOFactory; From 1b1bf327ca554bb01ce1ac0982b9b936c2521f1d Mon Sep 17 00:00:00 2001 From: Tom Birdsong Date: Wed, 1 Jun 2022 08:46:47 -0400 Subject: [PATCH 63/73] ENH: Bump ITK and replace http with https --- Modules/IO/IOMeshSTL/LICENSE | 4 +-- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 2 +- .../IOMeshSTL/include/itkSTLMeshIOFactory.h | 2 +- Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 30 +++++++++---------- .../IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx | 2 +- .../IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Modules/IO/IOMeshSTL/LICENSE b/Modules/IO/IOMeshSTL/LICENSE index d6456956733..62589edd12a 100644 --- a/Modules/IO/IOMeshSTL/LICENSE +++ b/Modules/IO/IOMeshSTL/LICENSE @@ -1,7 +1,7 @@ Apache License Version 2.0, January 2004 - http://www.apache.org/licenses/ + https://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION @@ -193,7 +193,7 @@ 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 + https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 04d53fff838..0e96e184fb2 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -6,7 +6,7 @@ * 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 + * https://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, diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h index 9c3db7a7fb5..4e6cc79235b 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIOFactory.h @@ -6,7 +6,7 @@ * 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 + * https://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, diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 455ce1d1608..1bae38ac578 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -6,7 +6,7 @@ * 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 + * https://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, @@ -180,7 +180,7 @@ STLMeshIO ::ReadMeshInternalFromAscii() while (!this->CheckStringFromAscii("endsolid")) { // - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // // facet normal ni nj nk // outer loop @@ -257,7 +257,7 @@ void STLMeshIO ::ReadMeshInternalFromBinary() { // - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // // UINT8[80] header // @@ -277,7 +277,7 @@ STLMeshIO ::ReadMeshInternalFromBinary() // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&numberOfTriangles); @@ -420,7 +420,7 @@ STLMeshIO ::WriteMeshInformation() else if (this->GetFileType() == IOFileEnum::BINARY) { // - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // // UINT8[80] header // @@ -556,7 +556,7 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) NormalType normal; // - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // // UINT32 -- Number of Triangles // @@ -601,7 +601,7 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) CrossProduct(normal, v12, v10); // - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // // foreach triangle // REAL32[3] – Normal vector @@ -677,7 +677,7 @@ STLMeshIO ::WriteInt32AsBinary(int32_t value) { // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); @@ -689,7 +689,7 @@ STLMeshIO ::WriteInt16AsBinary(int16_t value) { // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); @@ -704,7 +704,7 @@ STLMeshIO ::WriteNormalAsBinary(const NormalType & normal) float value = normal[i]; // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); @@ -720,7 +720,7 @@ STLMeshIO ::WritePointAsBinary(const PointType & point) float value = point[i]; // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); @@ -737,7 +737,7 @@ STLMeshIO ::ReadNormalAsBinary(NormalType & normal) this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); normal[i] = value; @@ -751,7 +751,7 @@ STLMeshIO ::ReadInt32AsBinary(int32_t & value) this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); } @@ -763,7 +763,7 @@ STLMeshIO ::ReadInt16AsBinary(int16_t & value) this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); } @@ -778,7 +778,7 @@ STLMeshIO ::ReadPointAsBinary(PointType & point) this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); // // Binary values in STL files are expected to be in little endian - // http://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL + // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL // ByteSwapper::SwapFromSystemToLittleEndian(&value); point[i] = value; diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx index e77b333688a..8653dfe6de6 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIOFactory.cxx @@ -6,7 +6,7 @@ * 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 + * https://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, diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index 1e584f3f0c5..a887c58a95f 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -6,7 +6,7 @@ * 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 + * https://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, From df365ebb1a33158246fa17a1275cc766ef8954e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Wed, 28 Dec 2022 16:42:11 -0500 Subject: [PATCH 64/73] COMP: Match CMake minimum required version to ITK's Match CMake minimum required version to ITK's. Fixes: ``` CMake Warning at D:/a/ITKIOMeshSTL/ITK/CMake/ITKModuleExternal.cmake:12 (message): -- cmake_minimum_required of 3.10.2 is not enough. cmake_minimum_required must be at least 3.16.3 Call Stack (most recent call first): CMakeLists.txt:8 (include) -- This is needed to allow proper setting of CMAKE_MSVC_RUNTIME_LIBRARY. -- Do not be surprised if you run into link errors of the style: LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_Static' doesn't match value 'MDd_Dynamic' in module.obj ``` raised for example at: https://open.cdash.org/build/8362376/configure --- Modules/IO/IOMeshSTL/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 90a56f1297b..45deffbedea 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10.2) +cmake_minimum_required(VERSION 3.16.3) project(IOMeshSTL) set(IOMeshSTL_LIBRARIES IOMeshSTL) From b02d674ed72e243c09851850c781c407c46d49ae Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Wed, 22 Apr 2026 18:52:43 -0500 Subject: [PATCH 65/73] ENH: Convert from md5 to .cid tags. --- Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.cid | 1 + Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 | 1 - Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.cid | 1 + Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 | 1 - Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.cid | 1 + Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 | 1 - Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.cid | 1 + Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 | 1 - 8 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.cid delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.cid delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.cid delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 create mode 100644 Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.cid delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.cid b/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.cid new file mode 100644 index 00000000000..00350e63653 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.cid @@ -0,0 +1 @@ +bafkreigjpheqapzh2bfdd7prplhccxc4kr452lgkjmmbigqidlos2slrzm diff --git a/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 b/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 deleted file mode 100644 index 3e9f76652ae..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/sphere.stl.md5 +++ /dev/null @@ -1 +0,0 @@ -545c2293b16e250f25395dabbaa53cbb diff --git a/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.cid b/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.cid new file mode 100644 index 00000000000..fb4ce908e40 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.cid @@ -0,0 +1 @@ +bafkreicks2ostzx2se6mfkbcgx3my5rpil4lwguga4gwomcjwo6rr5eyga diff --git a/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 b/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 deleted file mode 100644 index 44f4f16d7bd..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/sphere.vtk.md5 +++ /dev/null @@ -1 +0,0 @@ -2327dbe1884cbf2b58071501567400f6 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.cid b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.cid new file mode 100644 index 00000000000..ef63e2ea1b1 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.cid @@ -0,0 +1 @@ +bafkreidm3izfjpw456c5pezwg74xdiaoe7f6xeafo2jsnyyqgxeevrwj54 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 deleted file mode 100644 index 78055773cfb..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.stl.md5 +++ /dev/null @@ -1 +0,0 @@ -70a19e48a4393776cfe02f852f25cbe1 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.cid b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.cid new file mode 100644 index 00000000000..72bffdba630 --- /dev/null +++ b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.cid @@ -0,0 +1 @@ +bafkreihljrjpezuelqzwp5qqhhjzfnru4nvwthnjerkkffuha2t2budvpu diff --git a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 b/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 deleted file mode 100644 index eea81ea180b..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/tetrahedron.vtk.md5 +++ /dev/null @@ -1 +0,0 @@ -4cd09d26436a53a5adedb33d822cabcd From 58309d357d19af1de757cb51d1b8719b5a79cf7e Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 4 May 2026 14:50:52 -0500 Subject: [PATCH 66/73] STYLE: Apply gersemi 0.19.3 to IOMeshSTL src CMakeLists --- Modules/IO/IOMeshSTL/src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/src/CMakeLists.txt b/Modules/IO/IOMeshSTL/src/CMakeLists.txt index e2e927802e4..1ab15198734 100644 --- a/Modules/IO/IOMeshSTL/src/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/src/CMakeLists.txt @@ -1,4 +1,5 @@ -set(IOMeshSTL_SRC +set( + IOMeshSTL_SRC itkSTLMeshIO.cxx itkSTLMeshIOFactory.cxx ) From 8c09e1d45a19e88982a9807d59beaf9dc7e11b0a Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 4 May 2026 14:50:56 -0500 Subject: [PATCH 67/73] DOC: Add IOMeshSTL module README pointing at archived upstream --- Modules/IO/IOMeshSTL/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Modules/IO/IOMeshSTL/README.md diff --git a/Modules/IO/IOMeshSTL/README.md b/Modules/IO/IOMeshSTL/README.md new file mode 100644 index 00000000000..41cf600827d --- /dev/null +++ b/Modules/IO/IOMeshSTL/README.md @@ -0,0 +1,22 @@ +# IOMeshSTL + +In-tree ITK module providing read/write support for the +stereolithography (STL) mesh format, in both ASCII and binary +encodings. STL is the canonical interchange format for 3D-printing, +CAD, and surgical-planning workflows. + +The flagship classes are `itk::STLMeshIO` and the `STLMeshIOFactory` +plug-in registration that lets `itk::MeshFileReader` / +`itk::MeshFileWriter` discover STL automatically. + +## Origin + +Ingested from the standalone remote module +[**InsightSoftwareConsortium/ITKIOMeshSTL**](https://github.com/InsightSoftwareConsortium/ITKIOMeshSTL) +on 2026-05-04 via the v4 ingestion pipeline. The upstream repository +will be archived read-only after this PR merges; it remains +reachable at the URL above for historical reference. + +## References + +- Mueller D. *STL file format reader and writer for ITK.* The Insight Journal. 2014. From 0d5331daec93c863f8b9f0135f3432df87b22171 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 4 May 2026 14:50:59 -0500 Subject: [PATCH 68/73] COMP: Remove IOMeshSTL remote-fetch cmake (now in-tree) --- Modules/Remote/IOMeshSTL.remote.cmake | 52 --------------------------- 1 file changed, 52 deletions(-) delete mode 100644 Modules/Remote/IOMeshSTL.remote.cmake diff --git a/Modules/Remote/IOMeshSTL.remote.cmake b/Modules/Remote/IOMeshSTL.remote.cmake deleted file mode 100644 index 9c7d3c44612..00000000000 --- a/Modules/Remote/IOMeshSTL.remote.cmake +++ /dev/null @@ -1,52 +0,0 @@ -#-- # Grading Level Criteria Report -#-- EVALUATION DATE: 2020-03-01 -#-- EVALUATORS: [<>,<>] -#-- -#-- ## Compliance level 5 star (AKA ITK main modules, or remote modules that could become core modules) -#-- - [ ] Widespread community dependance -#-- - [ ] Above 90% code coverage -#-- - [ ] CI dashboards and testing monitored rigorously -#-- - [ ] Key API features are exposed in wrapping interface -#-- - [ ] All requirements of Levels 4,3,2,1 -#-- -#-- ## Compliance Level 4 star (Very high-quality code, perhaps small community dependance) -#-- - [ ] Meets all ITK code style standards -#-- - [ ] No external requirements beyond those needed by ITK proper -#-- - [ ] Builds and passes tests on all supported platforms within 1 month of each core tagged release -#-- - [ ] Windows Shared Library Build with Visual Studio -#-- - [ ] Mac with clang compiller -#-- - [ ] Linux with gcc compiler -#-- - [ ] Active developer community dedicated to maintaining code-base -#-- - [ ] 75% code coverage demonstrated for testing suite -#-- - [ ] Continuous integration testing performed -#-- - [ ] All requirements of Levels 3,2,1 -#-- -#-- ## Compliance Level 3 star (Quality beta code) -#-- - [ ] API | executable interface is considered mostly stable and feature complete -#-- - [ ] 10% C0-code coverage demonstrated for testing suite -#-- - [ ] Some tests exist and pass on at least some platform -#-- - [X] All requirements of Levels 2,1 -#-- -#-- ## Compliance Level 2 star (Alpha code feature API development or niche community/execution environment dependance ) -#-- - [X] Compiles for at least 1 niche set of execution envirionments, and perhaps others -#-- (may depend on specific external tools like a java environment, or specific external libraries to work ) -#-- - [X] All requirements of Levels 1 -#-- -#-- ## Compliance Level 1 star (Pre-alpha features under development and code of unknown quality) -#-- - [X] Code complies on at least 1 platform -#-- -#-- ## Compliance Level 0 star ( Code/Feature of known poor-quality or deprecated status ) -#-- - [ ] Code reviewed and explicitly identified as not recommended for use -#-- -#-- ### Please document here any justification for the criteria above -# Code style enforced by clang-format on 2020-02-19, and clang-tidy modernizations completed - -# Contact: Luis Ibanez -itk_fetch_module( - IOMeshSTL - "This module contains classes for reading and writing QuadEdgeMeshes using - the STL (STereoLithography) file format. https://doi.org/10.54294/7rr2te" - MODULE_COMPLIANCE_LEVEL 2 - GIT_REPOSITORY https://github.com/InsightSoftwareConsortium/ITKIOMeshSTL.git - GIT_TAG 8b76de8678c1a4ec2cd177fd32c44099dcd29667 - ) From fc256109f9d49cd7c53f9ad826500a3832a3f28e Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 4 May 2026 14:51:00 -0500 Subject: [PATCH 69/73] ENH: Enable Module_IOMeshSTL in configure-ci pixi task --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 52c56027848..79285e9fbab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ cmd = '''cmake -DModule_Montage:BOOL=ON -DModule_FastBilateral:BOOL=ON -DModule_GenericLabelInterpolator:BOOL=ON + -DModule_IOMeshSTL:BOOL=ON -DModule_LabelErodeDilate:BOOL=ON -DModule_MeshNoise:BOOL=ON -DModule_MGHIO:BOOL=ON From c1a9bc7df351ca721788a10cfdedc0772c4d6654 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Mon, 4 May 2026 15:17:49 -0500 Subject: [PATCH 70/73] =?UTF-8?q?BUG:=20IOMeshSTL=20=E2=80=94=20address=20?= =?UTF-8?q?Greptile=20review=20(uint32=20cells,=20cleanups)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Five concerns from Greptile's draft review of PR #6206: P1: STL binary spec is UINT32, but read/write paths declared int32_t. The high-bit case decremented through negative values (signed-integer overflow, UB) and SetNumberOfCells silently wrapped to huge unsigned IdentifierType. Switched both call sites to uint32_t and added Read/WriteUInt32AsBinary helpers (int32 helpers kept for source compat). P2: Three unreachable returns after itkExceptionMacro removed. P2: WriteMeshInformation 'Unable to open file' said 'inputFilename=' while opening the OUTPUT stream. Corrected to 'outputFilename='. P2: Test reader->Update() now wrapped in ITK_TRY_EXPECT_NO_EXCEPTION to match writer->Update() and the rest of ITK's tests. P2 (greptile false positive): STLMeshIO::Read() was suggested for an override specifier. MeshIOBase has no virtual Read() to override, so 'virtual void Read();' is correct as-is. Reverted. --- Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h | 4 +++ Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx | 36 +++++++++++-------- .../IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx | 2 +- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h index 0e96e184fb2..2f04ef52c5f 100644 --- a/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h +++ b/Modules/IO/IOMeshSTL/include/itkSTLMeshIO.h @@ -204,6 +204,8 @@ class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase void WriteInt32AsBinary(int32_t value); void + WriteUInt32AsBinary(uint32_t value); + void WriteInt16AsBinary(int16_t value); void WriteNormalAsBinary(const NormalType & normal); @@ -220,6 +222,8 @@ class IOMeshSTL_EXPORT STLMeshIO : public MeshIOBase void ReadInt32AsBinary(int32_t & value); void + ReadUInt32AsBinary(uint32_t & value); + void ReadInt16AsBinary(int16_t & value); void ReadNormalAsBinary(NormalType & normal); diff --git a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx index 1bae38ac578..cdb29980442 100644 --- a/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx +++ b/Modules/IO/IOMeshSTL/src/itkSTLMeshIO.cxx @@ -96,7 +96,6 @@ STLMeshIO ::ReadMeshInformation() itkExceptionMacro("Unable to open file\n" "inputFilename= " << this->m_FileName); - return; } @@ -130,7 +129,6 @@ STLMeshIO ::ReadMeshInformation() itkExceptionMacro("Unable to open file\n" "inputFilename= " << this->m_FileName); - return; } #endif } @@ -150,7 +148,6 @@ STLMeshIO ::ReadMeshInformation() itkExceptionMacro("Unable to open file\n" "inputFilename= " << this->m_FileName); - return; } #endif } @@ -272,14 +269,8 @@ STLMeshIO ::ReadMeshInternalFromBinary() // // UINT32 -- Number of Triangles // - int32_t numberOfTriangles; - this->m_InputStream.read(reinterpret_cast(&numberOfTriangles), sizeof(numberOfTriangles)); - - // - // Binary values in STL files are expected to be in little endian - // https://en.wikipedia.org/wiki/STL_(file_format)#Binary_STL - // - ByteSwapper::SwapFromSystemToLittleEndian(&numberOfTriangles); + uint32_t numberOfTriangles; + this->ReadUInt32AsBinary(numberOfTriangles); this->SetNumberOfCells(numberOfTriangles); @@ -408,9 +399,8 @@ STLMeshIO ::WriteMeshInformation() if (!this->m_OutputStream.is_open()) { itkExceptionMacro("Unable to open file\n" - "inputFilename= " + "outputFilename= " << this->m_FileName); - return; } if (this->GetFileType() == IOFileEnum::ASCII) @@ -560,7 +550,7 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) // // UINT32 -- Number of Triangles // - int32_t numberOfTriangles = 0; + uint32_t numberOfTriangles = 0; SizeValueType index2 = 0; @@ -584,7 +574,7 @@ STLMeshIO ::WriteCellsAsBinary(void * buffer) index2 += numberOfVerticesInCell; } - this->WriteInt32AsBinary(numberOfTriangles); + this->WriteUInt32AsBinary(numberOfTriangles); for (SizeValueType polygonItr = 0; polygonItr < numberOfPolygons; polygonItr++) { @@ -684,6 +674,14 @@ STLMeshIO ::WriteInt32AsBinary(int32_t value) } +void +STLMeshIO ::WriteUInt32AsBinary(uint32_t value) +{ + ByteSwapper::SwapFromSystemToLittleEndian(&value); + this->m_OutputStream.write(reinterpret_cast(&value), sizeof(value)); +} + + void STLMeshIO ::WriteInt16AsBinary(int16_t value) { @@ -757,6 +755,14 @@ STLMeshIO ::ReadInt32AsBinary(int32_t & value) } +void +STLMeshIO ::ReadUInt32AsBinary(uint32_t & value) +{ + this->m_InputStream.read(reinterpret_cast(&value), sizeof(value)); + ByteSwapper::SwapFromSystemToLittleEndian(&value); +} + + void STLMeshIO ::ReadInt16AsBinary(int16_t & value) { diff --git a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx index a887c58a95f..d8c41cc2b6a 100644 --- a/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx +++ b/Modules/IO/IOMeshSTL/test/itkSTLMeshIOTest.cxx @@ -61,7 +61,7 @@ itkSTLMeshIOTest(int argc, char * argv[]) writer->SetFileTypeAsBINARY(); } - reader->Update(); + ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update()); QEMeshType * mesh = reader->GetOutput(); writer->SetInput(reader->GetOutput()); From 93985caf8d75edd75222b7ad528b12d8960aef76 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 06:02:42 -0500 Subject: [PATCH 71/73] COMP: Drop standalone-build wrapper from IOMeshSTL CMakeLists In-tree, ITK_SOURCE_DIR is always defined, so the 'if(NOT ITK_SOURCE_DIR) ... find_package(ITK) ... else() itk_module_impl()' guard is dead code. Address @dzenanz review comment. --- Modules/IO/IOMeshSTL/CMakeLists.txt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 45deffbedea..7aea1b33aa0 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -2,10 +2,4 @@ cmake_minimum_required(VERSION 3.16.3) project(IOMeshSTL) set(IOMeshSTL_LIBRARIES IOMeshSTL) -if(NOT ITK_SOURCE_DIR) - find_package(ITK REQUIRED) - list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR}) - include(ITKModuleExternal) -else() - itk_module_impl() -endif() +itk_module_impl() From f100c257b6b11180a65158c760efa144e90a0ab1 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 06:02:46 -0500 Subject: [PATCH 72/73] COMP: Remove leftover ExternalData cache from IOMeshSTL Baseline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Four .ExternalData_MD5_ files survived the ingest from the upstream module's local fetch cache. They are not source — ExternalData re-creates them on demand alongside the .cid sidecars they correspond to (sphere.{stl,vtk}, tetrahedron.{stl,vtk}). Address @dzenanz review comment. --- ...lData_MD5_2327dbe1884cbf2b58071501567400f6 | 56 ----- ...lData_MD5_4cd09d26436a53a5adedb33d822cabcd | 14 -- ...lData_MD5_545c2293b16e250f25395dabbaa53cbb | 226 ------------------ ...lData_MD5_70a19e48a4393776cfe02f852f25cbe1 | 30 --- 4 files changed, 326 deletions(-) delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb delete mode 100644 Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 deleted file mode 100644 index 38a77c65d0e..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_2327dbe1884cbf2b58071501567400f6 +++ /dev/null @@ -1,56 +0,0 @@ -# vtk DataFile Version 2.0 -File written by itkVTKPolyDataWriter -ASCII -DATASET POLYDATA -POINTS 18 float -1 0 0 --1 0 0 -0 1 0 -0 -1 0 -0 0 1 -0 0 -1 -0 0.707107 0.707107 -0.707107 0 0.707107 -0.707107 0.707107 0 --0.707107 0.707107 0 --0.707107 0 0.707107 --0.707107 -0.707107 0 -0 -0.707107 0.707107 -0.707107 -0.707107 0 -0 0.707107 -0.707107 -0.707107 0 -0.707107 --0.707107 0 -0.707107 -0 -0.707107 -0.707107 -POLYGONS 32 128 -3 2 6 8 -3 6 4 7 -3 7 0 8 -3 6 7 8 -3 2 9 6 -3 9 1 10 -3 10 4 6 -3 9 10 6 -3 1 11 10 -3 11 3 12 -3 12 4 10 -3 11 12 10 -3 4 12 7 -3 12 3 13 -3 13 0 7 -3 12 13 7 -3 5 14 15 -3 14 2 8 -3 8 0 15 -3 14 8 15 -3 2 14 9 -3 14 5 16 -3 16 1 9 -3 14 16 9 -3 5 17 16 -3 17 3 11 -3 11 1 16 -3 17 11 16 -3 5 15 17 -3 15 0 13 -3 13 3 17 -3 15 13 17 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd deleted file mode 100644 index 9339517655d..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_4cd09d26436a53a5adedb33d822cabcd +++ /dev/null @@ -1,14 +0,0 @@ -# vtk DataFile Version 2.0 -File written by itkVTKPolyDataWriter -ASCII -DATASET POLYDATA -POINTS 4 float -0 0 0 -1 0 0 -0 1 0 -0 0 1 -POLYGONS 4 16 -3 0 2 1 -3 0 1 3 -3 0 3 2 -3 1 2 3 diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb deleted file mode 100644 index 7af8c1d6e28..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_545c2293b16e250f25395dabbaa53cbb +++ /dev/null @@ -1,226 +0,0 @@ -solid ascii - facet normal 0.357406 0.862856 0.357406 - outer loop - vertex 0 1 0 - vertex 0 0.707107 0.707107 - vertex 0.707107 0.707107 0 - endloop - endfacet - facet normal 0.357406 0.357406 0.862856 - outer loop - vertex 0 0.707107 0.707107 - vertex 0 0 1 - vertex 0.707107 0 0.707107 - endloop - endfacet - facet normal 0.862856 0.357406 0.357406 - outer loop - vertex 0.707107 0 0.707107 - vertex 1 0 0 - vertex 0.707107 0.707107 0 - endloop - endfacet - facet normal 0.57735 0.57735 0.57735 - outer loop - vertex 0 0.707107 0.707107 - vertex 0.707107 0 0.707107 - vertex 0.707107 0.707107 0 - endloop - endfacet - facet normal -0.357406 0.862856 0.357406 - outer loop - vertex 0 1 0 - vertex -0.707107 0.707107 0 - vertex 0 0.707107 0.707107 - endloop - endfacet - facet normal -0.862856 0.357406 0.357406 - outer loop - vertex -0.707107 0.707107 0 - vertex -1 0 0 - vertex -0.707107 0 0.707107 - endloop - endfacet - facet normal -0.357406 0.357406 0.862856 - outer loop - vertex -0.707107 0 0.707107 - vertex 0 0 1 - vertex 0 0.707107 0.707107 - endloop - endfacet - facet normal -0.57735 0.57735 0.57735 - outer loop - vertex -0.707107 0.707107 0 - vertex -0.707107 0 0.707107 - vertex 0 0.707107 0.707107 - endloop - endfacet - facet normal -0.862856 -0.357406 0.357406 - outer loop - vertex -1 0 0 - vertex -0.707107 -0.707107 0 - vertex -0.707107 0 0.707107 - endloop - endfacet - facet normal -0.357406 -0.862856 0.357406 - outer loop - vertex -0.707107 -0.707107 0 - vertex 0 -1 0 - vertex 0 -0.707107 0.707107 - endloop - endfacet - facet normal -0.357406 -0.357406 0.862856 - outer loop - vertex 0 -0.707107 0.707107 - vertex 0 0 1 - vertex -0.707107 0 0.707107 - endloop - endfacet - facet normal -0.57735 -0.57735 0.57735 - outer loop - vertex -0.707107 -0.707107 0 - vertex 0 -0.707107 0.707107 - vertex -0.707107 0 0.707107 - endloop - endfacet - facet normal 0.357406 -0.357406 0.862856 - outer loop - vertex 0 0 1 - vertex 0 -0.707107 0.707107 - vertex 0.707107 0 0.707107 - endloop - endfacet - facet normal 0.357406 -0.862856 0.357406 - outer loop - vertex 0 -0.707107 0.707107 - vertex 0 -1 0 - vertex 0.707107 -0.707107 0 - endloop - endfacet - facet normal 0.862856 -0.357406 0.357406 - outer loop - vertex 0.707107 -0.707107 0 - vertex 1 0 0 - vertex 0.707107 0 0.707107 - endloop - endfacet - facet normal 0.57735 -0.57735 0.57735 - outer loop - vertex 0 -0.707107 0.707107 - vertex 0.707107 -0.707107 0 - vertex 0.707107 0 0.707107 - endloop - endfacet - facet normal 0.357406 0.357406 -0.862856 - outer loop - vertex 0 0 -1 - vertex 0 0.707107 -0.707107 - vertex 0.707107 0 -0.707107 - endloop - endfacet - facet normal 0.357406 0.862856 -0.357406 - outer loop - vertex 0 0.707107 -0.707107 - vertex 0 1 0 - vertex 0.707107 0.707107 0 - endloop - endfacet - facet normal 0.862856 0.357406 -0.357406 - outer loop - vertex 0.707107 0.707107 0 - vertex 1 0 0 - vertex 0.707107 0 -0.707107 - endloop - endfacet - facet normal 0.57735 0.57735 -0.57735 - outer loop - vertex 0 0.707107 -0.707107 - vertex 0.707107 0.707107 0 - vertex 0.707107 0 -0.707107 - endloop - endfacet - facet normal -0.357406 0.862856 -0.357406 - outer loop - vertex 0 1 0 - vertex 0 0.707107 -0.707107 - vertex -0.707107 0.707107 0 - endloop - endfacet - facet normal -0.357406 0.357406 -0.862856 - outer loop - vertex 0 0.707107 -0.707107 - vertex 0 0 -1 - vertex -0.707107 0 -0.707107 - endloop - endfacet - facet normal -0.862856 0.357406 -0.357406 - outer loop - vertex -0.707107 0 -0.707107 - vertex -1 0 0 - vertex -0.707107 0.707107 0 - endloop - endfacet - facet normal -0.57735 0.57735 -0.57735 - outer loop - vertex 0 0.707107 -0.707107 - vertex -0.707107 0 -0.707107 - vertex -0.707107 0.707107 0 - endloop - endfacet - facet normal -0.357406 -0.357406 -0.862856 - outer loop - vertex 0 0 -1 - vertex 0 -0.707107 -0.707107 - vertex -0.707107 0 -0.707107 - endloop - endfacet - facet normal -0.357406 -0.862856 -0.357406 - outer loop - vertex 0 -0.707107 -0.707107 - vertex 0 -1 0 - vertex -0.707107 -0.707107 0 - endloop - endfacet - facet normal -0.862856 -0.357406 -0.357406 - outer loop - vertex -0.707107 -0.707107 0 - vertex -1 0 0 - vertex -0.707107 0 -0.707107 - endloop - endfacet - facet normal -0.57735 -0.57735 -0.57735 - outer loop - vertex 0 -0.707107 -0.707107 - vertex -0.707107 -0.707107 0 - vertex -0.707107 0 -0.707107 - endloop - endfacet - facet normal 0.357406 -0.357406 -0.862856 - outer loop - vertex 0 0 -1 - vertex 0.707107 0 -0.707107 - vertex 0 -0.707107 -0.707107 - endloop - endfacet - facet normal 0.862856 -0.357406 -0.357406 - outer loop - vertex 0.707107 0 -0.707107 - vertex 1 0 0 - vertex 0.707107 -0.707107 0 - endloop - endfacet - facet normal 0.357406 -0.862856 -0.357406 - outer loop - vertex 0.707107 -0.707107 0 - vertex 0 -1 0 - vertex 0 -0.707107 -0.707107 - endloop - endfacet - facet normal 0.57735 -0.57735 -0.57735 - outer loop - vertex 0.707107 0 -0.707107 - vertex 0.707107 -0.707107 0 - vertex 0 -0.707107 -0.707107 - endloop - endfacet -endsolid diff --git a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 b/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 deleted file mode 100644 index be14d23b637..00000000000 --- a/Modules/IO/IOMeshSTL/test/Baseline/.ExternalData_MD5_70a19e48a4393776cfe02f852f25cbe1 +++ /dev/null @@ -1,30 +0,0 @@ -solid ascii - facet normal 0 0 -1 - outer loop - vertex 0 0 0 - vertex 0 1 0 - vertex 1 0 0 - endloop - endfacet - facet normal 0 -1 0 - outer loop - vertex 0 0 0 - vertex 1 0 0 - vertex 0 0 1 - endloop - endfacet - facet normal -1 0 0 - outer loop - vertex 0 0 0 - vertex 0 0 1 - vertex 0 1 0 - endloop - endfacet - facet normal 1 1 1 - outer loop - vertex 1 0 0 - vertex 0 1 0 - vertex 0 0 1 - endloop - endfacet -endsolid From 1e7dcb41af4be50d237a4aa140af63f4c47c3aaf Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Tue, 5 May 2026 11:26:25 -0500 Subject: [PATCH 73/73] COMP: Drop redundant cmake_minimum_required from IOMeshSTL/CMakeLists.txt In-tree, ITK's top-level CMakeLists pins the CMake minimum, so the per-module declaration is dead code. Pre-emptive cleanup matching the v4 ingest-pipeline rule codified in PR #6204 (sanitize-history.py:patch_drop_cmake_minimum_required). --- Modules/IO/IOMeshSTL/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/IO/IOMeshSTL/CMakeLists.txt b/Modules/IO/IOMeshSTL/CMakeLists.txt index 7aea1b33aa0..9f9ce821e7f 100644 --- a/Modules/IO/IOMeshSTL/CMakeLists.txt +++ b/Modules/IO/IOMeshSTL/CMakeLists.txt @@ -1,4 +1,3 @@ -cmake_minimum_required(VERSION 3.16.3) project(IOMeshSTL) set(IOMeshSTL_LIBRARIES IOMeshSTL)