8 #ifndef VTKWRITER_GRIDS_HPP_
9 #define VTKWRITER_GRIDS_HPP_
11 #include <boost/mpl/pair.hpp>
12 #include "VTKWriter_grids_util.hpp"
13 #include "is_vtk_writable.hpp"
21 template <
typename Gr
id,
typename St>
26 typedef Grid value_type;
29 :
g(g),
offset(offset),spacing(spacing),dom(dom)
57 template<
typename ele_g,
typename St>
81 :v_out(v_out),vg(vg),ft(ft),prop_names(prop_names)
92 typedef typename boost::mpl::at<typename ele_g::value_type::value_type::type,boost::mpl::int_<T::value>>::type ptype;
93 typedef typename std::remove_all_extents<ptype>::type base_ptype;
106 v_out +=
"SCALARS domain float\n";
109 v_out +=
"LOOKUP_TABLE default\n";
112 for (
size_t k = 0 ; k <
vg.size() ; k++)
115 auto it =
vg.get(k).g.getIterator();
120 if (
vg.get(k).dom.isInside(it.get().toPoint()) ==
true)
141 template <
typename pair>
157 for (
size_t i = 0 ; i < vg.size() ; i++)
159 tot += vg.get(i).g.size();
178 v_out +=
"VERTICES " + std::to_string(get_total()) +
" " + std::to_string(get_total() * 2) +
"\n";
198 v_out +=
"POINTS " + std::to_string(get_total()) +
" float" +
"\n";
214 std::stringstream v_out;
218 for (
size_t i = 0 ; i < vg.size() ; i++)
221 auto it = vg.get(i).g.getIterator();
230 p = it.
get().toPoint();
231 p = pmul(p,vg.
get(i).spacing) + vg.get(i).offset;
233 output_point<pair::first::dims,typename pair::second>(p,v_out,ft);
256 for (
size_t i = 0 ; i < vg.size() ; i++)
259 auto it = vg.get(i).g.getIterator();
263 output_vertex(k,v_out,ft);
283 v_out +=
"POINT_DATA " + std::to_string(get_total()) +
"\n";
306 void add(
const typename pair::first & g,
328 template<
int prp = -1>
bool write(std::string file,
330 std::string f_name =
"grids",
331 file_type ft = file_type::ASCII)
334 std::string vtk_header;
336 std::string point_list;
338 std::string vertex_list;
340 std::string vtk_binary_or_ascii;
342 std::string point_prop_header;
344 std::string vertex_prop_header;
346 std::string point_data_header;
348 std::string point_data;
351 vtk_header =
"# vtk DataFile Version 3.0\n"
355 if (ft == file_type::ASCII)
356 {vtk_header +=
"ASCII\n";}
358 {vtk_header +=
"BINARY\n";}
361 vtk_header +=
"DATASET POLYDATA\n";
364 point_prop_header = get_point_properties_list();
367 point_list = get_point_list(ft);
370 vertex_prop_header = get_vertex_properties_list();
373 vertex_list = get_vertex_list(ft);
376 point_data_header = get_point_data_header();
383 boost::mpl::for_each< boost::mpl::range_c<int,0, pair::first::value_type::max_prop> >(pp);
385 boost::mpl::for_each< boost::mpl::range_c<int,prp, prp> >(pp);
392 std::ofstream ofs(file);
395 if (ofs.is_open() ==
false)
396 {std::cerr <<
"Error cannot create the VTK file: " + file +
"\n";}
398 ofs << vtk_header << point_prop_header << point_list <<
399 vertex_prop_header << vertex_list << point_data_header << point_data;
std::string get_vertex_list(file_type ft)
Create the VTK vertex definition.
openfpm::vector< ele_g< typename pair::first, typename pair::second > > vg
Vector of grids.
void operator()(T &t) const
std::string get_point_data_header()
Get the point data header.
std::string dataset
Dataset name.
std::string get_point_properties_list()
It get the vertex properties list.
prop_out_g(std::string &v_out, const openfpm::vector_std< ele_g > &vg, const openfpm::vector< std::string > &prop_names, file_type ft)
constructor
void add(const typename pair::first &g, const Point< pair::first::dims, typename pair::second > &offset, const Point< pair::first::dims, typename pair::second > &spacing, const Box< pair::first::dims, typename pair::second > &dom)
Add grid dataset.
std::string & v_out
property output string
std::string get_point_list(file_type ft)
Create the VTK point definition.
const openfpm::vector< std::string > & prop_names
list of names for the properties
Point< Grid::dims, St > offset
offset where it start
const T & get(size_t i) const
Get coordinate.
This class represent an N-dimensional box.
size_t get_total()
Get the total number of points.
bool write(std::string file, const openfpm::vector< std::string > &prop_names, std::string f_name="grids", file_type ft=file_type::ASCII)
It write a VTK file from a graph.
this class is a functor for "for_each" algorithm
Implementation of 1-D std::vector like structure.
std::string get_vertex_properties_list()
It get the vertex properties list.
const openfpm::vector_std< ele_g > & vg
grid that we are processing
void lastProp()
Write the last property.
check for T to be writable