Skip to content

Commit

Permalink
Merge pull request #9 from drlukeparry/dev
Browse files Browse the repository at this point in the history
Version 0.2.5
  • Loading branch information
drlukeparry authored Feb 7, 2022
2 parents 025fc7c + a8b628d commit 5e10156
Show file tree
Hide file tree
Showing 16 changed files with 392 additions and 44 deletions.
1 change: 1 addition & 0 deletions App/Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace slm {
struct Header
{
std::string fileName;
std::string creator;

void setVersion(std::tuple<int,int> version) { std::tie(vMajor, vMinor) = version; }
std::tuple<int, int> version() const { return std::make_tuple(vMajor, vMinor); }
Expand Down
1 change: 1 addition & 0 deletions App/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ BuildStyle::BuildStyle() : id(0),
pointExposureTime(0),
laserId(1),
laserMode(1),
pointDelay(0),
jumpSpeed(0),
jumpDelay(0)

Expand Down
1 change: 1 addition & 0 deletions App/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class SLM_EXPORT BuildStyle
float laserSpeed;

uint64_t pointDistance;
uint64_t pointDelay;
uint64_t pointExposureTime;
uint64_t jumpSpeed;
uint64_t jumpDelay;
Expand Down
54 changes: 54 additions & 0 deletions App/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <filesystem/resolver.h>
#include <filesystem/path.h>


#include "Layer.h"
#include "Model.h"

Expand All @@ -31,6 +32,23 @@ Reader::~Reader()
layers.clear();
}

int64_t Reader::getFileSize() const
{

if(!this->isReady()) {
return -1;
}

fs::path checkPath(this->filePath);
return checkPath.file_size();

//const auto begin = myfile.tellg();
//testFile.seekg (0, ios::end);
//const auto end = testFile.tellg();
//const auto fsize = (end-begin);

}

void Reader::setFilePath(std::string path)
{
fs::path checkPath(path);
Expand Down Expand Up @@ -59,6 +77,42 @@ Model::Ptr Reader::getModelById(uint64_t mid) const
return (result != models.cend()) ? *result : Model::Ptr();
}


Layer::Ptr Reader::getTopLayerByPosition(const std::vector<Layer::Ptr> &layers)
{
uint64_t zMax = 0;

Layer::Ptr fndLayer;

for(auto layer : layers) {

if(layer->getZ() > zMax) {
fndLayer = layer;
zMax = layer->getZ();
}
}

return fndLayer;
}

Layer::Ptr Reader::getTopLayerById(const std::vector<Layer::Ptr> &layers)
{
uint64_t zId = 0;

Layer::Ptr fndLayer;

for(auto layer : layers) {

if(layer->getLayerId() > zId) {
fndLayer = layer;
zId = layer->getLayerId();
}
}

return fndLayer;
}


int Reader::parse()
{
if(!this->isReady()) {
Expand Down
6 changes: 5 additions & 1 deletion App/Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ class SLM_EXPORT Reader

std::string getFilePath() { return filePath; }
void setFilePath(std::string path);
int64_t getFileSize() const;

virtual double getLayerThickness() const = 0;

Model::Ptr getModelById(uint64_t mid) const;
std::vector<Model::Ptr> getModels() const { return models;}
std::vector<Layer::Ptr> getLayers() const { return layers;}


Layer::Ptr getTopLayerByPosition(const std::vector<Layer::Ptr> &layers);
Layer::Ptr getTopLayerById(const std::vector<Layer::Ptr> &layers);

protected:
void setReady(bool state) { ready = state; }
std::string filePath;
Expand Down
137 changes: 134 additions & 3 deletions App/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace fs = filesystem;
using namespace slm;
using namespace base;

Writer::Writer(const char * fname) : ready(false)
Writer::Writer(const char * fname) : ready(false),
mSortLayers(false)
{
this->setFilePath(std::string(fname));
}

Writer::Writer(const std::string &fname) : ready(false)
Writer::Writer(const std::string &fname) : ready(false),
mSortLayers(false)
{
this->setFilePath(fname);
}
Expand All @@ -35,7 +37,7 @@ void Writer::getFileHandle(std::fstream &file) const
if(this->isReady()) {
file.open(filePath,std::fstream::in | std::fstream::out | std::fstream::trunc | std::fstream::binary);
if(!file.is_open()) {
std::cerr << "Cannot create file handler - " << filePath;
std::cerr << "Cannot create file handler - " << filePath << std::endl;
}
}
}
Expand All @@ -46,3 +48,132 @@ void Writer::setFilePath(const std::string &path)
this->filePath = path;
std::cout << "File '" << path << "' is ready to write" << std::endl;
}

Layer::Ptr Writer::getTopLayerByPosition(const std::vector<Layer::Ptr> &layers)
{
uint64_t zMax = 0;

Layer::Ptr fndLayer;

for(auto layer : layers) {

if(layer->getZ() > zMax) {
fndLayer = layer;
zMax = layer->getZ();
}
}

return fndLayer;
}

Layer::Ptr Writer::getTopLayerById(const std::vector<Layer::Ptr> &layers)
{
uint64_t zId = 0;

Layer::Ptr fndLayer;

for(auto layer : layers) {

if(layer->getLayerId() > zId) {
fndLayer = layer;
zId = layer->getLayerId();
}
}

return fndLayer;
}

std::vector<Layer::Ptr> Writer::sortLayers(const std::vector<Layer::Ptr> &layers)
{
std::vector<Layer::Ptr> layersCpy(layers);

std::sort(layersCpy.begin(), layersCpy.end(), [](Layer::Ptr a, Layer::Ptr b) {
return a->getZ() > b->getZ();
});

return layersCpy;
}

int64_t Writer::getTotalNumHatches(const std::vector<Layer::Ptr> &layers)
{
return Writer::getTotalGeoms<HatchGeometry>(layers);
}


int64_t Writer::getTotalNumContours(const std::vector<Layer::Ptr> &layers)
{
return Writer::getTotalGeoms<ContourGeometry>(layers);
}

void Writer::getLayerBoundingBox(float *bbox, Layer::Ptr layer)
{
float minX = 1e9, minY = 1e9 , maxX = -1e9, maxY = -1e9;

for(auto geom : layer->geometry()) {
auto minCols = geom->coords.colwise().minCoeff();
auto maxCols = geom->coords.colwise().maxCoeff();

if(minCols[0, 0] < minX)
minX = minCols[0,0];

if(minCols[0,1] < minY)
minY = minCols[0,1];

if(maxCols[0,0] > maxX)
maxX = maxCols[0,0];

if(maxCols[0,1] > maxY)
maxY = maxCols[0,1];
}
}

void Writer::getBoundingBox(float *bbox, const std::vector<Layer::Ptr> &layers)
{
float minX = 1e9, minY = 1e9 , maxX = -1e9, maxY = -1e9;

for (auto layer: layers) {
for(auto geom : layer->geometry()) {
auto minCols = geom->coords.colwise().minCoeff();
auto maxCols = geom->coords.colwise().maxCoeff();

if(minCols[0, 0] < minX)
minX = minCols[0,0];

if(minCols[0,1] < minY)
minY = minCols[0,1];

if(maxCols[0,0] > maxX)
maxX = maxCols[0,0];

if(maxCols[0,1] > maxY)
maxY = maxCols[0,1];

}
}

bbox[0] = minX;
bbox[1] = maxX;
bbox[2] = minY;
bbox[3] = maxY;
}

std::tuple<float, float> Writer::getLayerMinMax(const std::vector<slm::Layer::Ptr> &layers)
{
float zMin = 0.0;
float zMax = 0.0;
float zPos = 0.0;

for (auto layer : layers) {

zPos = layer->getZ();

if(zPos < zMin)
zMin = zPos;

if(zPos > zMax)
zMax = zPos;
}

return std::make_tuple(zMin, zMax);
}

27 changes: 26 additions & 1 deletion App/Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,41 @@ class SLM_EXPORT Writer
const std::vector<Model::Ptr> &models,
const std::vector<Layer::Ptr> &layers) = 0;

bool isSortingLayers() const { return mSortLayers; }
void setSortLayers(bool state) { mSortLayers = state; }

public:
static void getBoundingBox(float *bbox, const std::vector<Layer::Ptr> &layers);
static void getLayerBoundingBox(float *bbox, Layer::Ptr layer);
static std::tuple<float, float> getLayerMinMax(const std::vector<slm::Layer::Ptr> &layers);

static Layer::Ptr getTopLayerByPosition(const std::vector<Layer::Ptr> &layers);
static Layer::Ptr getTopLayerById(const std::vector<Layer::Ptr> &layers);

static int64_t getTotalNumHatches(const std::vector<Layer::Ptr> &layers);
static int64_t getTotalNumContours(const std::vector<Layer::Ptr> &layers);
static std::vector<Layer::Ptr> sortLayers(const std::vector<Layer::Ptr> &layers);
template <class T>
static int64_t getTotalGeoms(const std::vector<slm::Layer::Ptr> &layers)
{
int64_t numGeomT = 0;

for(auto layer : layers)
numGeomT += layer->getGeometryByType<T>().size();

return numGeomT;
}

protected:
void setReady(bool state) { ready = state; }
void getFileHandle(std::fstream &file) const;


protected:
std::string filePath;

private:
bool ready;
bool mSortLayers;
};

} // End of Namespace Base
Expand Down
14 changes: 5 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.0)

project(libSLM VERSION 0.2.3)
project(libSLM VERSION 0.2.5)

# Set c++ to use cx11 as a requirement
set(CMAKE_CXX_STANDARD 11)
Expand All @@ -26,7 +26,7 @@ if(WIN32)
# Remove Security definitions for the library
# Remove run time checks for windows
IF(MSVC)

set(COMMON_LANGUAGE_RUNTIME "")
set(EIGEN3_INCLUDE_DIR External/eigen)

Expand All @@ -37,7 +37,7 @@ if(WIN32)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})

else(WIN32)
else(WIN32)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")

Expand Down Expand Up @@ -78,21 +78,17 @@ SOURCE_GROUP("Base" FILES ${BASE_SRCS})

set(APP_H_SRCS
App/Header.h
# App/Iterator.h
App/Layer.h
App/Model.h
App/Reader.h
# App/Slm.h
App/Writer.h
App/Utils.h
)

set(APP_CPP_SRCS
# App/Iterator.cpp
App/Layer.cpp
App/Model.cpp
App/Reader.cpp
# App/Slm.cpp
App/Writer.cpp
App/Utils.cpp
)
Expand Down Expand Up @@ -159,14 +155,14 @@ if(BUILD_PYTHON)


add_executable(main ${App_SRCS})
target_link_libraries(main SLM_static MTT_static SLMSol_static)
target_link_libraries(main SLM_static MTT_static EOS_static SLMSol_static Realizer_static)

#install(TARGETS slm DESTINATION lib/libSLM)

else()

add_executable(main ${App_SRCS})
target_link_libraries(main SLM MTT)
target_link_libraries(main SLM EOS MTT Realizer SLMSol)

endif(BUILD_PYTHON)

Expand Down
2 changes: 1 addition & 1 deletion External/eigen
Submodule eigen updated from ecb7bc to ec4efb
2 changes: 1 addition & 1 deletion External/filesystem
Submodule filesystem updated 1 files
+62 −14 filesystem/path.h
2 changes: 1 addition & 1 deletion External/pybind11
Submodule pybind11 updated 226 files
Loading

0 comments on commit 5e10156

Please sign in to comment.