From e46086d72c120689b1536789832e9c1d96744057 Mon Sep 17 00:00:00 2001 From: Sam Jenkins <s.jenkins@stfc.ac.uk> Date: Tue, 2 Oct 2018 08:47:52 +0100 Subject: [PATCH] Re #23574 fixed more requested changes --- .../inc/MantidDataHandling/LoadBinaryStl.h | 16 +++++++--------- Framework/DataHandling/src/LoadBinaryStl.cpp | 14 ++++++-------- Framework/DataHandling/test/LoadBinaryStlTest.h | 6 +++--- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h b/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h index 60241c48c45..1d921f26571 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 5a2885442dc..6d5e66f69e1 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 d00f1045a88..250e7a3a7de 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 -- GitLab