8#ifndef VTKWRITER_GRAPH_HPP_
9#define VTKWRITER_GRAPH_HPP_
14template<
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]);}
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;
208 typename G::E_container &
vo;
237 e_node +=
"2 " + std::to_string(s) +
" " + std::to_string(d) +
"\n";
244template<
bool is_array>
257 template<
typename ele_v,
typename Graph,
unsigned int i>
258 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
260 v_out += std::to_string(g.vertex(p).template get<i>()) +
"\n";
280 template<
typename ele_v,
typename Graph,
unsigned int i>
281 static inline void write(std::string &v_out,
const Graph &g,
size_t p)
283 for (
size_t j = 0; j < 2; j++)
285 v_out += std::to_string(g.vertex(p).template get<i>()[j]) +
" ";
288 if (std::extent<ele_v>::value == 2)
291 v_out += std::to_string(g.vertex(p).template get<i>()[2]);
300template<
bool is_array>
313 template<
typename ele_v,
typename Graph,
unsigned int i>
314 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
316 v_out += std::to_string(
edge.template get<i>()) +
"\n";
336 template<
typename ele_v,
typename Graph,
unsigned int i>
337 static inline void write(std::string &v_out,
const Graph &g,
const typename Graph::E_container &
edge)
339 for (
size_t j = 0; j < 2; j++)
341 v_out += std::to_string(
edge.template get<i>()[j]) +
" ";
344 if (std::extent<ele_v>::value == 2)
347 v_out += std::to_string(
edge.template get<i>()[2]);
356template<
bool is_array>
363 static inline void write(std::string &v_out)
379 static inline void write(std::string &v_out)
399template<
bool has_attributes,
typename Graph,
unsigned int i>
417 auto it = g.getVertexIterator();
422 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type ele_v;
445 auto it_v = g.getVertexIterator();
448 while (it_v.isNext())
451 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
459 auto it_e = g.getEdgeIterator();
462 while (it_e.isNext())
464 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type ele_v;
490 typedef typename boost::mpl::at<typename Graph::V_type::type, boost::mpl::int_<i>>::type T;
494 if (std::rank<T>::value == 1)
497 type = getType<typename std::remove_all_extents<T>::type>();
500 if (type.size() == 0)
511 if (type.size() == 0)
518 v_out +=
"LOOKUP_TABLE default\n";
541 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
545 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
548 type = getType<typename std::remove_all_extents<T>::type>();
551 if (type.size() == 0)
562 if (type.size() == 0)
569 e_out +=
"LOOKUP_TABLE default\n";
584 return Graph::V_type::attributes::name[i];
594 return Graph::E_type::attributes::name[i];
611template<
typename Graph,
unsigned int i>
628 auto it = g.getVertexIterator();
634 v_out += std::to_string(g.vertex(it.get()).template get<i>()) +
"\n";
657 auto it_v = g.getVertexIterator();
660 while (it_v.isNext())
663 e_out += std::to_string(0) +
"\n";
670 auto it_e = g.getEdgeIterator();
673 while (it_e.isNext())
676 e_out += std::to_string(g.edge(it_e.get()).template get<i>()) +
"\n";
701 std::string type = getType<boost::fusion::result_of::at<typename Graph::V_type::type, boost::mpl::int_<i>>>(
"attr" + std::to_string(
prop));
704 if (type.size() == 0)
713 v_out +=
"LOOKUP_TABLE default\n";
735 typedef typename boost::mpl::at<typename Graph::E_type::type, boost::mpl::int_<i>>::type T;
739 if (std::is_array<T>::value ==
true && std::is_array<
typename std::remove_extent<T>::type>::value ==
false)
742 type = getType<typename std::remove_all_extents<T>::type>();
745 if (type.size() == 0)
756 if (type.size() == 0)
763 e_out +=
"LOOKUP_TABLE default\n";
778 return std::string(
"attr" + std::to_string(i));
788 return std::string(
"attr" + std::to_string(i));
805template<
typename Graph>
835 size_t sz =
v_out.size();
841 if (
v_out.size() != sz)
864template<
typename Graph>
894 size_t sz =
e_out.size();
900 if (
e_out.size() != sz)
918template<
typename Graph>
938 v_out +=
"VERTICES " + std::to_string(g.getNVertex()) +
" " + std::to_string(g.getNVertex() * 2) +
"\n";
958 v_out +=
"POINTS " + std::to_string(g.getNVertex()) +
" float" +
"\n";
978 e_out +=
"LINES " + std::to_string(g.getNEdge()) +
" " + std::to_string(3 * g.getNEdge()) +
"\n";
994 typename Graph::V_type::s_type x[3] = { 0, 0, 0 };
1000 auto it = g.getVertexIterator();
1006 auto obj = g.vertex(it.get());
1012 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop > >(vn);
1036 for (
size_t i = 0; i < g.getNVertex(); i++)
1038 v_out +=
"1 " + std::to_string(i) +
"\n";
1055 v_out +=
"POINT_DATA " + std::to_string(g.getNVertex()) +
"\n";
1070 v_out +=
"CELL_DATA " + std::to_string(g.getNVertex() + g.getNEdge()) +
"\n";
1087 auto it = g.getEdgeIterator();
1095 e_out +=
"2 " + std::to_string(it.source()) +
" " + std::to_string(it.target()) +
"\n";
1130 template<
int prp = -1>
bool write(std::string file, std::string graph_name =
"Graph", file_type ft = file_type::ASCII)
1136 std::cerr <<
"Error writing a graph: Vertex must has defines x,y,z properties" <<
"\n";
1141 std::string vtk_header;
1143 std::string point_list;
1145 std::string vertex_list;
1147 std::string vtk_binary_or_ascii;
1149 std::string edge_list;
1151 std::string point_prop_header;
1153 std::string vertex_prop_header;
1155 std::string edge_prop_header;
1157 std::string point_data_header;
1159 std::string point_data;
1161 std::string cell_data_header;
1163 std::string cell_data;
1166 vtk_header =
"# vtk DataFile Version 3.0\n" + graph_name +
"\n";
1169 if (ft == file_type::ASCII)
1171 vtk_header +=
"ASCII\n";
1175 vtk_header +=
"BINARY\n";
1179 vtk_header +=
"DATASET POLYDATA\n";
1182 point_prop_header = get_point_properties_list();
1185 point_list = get_point_list<has_attributes<typename Graph::V_type>::value>();
1188 vertex_prop_header = get_vertex_properties_list();
1191 vertex_list = get_vertex_list();
1194 edge_prop_header = get_edge_properties_list();
1197 edge_list = get_edge_list();
1200 point_data_header = get_point_data_header();
1203 cell_data_header = get_cell_data_header();
1210 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::V_type::max_prop> >(pp);
1212 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(pp);
1219 boost::mpl::for_each<boost::mpl::range_c<int, 0, Graph::E_type::max_prop> >(ep);
1221 boost::mpl::for_each<boost::mpl::range_c<int, prp, prp> >(ep);
1224 std::ofstream ofs(file);
1227 if (ofs.is_open() ==
false)
1229 std::cerr <<
"Error cannot create the VTK file: " + file;
1232 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;
std::string get_edge_list()
Return the edge list.
std::string get_vertex_properties_list()
It get the vertex properties list.
VTKWriter(const Graph &g)
std::string get_point_data_header()
Get the point data header.
std::string get_point_list()
Create the VTK point definition.
std::string get_point_properties_list()
It get the vertex properties list.
std::string get_vertex_list()
Create the VTK vertex definition.
std::string get_edge_properties_list()
It get the edge properties 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.
const Graph & g
graph we are writing
std::string get_cell_data_header()
Get the point data header.
Set a conversion map between A and B.
static std::string get_attributes_edge()
Get the attributes name for edge.
static std::string get_point_data(Graph &g)
Return the point data section for a graph g.
static std::string get_point_property_header(size_t prop)
Given a Graph return the point data header for the property prop.
static std::string get_cell_property_header(size_t prop)
Given a Graph return the cell data header.
static std::string get_cell_data(const Graph &g)
Return the cell data section for a graph g.
static std::string get_attributes_vertex()
Get the attributes name for vertex.
This class specialize functions in the case the type T has or not defined attributes.
static std::string get_cell_data(const Graph &g)
Get the cell data section for a graph g.
static std::string get_point_property_header(size_t prop)
Return the point header for the property prop.
static std::string get_attributes_edge()
Get the attributes name for edge property i (template parameter)
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_vertex()
Get the attributes name for the property i (template parameter)
static std::string get_point_data(const Graph &g)
Get the vtk point data section for a graph g.
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.
void operator()(T &t) const
It produce an output for each property.
prop_out_edge(std::string &e_out, const Graph &g)
constructor
std::string & e_out
property output string
this class is a functor for "for_each" algorithm
const Graph & g
Graph that we are processing.
prop_out_vertex(std::string &v_out, const Graph &g)
constructor
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.
std::string & e_node
edge node string
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.
std::string & v_node
vertex node string
vtk_vertex_node(std::string &v_node, typename G::V_container &n_obj)
Constructor.
void operator()(T &t)
It call the functor for each member.
G::V_container & vo
Vertex object container.
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 operator()(T &t)
It call the functor for each member.
vtk_vertex_node(std::string &v_node, typename G::V_container &n_obj, s_type(&x)[3])
Constructor.
std::string & v_node
vertex node string
void write()
Write collected information.
G::V_type::s_type s_type
Vertex spatial type information.
s_type(& x)[3]
point to write
bool z_set
Indicate if there is the information about the z coordinate.
G::V_container & vo
Vertex object container.