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

Re #23807 why is it slower now?!

parent dabc806b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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;
}
......
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