Files
OrcaSlicer/src/slic3r/Utils/MeshInspect.cpp
T
HanifKoh 84657ff11e Add Missing Includes Across the Remaining Sources and Tests (#16071)
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy

Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp.

* Ignore minilzo's Config Headers in clang-tidy

lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes.

* Add Missing Includes Across the Remaining Sources and Tests

Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo.

* Make the GUI and Test Headers Compile on Their Own

Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone.

* Keep Windows and nanosvg Setup Ahead of the Added Includes

OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build.

* Add the GUI Includes the First Pass Missed

Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass.

* Keep the Added Test Includes Below the NOMINMAX Guard

test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
2026-10-03 13:45:21 +08:00

68 lines
2.8 KiB
C++

#include "MeshInspect.hpp"
#include "libslic3r/LayOnFace.hpp"
#include "libslic3r/Model.hpp"
#include "libslic3r/Point.hpp"
#include "libslic3r/BoundingBox.hpp"
#include <cstddef>
#include <nlohmann/json.hpp>
#include <algorithm>
#include <cmath>
#include <ostream>
#include <vector>
#include <string>
#include <utility>
namespace Slic3r {
namespace MeshInspect {
using json = nlohmann::json;
static json to_json(const Vec3d &v) { return json::array({ v.x(), v.y(), v.z() }); }
static json to_json(const BoundingBoxf3 &bb)
{
return { { "min", to_json(bb.min) }, { "max", to_json(bb.max) }, { "size", to_json(bb.size()) } };
}
void inspect_to_json(const Model &model, const std::vector<std::string> &source_paths, std::ostream &out, size_t max_planes)
{
json objects = json::array();
for (const ModelObject *mo : model.objects) {
json obj = { { "name", mo->name },
{ "triangle_count", mo->facets_count() },
{ "instance_count", mo->instances.size() },
{ "bbox_object", to_json(mo->raw_mesh_bounding_box()) } };
if (!mo->instances.empty()) {
const std::vector<LayOnFacePlane> planes = lay_on_face_planes(*mo, mo->instances.front()->get_matrix_no_offset());
json planes_json = json::array();
for (size_t i = 0; i < std::min(planes.size(), max_planes); ++i)
planes_json.push_back({ { "normal", to_json(planes[i].normal) },
{ "area_mm2", std::round(double(planes[i].area) * 1000.) / 1000. },
{ "center", to_json(planes[i].center) } });
obj["bbox_world"] = to_json(mo->instance_bounding_box(0));
obj["instance_offset"] = to_json(mo->instances.front()->get_offset());
obj["plane_count"] = planes.size();
obj["planes"] = std::move(planes_json);
}
objects.push_back(std::move(obj));
}
const json root = {
{ "sources", source_paths },
{ "note", "Lengths in mm. bbox_object and the plane normals and centers are in object coordinates: the parts as "
"currently transformed, without the instance transformation. --ground-face-normal and "
"--ground-face-point take values in these coordinates. area_mm2 uses instance 0's scale, "
"bbox_world is instance 0 on the plate." },
{ "objects", std::move(objects) },
};
// Object names and file paths are arbitrary bytes, and dump() throws on invalid UTF-8 by default.
// Replace such sequences with U+FFFD so the output is always valid JSON.
out << root.dump(2, ' ', false, json::error_handler_t::replace) << std::endl;
}
} // namespace MeshInspect
} // namespace Slic3r