HighMap library (C++)
Loading...
Searching...
No Matches
export.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
17#pragma once
18#include <filesystem>
19#include <map>
20#include <opencv2/imgcodecs.hpp>
21#include <png.h>
22
23#include "highmap/array.hpp"
24#include "highmap/tensor.hpp"
25
26namespace hmap
27{
28
29enum Cmap : int; // highmap/colormap.hpp
30
38enum MeshType : int
39{
42};
43
52static std::map<MeshType, std::string> mesh_type_as_string = {
53 {TRI_OPTIMIZED, "triangles (optimized)"},
54 {TRI, "triangles"}};
55
85
105// clang-format off
106static std::map<AssetExportFormat, std::vector<std::string> >
107asset_export_format_as_string = {
108 {_3DS, {"Autodesk 3DS (legacy) - *.3ds", "3ds", "3ds"}},
109 {_3MF, {"The 3MF-File-Format - *.3mf", "3mf", "3mf"}},
110 {ASSBIN, {"Assimp Binary - *.assbin", "assbin", "assbin"}},
111 {ASSXML, {"Assxml Document - *.assxml", "assxml", "assxml"}},
112 {FXBA, {"Autodesk FBX (ascii) - *.fbx", "fbxa", "fbx"}},
113 {FBX, {"Autodesk FBX (binary) - *.fbx", "fbx", "fbx"}},
114 {COLLADA, {"COLLADA - Digital Asset Exchange Schema - *.dae", "collada", "dae"}},
115 {X3D, {"Extensible 3D - *.x3d", "x3d", "x3d"}},
116 {GLTF, {"GL Transmission Format - *.gltf", "gltf", "gltf"}},
117 {GLB, {"GL Transmission Format (binary) - *.glb", "glb", "glb"}},
118 {GTLF2, {"GL Transmission Format v. 2 - *.gltf", "gltf2", "gltf"}},
119 {GLB2, {"GL Transmission Format v. 2 (binary) - *.glb", "glb2", "glb"}},
120 {PLY, {"Stanford Polygon Library - *.ply", "ply", "ply"}},
121 {PLYB, {"Stanford Polygon Library (binary) - *.ply", "plyb", "ply"}},
122 {STP, {"Step Files - *.stp", "stp", "stp"}},
123 {STL, {"Stereolithography - *.stl", "stl", "stl"}},
124 {STLB, {"Stereolithography (binary) - *.stl", "stlb", "stl"}},
125 {OBJ, {"Wavefront OBJ format - *.obj", "obj", "obj"}},
126 {OBJNOMTL, {"Wavefront OBJ format without material file - *.obj", "objnomtl", "obj"}},
127};
128// clang-format on
129
158bool export_asset(const std::string &fname,
159 const Array &array,
160 MeshType mesh_type = MeshType::TRI,
162 float elevation_scaling = 0.2f,
163 const std::string &texture_fname = "",
164 const std::string &normal_map_fname = "",
165 float max_error = 5e-4f);
166
188std::string export_as_ascii(const Array &array,
189 const Vec2<int> &export_shape = {64, 64},
190 const std::string chars_map = " .:-=+*#%@");
191
230void export_as_cubemap(const std::string &fname,
231 const Array &z,
232 int cubemap_resolution = 128,
233 float overlap = 0.25f,
234 int ir = 16,
235 Cmap cmap = Cmap::GRAY,
236 bool splitted = false,
237 Array *p_cubemap = nullptr);
238
255void export_banner_png(const std::string &fname,
256 const std::vector<Array> &arrays,
257 int cmap,
258 bool hillshading = false);
259
275void export_normal_map_png(const std::string &fname,
276 const Array &array,
277 int depth = CV_8U);
278
308void export_splatmap_png(const std::string &fname,
309 const Array *p_r,
310 const Array *p_g = nullptr,
311 const Array *p_b = nullptr,
312 const Array *p_a = nullptr,
313 int depth = CV_8U);
314
347void export_tiled(const std::string &fname_radical,
348 const std::string &fname_extension,
349 const Array &array,
350 const Vec2<int> &tiling,
351 int leading_zeros = 0,
352 int depth = CV_8U,
353 bool overlapping_edges = false,
354 bool reverse_tile_y_indexing = false);
355
370Array read_to_array(const std::string &fname);
371
384void write_raw_16bit(const std::string &fname, const Array &array);
385
386// --- helpers
387
408std::filesystem::path add_filename_suffix(
409 const std::filesystem::path &file_path,
410 const std::string &suffix);
411
412} // namespace hmap
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Definition algebra.hpp:28
void export_banner_png(const std::string &fname, const std::vector< Array > &arrays, int cmap, bool hillshading=false)
Exports a set of arrays as a banner PNG image file.
Definition export_banner_png.cpp:11
void export_splatmap_png(const std::string &fname, const Array *p_r, const Array *p_g=nullptr, const Array *p_b=nullptr, const Array *p_a=nullptr, int depth=CV_8U)
Exports four arrays as an RGBA PNG splatmap.
Definition export_splatmap.cpp:29
void export_as_cubemap(const std::string &fname, const Array &z, int cubemap_resolution=128, float overlap=0.25f, int ir=16, Cmap cmap=Cmap::GRAY, bool splitted=false, Array *p_cubemap=nullptr)
Exports a 2D array as a cubemap texture with continuity enforcement and overlapping regions.
Definition export_as_cubemap.cpp:174
void write_raw_16bit(const std::string &fname, const Array &array)
Exports an array to a 16-bit 'raw' file format, commonly used for Unity terrain imports.
Definition format_raw.cpp:15
std::filesystem::path add_filename_suffix(const std::filesystem::path &file_path, const std::string &suffix)
Definition helpers.cpp:9
bool export_asset(const std::string &fname, const Array &array, MeshType mesh_type=MeshType::TRI, AssetExportFormat export_format=AssetExportFormat::GLB2, float elevation_scaling=0.2f, const std::string &texture_fname="", const std::string &normal_map_fname="", float max_error=5e-4f)
Exports a heightmap to various 3D file formats.
Definition export_asset.cpp:27
void export_tiled(const std::string &fname_radical, const std::string &fname_extension, const Array &array, const Vec2< int > &tiling, int leading_zeros=0, int depth=CV_8U, bool overlapping_edges=false, bool reverse_tile_y_indexing=false)
Exports a 2D array as a set of grayscale PNG image tiles.
Definition export_tiled.cpp:12
void export_normal_map_png(const std::string &fname, const Array &array, int depth=CV_8U)
Exports the heightmap normal map as an 8-bit PNG file.
Definition export_normal_map.cpp:15
std::string export_as_ascii(const Array &array, const Vec2< int > &export_shape={64, 64}, const std::string chars_map=" .:-=+*#%@")
Export a 2D array as an ASCII-art string representation.
Definition export_as_ascii.cpp:12
AssetExportFormat
Enumeration for asset export formats supported by Assimp.
Definition export.hpp:64
@ FBX
Autodesk FBX (binary) - *.fbx.
Definition export.hpp:70
@ PLY
Stanford Polygon Library - *.ply.
Definition export.hpp:77
@ GLB2
GL Transmission Format v. 2 (binary) - *.glb.
Definition export.hpp:76
@ STL
Stereolithography - *.stl.
Definition export.hpp:80
@ _3MF
The 3MF-File-Format - *.3mf.
Definition export.hpp:66
@ ASSBIN
Assimp Binary - *.assbin.
Definition export.hpp:67
@ GTLF2
GL Transmission Format v. 2 - *.gltf.
Definition export.hpp:75
@ X3D
Extensible 3D - *.x3d.
Definition export.hpp:72
@ COLLADA
COLLADA - Digital Asset Exchange Schema - *.dae.
Definition export.hpp:71
@ STP
Step Files - *.stp.
Definition export.hpp:79
@ GLB
GL Transmission Format (binary) - *.glb.
Definition export.hpp:74
@ ASSXML
Assxml Document - *.assxml.
Definition export.hpp:68
@ FXBA
Autodesk FBX (ascii) - *.fbx.
Definition export.hpp:69
@ GLTF
GL Transmission Format - *.gltf.
Definition export.hpp:73
@ STLB
Stereolithography (binary) - *.stl.
Definition export.hpp:81
@ OBJ
Wavefront OBJ format - *.obj.
Definition export.hpp:82
@ PLYB
Stanford Polygon Library (binary) - *.ply.
Definition export.hpp:78
@ _3DS
Autodesk 3DS (legacy) - *.3ds.
Definition export.hpp:65
@ OBJNOMTL
Wavefront OBJ format without material file - *.obj.
Definition export.hpp:83
Cmap
Enumeration for different colormap types.
Definition colormaps.hpp:81
@ GRAY
Definition colormaps.hpp:83
MeshType
Enumeration for different mesh types.
Definition export.hpp:39
@ TRI_OPTIMIZED
Triangles with optimized Delaunay triangulation.
Definition export.hpp:40
@ TRI
Triangle elements.
Definition export.hpp:41
Array read_to_array(const std::string &fname)
Reads an image file and converts it to a 2D array.
Definition read_to_array.cpp:14
Header file for the Tensor class.