diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h b/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h index 60241c48c4599a06840c8fde9d78cbd9aa00537a..1d921f26571668d4e1dfeb0e4c045f75271b2664 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h @@ -1,5 +1,5 @@ -#ifndef MANTID_DATAHANDLING_LOADBinaryStl_H_ -#define MANTID_DATAHANDLING_LOADBinaryStl_H_ +#ifndef MANTID_DATAHANDLING_LOADBINARYSTL_H_ +#define MANTID_DATAHANDLING_LOADBINARYSTL_H_ #include "MantidGeometry/Objects/MeshObject.h" #include "MantidKernel/BinaryStreamReader.h" #include <MantidKernel/V3D.h> @@ -9,9 +9,10 @@ namespace DataHandling { class DLLExport LoadBinaryStl { public: - LoadBinaryStl(std::string filename) - : m_filename(filename), M_HEADER_SIZE(80), M_SIZE_OF_TRIANGLE(50), - M_NUM_OF_TRIANGLES(4) {} + static constexpr int HEADER_SIZE = 80; + static constexpr uint32_t SIZE_OF_TRIANGLE = 50; + static constexpr uint32_t NUM_OF_TRIANGLES = 4; + LoadBinaryStl(std::string filename) : m_filename(filename){} std::unique_ptr<Geometry::MeshObject> readStl(); bool isBinarySTL(); @@ -22,13 +23,10 @@ private: std::vector<uint16_t> m_triangle; std::vector<Kernel::V3D> m_verticies; - const int M_HEADER_SIZE; - const uint32_t M_SIZE_OF_TRIANGLE; - const uint32_t M_NUM_OF_TRIANGLES; }; uint16_t addSTLVertex(Kernel::V3D &vertex, std::vector<Kernel::V3D> &vertices); bool areEqualVertices(Kernel::V3D const &v1, Kernel::V3D const &v2); } // namespace DataHandling } // namespace Mantid -#endif /* MANTID_DATAHANDLING_LOADBinaryStl_H_ */ \ No newline at end of file +#endif /* MANTID_DATAHANDLING_LOADBINARYSTL_H_ */ \ No newline at end of file diff --git a/Framework/DataHandling/src/LoadBinaryStl.cpp b/Framework/DataHandling/src/LoadBinaryStl.cpp index 5a2885442dc26f6f2b4237ea3d5981b01b468f9a..6d5e66f69e1b4ac10ad9d4222de855e6e5f5344e 100644 --- a/Framework/DataHandling/src/LoadBinaryStl.cpp +++ b/Framework/DataHandling/src/LoadBinaryStl.cpp @@ -10,11 +10,9 @@ namespace Mantid { namespace DataHandling { bool LoadBinaryStl::isBinarySTL() { - // each triangle is 50 bytes - Poco::File stlFile = Poco::File(m_filename); auto fileSize = stlFile.getSize(); - if (fileSize < M_HEADER_SIZE + M_NUM_OF_TRIANGLES) { + if (fileSize < HEADER_SIZE + NUM_OF_TRIANGLES) { // File is smaller than header plus number of triangles, cannot be binary // format stl return false; @@ -24,8 +22,8 @@ bool LoadBinaryStl::isBinarySTL() { Kernel::BinaryStreamReader streamReader = Kernel::BinaryStreamReader(myFile); numberTrianglesLong = getNumberTriangles(streamReader); myFile.close(); - if (!(fileSize == (M_HEADER_SIZE + M_NUM_OF_TRIANGLES + - (numberTrianglesLong * M_SIZE_OF_TRIANGLE)))) { + if (!(fileSize == (HEADER_SIZE + NUM_OF_TRIANGLES + + (numberTrianglesLong * SIZE_OF_TRIANGLE)))) { // File is not the Header plus the number of triangles it claims to be long, // invalid binary Stl return false; @@ -39,7 +37,7 @@ LoadBinaryStl::getNumberTriangles(Kernel::BinaryStreamReader streamReader) { uint32_t numberTrianglesLong; // skip header - streamReader.moveStreamToPosition(M_HEADER_SIZE); + streamReader.moveStreamToPosition(HEADER_SIZE); // Read the number of triangles streamReader >> numberTrianglesLong; return numberTrianglesLong; @@ -51,14 +49,14 @@ std::unique_ptr<Geometry::MeshObject> LoadBinaryStl::readStl() { Kernel::BinaryStreamReader streamReader = Kernel::BinaryStreamReader(myFile); const auto numberTrianglesLong = getNumberTriangles(streamReader); - uint32_t nextToRead = M_HEADER_SIZE + M_NUM_OF_TRIANGLES + SIZE_OF_NORMAL; + uint32_t nextToRead = HEADER_SIZE + NUM_OF_TRIANGLES + SIZE_OF_NORMAL; // now read in all the triangles for (uint32_t i = 0; i < numberTrianglesLong; i++) { // find next triangle, skipping the normal and attribute streamReader.moveStreamToPosition(nextToRead); readTriangle(streamReader); - nextToRead += M_SIZE_OF_TRIANGLE; + nextToRead += SIZE_OF_TRIANGLE; } myFile.close(); std::unique_ptr<Geometry::MeshObject> retVal = diff --git a/Framework/DataHandling/test/LoadBinaryStlTest.h b/Framework/DataHandling/test/LoadBinaryStlTest.h index d00f1045a88b331cc95eef3e08fea26fc32b7812..250e7a3a7de8d24ab743e0d79320ad171c3afebf 100644 --- a/Framework/DataHandling/test/LoadBinaryStlTest.h +++ b/Framework/DataHandling/test/LoadBinaryStlTest.h @@ -1,5 +1,5 @@ -#ifndef LOAD_BinaryStl_TEST_H_ -#define LOAD_BinaryStl_TEST_H_ +#ifndef LOAD_BINARYSTL_TEST_H_ +#define LOAD_BINARYSTL_TEST_H_ #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/FileFinder.h" @@ -84,4 +84,4 @@ public: } }; -#endif /* LOAD_BinaryStl_TEST_H_ */ \ No newline at end of file +#endif /* LOAD_BINARYSTL_TEST_H_ */ \ No newline at end of file