Commit 769eaffe authored by incardon's avatar incardon
Browse files

Fixing VTKWriter_unit_tests.hpp

parents c5b495c8 d968727b
......@@ -18,19 +18,19 @@ mv /tmp/openfpm_io openfpm_io
git clone git@git.mpi-cbg.de:openfpm/openfpm_devices.git openfpm_devices
cd openfpm_devices
git checkout master
git checkout develop
cd ..
git clone git@git.mpi-cbg.de:openfpm/openfpm_data.git openfpm_data
cd openfpm_data
git checkout master
git checkout develop
cd ..
git clone git@git.mpi-cbg.de:openfpm/openfpm_pdata.git openfpm_pdata
cd openfpm_pdata
git checkout master
git checkout develop
cd ..
git clone git@git.mpi-cbg.de:openfpm/openfpm_vcluster.git openfpm_vcluster
cd openfpm_vcluster
git checkout master
git checkout develop
cd ..
cd "$1/openfpm_io"
......
......@@ -7,9 +7,10 @@ if [ -d "$1/BOOST" ]; then
exit 0
fi
wget http://ppmcore.mpi-cbg.de/upload/boost_1_72_0.tar.bz2
tar -xvf boost_1_72_0.tar.bz2
cd boost_1_72_0
rm boost_1_75_0.tar.bz2
wget http://ppmcore.mpi-cbg.de/upload/boost_1_75_0.tar.bz2
tar -xvf boost_1_75_0.tar.bz2
cd boost_1_75_0
if [ x"$4" != x"" ]; then
if [ -f $HOME/user-config.jam ]; then
mv $HOME/user-config.jam $HOME/user-config.jam_bck
......@@ -23,10 +24,10 @@ fi
./bootstrap.sh --with-toolset=$3
mkdir $1/BOOST
./b2 -j $2 install --prefix=$1/BOOST
rm -rf boost_1_72_0
rm -rf boost_1_75_0
if [ -f $HOME/user-config.jam_bck ]; then
mv $HOME/user-config.jam_bck $HOME/user-config.jam
fi
rm -rf boost_1_72_0.tar.bz2
rm -rf boost_1_75_0.tar.bz2
......@@ -149,7 +149,7 @@ struct csv_col<Tobj,false>
}
};
#define VECTOR 1
//#define VECTOR 1
/*! \brief CSV Writer
*
......@@ -159,7 +159,7 @@ struct csv_col<Tobj,false>
* \tparam v_prp Property vector
*
*/
template <typename v_pos, typename v_prp, unsigned int impl = VECTOR>
template <typename v_pos, typename v_prp, unsigned int impl = 1>
class CSVWriter
{
/*! \brief Get the colums name (also the positional name)
......
......@@ -41,9 +41,9 @@ inline bool exists_test (const std::string& name) {
* #pixels per dimension.
* @return Std::vector containing the count of pixels for each dimension as it was read from the csv file.
*/
std::vector<size_t> get_size(const std::string & path_to_file)
std::vector<int> get_size(const std::string & path_to_file)
{
std::vector<size_t> stack_dimst_1d;
std::vector<int> stack_dimst_1d;
// check if file exists and stream input csv file
if(!exists_test(path_to_file)){
std::cout << "------------------------------------------------------------------------" << std::endl;
......@@ -67,7 +67,7 @@ std::vector<size_t> get_size(const std::string & path_to_file)
while ( getline(file, field) ) // 1 field per axis
{
std::istringstream iss(field);
size_t val;
int val;
iss >> val;
stack_dimst_1d.push_back(val); // add the #pixels for current axis to the array
}
......@@ -89,7 +89,7 @@ std::vector<size_t> get_size(const std::string & path_to_file)
* manually or loaded from a csv file before (see: #get_size())
*/
template <size_t Phi_0, typename grid_type>
void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <size_t> & stack_dims)
void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <int> & stack_dims)
{
constexpr size_t x = 0;
constexpr size_t y = 1;
......@@ -107,7 +107,7 @@ void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <
auto & v_cl = create_vcluster();
if (v_cl.rank() == 0)
{
for (size_t d = 0; d < grid_type::dims; d++)
for (int d = 0; d < grid_type::dims; d++)
{
std::cout << "# grid points in dimension " << d << " = " << grid.size(d) << std::endl;
}
......@@ -121,14 +121,14 @@ void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <
std::vector<BYTE> pixel_line; // one x-line of the image stack which will be read
size_t sz_img[grid_type::dims];
for (size_t d = 0; d < grid_type::dims; d++)
for (int d = 0; d < grid_type::dims; d++)
{
sz_img[d] = stack_dims[d];
}
grid_sm<grid_type::dims,void> ginfo_image(sz_img); // in order to get the image related key later on
double refinement[grid_type::dims];
for (size_t d = 0; d < grid_type::dims; d++)
for (int d = 0; d < grid_type::dims; d++)
{
refinement[d] = (double) grid.size(d) / (double)stack_dims[d]; // get the factor, by which the grid resolution differs from the image stack resolution
if (v_cl.rank() == 0) std::cout << "effective refinement in dimension " << d << " = " << refinement[d] << std::endl;
......@@ -141,7 +141,7 @@ void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <
// In case a patch starts within a group of nodes to which same pixel-value should be assigned, get the
// respective rest-offset
size_t rest_offset = (size_t) (fmod(gkey.get(0), refinement[x])); // get the remainder
int rest_offset = (int) (fmod(gkey.get(0), refinement[x])); // get the remainder
// get l as the length of one x-line of the original image stack for the specific patch on the processor
......@@ -154,7 +154,7 @@ void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <
// in case that the grid has a different resolution than the underlying image stack:
// create a key which is used to get the offset for the file reading
// the indices in this key are corrected by the refinement factor
for (size_t d = 0; d < grid_type::dims; d++)
for (int d = 0; d < grid_type::dims; d++)
{
gkey.set_d(d, floor(gkey.get(d) / refinement[d]));
}
......@@ -172,7 +172,7 @@ void load_pixel_onto_grid(grid_type & grid, std::string file_name, std::vector <
// run over a whole grid-line in x and assign pixel values from pixel_line to grid nodes
// if the grid is finer in x as the image stack, the same pixel value from pixel_line is
// assigned refinement[x] times
for (size_t k = 0; k < patch_size; ++k)
for (int k = 0; k < patch_size; ++k)
{
auto key = dom.get();
// get the correct index of the pixel to be read from pixel_line by considering a potential rest-offset,
......
......@@ -15,37 +15,74 @@
#include <fstream>
#include "util/common.hpp"
/*! \brief Get the type
/*! \brief Get the type Old
*
* It convert T to a string identify the corrispondent type in VTK format
*
*/
template <typename T> std::string getType()
{
// Create a property string based on the type of the property
if (std::is_same<T,float>::value)
return "float";
else if (std::is_same<T,double>::value)
return "double";
else if (std::is_same<T,char>::value)
return "char";
else if (std::is_same<T,unsigned char>::value)
return "unsigned_char";
else if (std::is_same<T,short>::value)
return "short";
else if (std::is_same<T,unsigned short>::value)
return "unsigned_short";
else if (std::is_same<T,int>::value)
return "int";
else if (std::is_same<T,unsigned int>::value)
return "unsigned_int";
else if (std::is_same<T,long int>::value)
return "int";
else if (std::is_same<T,unsigned long int>::value )
return "unsigned_int";
else if (std::is_same<T,bool>::value )
return "bit";
return "";
}
/*! \brief Get the type
*
* It convert T to a string identify the corrispondent type in VTK format
*
*/
template <typename T> std::string getTypeNew()
{
// Create a property string based on the type of the property
if (std::is_same<T,float>::value)
return "float";
return "Float32";
else if (std::is_same<T,double>::value)
return "double";
return "Float64";
else if (std::is_same<T,char>::value)
return "char";
return "Int8";
else if (std::is_same<T,unsigned char>::value)
return "unsigned_char";
return "Uint8";
else if (std::is_same<T,short>::value)
return "short";
return "Int16";
else if (std::is_same<T,unsigned short>::value)
return "unsigned_short";
return "Uint16";
else if (std::is_same<T,int>::value)
return "int";
return "Int32";
else if (std::is_same<T,unsigned int>::value)
return "unsigned_int";
return "Uint32";
else if (std::is_same<T,long int>::value)
return "int";
return "Int64";
else if (std::is_same<T,unsigned long int>::value )
return "unsigned_int";
return "Uint64";
else if (std::is_same<T,bool>::value )
return "bit";
return "Int8";
return "";
}
......
......@@ -214,14 +214,16 @@ class VTKWriter<pair,VECTOR_GRIDS>
* \return a string that define the vertex properties in graphML format
*
*/
std::string get_point_properties_list()
{
//! vertex property output string
std::string v_out;
// write the number of vertex
v_out += "POINTS " + std::to_string(get_total()) + " float" + "\n";
if (std::is_same<typename pair::second,float>::value == true)
{v_out += "POINTS " + std::to_string(get_total()) + " float" + "\n";}
else
{v_out += "POINTS " + std::to_string(get_total()) + " double" + "\n";}
// return the vertex properties string
return v_out;
......@@ -239,6 +241,11 @@ class VTKWriter<pair,VECTOR_GRIDS>
//! vertex node output string
std::stringstream v_out;
if (std::is_same<typename pair::second,float>::value == true)
{v_out << std::setprecision(7);}
else
{v_out << std::setprecision(16);}
//! For each defined grid
for (size_t i = 0 ; i < vg.size() ; i++)
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,6 +3,8 @@
*
* Created on: May 6, 2015
* Author: Pietro Incardona
*
* Modified by Abhinav Singh May 17, 2021
*/
#ifndef VTKWRITER_UNIT_TESTS_HPP_
......@@ -737,41 +739,43 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_grids)
{
// Create box grids
Point<1,float> offset1({0.0});
Point<1,float> spacing1({0.1});
Point<1,double> offset1({0.0});
Point<1,double> spacing1({0.1});
Box<1,size_t> d1({1},{14});
// Create box grids
Point<1,float> offset2({5.0});
Point<1,double> offset2({5.0});
Point<1,float> spacing2({0.2});
Box<1,size_t> d2({2},{13});
// Create box grids
Point<1,float> offset3({0.0});
Point<1,float> spacing3({0.05});
Point<1,double> offset3({0.0});
Point<1,double> spacing3({0.05});
Box<1,size_t> d3({3},{11});
// Create box grids
Point<1,float> offset4({5.0});
Point<1,float> spacing4({0.1});
Point<1,double> offset4({5.0});
Point<1,double> spacing4({0.1});
Box<1,size_t> d4({1},{7});
size_t sz[] = {16};
grid_cpu<1,Point_test<float>> g1(sz);
grid_cpu<1,Point_test<double>> g1(sz);
g1.setMemory();
fill_grid_some_data(g1);
grid_cpu<1,Point_test<float>> g2(sz);
grid_cpu<1,Point_test<double>> g2(sz);
g2.setMemory();
fill_grid_some_data(g2);
grid_cpu<1,Point_test<float>> g3(sz);
grid_cpu<1,Point_test<double>> g3(sz);
g3.setMemory();
fill_grid_some_data(g3);
grid_cpu<1,Point_test<float>> g4(sz);
grid_cpu<1,Point_test<double>> g4(sz);
g4.setMemory();
fill_grid_some_data(g4);
g4.template get<Point_test<double>::s>(0) = 1.0/3.0;
// Create a writer and write
VTKWriter<boost::mpl::pair<grid_cpu<1,Point_test<float>>,float>,VECTOR_GRIDS> vtk_g;
VTKWriter<boost::mpl::pair<grid_cpu<1,Point_test<double>>,double>,VECTOR_GRIDS> vtk_g;
vtk_g.add(g1,offset1,spacing1,d1);
vtk_g.add(g2,offset2,spacing2,d2);
vtk_g.add(g3,offset3,spacing3,d3);
......@@ -1110,14 +1114,22 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set )
vtk_v.add(v3ps,v3pp,90);
openfpm::vector<std::string> prp_names;
vtk_v.write("vtk_points.vtk",prp_names);
vtk_v.write("vtk_points.vtp",prp_names);
//auto &v_cl=create_vcluster();
//size_t n=v_cl.size();
vtk_v.write_pvtp("vtk_points",prp_names,2);
#ifndef SE_CLASS3
bool test = true;
// Check that match
test = compare("vtk_points.vtk",c2);
test = compare("vtk_points.vtp","test_data/vtk_points_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
//It just checks generation of the format and not actual data (File names)
test = compare("vtk_points.pvtp","test_data/pvtp_points_test.pvtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1126,12 +1138,12 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set )
VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,Point<3,float>>>>,VECTOR_POINTS> vtk_v2;
vtk_v2.add(v1ps,v4pp,75);
vtk_v2.write("vtk_points_pp.vtk",prp_names);
vtk_v2.write("vtk_points_pp.vtp",prp_names);
#ifndef SE_CLASS3
// Check that match
test = compare("vtk_points_pp.vtk",c3);
test = compare("vtk_points_pp.vtp","test_data/vtk_points_pp_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1140,15 +1152,18 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set )
VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,Point<3,float>>>>,VECTOR_POINTS> vtk_v3;
vtk_v3.add(v1ps,v4pp,75);
vtk_v3.write("vtk_points_pp_header.vtk",prp_names,"points","time=5.123");
vtk_v3.write("vtk_points_pp_header.vtp",prp_names,"points","time=5.123");
// We try binary
vtk_v3.write("vtk_points_pp_header_bin.vtk",prp_names,"points","time=5.123",file_type::BINARY);
vtk_v3.write("vtk_points_pp_header_bin.vtp",prp_names,"points","time=5.123",file_type::BINARY);
#ifndef SE_CLASS3
// Check that match
test = compare("vtk_points_pp_header.vtk",c4);
test = compare("vtk_points_pp_header.vtp","test_data/vtk_points_pp_header_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("vtk_points_pp_header_bin.vtp","test_data/vtk_points_pp_header_bin_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1206,12 +1221,12 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_properties )
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);
openfpm::vector<std::string> prp_names({"scalar","vector"});
vtk_v.write("vtk_points_with_prp_names.vtk",prp_names);
vtk_v.write("vtk_points_with_prp_names.vtp",prp_names);
#ifndef SE_CLASS3
// Check that match
bool test = compare("vtk_points_with_prp_names.vtk",c2);
bool test = compare("vtk_points_with_prp_names.vtp","test_data/vtk_points_with_prp_names_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1265,12 +1280,12 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_check_out_precision )
VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,double[3]>>>,VECTOR_POINTS> vtk_v;
vtk_v.add(v1ps,v1pp,75);
openfpm::vector<std::string> prp_names({"scalar","vector"});
vtk_v.write("vtk_points_with_prp_names_prec_check.vtk",prp_names);
vtk_v.write("vtk_points_with_prp_names_prec_check.vtp",prp_names);
#ifndef SE_CLASS3
// Check that match
bool test = compare("vtk_points_with_prp_names_prec_check.vtk",c2);
bool test = compare("vtk_points_with_prp_names_prec_check.vtp","test_data/vtk_points_with_prp_names_prec_check_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1368,17 +1383,17 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_binary )
vtk_v.add(v3ps,v3pp,90);
openfpm::vector<std::string> prp_names;
vtk_v.write("vtk_points_bin.vtk",prp_names,"vtk output","",file_type::BINARY);
vtk_v.write("vtk_points_bin2.vtk",prp_names,"vtk output","",file_type::BINARY);
vtk_v.write("vtk_points_bin.vtp",prp_names,"vtk output","",file_type::BINARY);
vtk_v.write("vtk_points_bin2.vtp",prp_names,"vtk output","",file_type::BINARY);
#ifndef SE_CLASS3
bool test = true;
// Check that match
test = compare("vtk_points_bin.vtk",c2);
test = compare("vtk_points_bin.vtp","test_data/vtk_points_bin_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
test = compare("vtk_points_bin2.vtk",c2);
test = compare("vtk_points_bin2.vtp","test_data/vtk_points_bin_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1387,12 +1402,12 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_binary )
VTKWriter<boost::mpl::pair<openfpm::vector<Point<3,double>>,openfpm::vector<aggregate<float,Point<3,float>>>>,VECTOR_POINTS> vtk_v2;
vtk_v2.add(v1ps,v4pp,75);
vtk_v2.write("vtk_points_pp_bin.vtk",prp_names,"vtk output","",file_type::BINARY);
vtk_v2.write("vtk_points_pp_bin.vtp",prp_names,"vtk output","",file_type::BINARY);
#ifndef SE_CLASS3
// Check that match
test = compare("vtk_points_pp_bin.vtk",c3);
test = compare("vtk_points_pp_bin.vtp","test_data/vtk_points_pp_bin_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1483,14 +1498,14 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_binary )
openfpm::vector<std::string> stub;
vtk_v.write("vtk_points_2d_bin.vtk",stub,"vtk output","",file_type::BINARY);
vtk_v.write("vtk_points_2d_bin.vtp",stub,"vtk output","",file_type::BINARY);
#ifndef SE_CLASS3
bool test = true;
// Check that match
test = compare("vtk_points_2d_bin.vtk",c4);
test = compare("vtk_points_2d_bin.vtp","test_data/vtk_points_2d_bin_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......@@ -1499,12 +1514,12 @@ BOOST_AUTO_TEST_CASE( vtk_writer_use_point_set_binary )
VTKWriter<boost::mpl::pair<openfpm::vector<Point<2,double>>,openfpm::vector<aggregate<float[3],double[2]>>>,VECTOR_POINTS> vtk_v2;
vtk_v2.add(v1ps,v4pp,75);
vtk_v2.write("vtk_points_2d_pp_bin.vtk",stub,"vtk output","",file_type::BINARY);
vtk_v2.write("vtk_points_2d_pp_bin.vtp",stub,"vtk output","",file_type::BINARY);
#ifndef SE_CLASS3
// Check that match
test = compare("vtk_points_2d_pp_bin.vtk",c5);
test = compare("vtk_points_2d_pp_bin.vtp","test_data/vtk_points_2d_pp_bin_test.vtp");
BOOST_REQUIRE_EQUAL(test,true);
#endif
......
......@@ -54,7 +54,7 @@ struct vtk_dims
//! dimensionality of the vtk property (scalar)
enum
{
value = 1
value = 0
};
};
......
......@@ -21,7 +21,7 @@
*
* @return Std::string of path to current working directory.
*/
std::string get_cwd()
static std::string get_cwd()
{
char *cwd = nullptr;
size_t size;
......@@ -39,7 +39,7 @@ std::string get_cwd()
* @param path Std::string with path of file for which existence should be checked.
* @return True, if file exists, false if not.
*/
bool check_if_file_exists(std::string path)
static bool check_if_file_exists(std::string path)
{
try
{
......@@ -63,7 +63,7 @@ bool check_if_file_exists(std::string path)
*
* @param path Std::string that contains path including filename of the file that should be created.
*/
void create_file_if_not_exist(std::string path)
static void create_file_if_not_exist(std::string path)
{
auto & v_cl = create_vcluster();
if (v_cl.rank() == 0)
......@@ -82,7 +82,7 @@ void create_file_if_not_exist(std::string path)
* @param path Std::string with path of directory for which existence should be checked.
* @return True, if directory exists, false if not.
*/
bool check_if_directory_exists(std::string path)
static bool check_if_directory_exists(std::string path)
{
try
{
......@@ -100,7 +100,7 @@ bool check_if_directory_exists(std::string path)
*
* @param path Std::string that contains path including name of the folder that should be created.
*/
void create_directory_if_not_exist(std::string path)
static void create_directory_if_not_exist(std::string path)
{
auto & v_cl = create_vcluster();
if (v_cl.rank() == 0)
......
......@@ -176,4 +176,215 @@ static inline bool hasEnding (std::string const &fullString, std::string const &
{return false;}
}
static const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
static inline bool is_base64(unsigned char c) {
return (isalnum(c) || (c == '+') || (c == '/'));
}
/*! \brief Encode to base64
*
* \param Byte String to encode
* \param Number of bytes to encode
*
*/
/*std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len) {
std::string ret;
int i = 0;
int j = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];
while (in_len--) {
char_array_3[i++] = *(bytes_to_encode++);
if (i == 3) {
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for(i = 0; (i <4) ; i++)
ret += base64_chars[char_array_4[i]];
i = 0;
}
}
if (i)
{
for(j = i; j < 3; j++)
char_array_3[j] = '\0';
char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
char_array_4[3] = char_array_3[2] & 0x3f;
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while((i++ < 3))