8 #ifndef VTKWRITER_VECTOR_BOX_HPP_
9 #define VTKWRITER_VECTOR_BOX_HPP_
11 #include <boost/math/special_functions/pow.hpp>
12 #include "Space/Shape/HyperCube.hpp"
16 template <
typename vector>
21 v_box(
const vector & v)
37 template <
typename vector>
40 openfpm::vector<v_box<vector>> v;
59 for (
size_t i = 0 ; i < v.size() ; i++)
61 np += v.get(i).v.size() * boost::math::pow<vector::value_type::dims>(2);
65 v_out +=
"POINTS " + std::to_string(np) +
" float" +
"\n";
89 for (
size_t i = 0 ; i < v.size() ; i++)
91 nb += v.get(i).v.size();
94 nc = nb * (boost::math::pow<vector::value_type::dims>(2) + 1);
97 e_out +=
"CELLS " + std::to_string(nb) +
" " + std::to_string(nc) +
"\n";
117 for (
size_t i = 0 ; i < v.size() ; i++)
119 auto it = v.get(i).v.getIterator();
125 auto box = v.get(i).v.get(it.get());
129 HyperCube<vector::value_type::dims> hyp;
130 std::vector<comb<vector::value_type::dims>> comb = hyp.getCombinations_R(0);
134 for (
size_t j = 0; j < comb.size() ; j++)
136 Point<vector::value_type::dims,float> p;
138 for (
size_t k = 0 ; k < 3 ; k++)
140 if (k < vector::value_type::dims)
142 if (comb[j].value(k) < 0)
143 v_out += std::to_string(box.template get<vector::value_type::p1>()[k]) +
" ";
145 v_out += std::to_string(box.template get<vector::value_type::p2>()[k]) +
" ";
180 for (
size_t i = 0 ; i < v.size() ; i++)
182 auto it = v.get(i).v.getIterator();
188 v_out += std::to_string((
size_t)boost::math::pow<vector::value_type::dims>(2)) +
" ";
189 for (
size_t k = 0 ; k < boost::math::pow<vector::value_type::dims>(2) ; k++)
191 v_out +=
" " + std::to_string(base+k);
193 base += boost::math::pow<vector::value_type::dims>(2);
219 for (
size_t i = 0 ; i < v.size() ; i++)
221 np += v.get(i).v.size() * boost::math::pow<vector::value_type::dims>(2);
225 v_out +=
"POINT_DATA " + std::to_string(np) +
"\n";
239 for (
size_t i = 0 ; i < v.size() ; i++)
241 nb += v.get(i).v.size();
245 e_out +=
"CELL_TYPES " + std::to_string(nb) +
"\n";
255 if (vector::value_type::dims == 2)
265 for (
size_t i = 0 ; i < v.size() ; i++)
267 auto it = v.get(i).v.getIterator();
272 v_out += std::to_string(cell_id) +
"\n";
292 for (
size_t i = 0 ; i < v.size() ; i++)
294 nb += v.get(i).v.size();
298 e_out +=
"CELL_DATA " + std::to_string(nb) +
"\n";
299 e_out +=
"COLOR_SCALARS data 4\n";
313 size_t col_group = 0;
316 for (
size_t i = 0 ; i < v.size() ; i++)
318 auto it = v.get(i).v.getIterator();
324 v_out += getColor(col_group,rng).toString() +
" 1.0" +
"\n";
351 void add(
const vector & vc)
368 template<
int prp = -1>
bool write(std::string file, std::string graph_name=
"Graph", file_type ft = file_type::ASCII)
371 std::string vtk_header;
373 std::string point_list;
375 std::string cell_list;
377 std::string vtk_binary_or_ascii;
379 std::string edge_list;
381 std::string point_prop_header;
383 std::string cell_prop_header;
385 std::string edge_prop_header;
387 std::string point_data_header;
389 std::string point_data;
391 std::string cell_types_header;
393 std::string cell_types_list;
395 std::string cell_data_header;
397 std::string cell_data_list;
400 vtk_header =
"# vtk DataFile Version 3.0\n"
404 if (ft == file_type::ASCII)
405 {vtk_header +=
"ASCII\n";}
407 {vtk_header +=
"BINARY\n";}
410 vtk_header +=
"DATASET UNSTRUCTURED_GRID\n";
413 point_prop_header = get_point_properties_list();
416 point_list = get_point_list();
419 cell_prop_header = get_cell_properties_list();
422 cell_list = get_cell_list();
425 cell_types_header = get_cell_types_header();
428 cell_types_list = get_cell_types_list();
431 cell_data_header = get_cell_data_header();
434 cell_data_list = get_cell_data_list();
437 std::ofstream ofs(file);
440 if (ofs.is_open() ==
false)
441 {std::cerr <<
"Error cannot create the VTK file: " + file +
"\n";}
443 ofs << vtk_header << point_prop_header << point_list <<
444 cell_prop_header << cell_list << cell_types_header << cell_types_list << cell_data_header << cell_data_list;
void add(const vector &vc)
Add box vector dataset.
std::string get_cell_properties_list()
It get the edge properties list.
std::string get_cell_data_list()
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_cell_types_header()
std::string get_cell_list()
Create the VTK vertex definition.
std::string get_point_data_header()
Get the point data header.
std::string get_cell_data_header()
std::string get_cell_types_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.