Skip to content

Commit 5e10156

Browse files
authored
Merge pull request #9 from drlukeparry/dev
Version 0.2.5
2 parents 025fc7c + a8b628d commit 5e10156

File tree

16 files changed

+392
-44
lines changed

16 files changed

+392
-44
lines changed

App/Header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace slm {
1111
struct Header
1212
{
1313
std::string fileName;
14+
std::string creator;
1415

1516
void setVersion(std::tuple<int,int> version) { std::tie(vMajor, vMinor) = version; }
1617
std::tuple<int, int> version() const { return std::make_tuple(vMajor, vMinor); }

App/Model.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ BuildStyle::BuildStyle() : id(0),
1818
pointExposureTime(0),
1919
laserId(1),
2020
laserMode(1),
21+
pointDelay(0),
2122
jumpSpeed(0),
2223
jumpDelay(0)
2324

App/Model.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class SLM_EXPORT BuildStyle
5353
float laserSpeed;
5454

5555
uint64_t pointDistance;
56+
uint64_t pointDelay;
5657
uint64_t pointExposureTime;
5758
uint64_t jumpSpeed;
5859
uint64_t jumpDelay;

App/Reader.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <filesystem/resolver.h>
77
#include <filesystem/path.h>
88

9+
910
#include "Layer.h"
1011
#include "Model.h"
1112

@@ -31,6 +32,23 @@ Reader::~Reader()
3132
layers.clear();
3233
}
3334

35+
int64_t Reader::getFileSize() const
36+
{
37+
38+
if(!this->isReady()) {
39+
return -1;
40+
}
41+
42+
fs::path checkPath(this->filePath);
43+
return checkPath.file_size();
44+
45+
//const auto begin = myfile.tellg();
46+
//testFile.seekg (0, ios::end);
47+
//const auto end = testFile.tellg();
48+
//const auto fsize = (end-begin);
49+
50+
}
51+
3452
void Reader::setFilePath(std::string path)
3553
{
3654
fs::path checkPath(path);
@@ -59,6 +77,42 @@ Model::Ptr Reader::getModelById(uint64_t mid) const
5977
return (result != models.cend()) ? *result : Model::Ptr();
6078
}
6179

80+
81+
Layer::Ptr Reader::getTopLayerByPosition(const std::vector<Layer::Ptr> &layers)
82+
{
83+
uint64_t zMax = 0;
84+
85+
Layer::Ptr fndLayer;
86+
87+
for(auto layer : layers) {
88+
89+
if(layer->getZ() > zMax) {
90+
fndLayer = layer;
91+
zMax = layer->getZ();
92+
}
93+
}
94+
95+
return fndLayer;
96+
}
97+
98+
Layer::Ptr Reader::getTopLayerById(const std::vector<Layer::Ptr> &layers)
99+
{
100+
uint64_t zId = 0;
101+
102+
Layer::Ptr fndLayer;
103+
104+
for(auto layer : layers) {
105+
106+
if(layer->getLayerId() > zId) {
107+
fndLayer = layer;
108+
zId = layer->getLayerId();
109+
}
110+
}
111+
112+
return fndLayer;
113+
}
114+
115+
62116
int Reader::parse()
63117
{
64118
if(!this->isReady()) {

App/Reader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@ class SLM_EXPORT Reader
2727

2828
std::string getFilePath() { return filePath; }
2929
void setFilePath(std::string path);
30+
int64_t getFileSize() const;
3031

3132
virtual double getLayerThickness() const = 0;
3233

3334
Model::Ptr getModelById(uint64_t mid) const;
3435
std::vector<Model::Ptr> getModels() const { return models;}
3536
std::vector<Layer::Ptr> getLayers() const { return layers;}
36-
37+
38+
Layer::Ptr getTopLayerByPosition(const std::vector<Layer::Ptr> &layers);
39+
Layer::Ptr getTopLayerById(const std::vector<Layer::Ptr> &layers);
40+
3741
protected:
3842
void setReady(bool state) { ready = state; }
3943
std::string filePath;

App/Writer.cpp

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ namespace fs = filesystem;
1212
using namespace slm;
1313
using namespace base;
1414

15-
Writer::Writer(const char * fname) : ready(false)
15+
Writer::Writer(const char * fname) : ready(false),
16+
mSortLayers(false)
1617
{
1718
this->setFilePath(std::string(fname));
1819
}
1920

20-
Writer::Writer(const std::string &fname) : ready(false)
21+
Writer::Writer(const std::string &fname) : ready(false),
22+
mSortLayers(false)
2123
{
2224
this->setFilePath(fname);
2325
}
@@ -35,7 +37,7 @@ void Writer::getFileHandle(std::fstream &file) const
3537
if(this->isReady()) {
3638
file.open(filePath,std::fstream::in | std::fstream::out | std::fstream::trunc | std::fstream::binary);
3739
if(!file.is_open()) {
38-
std::cerr << "Cannot create file handler - " << filePath;
40+
std::cerr << "Cannot create file handler - " << filePath << std::endl;
3941
}
4042
}
4143
}
@@ -46,3 +48,132 @@ void Writer::setFilePath(const std::string &path)
4648
this->filePath = path;
4749
std::cout << "File '" << path << "' is ready to write" << std::endl;
4850
}
51+
52+
Layer::Ptr Writer::getTopLayerByPosition(const std::vector<Layer::Ptr> &layers)
53+
{
54+
uint64_t zMax = 0;
55+
56+
Layer::Ptr fndLayer;
57+
58+
for(auto layer : layers) {
59+
60+
if(layer->getZ() > zMax) {
61+
fndLayer = layer;
62+
zMax = layer->getZ();
63+
}
64+
}
65+
66+
return fndLayer;
67+
}
68+
69+
Layer::Ptr Writer::getTopLayerById(const std::vector<Layer::Ptr> &layers)
70+
{
71+
uint64_t zId = 0;
72+
73+
Layer::Ptr fndLayer;
74+
75+
for(auto layer : layers) {
76+
77+
if(layer->getLayerId() > zId) {
78+
fndLayer = layer;
79+
zId = layer->getLayerId();
80+
}
81+
}
82+
83+
return fndLayer;
84+
}
85+
86+
std::vector<Layer::Ptr> Writer::sortLayers(const std::vector<Layer::Ptr> &layers)
87+
{
88+
std::vector<Layer::Ptr> layersCpy(layers);
89+
90+
std::sort(layersCpy.begin(), layersCpy.end(), [](Layer::Ptr a, Layer::Ptr b) {
91+
return a->getZ() > b->getZ();
92+
});
93+
94+
return layersCpy;
95+
}
96+
97+
int64_t Writer::getTotalNumHatches(const std::vector<Layer::Ptr> &layers)
98+
{
99+
return Writer::getTotalGeoms<HatchGeometry>(layers);
100+
}
101+
102+
103+
int64_t Writer::getTotalNumContours(const std::vector<Layer::Ptr> &layers)
104+
{
105+
return Writer::getTotalGeoms<ContourGeometry>(layers);
106+
}
107+
108+
void Writer::getLayerBoundingBox(float *bbox, Layer::Ptr layer)
109+
{
110+
float minX = 1e9, minY = 1e9 , maxX = -1e9, maxY = -1e9;
111+
112+
for(auto geom : layer->geometry()) {
113+
auto minCols = geom->coords.colwise().minCoeff();
114+
auto maxCols = geom->coords.colwise().maxCoeff();
115+
116+
if(minCols[0, 0] < minX)
117+
minX = minCols[0,0];
118+
119+
if(minCols[0,1] < minY)
120+
minY = minCols[0,1];
121+
122+
if(maxCols[0,0] > maxX)
123+
maxX = maxCols[0,0];
124+
125+
if(maxCols[0,1] > maxY)
126+
maxY = maxCols[0,1];
127+
}
128+
}
129+
130+
void Writer::getBoundingBox(float *bbox, const std::vector<Layer::Ptr> &layers)
131+
{
132+
float minX = 1e9, minY = 1e9 , maxX = -1e9, maxY = -1e9;
133+
134+
for (auto layer: layers) {
135+
for(auto geom : layer->geometry()) {
136+
auto minCols = geom->coords.colwise().minCoeff();
137+
auto maxCols = geom->coords.colwise().maxCoeff();
138+
139+
if(minCols[0, 0] < minX)
140+
minX = minCols[0,0];
141+
142+
if(minCols[0,1] < minY)
143+
minY = minCols[0,1];
144+
145+
if(maxCols[0,0] > maxX)
146+
maxX = maxCols[0,0];
147+
148+
if(maxCols[0,1] > maxY)
149+
maxY = maxCols[0,1];
150+
151+
}
152+
}
153+
154+
bbox[0] = minX;
155+
bbox[1] = maxX;
156+
bbox[2] = minY;
157+
bbox[3] = maxY;
158+
}
159+
160+
std::tuple<float, float> Writer::getLayerMinMax(const std::vector<slm::Layer::Ptr> &layers)
161+
{
162+
float zMin = 0.0;
163+
float zMax = 0.0;
164+
float zPos = 0.0;
165+
166+
for (auto layer : layers) {
167+
168+
zPos = layer->getZ();
169+
170+
if(zPos < zMin)
171+
zMin = zPos;
172+
173+
if(zPos > zMax)
174+
zMax = zPos;
175+
}
176+
177+
return std::make_tuple(zMin, zMax);
178+
}
179+

App/Writer.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,41 @@ class SLM_EXPORT Writer
3434
const std::vector<Model::Ptr> &models,
3535
const std::vector<Layer::Ptr> &layers) = 0;
3636

37+
bool isSortingLayers() const { return mSortLayers; }
38+
void setSortLayers(bool state) { mSortLayers = state; }
39+
40+
public:
41+
static void getBoundingBox(float *bbox, const std::vector<Layer::Ptr> &layers);
42+
static void getLayerBoundingBox(float *bbox, Layer::Ptr layer);
43+
static std::tuple<float, float> getLayerMinMax(const std::vector<slm::Layer::Ptr> &layers);
44+
45+
static Layer::Ptr getTopLayerByPosition(const std::vector<Layer::Ptr> &layers);
46+
static Layer::Ptr getTopLayerById(const std::vector<Layer::Ptr> &layers);
47+
48+
static int64_t getTotalNumHatches(const std::vector<Layer::Ptr> &layers);
49+
static int64_t getTotalNumContours(const std::vector<Layer::Ptr> &layers);
50+
static std::vector<Layer::Ptr> sortLayers(const std::vector<Layer::Ptr> &layers);
51+
template <class T>
52+
static int64_t getTotalGeoms(const std::vector<slm::Layer::Ptr> &layers)
53+
{
54+
int64_t numGeomT = 0;
55+
56+
for(auto layer : layers)
57+
numGeomT += layer->getGeometryByType<T>().size();
58+
59+
return numGeomT;
60+
}
61+
3762
protected:
3863
void setReady(bool state) { ready = state; }
3964
void getFileHandle(std::fstream &file) const;
4065

41-
4266
protected:
4367
std::string filePath;
4468

4569
private:
4670
bool ready;
71+
bool mSortLayers;
4772
};
4873

4974
} // End of Namespace Base

CMakeLists.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.0)
22

3-
project(libSLM VERSION 0.2.3)
3+
project(libSLM VERSION 0.2.5)
44

55
# Set c++ to use cx11 as a requirement
66
set(CMAKE_CXX_STANDARD 11)
@@ -26,7 +26,7 @@ if(WIN32)
2626
# Remove Security definitions for the library
2727
# Remove run time checks for windows
2828
IF(MSVC)
29-
29+
3030
set(COMMON_LANGUAGE_RUNTIME "")
3131
set(EIGEN3_INCLUDE_DIR External/eigen)
3232

@@ -37,7 +37,7 @@ if(WIN32)
3737
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
3838
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
3939

40-
else(WIN32)
40+
else(WIN32)
4141

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

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

7979
set(APP_H_SRCS
8080
App/Header.h
81-
# App/Iterator.h
8281
App/Layer.h
8382
App/Model.h
8483
App/Reader.h
85-
# App/Slm.h
8684
App/Writer.h
8785
App/Utils.h
8886
)
8987

9088
set(APP_CPP_SRCS
91-
# App/Iterator.cpp
9289
App/Layer.cpp
9390
App/Model.cpp
9491
App/Reader.cpp
95-
# App/Slm.cpp
9692
App/Writer.cpp
9793
App/Utils.cpp
9894
)
@@ -159,14 +155,14 @@ if(BUILD_PYTHON)
159155

160156

161157
add_executable(main ${App_SRCS})
162-
target_link_libraries(main SLM_static MTT_static SLMSol_static)
158+
target_link_libraries(main SLM_static MTT_static EOS_static SLMSol_static Realizer_static)
163159

164160
#install(TARGETS slm DESTINATION lib/libSLM)
165161

166162
else()
167163

168164
add_executable(main ${App_SRCS})
169-
target_link_libraries(main SLM MTT)
165+
target_link_libraries(main SLM EOS MTT Realizer SLMSol)
170166

171167
endif(BUILD_PYTHON)
172168

External/eigen

Submodule eigen updated from ecb7bc9 to ec4efbd

External/filesystem

0 commit comments

Comments
 (0)