8 #ifndef VTKWRITER_DIST_GRAPH_HPP_
9 #define VTKWRITER_DIST_GRAPH_HPP_
11 #include "VCluster.hpp"
16 template<
bool is_array>
30 template<
typename T,
typename ele_v,
typename G,
typename s_type>
31 static inline void move(
typename G::V_container &vo, s_type (&x)[3],
bool &z_set)
33 if (G::V_type::attributes::name[T::value] ==
"x")
35 x[0] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>())>::type>::template to<s_type>(vo.template get<T::value>());
37 else if (G::V_type::attributes::name[T::value] ==
"y")
39 x[1] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>())>::type>::template to<s_type>(vo.template get<T::value>());
41 else if (G::V_type::attributes::name[T::value] ==
"z")
43 x[2] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>())>::type>::template to<s_type>(vo.template get<T::value>());
66 template<
typename T,
typename ele_v,
typename G,
typename s_type>
67 static inline void move(
typename G::V_container &vo, s_type (&x)[3],
bool &z_set)
69 if (std::extent<ele_v>::value == 3)
72 for (
size_t i = 0; i < std::extent<ele_v>::value; i++)
73 x[i] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>()[i])>::type>::template to<s_type>(vo.template get<T::value>()[i]);
90 template<
typename G,
bool attr>
94 typedef typename G::V_type::s_type s_type;
101 typename G::V_container & vo;
104 std::string & v_node;
115 :z_set(false),x(x), vo(n_obj), v_node(v_node)
122 v_node += std::to_string(x[0]) +
" " + std::to_string(x[1]) +
" " + std::to_string(x[2]) +
"\n";
129 typedef typename boost::mpl::at<typename G::V_type::type, boost::mpl::int_<T::value>>::type ele_v;
155 typename G::V_container & vo;
158 std::string & v_node;
169 vo(n_obj), v_node(v_node)
195 typename G::E_container & vo;
198 std::string & e_node;
210 vo(n_obj), e_node(e_node)
223 e_node +=
"2 " + std::to_string(s) +
" " + std::to_string(d) +
"\n";
230 template<
bool is_array>
243 template<
typename ele_v,
typename Graph,
unsigned int i>
244 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
246 v_out += std::to_string(g.vertex(p).template get<i>()) +
"\n";
266 template<
typename ele_v,
typename Graph,
unsigned int i>
267 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
269 for (
size_t j = 0; j < 2; j++)
271 v_out += std::to_string(g.vertex(p).template get<i>()[j]) +
" ";
274 if (std::extent<ele_v>::value == 2)
277 v_out += std::to_string(g.vertex(p).template get<i>()[2]);
286 template<
bool is_array>
299 template<
typename ele_v,
typename Graph,
unsigned int i>
300 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
302 v_out += std::to_string(edge.template get<i>()) +
"\n";
322 template<
typename ele_v,
typename Graph,
unsigned int i>
323 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
325 for (
size_t j = 0; j < 2; j++)
327 v_out += std::to_string(edge.template get<i>()[j]) +
" ";
330 if (std::extent<ele_v>::value == 2)
333 v_out += std::to_string(edge.template get<i>()[2]);
342 template<
bool is_array>
349 static inline void write(std::string &v_out)
365 static inline void write(std::string &v_out)
385 template<
bool has_attributes,
typename Graph,
unsigned int i>
402 auto it = g.getVertexIterator();
407 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type ele_v;
429 auto it_v = g.getVertexIterator();
432 while (it_v.isNext())
435 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
443 auto it_e = g.getEdgeIterator();
446 while (it_e.isNext())
448 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
473 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type T;
477 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
480 type = getType<typename std::remove_all_extents<T>::type>();
483 if (type.size() == 0)
494 if (type.size() == 0)
501 v_out +=
"LOOKUP_TABLE default\n";
524 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
528 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
531 type = getType<typename std::remove_all_extents<T>::type>();
534 if (type.size() == 0)
545 if (type.size() == 0)
552 e_out +=
"LOOKUP_TABLE default\n";
566 return Graph::V_type::attributes::name[i];
575 return Graph::E_type::attributes::name[i];
592 template<
typename Graph,
unsigned int i>
607 auto it = g.getVertexIterator();
613 v_out += std::to_string(g.vertex(it.get()).
template get<i>()) +
"\n";
634 auto it_v = g.getVertexIterator();
637 while (it_v.isNext())
640 e_out += std::to_string(0) +
"\n";
647 auto it_e = g.getEdgeIterator();
650 while (it_e.isNext())
653 e_out += std::to_string(g.edge(it_e.get()).
template get<i>()) +
"\n";
679 std::string type = getType<boost::fusion::result_of::at<typename Graph::V_type::type, boost::mpl::int_<i>>>(
"attr" + std::to_string(prop));
682 if (type.size() == 0)
691 v_out +=
"LOOKUP_TABLE default\n";
711 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
715 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
718 type = getType<typename std::remove_all_extents<T>::type>();
721 if (type.size() == 0)
732 if (type.size() == 0)
739 e_out +=
"LOOKUP_TABLE default\n";
753 return Graph::V_type::attributes::name[i];
762 return Graph::E_type::attributes::name[i];
779 template<
typename Graph>
804 size_t sz = v_out.size();
810 if (v_out.size() != sz)
833 template<
typename Graph>
858 size_t sz = e_out.size();
864 if (e_out.size() != sz)
882 template<
typename Graph>
901 v_out +=
"VERTICES " + std::to_string(g.getNVertex()) +
" " + std::to_string(g.getNVertex() * 2) +
"\n";
921 v_out +=
"POINTS " + std::to_string(g.getNVertex()) +
" float" +
"\n";
933 v_out +=
"SCALARS id unsigned_long\nLOOKUP_TABLE default\n";
935 for (
size_t i = 0; i < g.getNVertex(); ++i)
937 v_out += std::to_string(g.getVertexId(i)) +
"\n";
941 v_out +=
"SCALARS gid unsigned_long\nLOOKUP_TABLE default\n";
943 for (
size_t i = 0; i < g.getNVertex(); ++i)
945 v_out += std::to_string(g.getVertexGlobalId(i)) +
"\n";
966 e_out +=
"LINES " + std::to_string(g.getNEdge()) +
" " + std::to_string(3 * g.getNEdge()) +
"\n";
982 typename Graph::V_type::s_type x[3] = { 0, 0, 0 };
988 auto it = g.getVertexIterator();
994 auto obj = g.vertex(it.get());
1000 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop> >(vn);
1026 for (
size_t i = 0; i < g.getNVertex(); i++)
1028 v_out +=
"1 " + std::to_string(i) +
"\n";
1045 v_out +=
"POINT_DATA " + std::to_string(g.getNVertex()) +
"\n";
1060 v_out +=
"CELL_DATA " + std::to_string(g.getNVertex() + g.getNEdge()) +
"\n";
1077 auto it = g.getEdgeIterator();
1082 e_out +=
"2 " + std::to_string(it.source()) +
" " + std::to_string(g.nodeById(it.target())) +
"\n";
1116 template<
int prp = -1>
bool write(std::string file, std::string graph_name =
"Graph", file_type ft = file_type::ASCII)
1119 Vcluster & v_cl = *global_v_cluster;
1123 if (v_cl.getProcessUnitID() == 0)
1125 for (
size_t i = 0; i < g.getTotNVertex(); ++i)
1133 if (v_cl.getProcessUnitID() == 0)
1137 if (has_attributes<typename Graph::V_type>::value ==
false)
1139 std::cerr <<
"Error writing a graph: Vertex must has defines x,y,z properties" <<
"\n";
1144 std::string vtk_header;
1146 std::string point_list;
1148 std::string vertex_list;
1150 std::string vtk_binary_or_ascii;
1152 std::string edge_list;
1154 std::string point_prop_header;
1156 std::string vertex_prop_header;
1158 std::string edge_prop_header;
1160 std::string point_data_header;
1162 std::string point_ids;
1164 std::string point_data;
1166 std::string cell_data_header;
1168 std::string cell_data;
1171 vtk_header =
"# vtk DataFile Version 3.0\n" + graph_name +
"\n";
1174 if (ft == file_type::ASCII)
1176 vtk_header +=
"ASCII\n";
1180 vtk_header +=
"BINARY\n";
1184 vtk_header +=
"DATASET POLYDATA\n";
1187 point_prop_header = get_point_properties_list();
1190 point_list = get_point_list<has_attributes<typename Graph::V_type>::value>();
1193 vertex_prop_header = get_vertex_properties_list();
1196 vertex_list = get_vertex_list();
1199 edge_prop_header = get_edge_properties_list();
1202 edge_list = get_edge_list();
1205 point_data_header = get_point_data_header();
1208 point_ids = get_point_info();
1211 cell_data_header = get_cell_data_header();
1218 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop> >(pp);
1220 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(pp);
1227 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::E_type::max_prop> >(ep);
1229 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(ep);
1232 std::ofstream ofs(file);
1235 if (ofs.is_open() ==
false)
1237 std::cerr <<
"Error cannot create the VTK file: " + file;
1240 ofs << vtk_header << point_prop_header << point_list << vertex_prop_header << vertex_list << edge_prop_header << edge_list << point_data_header << point_ids << point_data << cell_data_header << cell_data;
static void write(std::string &v_out, const Graph &g, size_t p)
Writer in case the property is not an array.
Property writer for scalar and vector, it fill the vertex data (needed for edge representation in vtk...
std::string get_cell_data_header()
Get the point data header.
static std::string get_point_data(const Graph &g)
For each vertex set the value.
Set a conversion map between A and B.
static void move(typename G::V_container &vo, s_type(&x)[3], bool &z_set)
Store the geometric informations in case it is an array.
vtk_dist_vertex_node(std::string &v_node, typename G::V_container &n_obj)
Constructor.
void operator()(T &t)
It call the functor for each member.
Property writer for scalar and vector.
std::string get_vertex_properties_list()
It get the vertex properties list.
std::string get_edge_list()
Return the edge list.
static void write(std::string &v_out)
Writer in case the property is an array.
static std::string get_point_data(Graph &g)
For each vertex set the value.
static std::string get_cell_property_header(size_t prop)
Given a Graph return the cell data header for a typename T.
void operator()(T &t) const
It produce an output for each property.
dist_prop_out_vertex(std::string &v_out, const Graph &g)
constructor
static std::string get_point_property_header(size_t prop)
Given a Graph return the point data header for a typename T.
std::string get_vertex_list()
Create the VTK vertex definition.
this class is a functor for "for_each" algorithm
void operator()(T &t) const
It produce an output for each property.
static std::string get_cell_data(const Graph &g)
For each edge set the value, set 1 on vertices, needed by vtk file format.
std::string get_point_list()
Create the VTK point definition.
this class is a functor for "for_each" algorithm
static std::string get_attributes_vertex()
Get the attributes name for vertex.
static std::string get_point_property_header(size_t prop)
Given a Graph return the point data header for a typename T.
this class is a functor for "for_each" algorithm
static std::string get_attributes_edge()
Get the attributes name for edge.
void new_node(size_t v_c, size_t s, size_t d)
Create a new node.
static void write(std::string &v_out)
Writer in case the property is not an array.
vtk_dist_edge_node(std::string &e_node, typename G::E_container &n_obj)
Constructor.
std::string get_point_properties_list()
It get the vertex properties list.
std::string get_edge_properties_list()
It get the edge properties list.
std::string get_point_info()
static std::string get_cell_data(const Graph &g)
For each edge set the value.
This class specialize functions in the case the type T has or not defined attributes.
static std::string get_cell_property_header(size_t prop)
Given a Graph return the cell data header for a typename T.
static void write(std::string &v_out, const Graph &g, const typename Graph::E_container &edge)
Writer in case the property is an array.
Property writer for scalar and vector.
static std::string get_attributes_vertex()
Get the attributes name for vertex.
bool write(std::string file, std::string graph_name="Graph", file_type ft=file_type::ASCII)
It write a VTK file from a graph.
static std::string get_attributes_edge()
Get the attributes name for edge.
void operator()(T &t)
It call the functor for each member.
vtk_dist_vertex_node(std::string &v_node, typename G::V_container &n_obj, s_type(&x)[3])
Constructor.
dist_prop_out_edge(std::string &e_out, const Graph &g)
constructor
static void write(std::string &v_out, const Graph &g, const typename Graph::E_container &edge)
Writer in case the property is not an array.
this class is a functor for "for_each" algorithm
std::string get_point_data_header()
Get the point data header.
void write()
Write collected information.
static void move(typename G::V_container &vo, s_type(&x)[3], bool &z_set)
static void write(std::string &v_out, const Graph &g, size_t p)
Writer in case the property is an array.