diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h b/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h index 0c09059a175c0fae07c4562bfd97ac392c17ab55..e818f93ab81d0ec296d7189e424e95457fa35fc0 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadBinaryStl.h @@ -24,9 +24,10 @@ public: bool isBinarySTL(); private: - Kernel::V3D LoadBinaryStl::makeV3D(char* facet, int index); + Kernel::V3D makeV3D(char* facet, int index); uint32_t getNumberTriangles(Kernel::BinaryStreamReader); void readTriangle(Kernel::BinaryStreamReader); + void add3Vertex(Kernel::V3D vec1, Kernel::V3D vec2, Kernel::V3D vec3); }; } // namespace DataHandling diff --git a/Framework/DataHandling/src/LoadBinaryStl.cpp b/Framework/DataHandling/src/LoadBinaryStl.cpp index 75cf86a9aa05b462b08e8742ffa3abd5b8a99780..0803078d3e32e9be5898c238687c88ed4d5ea04a 100644 --- a/Framework/DataHandling/src/LoadBinaryStl.cpp +++ b/Framework/DataHandling/src/LoadBinaryStl.cpp @@ -5,11 +5,14 @@ // & Institut Laue - Langevin // SPDX - License - Identifier: GPL - 3.0 + #include "MantidDataHandling/LoadBinaryStl.h" +#include "MantidKernel/MultiThreaded.h" #include <Poco/File.h> #include <fstream> #include <string> #include <vector> +#include <string> #include <boost/make_shared.hpp> +#include <chrono> namespace Mantid { namespace DataHandling { @@ -47,38 +50,51 @@ LoadBinaryStl::getNumberTriangles(Kernel::BinaryStreamReader streamReader) { } -std::unique_ptr<Geometry::MeshObject> LoadBinaryStl::readStl() { - std::ifstream myFile(m_filename.c_str(), std::ios::in | std::ios::binary); - myFile.seekg(0, std::ios_base::end); - std::size_t size=myFile.tellg(); - myFile.seekg(0, std::ios_base::beg); - char Header[80]; - char buffer[size-84]; - char temp[4]; - myFile.read(Header, 80); - myFile.read(temp,4); - myFile.read(buffer, size); - uint32_t nTriLong = *((uint32_t*)temp) ; - for(int i =0;i++;i<nTriLong){ - for (int j = 0; j < 3; j++) { - auto vec =makeV3D(buffer,(12+(i*50)+(j*12))); - m_triangle.emplace_back(addSTLVertex(vec)); - } - } - m_verticies.shrink_to_fit(); - m_triangle.shrink_to_fit(); - // Close the file - myFile.close(); - std::unique_ptr<Geometry::MeshObject> retVal = - std::unique_ptr<Geometry::MeshObject>(new Geometry::MeshObject( - std::move(m_triangle), std::move(m_verticies), - Mantid::Kernel::Material())); - return retVal; -} +// std::unique_ptr<Geometry::MeshObject> LoadBinaryStl::readStl() { +// std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); +// std::ifstream myFile(m_filename.c_str(), std::ios::in | std::ios::binary); +// myFile.seekg(0, std::ios_base::end); +// const std::size_t size=myFile.tellg(); +// myFile.seekg(0, std::ios_base::beg); +// char Header[80]; +// std::unique_ptr<char[]> buffer(new char[size-84]); +// char temp[4]; +// myFile.read(Header, 80); +// myFile.read(temp,4); +// myFile.read(buffer.get(), size); +// const uint32_t nTriLong = *((uint32_t*)temp); +// g_logstl.debug(std::to_string(nTriLong) + " Triangles to read"); +// PARALLEL_FOR_NO_WSP_CHECK() +// for(uint32_t i = 0;i<nTriLong;i++){ +// auto vec1 = makeV3D(buffer.get(),((i*TRIANGLE_DATA_SIZE)+(VECTOR_DATA_SIZE))); +// auto vec2 = makeV3D(buffer.get(),((i*TRIANGLE_DATA_SIZE)+(2*VECTOR_DATA_SIZE))); +// auto vec3 = makeV3D(buffer.get(),((i*TRIANGLE_DATA_SIZE)+(3*VECTOR_DATA_SIZE))); +// #pragma omp critical +// add3Vertex(vec1, vec2, vec3); +// } +// m_verticies.shrink_to_fit(); +// m_triangle.shrink_to_fit(); +// // Close the file +// myFile.close(); +// std::unique_ptr<Geometry::MeshObject> retVal = +// std::unique_ptr<Geometry::MeshObject>(new Geometry::MeshObject( +// std::move(m_triangle), std::move(m_verticies), +// Mantid::Kernel::Material())); +// std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); +// auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); +// g_logstl.information("Took "+ std::to_string(duration)+" microseconds"); +// return retVal; +// } +// void LoadBinaryStl::add3Vertex(Kernel::V3D vec1, Kernel::V3D vec2, Kernel::V3D vec3){ +// m_triangle.emplace_back(addSTLVertex(vec1)); +// m_triangle.emplace_back(addSTLVertex(vec2)); +// m_triangle.emplace_back(addSTLVertex(vec3)); +// } std::unique_ptr<Geometry::MeshObject> LoadBinaryStl::readStl() { +std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); std::ifstream myFile(m_filename.c_str(), std::ios::in | std::ios::binary); Kernel::BinaryStreamReader streamReader = Kernel::BinaryStreamReader(myFile); @@ -103,6 +119,9 @@ std::unique_ptr<Geometry::MeshObject> LoadBinaryStl::readStl() { std::unique_ptr<Geometry::MeshObject>(new Geometry::MeshObject( std::move(m_triangle), std::move(m_verticies), Mantid::Kernel::Material())); + std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); + auto duration = std::chrono::duration_cast<std::chrono::microseconds>( t2 - t1 ).count(); + g_logstl.information("Took "+ std::to_string(duration)+" microseconds"); return retVal; }