Skip to content

Commit

Permalink
Use PolySet::createEmpty()
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel committed Mar 5, 2024
1 parent bc8491f commit c1c146e
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/core/ImportNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ std::unique_ptr<const Geometry> ImportNode::createGeometry() const
#endif
default:
LOG(message_group::Error, "Unsupported file format while trying to import file '%1$s', import() at line %2$d", this->filename, loc.firstLine());
g = std::make_unique<PolySet>(3);
g = PolySet::createEmpty();
}

g->setConvexity(this->convexity);
Expand Down
8 changes: 4 additions & 4 deletions src/core/primitives.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ std::unique_ptr<const Geometry> CubeNode::createGeometry() const
|| this->y <= 0 || !std::isfinite(this->y)
|| this->z <= 0 || !std::isfinite(this->z)
) {
return std::make_unique<PolySet>(3, true);
return PolySet::createEmpty();
}

double x1, x2, y1, y2, z1, z2;
Expand Down Expand Up @@ -184,7 +184,7 @@ static std::shared_ptr<AbstractNode> builtin_cube(const ModuleInstantiation *ins
std::unique_ptr<const Geometry> SphereNode::createGeometry() const
{
if (this->r <= 0 || !std::isfinite(this->r)) {
return std::make_unique<PolySet>(3, true);
return PolySet::createEmpty();
}

auto num_fragments = Calc::get_fragments_from_r(r, fn, fs, fa);
Expand Down Expand Up @@ -263,7 +263,7 @@ std::unique_ptr<const Geometry> CylinderNode::createGeometry() const
|| this->r2 < 0 || !std::isfinite(this->r2)
|| (this->r1 <= 0 && this->r2 <= 0)
) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

auto num_fragments = Calc::get_fragments_from_r(std::fmax(this->r1, this->r2), this->fn, this->fs, this->fa);
Expand Down Expand Up @@ -404,7 +404,7 @@ std::string PolyhedronNode::toString() const

std::unique_ptr<const Geometry> PolyhedronNode::createGeometry() const
{
auto p = std::make_unique<PolySet>(3);
auto p = PolySet::createEmpty();
p->setConvexity(this->convexity);
p->vertices=this->points;
p->indices=this->faces;
Expand Down
6 changes: 3 additions & 3 deletions src/geometry/GeometryEvaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ std::unique_ptr<Geometry> GeometryEvaluator::applyHull3D(const AbstractNode& nod
{
Geometry::Geometries children = collectChildren3D(node);

auto P = std::make_unique<PolySet>(3);
auto P = PolySet::createEmpty();
return applyHull(children);
}

Expand Down Expand Up @@ -1041,7 +1041,7 @@ static std::unique_ptr<Geometry> extrudePolygon(const LinearExtrudeNode& node, c
if (isConvex && non_linear) isConvex = unknown;
PolySetBuilder builder(0, 0, 3, isConvex);
builder.setConvexity(node.convexity);
if (node.height <= 0) return std::make_unique<PolySet>(3);
if (node.height <= 0) return PolySet::createEmpty();

size_t slices;
if (node.has_slices) {
Expand Down Expand Up @@ -1567,7 +1567,7 @@ Response GeometryEvaluator::visit(State& state, const RoofNode& node)
} catch (RoofNode::roof_exception& e) {
LOG(message_group::Error, node.modinst->location(), this->tree.getDocumentPath(),
"Skeleton computation error. " + e.message());
roof = std::make_unique<PolySet>(3);
roof = PolySet::createEmpty();
}
assert(roof);
geom = std::move(roof);
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/PolySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PolySet : public Geometry
boost::tribool convexValue() const { return this->convex; }
bool isTriangular = false;

static std::unique_ptr<PolySet> createEmpty() { return PolySet::createEmpty(); }
}
static std::unique_ptr<PolySet> createEmpty() { return std::make_unique<PolySet>(3); }

private:
unsigned int dim;
mutable boost::tribool convex;
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/PolySetUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ std::shared_ptr<const PolySet> getGeometryAsPolySet(const std::shared_ptr<const
}
LOG(message_group::Error, "Nef->PolySet failed.");
}
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
if (auto hybrid = std::dynamic_pointer_cast<const CGALHybridPolyhedron>(geom)) {
return hybrid->toPolySet();
Expand Down
2 changes: 1 addition & 1 deletion src/geometry/cgal/cgalutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ std::unique_ptr<PolySet> createPolySetFromNefPolyhedron3(const CGAL::Nef_polyhed
LOG(message_group::Error, "Non-manifold mesh created: %1$d unconnected edges", unconnected2);
}

auto polyset = std::make_unique<PolySet>(3);
auto polyset = PolySet::createEmpty();
polyset->vertices.reserve(verts.size());
for (const auto& v : verts) {
polyset->vertices.emplace_back(v.cast<double>());
Expand Down
2 changes: 1 addition & 1 deletion src/io/export.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct LexographicLess {

std::unique_ptr<PolySet> createSortedPolySet(const PolySet& ps)
{
auto out = std::make_unique<PolySet>(3);
auto out = PolySet::createEmpty();

std::map<Vector3d, int, LexographicLess> vertexMap;

Expand Down
44 changes: 22 additions & 22 deletions src/io/import_3mf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static std::unique_ptr<PolySet> import_3mf_error(PLib3MFModel *model = nullptr,
lib3mf_release(object_it);
}

return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location& loc)
Expand All @@ -74,14 +74,14 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
HRESULT result = lib3mf_getinterfaceversion(&interfaceVersionMajor, &interfaceVersionMinor, &interfaceVersionMicro);
if (result != LIB3MF_OK) {
LOG(message_group::Error, "Error reading 3MF library version");
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

if ((interfaceVersionMajor != NMR_APIVERSION_INTERFACE_MAJOR)) {
LOG(message_group::Error, "Invalid 3MF library major version %1$d.%2$d.%3$d, expected %4$d.%5$d.%6$d",
interfaceVersionMajor, interfaceVersionMinor, interfaceVersionMicro,
NMR_APIVERSION_INTERFACE_MAJOR, NMR_APIVERSION_INTERFACE_MINOR, NMR_APIVERSION_INTERFACE_MICRO);
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

PLib3MFModel *model;
Expand Down Expand Up @@ -173,7 +173,7 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
lib3mf_release(model);

if (!first_mesh) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
} else if (meshes.empty()) {
return first_mesh;
} else {
Expand All @@ -187,10 +187,10 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
if (auto ps = PolySetUtils::getGeometryAsPolySet(CGALUtils::applyUnion3D(children.begin(), children.end()))) {
p = std::make_unique<PolySet>(*ps);
} else {
p = std::make_unique<PolySet>(3);
p = PolySet::createEmpty();
}
#else
p = std::make_unique<PolySet>(3);
p = PolySet::createEmpty();
#endif // ifdef ENABLE_CGAL
return p;
}
Expand Down Expand Up @@ -237,48 +237,48 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
LOG(message_group::Error, "Invalid 3MF library major version %1$d.%2$d.%3$d, expected %4$d.%5$d.%6$d",
interfaceVersionMajor, interfaceVersionMinor, interfaceVersionMicro,
LIB3MF_VERSION_MAJOR, LIB3MF_VERSION_MINOR, LIB3MF_VERSION_MICRO);
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
} catch (const Lib3MF::ELib3MFException& e) {
LOG(message_group::Export_Error, e.what());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

Lib3MF::PModel model;
try {
model = wrapper->CreateModel();
if (!model) {
LOG(message_group::Error, "Could not create model");
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
} catch (const Lib3MF::ELib3MFException& e) {
LOG(message_group::Export_Error, e.what());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

Lib3MF::PReader reader;
try {
reader = model->QueryReader("3mf");
if (!reader) {
LOG(message_group::Error, "Could not create 3MF reader");
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
} catch (const Lib3MF::ELib3MFException& e) {
LOG(message_group::Export_Error, "Could create 3MF reader, import() at line %1$d: %2$s", loc.firstLine(), e.what());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

try {
reader->ReadFromFile(filename);
} catch (const Lib3MF::ELib3MFException& e) {
LOG(message_group::Warning, "Could not read file '%1$s', import() at line %2$d: %3$s", filename.c_str(), loc.firstLine(), e.what());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

Lib3MF::PMeshObjectIterator object_it;
object_it = model->GetMeshObjects();
if (!object_it) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

std::unique_ptr<PolySet> first_mesh;
Expand All @@ -290,20 +290,20 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
try {
object = object_it->GetCurrentMeshObject();
if (!object) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
} catch (const Lib3MF::ELib3MFException& e) {
LOG(message_group::Error, e.what());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

Lib3MF_uint64 vertex_count = object->GetVertexCount();
if (!vertex_count) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
Lib3MF_uint64 triangle_count = object->GetTriangleCount();
if (!triangle_count) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

PRINTDB("%s: mesh %d, vertex count: %lu, triangle count: %lu", filename.c_str() % mesh_idx % vertex_count % triangle_count);
Expand All @@ -330,7 +330,7 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
}

if (first_mesh == 0) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
} else if (meshes.empty()) {
return first_mesh;
} else {
Expand All @@ -347,10 +347,10 @@ std::unique_ptr<Geometry> import_3mf(const std::string& filename, const Location
// FIXME: unnecessary copy
p = std::make_unique<PolySet>(*ps);
} else {
p = std::make_unique<PolySet>(3);
p = PolySet::createEmpty();
}
#else
p = std::make_unique<PolySet>(3);
p = PolySet::createEmpty();
#endif // ifdef ENABLE_CGAL
return p;
}
Expand All @@ -368,7 +368,7 @@ const std::string get_lib3mf_version() {
std::unique_ptr<Geometry> import_3mf(const std::string&, const Location& loc)
{
LOG(message_group::Warning, "Import from 3MF format was not enabled when building the application, import() at line %1$d", loc.firstLine());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

#endif // ENABLE_LIB3MF
4 changes: 2 additions & 2 deletions src/io/import_amf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ std::unique_ptr<PolySet> AmfImporter::read(const std::string& filename)
vertex_list.clear();

if (polySets.empty()) {
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
if (polySets.size() == 1) {
return std::move(polySets[0]);
Expand All @@ -274,7 +274,7 @@ std::unique_ptr<PolySet> AmfImporter::read(const std::string& filename)
#endif // ENABLE_CGAL
LOG(message_group::Error, "Error importing multi-object AMF file '%1$s', import() at line %2$d", filename, this->loc.firstLine());
}
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}

#ifdef ENABLE_LIBZIP
Expand Down
20 changes: 10 additions & 10 deletions src/io/import_obj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::unique_ptr<PolySet> import_obj(const std::string& filename, const Location&
LOG(message_group::Warning,
"Can't open import file '%1$s', import() at line %2$d",
filename, loc.firstLine());
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
boost::regex ex_comment(R"(^\s*#)");
boost::regex ex_v( R"(^\s*v\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*$)");
Expand All @@ -36,7 +36,7 @@ std::unique_ptr<PolySet> import_obj(const std::string& filename, const Location&
"OBJ File line %1$s, %2$s line '%3$s' importing file '%4$s'",
lineno, errstr, line, filename);
};
std::vector<int> vertex_map;
std::vector<int> vertex_map;

while (!f.eof()) {
lineno++;
Expand All @@ -48,14 +48,14 @@ std::unique_ptr<PolySet> import_obj(const std::string& filename, const Location&
continue;
} else if (boost::regex_search(line, results, ex_v) && results.size() >= 4) {
try {
Vector3d v;
Vector3d v;
for (int i = 0; i < 3; i++) {
v[i]= boost::lexical_cast<double>(results[i + 1]);
}
vertex_map.push_back(builder.vertexIndex(v));
} catch (const boost::bad_lexical_cast& blc) {
AsciiError("can't parse vertex");
return std::make_unique<PolySet>(3);
return PolySet::createEmpty();
}
} else if (boost::regex_search(line, results, ex_f) && results.size() >= 2) {
std::string args=results[1];
Expand All @@ -65,16 +65,16 @@ std::unique_ptr<PolySet> import_obj(const std::string& filename, const Location&
for (const std::string& word : words) {
std::vector<std::string> wordindex;
boost::split(wordindex, word, boost::is_any_of("/"));
if(wordindex.size() < 1)
if(wordindex.size() < 1)
LOG(message_group::Warning, "Invalid Face index in File %1$s in Line %2$d", filename, lineno);
else {
int ind=boost::lexical_cast<int>(wordindex[0]);
else {
int ind=boost::lexical_cast<int>(wordindex[0]);
if(ind >= 1 && ind <= vertex_map.size()) {
builder.appendVertex(vertex_map[ind-1]);
} else {
} else {
LOG(message_group::Warning, "Index %1$d out of range in Line %2$d", filename, lineno);
}
}
}
}
}

} else if (boost::regex_search(line, results, ex_vt)) { // ignore texture coords
Expand Down

0 comments on commit c1c146e

Please sign in to comment.