Skip to content
Snippets Groups Projects
Commit e46086d7 authored by Sam Jenkins's avatar Sam Jenkins
Browse files

Re #23574 fixed more requested changes

parent 25472383
No related branches found
No related tags found
No related merge requests found
#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
......@@ -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 =
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment