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"
21template <
typename Gr
id,
typename St>
26 typedef Grid value_type;
57template<
typename ele_g,
typename St>
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 (
ft == file_type::ASCII)
122 if (
vg.get(k).dom.isInside(it.get().toPoint()) ==
true)
125 flag +=
vg.get(k).g.getFlag(it.get()) * 2;
126 v_out += std::to_string(flag) +
"\n";
131 flag +=
vg.get(k).g.getFlag(it.get()) * 2;
132 v_out += std::to_string(flag) +
"\n";
137 if (
vg.get(k).dom.isInside(it.get().toPoint()) ==
true)
140 flag = swap_endian_lt(flag);
141 v_out.append((
const char *)&flag,
sizeof(flag));
146 flag = swap_endian_lt(flag);
147 v_out.append((
const char *)&flag,
sizeof(flag));
167template <
typename pair>
183 for (
size_t i = 0 ; i < vg.
size() ; i++)
185 tot += vg.get(i).g.
size();
204 v_out +=
"VERTICES " + std::to_string(get_total()) +
" " + std::to_string(get_total() * 2) +
"\n";
223 if (std::is_same<typename pair::second,float>::value ==
true)
224 {v_out +=
"POINTS " + std::to_string(get_total()) +
" float" +
"\n";}
226 {v_out +=
"POINTS " + std::to_string(get_total()) +
" double" +
"\n";}
242 std::stringstream v_out;
244 if (std::is_same<typename pair::second,float>::value ==
true)
245 {v_out << std::setprecision(7);}
247 {v_out << std::setprecision(16);}
251 for (
size_t i = 0 ; i < vg.
size() ; i++)
254 auto it = vg.get(i).g.getIterator();
263 p = it.
get().toPoint();
264 p = pmul(p,vg.get(i).spacing) + vg.get(i).offset;
266 output_point<pair::first::dims,typename pair::second>(p,v_out,ft);
289 for (
size_t i = 0 ; i < vg.
size() ; i++)
292 auto it = vg.get(i).g.getIterator();
296 output_vertex(k,v_out,ft);
316 v_out +=
"POINT_DATA " + std::to_string(get_total()) +
"\n";
339 void add(
const typename pair::first & g,
361 template<
int prp = -1>
bool write(std::string file,
363 std::string f_name =
"grids",
364 file_type ft = file_type::ASCII)
367 std::string vtk_header;
369 std::string point_list;
371 std::string vertex_list;
373 std::string vtk_binary_or_ascii;
375 std::string point_prop_header;
377 std::string vertex_prop_header;
379 std::string point_data_header;
381 std::string point_data;
384 vtk_header =
"# vtk DataFile Version 3.0\n"
388 if (ft == file_type::ASCII)
389 {vtk_header +=
"ASCII\n";}
391 {vtk_header +=
"BINARY\n";}
394 vtk_header +=
"DATASET POLYDATA\n";
397 point_prop_header = get_point_properties_list();
400 point_list = get_point_list(ft);
403 vertex_prop_header = get_vertex_properties_list();
406 vertex_list = get_vertex_list(ft);
409 point_data_header = get_point_data_header();
416 {boost::mpl::for_each< boost::mpl::range_c<int,0, pair::first::value_type::max_prop> >(pp);}
418 {boost::mpl::for_each< boost::mpl::range_c<int,prp, prp> >(pp);}
425 std::ofstream ofs(file);
428 if (ofs.is_open() ==
false)
429 {std::cerr <<
"Error cannot create the VTK file: " + file +
"\n";}
431 ofs << vtk_header << point_prop_header << point_list <<
432 vertex_prop_header << vertex_list << point_data_header << point_data;
This class represent an N-dimensional box.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
openfpm::vector< ele_g< typename pair::first, typename pair::second > > vg
Vector of grids.
std::string get_vertex_properties_list()
It get the vertex properties list.
size_t get_total()
Get the total number of points.
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 get_point_data_header()
Get the point data header.
std::string get_vertex_list(file_type ft)
Create the VTK vertex definition.
std::string get_point_properties_list()
It get the vertex properties list.
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.
std::string get_point_list(file_type ft)
Create the VTK point definition.
std::string dataset
Dataset name.
Point< Grid::dims, St > offset
offset where it start
Implementation of 1-D std::vector like structure.
check for T to be writable
this class is a functor for "for_each" algorithm
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
const openfpm::vector< std::string > & prop_names
list of names for the properties
const openfpm::vector_std< ele_g > & vg
grid that we are processing
std::string & v_out
property output string
void operator()(T &t) const
void lastProp()
Write the last property.