Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2019-04-11 16:44:32 +0300
committerbubnikv <bubnikv@gmail.com>2019-04-11 16:44:32 +0300
commit4a210aeecf3a720a12d3e249c6e2da5cea533085 (patch)
tree33b25ab0e341e24572b29e8f59f79fe488644a02 /src/admesh
parent678c513cb96bbca0be1e31c3c98fc42ddd581cf4 (diff)
Vojtech's improvements in the SLA preview cutting dialog.
Diffstat (limited to 'src/admesh')
-rw-r--r--src/admesh/stl.h14
-rw-r--r--src/admesh/stlinit.cpp39
2 files changed, 33 insertions, 20 deletions
diff --git a/src/admesh/stl.h b/src/admesh/stl.h
index 2c436b426..d682b2434 100644
--- a/src/admesh/stl.h
+++ b/src/admesh/stl.h
@@ -43,11 +43,21 @@ typedef Eigen::Matrix<float, 3, 1, Eigen::DontAlign> stl_normal;
static_assert(sizeof(stl_vertex) == 12, "size of stl_vertex incorrect");
static_assert(sizeof(stl_normal) == 12, "size of stl_normal incorrect");
-typedef struct {
+struct stl_facet {
stl_normal normal;
stl_vertex vertex[3];
char extra[2];
-} stl_facet;
+
+ stl_facet rotated(const Eigen::Quaternion<float, Eigen::DontAlign> &rot) {
+ stl_facet out;
+ out.normal = rot * this->normal;
+ out.vertex[0] = rot * this->vertex[0];
+ out.vertex[1] = rot * this->vertex[1];
+ out.vertex[2] = rot * this->vertex[2];
+ return out;
+ }
+};
+
#define SIZEOF_STL_FACET 50
static_assert(offsetof(stl_facet, normal) == 0, "stl_facet.normal has correct offset");
diff --git a/src/admesh/stlinit.cpp b/src/admesh/stlinit.cpp
index e2939b8af..911f4f5e8 100644
--- a/src/admesh/stlinit.cpp
+++ b/src/admesh/stlinit.cpp
@@ -41,10 +41,12 @@ stl_open(stl_file *stl, const char *file) {
stl_count_facets(stl, file);
stl_allocate(stl);
stl_read(stl, 0, true);
- if (!stl->error) fclose(stl->fp);
+ if (stl->fp != nullptr) {
+ fclose(stl->fp);
+ stl->fp = nullptr;
+ }
}
-
void
stl_initialize(stl_file *stl) {
memset(stl, 0, sizeof(stl_file));
@@ -118,7 +120,7 @@ stl_count_facets(stl_file *stl, const char *file) {
}
/* Read the int following the header. This should contain # of facets */
- bool header_num_faces_read = fread(&header_num_facets, sizeof(uint32_t), 1, stl->fp);
+ bool header_num_faces_read = fread(&header_num_facets, sizeof(uint32_t), 1, stl->fp) != 0;
#ifndef BOOST_LITTLE_ENDIAN
// Convert from little endian to big endian.
stl_internal_reverse_quads((char*)&header_num_facets, 4);
@@ -257,7 +259,6 @@ stl_reallocate(stl_file *stl) {
time running this for the stl and therefore we should reset our max and min stats. */
void stl_read(stl_file *stl, int first_facet, bool first) {
stl_facet facet;
- int i;
if (stl->error) return;
@@ -268,7 +269,7 @@ void stl_read(stl_file *stl, int first_facet, bool first) {
}
char normal_buf[3][32];
- for(i = first_facet; i < stl->stats.number_of_facets; i++) {
+ for(uint32_t i = first_facet; i < stl->stats.number_of_facets; i++) {
if(stl->stats.type == binary)
/* Read a single facet from a binary .STL file */
{
@@ -366,17 +367,19 @@ void stl_facet_stats(stl_file *stl, stl_facet facet, bool &first)
}
}
-void
-stl_close(stl_file *stl) {
- if (stl->error) return;
-
- if(stl->neighbors_start != NULL)
- free(stl->neighbors_start);
- if(stl->facet_start != NULL)
- free(stl->facet_start);
- if(stl->v_indices != NULL)
- free(stl->v_indices);
- if(stl->v_shared != NULL)
- free(stl->v_shared);
+void stl_close(stl_file *stl)
+{
+ assert(stl->fp == nullptr);
+ assert(stl->heads == nullptr);
+ assert(stl->tail == nullptr);
+
+ if (stl->facet_start != NULL)
+ free(stl->facet_start);
+ if (stl->neighbors_start != NULL)
+ free(stl->neighbors_start);
+ if (stl->v_indices != NULL)
+ free(stl->v_indices);
+ if (stl->v_shared != NULL)
+ free(stl->v_shared);
+ memset(stl, 0, sizeof(stl_file));
}
-