8 #ifndef VTKWRITER_GRAPH_HPP_
9 #define VTKWRITER_GRAPH_HPP_
14 template<
bool is_array>
28 template<
typename T,
typename ele_v,
typename G,
typename s_type>
29 static inline void move(
typename G::V_container &vo, s_type (&x)[3],
bool &z_set)
31 if (G::V_type::attributes::name[T::value] ==
"x")
33 x[0] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>())>::type>::template to<s_type>(vo.template get<T::value>());
35 else if (G::V_type::attributes::name[T::value] ==
"y")
37 x[1] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>())>::type>::template to<s_type>(vo.template get<T::value>());
39 else if (G::V_type::attributes::name[T::value] ==
"z")
41 x[2] =
convert<
typename boost::remove_reference<decltype(vo.template get<T::value>())>::type>::template to<s_type>(vo.template get<T::value>());
64 template<
typename T,
typename ele_v,
typename G,
typename s_type>
65 static inline void move(
typename G::V_container &vo, s_type (&x)[3],
bool &z_set)
67 if (G::V_type::attributes::name[T::value] !=
"x")
70 if (std::extent<ele_v>::value == 3)
73 for (
size_t i = 0; i < std::extent<ele_v>::value; i++)
74 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]);
91 template<
typename G,
bool attr>
95 typedef typename G::V_type::s_type s_type;
102 typename G::V_container & vo;
105 std::string & v_node;
115 vtk_vertex_node(std::string & v_node,
typename G::V_container & n_obj, s_type (&x)[3])
116 :z_set(false),x(x),vo(n_obj),v_node(v_node)
123 v_node += std::to_string(x[0]) +
" " + std::to_string(x[1]) +
" " + std::to_string(x[2]) +
"\n";
130 typedef typename boost::mpl::at<typename G::V_type::type, boost::mpl::int_<T::value>>::type ele_v;
156 typename G::V_container & vo;
159 std::string & v_node;
170 vo(n_obj), v_node(v_node)
196 typename G::E_container & vo;
199 std::string & e_node;
211 vo(n_obj), e_node(e_node)
224 e_node +=
"2 " + std::to_string(s) +
" " + std::to_string(d) +
"\n";
231 template<
bool is_array>
244 template<
typename ele_v,
typename Graph,
unsigned int i>
245 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
247 v_out += std::to_string(g.vertex(p).template get<i>()) +
"\n";
267 template<
typename ele_v,
typename Graph,
unsigned int i>
268 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
270 for (
size_t j = 0; j < 2; j++)
272 v_out += std::to_string(g.vertex(p).template get<i>()[j]) +
" ";
275 if (std::extent<ele_v>::value == 2)
278 v_out += std::to_string(g.vertex(p).template get<i>()[2]);
287 template<
bool is_array>
300 template<
typename ele_v,
typename Graph,
unsigned int i>
301 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
303 v_out += std::to_string(edge.template get<i>()) +
"\n";
323 template<
typename ele_v,
typename Graph,
unsigned int i>
324 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
326 for (
size_t j = 0; j < 2; j++)
328 v_out += std::to_string(edge.template get<i>()[j]) +
" ";
331 if (std::extent<ele_v>::value == 2)
334 v_out += std::to_string(edge.template get<i>()[2]);
343 template<
bool is_array>
350 static inline void write(std::string &v_out)
366 static inline void write(std::string &v_out)
386 template<
bool has_attributes,
typename Graph,
unsigned int i>
403 auto it = g.getVertexIterator();
408 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type ele_v;
430 auto it_v = g.getVertexIterator();
433 while (it_v.isNext())
436 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
444 auto it_e = g.getEdgeIterator();
447 while (it_e.isNext())
449 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
474 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type T;
478 if (std::rank<T>::value == 1)
481 type = getType<typename std::remove_all_extents<T>::type>();
484 if (type.size() == 0)
495 if (type.size() == 0)
502 v_out +=
"LOOKUP_TABLE default\n";
525 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
529 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
532 type = getType<typename std::remove_all_extents<T>::type>();
535 if (type.size() == 0)
546 if (type.size() == 0)
553 e_out +=
"LOOKUP_TABLE default\n";
567 return Graph::V_type::attributes::name[i];
576 return Graph::E_type::attributes::name[i];
593 template<
typename Graph,
unsigned int i>
608 auto it = g.getVertexIterator();
614 v_out += std::to_string(g.vertex(it.get()).
template get<i>()) +
"\n";
635 auto it_v = g.getVertexIterator();
638 while (it_v.isNext())
641 e_out += std::to_string(0) +
"\n";
648 auto it_e = g.getEdgeIterator();
651 while (it_e.isNext())
654 e_out += std::to_string(g.edge(it_e.get()).
template get<i>()) +
"\n";
680 std::string type = getType<boost::fusion::result_of::at<typename Graph::V_type::type, boost::mpl::int_<i>>>(
"attr" + std::to_string(prop));
683 if (type.size() == 0)
692 v_out +=
"LOOKUP_TABLE default\n";
712 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
716 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
719 type = getType<typename std::remove_all_extents<T>::type>();
722 if (type.size() == 0)
733 if (type.size() == 0)
740 e_out +=
"LOOKUP_TABLE default\n";
754 return Graph::V_type::attributes::name[i];
763 return Graph::E_type::attributes::name[i];
780 template<
typename Graph>
805 size_t sz = v_out.size();
811 if (v_out.size() != sz)
834 template<
typename Graph>
859 size_t sz = e_out.size();
865 if (e_out.size() != sz)
883 template<
typename Graph>
902 v_out +=
"VERTICES " + std::to_string(g.getNVertex()) +
" " + std::to_string(g.getNVertex() * 2) +
"\n";
922 v_out +=
"POINTS " + std::to_string(g.getNVertex()) +
" float" +
"\n";
942 e_out +=
"LINES " + std::to_string(g.getNEdge()) +
" " + std::to_string(3 * g.getNEdge()) +
"\n";
958 typename Graph::V_type::s_type x[3] = { 0, 0, 0 };
964 auto it = g.getVertexIterator();
970 auto obj = g.vertex(it.get());
976 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop > >(vn);
1002 for (
size_t i = 0; i < g.getNVertex(); i++)
1004 v_out +=
"1 " + std::to_string(i) +
"\n";
1021 v_out +=
"POINT_DATA " + std::to_string(g.getNVertex()) +
"\n";
1036 v_out +=
"CELL_DATA " + std::to_string(g.getNVertex() + g.getNEdge()) +
"\n";
1053 auto it = g.getEdgeIterator();
1061 e_out +=
"2 " + std::to_string(it.source()) +
" " + std::to_string(it.target()) +
"\n";
1095 template<
int prp = -1>
bool write(std::string file, std::string graph_name =
"Graph", file_type ft = file_type::ASCII)
1099 if (has_attributes<typename Graph::V_type>::value ==
false)
1101 std::cerr <<
"Error writing a graph: Vertex must has defines x,y,z properties" <<
"\n";
1106 std::string vtk_header;
1108 std::string point_list;
1110 std::string vertex_list;
1112 std::string vtk_binary_or_ascii;
1114 std::string edge_list;
1116 std::string point_prop_header;
1118 std::string vertex_prop_header;
1120 std::string edge_prop_header;
1122 std::string point_data_header;
1124 std::string point_data;
1126 std::string cell_data_header;
1128 std::string cell_data;
1131 vtk_header =
"# vtk DataFile Version 3.0\n" + graph_name +
"\n";
1134 if (ft == file_type::ASCII)
1136 vtk_header +=
"ASCII\n";
1140 vtk_header +=
"BINARY\n";
1144 vtk_header +=
"DATASET POLYDATA\n";
1147 point_prop_header = get_point_properties_list();
1150 point_list = get_point_list<has_attributes<typename Graph::V_type>::value>();
1153 vertex_prop_header = get_vertex_properties_list();
1156 vertex_list = get_vertex_list();
1159 edge_prop_header = get_edge_properties_list();
1162 edge_list = get_edge_list();
1165 point_data_header = get_point_data_header();
1168 cell_data_header = get_cell_data_header();
1175 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop> >(pp);
1177 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(pp);
1184 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::E_type::max_prop> >(ep);
1186 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(ep);
1189 std::ofstream ofs(file);
1192 if (ofs.is_open() ==
false)
1194 std::cerr <<
"Error cannot create the VTK file: " + file;
1197 ofs << vtk_header << point_prop_header << point_list << vertex_prop_header << vertex_list << edge_prop_header << edge_list << point_data_header << point_data << cell_data_header << cell_data;
static std::string get_cell_property_header(size_t prop)
Given a Graph return the cell data header for a typename T.
this class is a functor for "for_each" algorithm
void operator()(T &t)
It call the functor for each member.
std::string get_point_data_header()
Get the point data header.
static void write(std::string &v_out)
Writer in case the property is not an array.
Set a conversion map between A and B.
prop_out_vertex(std::string &v_out, const Graph &g)
constructor
static std::string get_point_data(Graph &g)
For each vertex set the value.
std::string get_edge_properties_list()
It get the edge properties list.
static std::string get_attributes_edge()
Get the attributes name for edge.
static void write(std::string &v_out, const Graph &g, const typename Graph::E_container &edge)
Writer in case the property is an array.
this class is a functor for "for_each" algorithm
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 std::string get_attributes_vertex()
Get the attributes name for vertex.
prop_out_edge(std::string &e_out, const Graph &g)
constructor
VTKWriter(const Graph &g)
void operator()(T &t) const
It produce an output for each property.
static void write(std::string &v_out, const Graph &g, size_t p)
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.
std::string get_vertex_properties_list()
It get the vertex properties list.
this class is a functor for "for_each" algorithm
Property writer for scalar and vector, it fill the vertex data (needed for edge representation in vtk...
std::string get_edge_list()
Return the edge list.
static std::string get_attributes_vertex()
Get the attributes name for vertex.
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.
static void write(std::string &v_out)
Writer in case the property is an array.
Property writer for scalar and vector.
std::string get_vertex_list()
Create the VTK vertex definition.
static void move(typename G::V_container &vo, s_type(&x)[3], bool &z_set)
static std::string get_cell_data(const Graph &g)
For each edge set the value, set 1 on vertices, needed by vtk file format.
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.
static std::string get_point_property_header(size_t prop)
Given a Graph return the point data header for a typename T.
bool write(std::string file, std::string graph_name="Graph", file_type ft=file_type::ASCII)
It write a VTK file from a graph.
Property writer for scalar and vector.
This class specialize functions in the case the type T has or not defined attributes.
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_edge_node(std::string &e_node, typename G::E_container &n_obj)
Constructor.
void new_node(size_t v_c, size_t s, size_t d)
Create a new node.
static std::string get_point_property_header(size_t prop)
Given a Graph return the point data header for a typename T.
vtk_vertex_node(std::string &v_node, typename G::V_container &n_obj, s_type(&x)[3])
Constructor.
void write()
Write collected information.
this class is a functor for "for_each" algorithm
std::string get_point_list()
Create the VTK point definition.
void operator()(T &t)
It call the functor for each member.
vtk_vertex_node(std::string &v_node, typename G::V_container &n_obj)
Constructor.
std::string get_point_properties_list()
It get the vertex properties list.
static std::string get_point_data(const Graph &g)
For each vertex set the value.
std::string get_cell_data_header()
Get the point data header.