8 #ifndef OPENFPM_IO_SRC_VTKWRITER_POINT_SET_HPP_
9 #define OPENFPM_IO_SRC_VTKWRITER_POINT_SET_HPP_
12 #include <boost/mpl/pair.hpp>
13 #include "VTKWriter_grids_util.hpp"
14 #include "is_vtk_writable.hpp"
16 #include "byteswap_portable.hpp"
23 template <
typename Vps>
49 template <
typename Vpp>
82 template<
typename ele_v,
typename St>
108 :ft(ft),v_out(v_out),vv(vv),prop_names(prop_names)
119 typedef typename boost::mpl::at<typename ele_v::value_type::value_type::type,boost::mpl::int_<T::value>>::type ptype;
120 typedef typename std::remove_all_extents<ptype>::type base_ptype;
128 v_out +=
"SCALARS domain float\n";
131 v_out +=
"LOOKUP_TABLE default\n";
134 for (
size_t k = 0 ; k <
vv.size() ; k++)
137 auto it =
vv.get(k).g.getIterator();
142 if (
ft == file_type::ASCII)
144 if (it.get() <
vv.get(k).mark)
151 if (it.get() <
vv.get(k).mark)
154 one = swap_endian_lt(one);
155 v_out.append((
const char *)&one,
sizeof(
int));
160 zero = swap_endian_lt(zero);
161 v_out.append((
const char *)&zero,
sizeof(
int));
182 template <
typename pair>
200 for (
size_t i = 0 ; i < vps.size() ; i++)
202 tot += vps.get(i).g.size();
220 v_out +=
"VERTICES " + std::to_string(get_total()) +
" " + std::to_string(get_total() * 2) +
"\n";
241 if (ft == file_type::ASCII)
242 v_out +=
"POINTS " + std::to_string(get_total()) +
" float" +
"\n";
244 v_out +=
"POINTS " + std::to_string(get_total()) +
" " + getType<typename pair::first::value_type::coord_type>() +
"\n";
260 std::stringstream v_out;
264 for (
size_t i = 0 ; i < vps.size() ; i++)
267 auto it = vps.get(i).g.getIterator();
273 p = vps.
get(i).g.get(it.get());
275 output_point<pair::first::value_type::dims,typename pair::first::value_type::coord_type>(p,v_out,ft);
283 if (ft == file_type::BINARY)
304 for (
size_t i = 0 ; i < vps.size() ; i++)
307 auto it = vps.get(i).g.getIterator();
311 output_vertex(k,v_out,ft);
319 if (ft == file_type::BINARY)
335 v_out +=
"POINT_DATA " + std::to_string(get_total()) +
"\n";
358 void add(
const typename pair::first & vps,
359 const typename pair::second & vpp,
381 template<
int prp = -1>
bool write(std::string file,
383 std::string f_name =
"points" ,
384 file_type ft = file_type::ASCII)
387 std::string vtk_header;
389 std::string point_list;
391 std::string vertex_list;
393 std::string vtk_binary_or_ascii;
395 std::string point_prop_header;
397 std::string vertex_prop_header;
399 std::string point_data_header;
401 std::string point_data;
404 vtk_header =
"# vtk DataFile Version 3.0\n"
408 if (ft == file_type::ASCII)
409 {vtk_header +=
"ASCII\n";}
411 {vtk_header +=
"BINARY\n";}
414 vtk_header +=
"DATASET POLYDATA\n";
417 point_prop_header = get_point_properties_list(ft);
420 point_list = get_point_list(ft);
423 vertex_prop_header = get_vertex_properties_list();
426 vertex_list = get_vertex_list(ft);
429 point_data_header = get_point_data_header();
436 boost::mpl::for_each< boost::mpl::range_c<int,0, pair::second::value_type::max_prop> >(pp);
438 boost::mpl::for_each< boost::mpl::range_c<int,prp, prp> >(pp);
445 std::ofstream ofs(file);
448 if (ofs.is_open() ==
false)
449 {std::cerr <<
"Error cannot create the VTK file: " + file +
"\n";}
451 ofs << vtk_header << point_prop_header << point_list <<
452 vertex_prop_header << vertex_list << point_data_header << point_data;
file_type ft
Binary or ASCII.
openfpm::vector< ele_vpp< typename pair::second > > vpp
Vector of properties.
const Vps & g
particle position vector
openfpm::vector< ele_vps< typename pair::first > > vps
Vector of position.
void operator()(T &t) const
It produce an output for each property.
std::string get_point_list(file_type ft)
Create the VTK point list.
ele_vpp(const Vpp &vpp, size_t mark)
constructor
This class implement the point shape in an N-dimensional space.
Store a reference to the vector position.
bool write(std::string file, const openfpm::vector< std::string > &prop_names, std::string f_name="points", file_type ft=file_type::ASCII)
It write a VTK file from a vector of points.
const openfpm::vector_std< ele_v > & vv
vector that we are processing
this class is a functor for "for_each" algorithm
ele_vps(const Vps &g, size_t mark)
constructor
It model an expression expr1 * expr2.
std::string get_vertex_properties_list()
It get the vertex properties list.
std::string get_point_properties_list(file_type ft)
It get the vertex properties list.
std::string get_point_data_header()
Get the point data header.
std::string get_vertex_list(file_type ft)
Create the VTK vertex list.
Store a reference to the vector properties.
Vps value_type
type of vector that store the particle position
const Vpp & g
Reference to the particle properties.
std::string & v_out
property output string
const T & get(size_t i) const
Get coordinate.
size_t get_total()
Get the total number of points.
Vpp value_type
type of vector that store the particle properties
prop_out_v(std::string &v_out, const openfpm::vector_std< ele_v > &vv, const openfpm::vector< std::string > &prop_names, file_type ft)
constructor
Implementation of 1-D std::vector like structure.
void add(const typename pair::first &vps, const typename pair::second &vpp, size_t mark)
Add a vector dataset.
const openfpm::vector< std::string > & prop_names
properties names
check for T to be writable