This example shows how to load a graph from a file and save a graph into a file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <easy3d/core/graph.h>
28#include <easy3d/fileio/graph_io.h>
29#include <easy3d/util/resource.h>
30#include <easy3d/util/initializer.h>
31
36
37
39
40
41int main(int argc, char** argv) {
42
44
45
48 if (!graph) {
49 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
50 return EXIT_FAILURE;
51 }
52 std::cout << "graph loaded. " << std::endl;
53 std::cout <<
"\tvertices: " << graph->
n_vertices() << std::endl;
54 std::cout <<
"\tedges: " << graph->
n_edges() << std::endl;
55
56
57
58
59
60
61 const std::string save_file_name = "./graph-copy.ply";
63 std::cout << "graph saved to \'" << save_file_name << "\'" << std::endl;
64 else
65 std::cerr << "failed create the new file" << std::endl;
66
67
68 delete graph;
69
70 return EXIT_SUCCESS;
71}
72
A Graph data structure with easy property management.
Definition graph.h:50
unsigned int n_edges() const
Returns number of edges in the graph.
Definition graph.h:784
unsigned int n_vertices() const
Returns number of vertices in the graph.
Definition graph.h:779
static Graph * load(const std::string &file_name)
Reads a graph from file file_name.
Definition graph_io.cpp:37
static bool save(const std::string &file_name, const Graph *graph)
Saves graph to file file_name.
Definition graph_io.cpp:72
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
Definition collider.cpp:182
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39