MeshLib
 
Loading...
Searching...
No Matches
MRSerializer.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRVector2.h"
5#include "MRVector3.h"
6#include "MRVector4.h"
7#include "MRMatrix2.h"
8#include "MRColor.h"
9#include "MRPlane3.h"
10#include "MRIOFilters.h"
11#include "MRProgressCallback.h"
12#include "MRExpected.h"
13#include <filesystem>
14
15namespace Json
16{
17class Value;
18}
19
20namespace MR
21{
22
26
28using FolderCallback = std::function<void( const std::filesystem::path& tempFolderName )>;
29
31{
32public:
37
38 explicit operator bool() const
39 {
40 return !folder_.empty();
41 }
42 operator const std::filesystem::path& ( ) const
43 {
44 return folder_;
45 }
46 std::filesystem::path operator /( const std::filesystem::path& child ) const
47 {
48 return folder_ / child;
49 }
50
51private:
52 std::filesystem::path folder_;
53 FolderCallback onPreTempFolderDelete_;
54};
55
58
61MRMESH_API Expected<Json::Value> deserializeJsonValue( const std::filesystem::path& path );
62
73 const std::filesystem::path& path, ProgressCallback progress = {}, FolderCallback preCompress = {} );
84 FolderCallback postDecompress = {}, ProgressCallback progressCb = {} );
85
95 ProgressCallback progressCb = {} );
96
100MRMESH_API VoidOrErrStr serializeMesh( const Mesh& mesh, const std::filesystem::path& path, const FaceBitSet* selection = nullptr,
101 const char * saveMeshFormat = ".mrmesh" );
102
104MRMESH_API void serializeToJson( const Vector2i& vec, Json::Value& root );
105MRMESH_API void serializeToJson( const Vector2f& vec, Json::Value& root );
106MRMESH_API void serializeToJson( const Vector3i& vec, Json::Value& root );
107MRMESH_API void serializeToJson( const Vector3f& vec, Json::Value& root );
108MRMESH_API void serializeToJson( const Vector4f& vec, Json::Value& root );
109MRMESH_API void serializeToJson( const Box3i& box, Json::Value& root );
110MRMESH_API void serializeToJson( const Box3f& box, Json::Value& root );
111MRMESH_API void serializeToJson( const Color& col, Json::Value& root );
112MRMESH_API void serializeToJson( const Matrix2f& matrix, Json::Value& root, bool skipIdentity = true );
113MRMESH_API void serializeToJson( const Matrix3f& matrix, Json::Value& root, bool skipIdentity = true );
114MRMESH_API void serializeToJson( const AffineXf2f& xf, Json::Value& root, bool skipIdentity = true );
115MRMESH_API void serializeToJson( const AffineXf3f& xf, Json::Value& root, bool skipIdentity = true );
116MRMESH_API void serializeToJson( const BitSet& bitset, Json::Value& root );
117MRMESH_API VoidOrErrStr serializeToJson( const Mesh& mesh, Json::Value& root );
118MRMESH_API void serializeToJson( const Plane3f& plane, Json::Value& root );
119MRMESH_API void serializeToJson( const TriPointf& tp, Json::Value& root );
120MRMESH_API void serializeToJson( const MeshTexture& texture, Json::Value& root );
121MRMESH_API void serializeToJson( const std::vector<TextureId>& texturePerFace, Json::Value& root );
122MRMESH_API void serializeToJson( const std::vector<UVCoord>& uvCoords, Json::Value& root );
123MRMESH_API void serializeToJson( const std::vector<Color>& colors, Json::Value& root );
126MRMESH_API void serializeToJson( const MeshTriPoint& mtp, const MeshTopology& topology, Json::Value& root );
127MRMESH_API void serializeToJson( const PointOnFace& pf, Json::Value& root );
128
131MRMESH_API void serializeViaVerticesToJson( const UndirectedEdgeBitSet& edges, const MeshTopology & topology, Json::Value& root );
132MRMESH_API void deserializeViaVerticesFromJson( const Json::Value& root, UndirectedEdgeBitSet& edges, const MeshTopology & topology );
133
135MRMESH_API void deserializeFromJson( const Json::Value& root, Vector2i& vec );
136MRMESH_API void deserializeFromJson( const Json::Value& root, Vector2f& vec );
137MRMESH_API void deserializeFromJson( const Json::Value& root, Vector3i& vec );
138MRMESH_API void deserializeFromJson( const Json::Value& root, Vector3f& vec );
139MRMESH_API void deserializeFromJson( const Json::Value& root, Vector4f& vec );
140MRMESH_API void deserializeFromJson( const Json::Value& root, Color& col );
141MRMESH_API void deserializeFromJson( const Json::Value& root, Matrix2f& matrix );
142MRMESH_API void deserializeFromJson( const Json::Value& root, Matrix3f& matrix );
143MRMESH_API void deserializeFromJson( const Json::Value& root, AffineXf2f& xf );
144MRMESH_API void deserializeFromJson( const Json::Value& root, AffineXf3f& xf );
145MRMESH_API void deserializeFromJson( const Json::Value& root, BitSet& bitset );
146MRMESH_API Expected<Mesh> deserializeFromJson( const Json::Value& root, VertColors* colors = nullptr );
147MRMESH_API void deserializeFromJson( const Json::Value& root, Plane3f& plane );
148MRMESH_API void deserializeFromJson( const Json::Value& root, TriPointf& tp );
149MRMESH_API void deserializeFromJson( const Json::Value& root, MeshTexture& texture );
150MRMESH_API void deserializeFromJson( const Json::Value& root, std::vector<TextureId>& texturePerFace );
151MRMESH_API void deserializeFromJson( const Json::Value& root, std::vector<UVCoord>& uvCoords );
152MRMESH_API void deserializeFromJson( const Json::Value& root, std::vector<Color>& colors );
155MRMESH_API void deserializeFromJson( const Json::Value& root, MeshTriPoint& mtp, const MeshTopology& topology );
156MRMESH_API void deserializeFromJson( const Json::Value& root, PointOnFace& pf );
157
159
160} // namespace MR
#define MRMESH_API
Definition MRMesh/MRMeshFwd.h:46
Definition MRDotNet/MRBitSet.h:39
container of bits
Definition MRMesh/MRBitSet.h:26
Definition MRMesh/MRMeshTopology.h:18
named object in the data model
Definition MRObject.h:60
Definition MRSerializer.h:31
MRMESH_API ~UniqueTemporaryFolder()
removes folder with all its content
MRMESH_API UniqueTemporaryFolder(FolderCallback onPreTempFolderDelete)
creates new folder in temp directory
std::filesystem::path operator/(const std::filesystem::path &child) const
Definition MRSerializer.h:46
represents a 3-dimentional float-typed vector
Definition MRDotNet/MRVector3.h:8
std::function< bool(float)> ProgressCallback
Definition MRMesh/MRMeshFwd.h:589
std::vector< IOFilter > IOFilters
Definition MRIOFilters.h:23
MRMESH_API const IOFilters SceneFileFilters
std::function< void(const std::filesystem::path &tempFolderName)> FolderCallback
this callback will be called before compression on serialization and after decompression on deseriali...
Definition MRSerializer.h:28
MRMESH_API Expected< std::shared_ptr< Object > > deserializeObjectTree(const std::filesystem::path &path, FolderCallback postDecompress={}, ProgressCallback progressCb={})
loads objects tree from given scene file (zip/mru)
MRMESH_API Expected< Json::Value > deserializeJsonValue(std::istream &in)
MRMESH_API const IOFilters SceneFileWriteFilters
MRMESH_API void deserializeFromJson(const Json::Value &root, Vector2i &vec)
loads an object from json value
MRMESH_API Expected< std::shared_ptr< Object > > deserializeObjectTreeFromFolder(const std::filesystem::path &folder, ProgressCallback progressCb={})
loads objects tree from given scene folder
MRMESH_API void serializeViaVerticesToJson(const UndirectedEdgeBitSet &edges, const MeshTopology &topology, Json::Value &root)
MRMESH_API void deserializeViaVerticesFromJson(const Json::Value &root, UndirectedEdgeBitSet &edges, const MeshTopology &topology)
MRMESH_API VoidOrErrStr serializeObjectTree(const Object &object, const std::filesystem::path &path, ProgressCallback progress={}, FolderCallback preCompress={})
saves object subtree in given scene file (zip/mru)
MRMESH_API VoidOrErrStr serializeMesh(const Mesh &mesh, const std::filesystem::path &path, const FaceBitSet *selection=nullptr, const char *saveMeshFormat=".mrmesh")
MRMESH_API void serializeToJson(const Vector2i &vec, Json::Value &root)
saves an object into json value
Definition MRCameraOrientationPlugin.h:7
tl::expected< T, E > Expected
Definition MRExpected.h:49
MRMESH_CLASS Vector3< double > Matrix2< double > Matrix4< double > SymMatrix3< double > AffineXf2f
Definition MRMesh/MRMeshFwd.h:201
Expected< void > VoidOrErrStr
return type for a void function that can produce an error string
Definition MRExpected.h:60
Definition MRColor.h:9
Definition MRMeshTexture.h:13
Definition MRMesh/MRMeshTriPoint.h:23
Definition MRMesh/MRMesh.h:23
Definition MRPointOnFace.h:11