Vojtech's improvements in the SLA preview cutting dialog.

This commit is contained in:
bubnikv 2019-04-11 15:44:32 +02:00
parent 678c513cb9
commit 4a210aeecf
7 changed files with 86 additions and 65 deletions

View file

@ -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");

View file

@ -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;
void stl_close(stl_file *stl)
{
assert(stl->fp == nullptr);
assert(stl->heads == nullptr);
assert(stl->tail == nullptr);
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);
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));
}