MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMeshSave.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRExpected.h"
5#include "MRIOFilters.h"
6#include "MRSaveSettings.h"
7#include <filesystem>
8#include <iosfwd>
9
10namespace MR
11{
12
13namespace MeshSave
14{
15
19
22MRMESH_API Expected<void> toMrmesh( const Mesh & mesh, const std::filesystem::path & file,
23 const SaveSettings & settings = {} );
24MRMESH_API Expected<void> toMrmesh( const Mesh & mesh, std::ostream & out,
25 const SaveSettings & settings = {} );
26
28MRMESH_API Expected<void> toOff( const Mesh & mesh, const std::filesystem::path & file,
29 const SaveSettings & settings = {} );
30MRMESH_API Expected<void> toOff( const Mesh & mesh, std::ostream & out,
31 const SaveSettings & settings = {} );
32
36MRMESH_API Expected<void> toOff( const TriMesh & mesh, const std::filesystem::path & file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
37MRMESH_API Expected<void> toOff( const TriMesh & mesh, std::ostream & out, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
38
41MRMESH_API Expected<void> toObj( const Mesh & mesh, const std::filesystem::path & file,
42 const SaveSettings & settings, int firstVertId );
43MRMESH_API Expected<void> toObj( const Mesh & mesh, std::ostream & out,
44 const SaveSettings & settings, int firstVertId );
45MRMESH_API Expected<void> toObj( const Mesh & mesh, const std::filesystem::path & file, const SaveSettings & settings = {} );
46MRMESH_API Expected<void> toObj( const Mesh & mesh, std::ostream & out, const SaveSettings & settings = {} );
47
52MRMESH_API Expected<void> toObj( const TriMesh & mesh, const std::filesystem::path & file, const SaveSettings & settings, int firstVertId, const FaceBitSet * region = nullptr );
53MRMESH_API Expected<void> toObj( const TriMesh & mesh, std::ostream & out, const SaveSettings & settings, int firstVertId, const FaceBitSet * region = nullptr );
54MRMESH_API Expected<void> toObj( const TriMesh & mesh, const std::filesystem::path & file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
55MRMESH_API Expected<void> toObj( const TriMesh & mesh, std::ostream & out, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
56
59MRMESH_API Expected<void> toBinaryStl( const Mesh & mesh, const std::filesystem::path & file, const SaveSettings & settings = {} );
60MRMESH_API Expected<void> toBinaryStl( const Mesh & mesh, std::ostream & out, const SaveSettings & settings = {} );
62MRMESH_API Expected<void> toBinaryStl( const TriMesh & mesh, const std::filesystem::path & file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
63MRMESH_API Expected<void> toBinaryStl( const TriMesh & mesh, std::ostream & out, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
64
67{
68public:
70 MRMESH_API explicit BinaryStlSaver( std::ostream & out, const SaveSettings & settings = {}, std::uint32_t expectedNumTris = 0 );
71
72 BinaryStlSaver( const BinaryStlSaver& ) = delete;
73 BinaryStlSaver( BinaryStlSaver&& ) noexcept = delete;
74
76 MRMESH_API bool writeTri( const Triangle3f& tri );
77
81
84
85private:
86 std::ostream & out_;
87 SaveSettings settings_;
88 std::streamoff numTrisPos_ = 0;
89 std::uint32_t headNumTris_ = 0;
90 std::uint32_t savedNumTris_ = 0;
91 std::uint16_t triAttr_ = 0;
92};
93
96MRMESH_API Expected<void> toAsciiStl( const Mesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {} );
97MRMESH_API Expected<void> toAsciiStl( const Mesh & mesh, std::ostream& out, const SaveSettings & settings = {} );
99MRMESH_API Expected<void> toAsciiStl( const TriMesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
100MRMESH_API Expected<void> toAsciiStl( const TriMesh & mesh, std::ostream& out, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
101
103MRMESH_API Expected<void> toPly( const Mesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {} );
104MRMESH_API Expected<void> toPly( const Mesh & mesh, std::ostream & out, const SaveSettings & settings = {} );
105
109MRMESH_API Expected<void> toPly( const TriMesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
110MRMESH_API Expected<void> toPly( const TriMesh & mesh, std::ostream & out, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
111
113MRMESH_API Expected<void> toModel3mf( const Mesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {} );
114MRMESH_API Expected<void> toModel3mf( const Mesh & mesh, std::ostream & out, const SaveSettings & settings = {} );
115
119MRMESH_API Expected<void> toModel3mf( const TriMesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
120MRMESH_API Expected<void> toModel3mf( const TriMesh & mesh, std::ostream & out, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
121
123MRMESH_API Expected<void> to3mf( const Mesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {} );
124
128MRMESH_API Expected<void> to3mf( const TriMesh & mesh, const std::filesystem::path& file, const SaveSettings & settings = {}, const FaceBitSet * region = nullptr );
129
131MR_BIND_OVERLOAD_SUFFIX() MRMESH_API Expected<void> toAnySupportedFormat( const Mesh & mesh, const std::filesystem::path & file, const SaveSettings & settings = {} );
133MR_BIND_OVERLOAD_SUFFIX(stream) MRMESH_API Expected<void> toAnySupportedFormat( const Mesh & mesh, const std::string& extension, std::ostream& out, const SaveSettings & settings = {} );
134
136
137}
138
139}
#define MRMESH_API
Definition MRMeshFwd.h:85
BinaryStlSaver(BinaryStlSaver &&) noexcept=delete
bool writeTri(const Triangle3f &tri)
writes one more triangle in the stream
BinaryStlSaver(std::ostream &out, const SaveSettings &settings={}, std::uint32_t expectedNumTris=0)
writes STL header in the stream
BinaryStlSaver(const BinaryStlSaver &)=delete
tl::expected< T, E > Expected
Definition MRExpected.h:31
Triangle3< float > Triangle3f
Definition MRMeshFwd.h:466
Expected< void > toAsciiStl(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
Expected< void > toPly(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
saves in .ply file
Expected< void > toObj(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings, int firstVertId)
Expected< void > toBinaryStl(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
Expected< void > toAnySupportedFormat(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
detects the format from file extension and save mesh to it
Expected< void > to3mf(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
saves in .3mf file
Expected< void > toOff(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
saves in .off file
Expected< void > toMrmesh(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
Expected< void > toModel3mf(const Mesh &mesh, const std::filesystem::path &file, const SaveSettings &settings={})
saves in 3mf .model file
Definition MRCtm.h:30
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh.h:24
determines how to save points/lines/mesh
Definition MRSaveSettings.h:20
Definition MRTriMesh.h:16