Commit f8a9ae64 authored by Pietro Incardona's avatar Pietro Incardona

VTK writer for a set of point or particles

parent 45f102f9
......@@ -38,7 +38,6 @@ Thumbs.db
###### Other
*.vtk
AUTHORS
COPYING
ChangeLog
......
......@@ -98,6 +98,7 @@ enum file_type
#define VECTOR_BOX 2
#define VECTOR_GRIDS 3
#define VECTOR_ST_GRIDS 4
#define VECTOR_POINTS 5
template <typename Graph, unsigned int imp>
class VTKWriter
......@@ -109,5 +110,6 @@ class VTKWriter
#include "VTKWriter_vector_box.hpp"
#include "VTKWriter_grids.hpp"
#include "VTKWriter_grids_st.hpp"
#include "VTKWriter_point_set.hpp"
#endif /* VTKWRITER_HPP_ */
......@@ -11,6 +11,12 @@
#include <boost/mpl/pair.hpp>
#include "VTKWriter_grids_util.hpp"
/*! \brief It store one grid
*
* \tparam Grid type of grid
* \tparam St type of space where the grid is defined
*
*/
template <typename Grid, typename St>
class ele_g
{
......@@ -22,6 +28,7 @@ public:
:g(g),offset(offset),spacing(spacing),dom(dom)
{}
//! Dataset name
std::string dataset;
//! Grid
const Grid & g;
......@@ -41,10 +48,8 @@ public:
* element of the boost::vector the operator() is called.
* Is mainly used to produce at output for each property
*
* \tparam Graph graph we are processing
*
* \param dim Dimensionality
* \param S type of grid
* \tparam ele_g element that store the grid and its attributes
* \param St type of space where the grid live
*
*/
......
......@@ -198,7 +198,10 @@ public:
/*! \brief This class is an helper to create properties output from scalar and compile-time array elements
*
* This class is an helper to copy scalar and compile-time array elements
* \tparam I It is an boost::mpl::int_ that indicate which property we are writing
* \tparam ele_g element type that store the grid information
* \tparam St type of space where the grid live
* \tparam T the type of the property
*
*/
template<typename I, typename ele_g, typename St, typename T>
......
......@@ -8,6 +8,9 @@
#ifndef VTKWRITER_UNIT_TESTS_HPP_
#define VTKWRITER_UNIT_TESTS_HPP_
#include "data_type/aggregate.hpp"
#include <random>
BOOST_AUTO_TEST_SUITE( vtk_writer_test )
/* \brief Sub-domain vertex graph node
......@@ -754,6 +757,76 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_grids)
}
}
BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set )
{
{
// Create 3 vectors with random particles
openfpm::vector<Point<3,double>> v1ps;
openfpm::vector<Point<3,double>> v2ps;
openfpm::vector<Point<3,double>> v3ps;
openfpm::vector<aggregate<float,float[3]>> v1pp;
openfpm::vector<aggregate<float,float[3]>> v2pp;
openfpm::vector<aggregate<float,float[3]>> v3pp;
// set the seed
// create the random generator engine
std::srand(0);
std::default_random_engine eg;
std::uniform_real_distribution<float> ud(0.0f, 1.0f);
// fill the vector with random data
v1ps.resize(100);
v2ps.resize(100);
v3ps.resize(100);
v1pp.resize(100);
v2pp.resize(100);
v3pp.resize(100);
for (size_t i = 0 ; i < v1ps.size(); i++)
{
v1ps.template get<0>(i)[0] = ud(eg);
v1ps.template get<0>(i)[1] = ud(eg);
v1ps.template get<0>(i)[2] = ud(eg);
v2ps.template get<0>(i)[0] = ud(eg)*0.5;
v2ps.template get<0>(i)[1] = ud(eg)*0.5;
v2ps.template get<0>(i)[2] = ud(eg)*0.5;
v3ps.template get<0>(i)[0] = ud(eg)*0.3;
v3ps.template get<0>(i)[1] = ud(eg)*0.3;
v3ps.template get<0>(i)[2] = ud(eg)*0.3;
v1pp.template get<0>(i) = ud(eg);
v1pp.template get<1>(i)[0] = ud(eg);
v1pp.template get<1>(i)[1] = ud(eg);
v1pp.template get<1>(i)[2] = ud(eg);
v2pp.template get<0>(i) = ud(eg);
v2pp.template get<1>(i)[0] = ud(eg);
v2pp.template get<1>(i)[1] = ud(eg);
v2pp.template get<1>(i)[2] = ud(eg);
v3pp.template get<0>(i) = ud(eg);
v3pp.template get<1>(i)[0] = ud(eg);
v3pp.template get<1>(i)[1] = ud(eg);
v3pp.template get<1>(i)[2] = ud(eg);
}
// Create a writer and write
VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,float[3]>>>,VECTOR_POINTS> vtk_v;
vtk_v.add(v1ps,v1pp,75);
vtk_v.add(v2ps,v2pp,88);
vtk_v.add(v3ps,v3pp,90);
vtk_v.write("vtk_points.vtk");
// Check that match
bool test = compare("vtk_points.vtk","vtk_points_test.vtk");
BOOST_REQUIRE_EQUAL(test,true);
}
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* VTKWRITER_UNIT_TESTS_HPP_ */
# vtk DataFile Version 3.0
grids
ASCII
DATASET POLYDATA
POINTS 300 float
0.000008 0.000000 0.000000
0.678865 0.000000 0.000000
0.053462 0.000000 0.000000
0.686773 0.000000 0.000000
0.415999 0.000000 0.000000
0.328234 0.000000 0.000000
0.722660 0.000000 0.000000
0.436411 0.000000 0.000000
0.486517 0.000000 0.000000
0.319033 0.000000 0.000000
0.500707 0.000000 0.000000
0.050084 0.000000 0.000000
0.868247 0.000000 0.000000
0.306322 0.000000 0.000000
0.269317 0.000000 0.000000
0.571655 0.000000 0.000000
0.554584 0.000000 0.000000
0.130427 0.000000 0.000000
0.937897 0.000000 0.000000
0.681346 0.000000 0.000000
0.590109 0.000000 0.000000
0.564899 0.000000 0.000000
0.319250 0.000000 0.000000
0.476432 0.000000 0.000000
0.947487 0.000000 0.000000
0.365339 0.000000 0.000000
0.808945 0.000000 0.000000
0.860860 0.000000 0.000000
0.951367 0.000000 0.000000
0.954415 0.000000 0.000000
0.576717 0.000000 0.000000
0.706535 0.000000 0.000000
0.713422 0.000000 0.000000
0.890019 0.000000 0.000000
0.315732 0.000000 0.000000
0.211519 0.000000 0.000000
0.773352 0.000000 0.000000
0.836420 0.000000 0.000000
0.213852 0.000000 0.000000
0.269215 0.000000 0.000000
0.193967 0.000000 0.000000
0.398144 0.000000 0.000000
0.233599 0.000000 0.000000
0.752940 0.000000 0.000000
0.699834 0.000000 0.000000
0.702989 0.000000 0.000000
0.738997 0.000000 0.000000
0.430848 0.000000 0.000000
0.279293 0.000000 0.000000
0.728608 0.000000 0.000000
0.517145 0.000000 0.000000
0.343818 0.000000 0.000000
0.546137 0.000000 0.000000
0.455752 0.000000 0.000000
0.582421 0.000000 0.000000
0.004254 0.000000 0.000000
0.436426 0.000000 0.000000
0.215826 0.000000 0.000000
0.815932 0.000000 0.000000
0.775880 0.000000 0.000000
0.050603 0.000000 0.000000
0.833682 0.000000 0.000000
0.542393 0.000000 0.000000
0.738959 0.000000 0.000000
0.351319 0.000000 0.000000
0.838102 0.000000 0.000000
0.244586 0.000000 0.000000
0.209562 0.000000 0.000000
0.082507 0.000000 0.000000
0.080353 0.000000 0.000000
0.499955 0.000000 0.000000
0.221667 0.000000 0.000000
0.653012 0.000000 0.000000
0.949157 0.000000 0.000000
0.496582 0.000000 0.000000
0.977180 0.000000 0.000000
0.372520 0.000000 0.000000
0.160083 0.000000 0.000000
0.713547 0.000000 0.000000
0.935242 0.000000 0.000000
0.083086 0.000000 0.000000
0.527439 0.000000 0.000000
0.081006 0.000000 0.000000
0.664689 0.000000 0.000000
0.171155 0.000000 0.000000
0.834338 0.000000 0.000000
0.153315 0.000000 0.000000
0.088993 0.000000 0.000000
0.200645 0.000000 0.000000
0.034243 0.000000 0.000000
0.232078 0.000000 0.000000
0.867514 0.000000 0.000000
0.690773 0.000000 0.000000
0.155414 0.000000 0.000000
0.561484 0.000000 0.000000
0.191984 0.000000 0.000000
0.380115 0.000000 0.000000
0.077324 0.000000 0.000000
0.919236 0.000000 0.000000
0.574360 0.000000 0.000000
0.000000 0.131538 0.000000
0.000000 0.679296 0.000000
0.000000 0.529700 0.000000
0.000000 0.588977 0.000000
0.000000 0.701191 0.000000
0.000000 0.632639 0.000000
0.000000 0.753356 0.000000
0.000000 0.766495 0.000000
0.000000 0.897656 0.000000
0.000000 0.986642 0.000000
0.000000 0.384142 0.000000
0.000000 0.761514 0.000000
0.000000 0.629543 0.000000
0.000000 0.351015 0.000000
0.000000 0.415395 0.000000
0.000000 0.802406 0.000000
0.000000 0.890737 0.000000
0.000000 0.090990 0.000000
0.000000 0.239911 0.000000
0.000000 0.385815 0.000000
0.000000 0.955409 0.000000
0.000000 0.252126 0.000000
0.000000 0.629269 0.000000
0.000000 0.389314 0.000000
0.000000 0.410313 0.000000
0.000000 0.253057 0.000000
0.000000 0.931674 0.000000
0.000000 0.471262 0.000000
0.000000 0.632739 0.000000
0.000000 0.851270 0.000000
0.000000 0.876566 0.000000
0.000000 0.741716 0.000000
0.000000 0.488943 0.000000
0.000000 0.543948 0.000000
0.000000 0.514659 0.000000
0.000000 0.999117 0.000000
0.000000 0.727335 0.000000
0.000000 0.708921 0.000000
0.000000 0.213547 0.000000
0.000000 0.692169 0.000000
0.000000 0.011316 0.000000
0.000000 0.601010 0.000000
0.000000 0.101637 0.000000
0.000000 0.669521 0.000000
0.000000 0.117437 0.000000
0.000000 0.143045 0.000000
0.000000 0.316007 0.000000
0.000000 0.258843 0.000000
0.000000 0.078263 0.000000
0.000000 0.720768 0.000000
0.000000 0.661355 0.000000
0.000000 0.541710 0.000000
0.000000 0.917848 0.000000
0.000000 0.817101 0.000000
0.000000 0.751710 0.000000
0.000000 0.495691 0.000000
0.000000 0.006342 0.000000
0.000000 0.385769 0.000000
0.000000 0.371910 0.000000
0.000000 0.220685 0.000000
0.000000 0.477804 0.000000
0.000000 0.695637 0.000000
0.000000 0.001657 0.000000
0.000000 0.679332 0.000000
0.000000 0.614125 0.000000
0.000000 0.974252 0.000000
0.000000 0.760617 0.000000
0.000000 0.113676 0.000000
0.000000 0.687414 0.000000
0.000000 0.494245 0.000000
0.000000 0.749252 0.000000
0.000000 0.562602 0.000000
0.000000 0.165928 0.000000
0.000000 0.484180 0.000000
0.000000 0.053694 0.000000
0.000000 0.467741 0.000000
0.000000 0.939725 0.000000
0.000000 0.517707 0.000000
0.000000 0.576776 0.000000
0.000000 0.605603 0.000000
0.000000 0.421579 0.000000
0.000000 0.668820 0.000000
0.000000 0.459763 0.000000
0.000000 0.425191 0.000000
0.000000 0.606001 0.000000
0.000000 0.726443 0.000000
0.000000 0.767065 0.000000
0.000000 0.699691 0.000000
0.000000 0.232608 0.000000
0.000000 0.523772 0.000000
0.000000 0.536528 0.000000
0.000000 0.311605 0.000000
0.000000 0.815407 0.000000
0.000000 0.041075 0.000000
0.000000 0.856876 0.000000
0.000000 0.670991 0.000000
0.000000 0.586016 0.000000
0.000000 0.589809 0.000000
0.000000 0.601638 0.000000
0.000000 0.273251 0.000000
0.000000 0.000000 0.755605
0.000000 0.000000 0.934693
0.000000 0.000000 0.671149
0.000000 0.000000 0.930436
0.000000 0.000000 0.910321
0.000000 0.000000 0.756410
0.000000 0.000000 0.651519
0.000000 0.000000 0.477732
0.000000 0.000000 0.909208
0.000000 0.000000 0.493977
0.000000 0.000000 0.277082
0.000000 0.000000 0.770205
0.000000 0.000000 0.736225
0.000000 0.000000 0.513274
0.000000 0.000000 0.537304
0.000000 0.000000 0.033054
0.000000 0.000000 0.624849
0.000000 0.000000 0.274588
0.000000 0.000000 0.180896
0.000000 0.000000 0.387725
0.000000 0.000000 0.556146
0.000000 0.000000 0.488515
0.000000 0.000000 0.126712
0.000000 0.000000 0.203250
0.000000 0.000000 0.131189
0.000000 0.000000 0.135109
0.000000 0.000000 0.651646
0.000000 0.000000 0.505956
0.000000 0.000000 0.439330
0.000000 0.000000 0.289316
0.000000 0.000000 0.440039
0.000000 0.000000 0.019092
0.000000 0.000000 0.667679
0.000000 0.000000 0.139195
0.000000 0.000000 0.881504
0.000000 0.000000 0.153604
0.000000 0.000000 0.319178
0.000000 0.000000 0.828708
0.000000 0.000000 0.081061
0.000000 0.000000 0.284035
0.000000 0.000000 0.191824
0.000000 0.000000 0.176880
0.000000 0.000000 0.219411
0.000000 0.000000 0.633430
0.000000 0.000000 0.762571
0.000000 0.000000 0.161688
0.000000 0.000000 0.135332
0.000000 0.000000 0.370226
0.000000 0.000000 0.369742
0.000000 0.000000 0.944753
0.000000 0.000000 0.401833
0.000000 0.000000 0.522808
0.000000 0.000000 0.266613
0.000000 0.000000 0.022084
0.000000 0.000000 0.991533
0.000000 0.000000 0.079917
0.000000 0.000000 0.584787
0.000000 0.000000 0.626861
0.000000 0.000000 0.686102
0.000000 0.000000 0.055279
0.000000 0.000000 0.457162
0.000000 0.000000 0.577776
0.000000 0.000000 0.856193
0.000000 0.000000 0.536267
0.000000 0.000000 0.607611
0.000000 0.000000 0.259014
0.000000 0.000000 0.694856
0.000000 0.000000 0.546975
0.000000 0.000000 0.375310
0.000000 0.000000 0.769437
0.000000 0.000000 0.671903
0.000000 0.000000 0.652622
0.000000 0.000000 0.744104
0.000000 0.000000 0.621046
0.000000 0.000000 0.441633
0.000000 0.000000 0.329056
0.000000 0.000000 0.964851
0.000000 0.000000 0.105185
0.000000 0.000000 0.871884
0.000000 0.000000 0.362084
0.000000 0.000000 0.472380
0.000000 0.000000 0.863643
0.000000 0.000000 0.232867
0.000000 0.000000 0.186825
0.000000 0.000000 0.063804
0.000000 0.000000 0.329434
0.000000 0.000000 0.061731
0.000000 0.000000 0.706461
0.000000 0.000000 0.436096
0.000000 0.000000 0.031639
0.000000 0.000000 0.430618
0.000000 0.000000 0.148390
0.000000 0.000000 0.541535
0.000000 0.000000 0.343613
0.000000 0.000000 0.516908
0.000000 0.000000 0.345872
0.000000 0.000000 0.167313
0.000000 0.000000 0.925503
0.000000 0.000000 0.723836
0.000000 0.000000 0.531427
VERTICES 300 600
1 0
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 61
1 62
1 63
1 64
1 65
1 66
1 67
1 68
1 69
1 70
1 71
1 72
1 73
1 74
1 75
1 76
1 77
1 78
1 79
1 80
1 81
1 82
1 83
1 84
1 85
1 86
1 87
1 88
1 89
1 90
1 91
1 92
1 93
1 94
1 95
1 96
1 97
1 98
1 99
1 100
1 101
1 102
1 103
1 104
1 105
1 106
1 107
1 108
1 109
1 110
1 111
1 112
1 113
1 114
1 115
1 116
1 117
1 118
1 119
1 120
1 121
1 122
1 123
1 124
1 125
1 126
1 127
1 128
1 129
1 130
1 131
1 132
1 133
1 134
1 135
1 136
1 137
1 138
1 139
1 140
1 141
1 142
1 143
1 144
1 145
1 146
1 147
1 148
1 149
1 150
1 151
1 152
1 153
1 154
1 155
1 156
1 157
1 158
1 159
1 160
1 161
1 162
1 163
1 164
1 165
1 166
1 167
1 168
1 169
1 170
1 171
1 172
1 173
1 174
1 175
1 176
1 177
1 178
1 179
1 180
1 181
1 182
1 183
1 184
1 185
1 186
1 187
1 188
1 189
1 190
1 191
1 192
1 193
1 194
1 195
1 196
1 197
1 198
1 199
1 200
1 201
1 202
1 203
1 204
1 205
1 206
1 207
1 208
1 209
1 210
1 211
1 212
1 213
1 214
1 215
1 216
1 217
1 218
1 219
1 220
1 221
1 222
1 223
1 224
1 225
1 226
1 227
1 228
1 229
1 230
1 231
1 232
1 233
1 234
1 235
1 236
1 237
1 238
1 239
1 240
1 241
1 242
1 243
1 244
1 245
1 246
1 247
1 248
1 249
1 250
1 251
1 252
1 253
1 254
1 255
1 256
1 257
1 258
1 259
1 260
1 261
1 262
1 263
1 264
1 265
1 266
1 267
1 268
1 269
1 270
1 271
1 272
1 273
1 274
1 275
1 276
1 277
1 278
1 279
1 280
1 281
1 282
1 283
1 284
1 285
1 286
1 287
1 288
1 289
1 290
1 291
1 292
1 293
1 294
1 295
1 296
1 297
1 298
1 299
POINT_DATA 300
SCALARS attr0 float
LOOKUP_TABLE default
0.458650
0.383502
0.007698
0.846167
0.762198
0.991037
0.072686
0.237774
0.060564
0.266145
0.913817
0.827817
0.725412
0.591114
0.467917
0.534450
0.842040
0.003000
0.317540
0.499741