8#ifndef VTKWRITER_DIST_GRAPH_HPP_
9#define VTKWRITER_DIST_GRAPH_HPP_
11#include "VCluster/VCluster.hpp"
16template<
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]);
90template<
typename G,
bool attr>
94 typedef typename G::V_type::s_type
s_type;
103 typename G::V_container &
vo;
125 v_node += std::to_string(
x[0]) +
" " + std::to_string(
x[1]) +
" " + std::to_string(
x[2]) +
"\n";
136 typedef typename boost::mpl::at<typename G::V_type::type, boost::mpl::int_<T::value>>::type ele_v;
162 typename G::V_container &
vo;
205 typename G::E_container &
vo;
233 e_node +=
"2 " + std::to_string(s) +
" " + std::to_string(d) +
"\n";
240template<
bool is_array>
253 template<
typename ele_v,
typename Graph,
unsigned int i>
254 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
256 v_out += std::to_string(g.vertex(p).template get<i>()) +
"\n";
276 template<
typename ele_v,
typename Graph,
unsigned int i>
277 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
279 for (
size_t j = 0; j < 2; j++)
281 v_out += std::to_string(g.vertex(p).template get<i>()[j]) +
" ";
284 if (std::extent<ele_v>::value == 2)
287 v_out += std::to_string(g.vertex(p).template get<i>()[2]);
296template<
bool is_array>
309 template<
typename ele_v,
typename Graph,
unsigned int i>
310 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
312 v_out += std::to_string(
edge.template get<i>()) +
"\n";
332 template<
typename ele_v,
typename Graph,
unsigned int i>
333 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
335 for (
size_t j = 0; j < 2; j++)
337 v_out += std::to_string(
edge.template get<i>()[j]) +
" ";
340 if (std::extent<ele_v>::value == 2)
343 v_out += std::to_string(
edge.template get<i>()[2]);
352template<
bool is_array>
359 static inline void write(std::string &v_out)
375 static inline void write(std::string &v_out)
395template<
bool has_attributes,
typename Graph,
unsigned int i>
414 auto it = g.getVertexIterator();
419 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type ele_v;
443 auto it_v = g.getVertexIterator();
446 while (it_v.isNext())
449 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
457 auto it_e = g.getEdgeIterator();
460 while (it_e.isNext())
462 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
487 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type T;
491 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
494 type = getType<typename std::remove_all_extents<T>::type>();
497 if (type.size() == 0)
508 if (type.size() == 0)
515 v_out +=
"LOOKUP_TABLE default\n";
538 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
542 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
545 type = getType<typename std::remove_all_extents<T>::type>();
548 if (type.size() == 0)
559 if (type.size() == 0)
566 e_out +=
"LOOKUP_TABLE default\n";
581 return Graph::V_type::attributes::name[i];
591 return Graph::E_type::attributes::name[i];
608template<
typename Graph,
unsigned int i>
624 auto it = g.getVertexIterator();
630 v_out += std::to_string(g.vertex(it.get()).template get<i>()) +
"\n";
652 auto it_v = g.getVertexIterator();
655 while (it_v.isNext())
658 e_out += std::to_string(0) +
"\n";
665 auto it_e = g.getEdgeIterator();
668 while (it_e.isNext())
671 e_out += std::to_string(g.edge(it_e.get()).template get<i>()) +
"\n";
695 std::string type = getType<boost::fusion::result_of::at<typename Graph::V_type::type, boost::mpl::int_<i>>>(
"attr" + std::to_string(
prop));
698 if (type.size() == 0)
707 v_out +=
"LOOKUP_TABLE default\n";
728 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
732 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
735 type = getType<typename std::remove_all_extents<T>::type>();
738 if (type.size() == 0)
749 if (type.size() == 0)
756 e_out +=
"LOOKUP_TABLE default\n";
771 return Graph::V_type::attributes::name[i];
781 return Graph::E_type::attributes::name[i];
798template<
typename Graph>
827 size_t sz =
v_out.size();
833 if (
v_out.size() != sz)
856template<
typename Graph>
884 size_t sz =
e_out.size();
890 if (
e_out.size() != sz)
908template<
typename Graph>
928 v_out +=
"VERTICES " + std::to_string(g.getNVertex()) +
" " + std::to_string(g.getNVertex() * 2) +
"\n";
948 v_out +=
"POINTS " + std::to_string(g.getNVertex()) +
" float" +
"\n";
965 v_out +=
"SCALARS id unsigned_long\nLOOKUP_TABLE default\n";
967 for (
size_t i = 0; i < g.getNVertex(); ++i)
969 v_out += std::to_string(g.getVertexId(i)) +
"\n";
973 v_out +=
"SCALARS gid unsigned_long\nLOOKUP_TABLE default\n";
975 for (
size_t i = 0; i < g.getNVertex(); ++i)
977 v_out += std::to_string(g.getVertexGlobalId(i)) +
"\n";
998 e_out +=
"LINES " + std::to_string(g.getNEdge()) +
" " + std::to_string(3 * g.getNEdge()) +
"\n";
1015 typename Graph::V_type::s_type x[3] = { 0, 0, 0 };
1021 auto it = g.getVertexIterator();
1027 auto obj = g.vertex(it.get());
1033 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop> >(vn);
1059 for (
size_t i = 0; i < g.getNVertex(); i++)
1061 v_out +=
"1 " + std::to_string(i) +
"\n";
1078 v_out +=
"POINT_DATA " + std::to_string(g.getNVertex()) +
"\n";
1093 v_out +=
"CELL_DATA " + std::to_string(g.getNVertex() + g.getNEdge()) +
"\n";
1110 auto it = g.getEdgeIterator();
1115 e_out +=
"2 " + std::to_string(it.source()) +
" " + std::to_string(g.nodeById(it.target())) +
"\n";
1150 template<
int prp = -1>
bool write(std::string file, std::string graph_name =
"Graph", file_type ft = file_type::ASCII)
1159 for (
size_t i = 0; i < g.getTotNVertex(); ++i)
1173 std::cerr <<
"Error writing a graph: Vertex must has defines x,y,z properties" <<
"\n";
1178 std::string vtk_header;
1180 std::string point_list;
1182 std::string vertex_list;
1184 std::string vtk_binary_or_ascii;
1186 std::string edge_list;
1188 std::string point_prop_header;
1190 std::string vertex_prop_header;
1192 std::string edge_prop_header;
1194 std::string point_data_header;
1196 std::string point_ids;
1198 std::string point_data;
1200 std::string cell_data_header;
1202 std::string cell_data;
1205 vtk_header =
"# vtk DataFile Version 3.0\n" + graph_name +
"\n";
1208 if (ft == file_type::ASCII)
1210 vtk_header +=
"ASCII\n";
1214 vtk_header +=
"BINARY\n";
1218 vtk_header +=
"DATASET POLYDATA\n";
1221 point_prop_header = get_point_properties_list();
1224 point_list = get_point_list<has_attributes<typename Graph::V_type>::value>();
1227 vertex_prop_header = get_vertex_properties_list();
1230 vertex_list = get_vertex_list();
1233 edge_prop_header = get_edge_properties_list();
1236 edge_list = get_edge_list();
1239 point_data_header = get_point_data_header();
1242 point_ids = get_point_info();
1245 cell_data_header = get_cell_data_header();
1252 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop> >(pp);
1254 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(pp);
1261 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::E_type::max_prop> >(ep);
1263 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(ep);
1266 std::ofstream ofs(file);
1269 if (ofs.is_open() ==
false)
1271 std::cerr <<
"Error cannot create the VTK file: " + file;
1274 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;
Graph & g
Graph to output.
std::string get_vertex_list()
Create the VTK vertex definition.
std::string get_cell_data_header()
Get the point data header.
std::string get_vertex_properties_list()
It get the vertex properties list.
std::string get_edge_list()
Return the edge list.
bool write(std::string file, std::string graph_name="Graph", file_type ft=file_type::ASCII)
It write a VTK file from a graph.
std::string get_edge_properties_list()
It get the edge properties list.
std::string get_point_properties_list()
It get the vertex properties list.
std::string get_point_info()
Get the VTK point info string.
std::string get_point_list()
Create the VTK point definition.
std::string get_point_data_header()
Get the point data header.
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
Set a conversion map between A and B.
static std::string get_point_data(Graph &g)
For each vertex output the property string.
static std::string get_attributes_vertex()
Get the attributes name for vertex.
static std::string get_cell_data(const Graph &g)
For each edge output the property string.
static std::string get_point_property_header(size_t prop)
Given a Graph return the point data header for a typename T.
static std::string get_cell_property_header(size_t prop)
Given a Graph return the cell data header for a typename T.
static std::string get_attributes_edge()
Get the attributes name for edge.
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 std::string get_point_data(const Graph &g)
For each vertex set the value.
static std::string get_attributes_edge()
Get the attributes name for edge.
static std::string get_cell_data(const Graph &g)
For each edge set the value, set 1 on vertices, needed by vtk file format.
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.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
this class is a functor for "for_each" algorithm
const Graph & g
Graph that we are processing.
std::string & e_out
property output string
dist_prop_out_edge(std::string &e_out, const Graph &g)
constructor
void operator()(T &t) const
It produce an output for each property.
this class is a functor for "for_each" algorithm
dist_prop_out_vertex(std::string &v_out, const Graph &g)
constructor
const Graph & g
Graph that we are processing.
std::string & v_out
property output string
void operator()(T &t) const
It produce an output for each property.
static void write(std::string &v_out, const Graph &g, const typename Graph::E_container &edge)
Writer in case the property is an array.
static void write(std::string &v_out)
Writer in case the property is an array.
Property writer for scalar and vector, it fill the vertex data (needed for edge representation in vtk...
static void write(std::string &v_out)
Writer in case the property is not an array.
Property writer for scalar and vector.
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.
static void write(std::string &v_out, const Graph &g, size_t p)
Writer in case the property is an array.
Property writer for scalar and vector.
static void write(std::string &v_out, const Graph &g, size_t p)
Writer in case the property is not an array.
Sub-domain vertex graph node.
this class is a functor for "for_each" algorithm
G::E_container & vo
Vertex object container.
vtk_dist_edge_node(std::string &e_node, typename G::E_container &n_obj)
Constructor.
void new_node(size_t vc, size_t s, size_t d)
Create an edge.
std::string & e_node
edge node string
std::string & v_node
vertex position string
void operator()(T &t)
It call the functor for each attribute.
G::V_container & vo
Vertex object container.
vtk_dist_vertex_node(std::string &v_node, typename G::V_container &n_obj)
Constructor.
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.
static void move(typename G::V_container &vo, s_type(&x)[3], bool &z_set)
this class is a functor for "for_each" algorithm
void write()
Write collected information.
std::string & v_node
vertex position converted to string
bool z_set
indicate if the z coordinate has been set
G::V_type::s_type s_type
Vertex spatial type information.
vtk_dist_vertex_node(std::string &v_node, typename G::V_container &n_obj, s_type(&x)[3])
Constructor.
s_type(& x)[3]
coordinate of the vertex node
void operator()(T &t)
It call the functor for each attribute.
G::V_container & vo
Vertex object container.