mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-17 10:32:20 +00:00
* Update eigen from v3.3.7 to v5.0.1. This updates eigen from v3.3.7 released on December 11, 2018-12-11 to v5.0.1 released on 2025-11-11. There have be a large number of bug-fixes, optimizations, and improvements between these releases. See the details at; https://gitlab.com/libeigen/eigen/-/releases It retains the previous custom minimal `CMakeLists.txt`, and adds a README-OrcaSlicer.md that explains what version and parts of the upstream eigen release have been included, and where the full release can be found. * Update libigl from v2.0.0 (or older) to v2.6.0. This updates libigl from what was probably v2.0.0 released on 2018-10-16 to v2.6.0 released on 2025-05-15. It's possible the old version was even older than that but there is no version indicators in the code and I ran out of patience identifying missing changes and only went back as far as v2.0.0. There have been a large number of bug-fixes, optimizations, and improvements between these versions. See the following for details; https://github.com/libigl/libigl/releases I retained the minimal custom `CMakeLists.txt`, added `README.md` from the libigl distribution which identifies the version, and added a README-OrcaSlicer.md that details the version and parts that have been included. * Update libslic3r for libigl v2.6.0 changes. This updates libslic3r for all changes moving to eigen v5.0.1 and libigl v2.6.0. Despite the large number of updates to both dependencies, no changes were required for the eigen update, and only one change was required for the libigl update. For libigl, `igl::Hit` was changed to a template taking the Scalar type to use. Previously it was hard-coded to `float`, so to minimize possible impact I've updated all places it is used from `igl::Hit` to `igl::Hit<float>`. * Add compiler option `-DNOMINMAX` for libigl with MSVC. MSVC by default defines `min(()` and `max()` macros that break `std::numeric_limits<>::max()`. The upstream cmake that we don't include adds `-DNOMINMAX` for the libigl module when compiling with MSVC, so we need to add the same thing here. * Fix src/libslic3r/TriangleMeshDeal.cpp for the unmodified upstream libigl. This fixes `TriangleMeshDeal.cpp` to work with the unmodified upstream libigl v2.6.0. loop.{h,cpp} implementation. This file and feature was added in PR "BBS Port: Mesh Subdivision" (#12150) which included changes to `loop.{h,cpp}` in the old version of libigl. This PR avoids modifying the included dependencies, and uses the updated upstream versions of those files without any modifications, which requires fixing TriangleMeshDeal.cpp to work with them. In particular, the modifications made to `loop.{h,cpp}` included changing the return type from void to bool, adding additional validation checking of the input meshes, and returning false if they failed validation. These added checks looked unnecessary and would only have caught problems if the input mesh was very corrupt. To make `TriangleMeshDeal.cpp` work without this built-in checking functionality, I removed checking/handling of any `false` return value. There was also a hell of a lot of redundant copying and casting back and forth between float and double, so I cleaned that up. The input and output meshs use floats for the vertexes, and there would be no accuracy benefits from casting to and from doubles for the simple weighted average operations done by igl::loop(). So this just uses `Eigen:Map` to use the original input mesh vertex data directly without requiring any copy or casting. * Move eigen from included `deps_src` to externaly fetched `deps`. This copys what PrusaSlicer did and moved it from an included dependency under `deps_src` to an externaly fetched dependency under `deps`. This requires updating some `CMakeList.txt` configs and removing the old and obsolete `cmake/modules/FindEigen3.cmake`. The details of when this was done in PrusaSlicer and the followup fixes are at; *21116995d7* https://github.com/prusa3d/PrusaSlicer/issues/13608 * https://github.com/prusa3d/PrusaSlicer/pull/13609 *e3c277b9eeFor some reason I don't fully understand this also required fixing `src/slic3r/GUI/GUI_App.cpp` by adding `#include <boost/nowide/cstdio.hpp>` to fix an `error: ‘remove’ is not a member of ‘boost::nowide'`. The main thing I don't understand is how it worked before. Note that this include is in the PrusaSlicer version of this file, but it also significantly deviates from what is currently in OrcaSlicer in many other ways. * Whups... I missed adding the deps/Eigen/Eigen.cmake file... * Tidy some whitespace indenting in CMakeLists.txt. * Ugh... tabs indenting needing fixes. * Change the include order of deps/Eigen. It turns out that although Boost includes some references to Eigen, Eigen also includes some references to Boost for supporting some of it's additional numeric types. I don't think it matters much since we are not using these features, but I think technically its more correct to say Eigen depends on Boost than the other way around, so I've re-ordered them. * Add source for Eigen 5.0.1 download to flatpak yml config. * Add explicit `DEPENDS dep_Boost to deps/Eigen. I missed this before. This ensures we don't rely on include orders to make sure Boost is installed before we configure Eigen. * Add `DEPENDS dep_Boost dep_GMP dep_MPFR` to deps/Eigen. It turns out Eigen can also use GMP and MPFR for multi-precision and multi-precision-rounded numeric types if they are available. Again, I don't think we are using these so it doesn't really matter, but it is technically correct and ensures they are there if we ever do need them. * Fix deps DEPENDENCY ordering for GMP, MPFR, Eigen, and CGAL. I think this is finally correct. Apparently CGAL also optionally depends on Eigen, so the correct dependency order from lowest to highest is GMP, MPFR, Eigen, and CGAL. --------- Co-authored-by: Donovan Baarda <dbaarda@google.com> Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
193 lines
7.4 KiB
C++
193 lines
7.4 KiB
C++
// based on MSH reader from PyMesh
|
|
|
|
// Copyright (c) 2015 Qingnan Zhou <qzhou@adobe.com>
|
|
// Copyright (C) 2020 Vladimir Fonov <vladimir.fonov@gmail.com>
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla
|
|
// Public License v. 2.0. If a copy of the MPL was not distributed
|
|
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
#ifndef IGL_MSH_LOADER_H
|
|
#define IGL_MSH_LOADER_H
|
|
#include "igl_inline.h"
|
|
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
namespace igl {
|
|
|
|
/// Class for loading information from .msh file
|
|
/// depends only on c++stl library
|
|
class MshLoader {
|
|
public:
|
|
|
|
struct msh_struct {
|
|
int tag,el_type;
|
|
msh_struct(int _tag=0,int _type=0):
|
|
tag(_tag),el_type(_type){}
|
|
bool operator== (const msh_struct& a) const {
|
|
return this->tag==a.tag &&
|
|
this->el_type==a.el_type;
|
|
}
|
|
|
|
bool operator< (const msh_struct& a) const {
|
|
return (this->tag*100+this->el_type) <
|
|
(a.tag*100+a.el_type);
|
|
}
|
|
};
|
|
|
|
typedef double Float;
|
|
|
|
typedef std::vector<int> IndexVector;
|
|
typedef std::vector<int> IntVector;
|
|
typedef std::vector<Float> FloatVector;
|
|
typedef std::vector<FloatVector> FloatField;
|
|
typedef std::vector<IntVector> IntField;
|
|
typedef std::vector<std::string> FieldNames;
|
|
typedef std::multimap<msh_struct,int> StructIndex;
|
|
typedef std::vector<msh_struct> StructVector;
|
|
|
|
enum {ELEMENT_LINE=1, ELEMENT_TRI=2, ELEMENT_QUAD=3,
|
|
ELEMENT_TET=4, ELEMENT_HEX=5, ELEMENT_PRISM=6,
|
|
ELEMENT_PYRAMID=7,
|
|
// 2nd order elements
|
|
ELEMENT_LINE_2ND_ORDER=8, ELEMENT_TRI_2ND_ORDER=9,
|
|
ELEMENT_QUAD_2ND_ORDER=10,ELEMENT_TET_2ND_ORDER=11,
|
|
ELEMENT_HEX_2ND_ORDER=12, ELEMENT_PRISM_2ND_ORDER=13,
|
|
ELEMENT_PYRAMID_2ND_ORDER=14,
|
|
// other elements
|
|
ELEMENT_POINT=15 };
|
|
public:
|
|
/// Load a .msh file from a given path
|
|
/// @param[in] filename path to .msh
|
|
MshLoader(const std::string &filename);
|
|
|
|
public:
|
|
|
|
// get nodes , x,y,z sequentially
|
|
const FloatVector& get_nodes() const { return m_nodes; }
|
|
// get elements , identifying nodes that create an element
|
|
// variable length per element
|
|
const IndexVector& get_elements() const { return m_elements; }
|
|
|
|
// get element types
|
|
const IntVector& get_elements_types() const { return m_elements_types; }
|
|
// get element lengths
|
|
const IntVector& get_elements_lengths() const { return m_elements_lengths; }
|
|
// get element tags ( physical (0) and elementary (1) )
|
|
const IntField& get_elements_tags() const { return m_elements_tags; }
|
|
// get element IDs
|
|
const IntVector& get_elements_ids() const { return m_elements_ids; }
|
|
|
|
// get reverse index from node to element
|
|
const IndexVector& get_elements_nodes_idx() const { return m_elements_nodes_idx; }
|
|
|
|
// get fields assigned per node, all fields and components sequentially
|
|
const FloatField& get_node_fields() const { return m_node_fields;}
|
|
// get node field names,
|
|
const FieldNames& get_node_fields_names() const { return m_node_fields_names;}
|
|
// get number of node field components
|
|
const IntVector& get_node_fields_components() const {return m_node_fields_components;}
|
|
|
|
int get_node_field_components(size_t c) const
|
|
{
|
|
return m_node_fields_components[c];
|
|
}
|
|
|
|
// get fields assigned per element, all fields and components sequentially
|
|
const FloatField& get_element_fields() const { return m_element_fields;}
|
|
// get element field names
|
|
const FieldNames& get_element_fields_names() const { return m_element_fields_names;}
|
|
// get number of element field components
|
|
const IntVector& get_element_fields_components() const {return m_element_fields_components;}
|
|
|
|
int get_element_field_components(size_t c) const {
|
|
return m_element_fields_components[c];
|
|
}
|
|
// check if field is present at node level
|
|
bool is_node_field(const std::string& fieldname) const {
|
|
return (std::find(std::begin(m_node_fields_names),
|
|
std::end(m_node_fields_names),
|
|
fieldname) != std::end(m_node_fields_names) );
|
|
}
|
|
// check if field is present at element level
|
|
bool is_element_field(const std::string& fieldname) const {
|
|
return (std::find(std::begin(m_element_fields_names),
|
|
std::end(m_element_fields_names),
|
|
fieldname) != std::end(m_node_fields_names) );
|
|
}
|
|
|
|
// check if all elements have ids assigned sequentially
|
|
bool is_element_map_identity() const ;
|
|
|
|
// create tag index
|
|
// tag_column: ( physical (0) or elementary (1) ) specifying which tag to use
|
|
void index_structures(int tag_column);
|
|
|
|
// get tag index, call index_structure_tags first
|
|
const StructIndex& get_structure_index() const
|
|
{
|
|
return m_structure_index;
|
|
}
|
|
|
|
// get size of a structure identified by tag and element type
|
|
const StructIndex& get_structure_length() const
|
|
{
|
|
return m_structure_length;
|
|
}
|
|
|
|
//! get list of structures
|
|
const StructVector& get_structures() const
|
|
{
|
|
return m_structures;
|
|
}
|
|
|
|
public:
|
|
// helper function, calculate number of nodes associated with an element
|
|
static int num_nodes_per_elem_type(int elem_type);
|
|
|
|
private:
|
|
void parse_nodes(std::ifstream& fin);
|
|
void parse_elements(std::ifstream& fin);
|
|
void parse_node_field(std::ifstream& fin);
|
|
void parse_element_field(std::ifstream& fin);
|
|
void parse_unknown_field(std::ifstream& fin,
|
|
const std::string& fieldname);
|
|
|
|
private:
|
|
bool m_binary;
|
|
size_t m_data_size;
|
|
|
|
FloatVector m_nodes; // len x 3 vector
|
|
|
|
IndexVector m_elements; // linear array for nodes corresponding to each element
|
|
IndexVector m_elements_nodes_idx; // element indexes
|
|
|
|
IntVector m_elements_ids; // element id's
|
|
IntVector m_elements_types; // Element types
|
|
IntVector m_elements_lengths; // Element lengths
|
|
IntField m_elements_tags; // Element tags, currently 2xtags per element
|
|
|
|
FloatField m_node_fields; // Float field defined at each node
|
|
IntVector m_node_fields_components; // Number of components for node field
|
|
FieldNames m_node_fields_names; // Node field name
|
|
|
|
FloatField m_element_fields; // Float field defined at each element
|
|
IntVector m_element_fields_components; // Number of components for element field
|
|
FieldNames m_element_fields_names; // Element field name
|
|
|
|
StructIndex m_structure_index; // index tag ids
|
|
StructVector m_structures; // unique structures
|
|
StructIndex m_structure_length; // length of structures with consistent element type
|
|
};
|
|
|
|
} //igl
|
|
|
|
#ifndef IGL_STATIC_LIBRARY
|
|
# include "MshLoader.cpp"
|
|
#endif
|
|
|
|
#endif //IGL_MSH_LOADER_H
|