Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
O
openfpm_io
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openfpm
openfpm_io
Commits
219f53f0
Commit
219f53f0
authored
Aug 11, 2015
by
incardon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compilable VTKWriter.hpp
parent
19eeb7f8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
638 additions
and
149 deletions
+638
-149
src/CSVWriter.hpp
src/CSVWriter.hpp
+1
-1
src/GraphMLWriter.hpp
src/GraphMLWriter.hpp
+2
-2
src/VTKWriter.hpp
src/VTKWriter.hpp
+2
-144
src/VTKWriter_graph.hpp
src/VTKWriter_graph.hpp
+146
-2
src/VTKWriter_grids.hpp
src/VTKWriter_grids.hpp
+406
-0
src/VTKWriter_unit_tests.hpp
src/VTKWriter_unit_tests.hpp
+81
-0
No files found.
src/CSVWriter.hpp
View file @
219f53f0
...
...
@@ -158,7 +158,7 @@ class CSVWriter
std
::
stringstream
str
;
// write positional columns
for
(
in
t
i
=
0
;
i
<
v_pos
::
value_type
::
dims
;
i
++
)
for
(
size_
t
i
=
0
;
i
<
v_pos
::
value_type
::
dims
;
i
++
)
{
if
(
i
==
0
)
str
<<
"x["
<<
i
<<
"]"
;
...
...
src/GraphMLWriter.hpp
View file @
219f53f0
...
...
@@ -23,7 +23,7 @@ void create_prop(std::string * str)
if
(
has_attributes
<
T
>::
value
)
{
// Create properties names based on the attributes name defined
for
(
in
t
i
=
0
;
i
<
T
::
max_prop
;
i
++
)
for
(
size_
t
i
=
0
;
i
<
T
::
max_prop
;
i
++
)
{
str
[
i
]
=
std
::
string
(
T
::
attributes
::
name
[
i
]);
}
...
...
@@ -31,7 +31,7 @@ void create_prop(std::string * str)
else
{
// Create default properties name
for
(
in
t
i
=
0
;
i
<
T
::
max_prop
;
i
++
)
for
(
size_
t
i
=
0
;
i
<
T
::
max_prop
;
i
++
)
{
str
[
i
]
=
"attr"
+
std
::
to_string
(
i
);
}
...
...
src/VTKWriter.hpp
View file @
219f53f0
...
...
@@ -93,152 +93,9 @@ enum file_type
ASCII
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to create a string containing all the vertex
* properties
*
* \tparam G graph type
* \tparam attr has the vertex attributes
*
*/
template
<
typename
G
,
bool
attr
>
struct
vtk_vertex_node
{
// Vertex spatial type information
typedef
typename
G
::
V_type
::
s_type
s_type
;
s_type
(
&
x
)[
3
];
// Vertex object container
typename
G
::
V_container
&
vo
;
// vertex node string
std
::
string
&
v_node
;
/*! \brief Constructor
*
* Create a vertex properties list
*
* \param v_node std::string that is filled with the graph properties in the GraphML format
* \param n_obj object container to access its properties for example encapc<...>
*
*/
vtk_vertex_node
(
std
::
string
&
v_node
,
typename
G
::
V_container
&
n_obj
,
s_type
(
&
x
)[
3
])
:
x
(
x
),
vo
(
n_obj
),
v_node
(
v_node
)
{
};
//! \brief Write collected information
void
write
()
{
v_node
+=
std
::
to_string
(
x
[
0
])
+
" "
+
std
::
to_string
(
x
[
1
])
+
" "
+
std
::
to_string
(
x
[
2
])
+
"
\n
"
;
}
//! It call the functor for each member
template
<
typename
T
>
void
operator
()(
T
&
t
)
{
// if the attribute name is x y or z, create a string with the value of the properties and store it
if
(
G
::
V_type
::
attributes
::
name
[
T
::
value
]
==
"x"
){
x
[
0
]
=
convert
<
typename
boost
::
remove_reference
<
decltype
(
vo
.
template
get
<
T
::
value
>())
>::
type
>::
template
to
<
s_type
>(
vo
.
template
get
<
T
::
value
>());}
else
if
(
G
::
V_type
::
attributes
::
name
[
T
::
value
]
==
"y"
){
x
[
1
]
=
convert
<
typename
boost
::
remove_reference
<
decltype
(
vo
.
template
get
<
T
::
value
>())
>::
type
>::
template
to
<
s_type
>(
vo
.
template
get
<
T
::
value
>());}
else
if
(
G
::
V_type
::
attributes
::
name
[
T
::
value
]
==
"z"
){
x
[
2
]
=
convert
<
typename
boost
::
remove_reference
<
decltype
(
vo
.
template
get
<
T
::
value
>())
>::
type
>::
template
to
<
s_type
>(
vo
.
template
get
<
T
::
value
>());}
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to create a string containing all the vertex
* properties
*
* Specialization when we do not have vertex attributes
*
* \tparam G graph type
*
*/
template
<
typename
G
>
struct
vtk_vertex_node
<
G
,
false
>
{
// Vertex object container
typename
G
::
V_container
&
vo
;
// vertex node string
std
::
string
&
v_node
;
/*! \brief Constructor
*
* Create a vertex properties list
*
* \param v_node std::string that is filled with the graph properties in the GraphML format
* \param n_obj object container to access its properties for example encapc<...>
*
*/
vtk_vertex_node
(
std
::
string
&
v_node
,
typename
G
::
V_container
&
n_obj
)
:
vo
(
n_obj
),
v_node
(
v_node
)
{
};
//! It call the functor for each member
template
<
typename
T
>
void
operator
()(
T
&
t
)
{
v_node
+=
"0 0 0
\n
"
;
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to create a string containing all the edge
* properties
*
*/
template
<
typename
G
>
struct
vtk_edge_node
{
// Vertex object container
typename
G
::
E_container
&
vo
;
// edge node string
std
::
string
&
e_node
;
/*! \brief Constructor
*
* Create an edge node
*
* \param e_node std::string that is filled with the graph properties in the GraphML format
* \param n_obj object container to access the object properties for example encapc<...>
* \param n_prop number of properties
*
*/
vtk_edge_node
(
std
::
string
&
e_node
,
typename
G
::
E_container
&
n_obj
)
:
vo
(
n_obj
),
e_node
(
e_node
)
{
};
/*! \brief Create a new node
*
* \param vc node number
*
*/
void
new_node
(
size_t
v_c
,
size_t
s
,
size_t
d
)
{
// start a new node
e_node
+=
"2 "
+
std
::
to_string
(
s
)
+
" "
+
std
::
to_string
(
d
)
+
"
\n
"
;
}
};
#define GRAPH 1
#define VECTOR_BOX 2
#define VECTOR_GRIDS 3
template
<
typename
Graph
,
unsigned
int
imp
>
class
VTKWriter
...
...
@@ -248,5 +105,6 @@ class VTKWriter
#include "VTKWriter_graph.hpp"
#include "VTKWriter_vector_box.hpp"
#include "VTKWriter_grids.hpp"
#endif
/* VTKWRITER_HPP_ */
src/VTKWriter_graph.hpp
View file @
219f53f0
...
...
@@ -2,12 +2,156 @@
* VTKWriter_graph.hpp
*
* Created on: May 5, 2015
* Author:
i-bird
* Author:
Pietro Incardona
*/
#ifndef VTKWRITER_GRAPH_HPP_
#define VTKWRITER_GRAPH_HPP_
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to create a string containing all the vertex
* properties
*
* \tparam G graph type
* \tparam attr has the vertex attributes
*
*/
template
<
typename
G
,
bool
attr
>
struct
vtk_vertex_node
{
// Vertex spatial type information
typedef
typename
G
::
V_type
::
s_type
s_type
;
s_type
(
&
x
)[
3
];
// Vertex object container
typename
G
::
V_container
&
vo
;
// vertex node string
std
::
string
&
v_node
;
/*! \brief Constructor
*
* Create a vertex properties list
*
* \param v_node std::string that is filled with the graph properties in the GraphML format
* \param n_obj object container to access its properties for example encapc<...>
*
*/
vtk_vertex_node
(
std
::
string
&
v_node
,
typename
G
::
V_container
&
n_obj
,
s_type
(
&
x
)[
3
])
:
x
(
x
),
vo
(
n_obj
),
v_node
(
v_node
)
{
};
//! \brief Write collected information
void
write
()
{
v_node
+=
std
::
to_string
(
x
[
0
])
+
" "
+
std
::
to_string
(
x
[
1
])
+
" "
+
std
::
to_string
(
x
[
2
])
+
"
\n
"
;
}
//! It call the functor for each member
template
<
typename
T
>
void
operator
()(
T
&
t
)
{
// if the attribute name is x y or z, create a string with the value of the properties and store it
if
(
G
::
V_type
::
attributes
::
name
[
T
::
value
]
==
"x"
){
x
[
0
]
=
convert
<
typename
boost
::
remove_reference
<
decltype
(
vo
.
template
get
<
T
::
value
>())
>::
type
>::
template
to
<
s_type
>(
vo
.
template
get
<
T
::
value
>());}
else
if
(
G
::
V_type
::
attributes
::
name
[
T
::
value
]
==
"y"
){
x
[
1
]
=
convert
<
typename
boost
::
remove_reference
<
decltype
(
vo
.
template
get
<
T
::
value
>())
>::
type
>::
template
to
<
s_type
>(
vo
.
template
get
<
T
::
value
>());}
else
if
(
G
::
V_type
::
attributes
::
name
[
T
::
value
]
==
"z"
){
x
[
2
]
=
convert
<
typename
boost
::
remove_reference
<
decltype
(
vo
.
template
get
<
T
::
value
>())
>::
type
>::
template
to
<
s_type
>(
vo
.
template
get
<
T
::
value
>());}
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to create a string containing all the vertex
* properties
*
* Specialization when we do not have vertex attributes
*
* \tparam G graph type
*
*/
template
<
typename
G
>
struct
vtk_vertex_node
<
G
,
false
>
{
// Vertex object container
typename
G
::
V_container
&
vo
;
// vertex node string
std
::
string
&
v_node
;
/*! \brief Constructor
*
* Create a vertex properties list
*
* \param v_node std::string that is filled with the graph properties in the GraphML format
* \param n_obj object container to access its properties for example encapc<...>
*
*/
vtk_vertex_node
(
std
::
string
&
v_node
,
typename
G
::
V_container
&
n_obj
)
:
vo
(
n_obj
),
v_node
(
v_node
)
{
};
//! It call the functor for each member
template
<
typename
T
>
void
operator
()(
T
&
t
)
{
v_node
+=
"0 0 0
\n
"
;
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to create a string containing all the edge
* properties
*
*/
template
<
typename
G
>
struct
vtk_edge_node
{
// Vertex object container
typename
G
::
E_container
&
vo
;
// edge node string
std
::
string
&
e_node
;
/*! \brief Constructor
*
* Create an edge node
*
* \param e_node std::string that is filled with the graph properties in the GraphML format
* \param n_obj object container to access the object properties for example encapc<...>
* \param n_prop number of properties
*
*/
vtk_edge_node
(
std
::
string
&
e_node
,
typename
G
::
E_container
&
n_obj
)
:
vo
(
n_obj
),
e_node
(
e_node
)
{
};
/*! \brief Create a new node
*
* \param vc node number
*
*/
void
new_node
(
size_t
v_c
,
size_t
s
,
size_t
d
)
{
// start a new node
e_node
+=
"2 "
+
std
::
to_string
(
s
)
+
" "
+
std
::
to_string
(
d
)
+
"
\n
"
;
}
};
/*! \brief This class specialize functions in the case the type T
* has or not defined attributes
*
...
...
@@ -18,7 +162,7 @@
* define or not attributes name
*
* \tparam Graph type of graph we are processing
* \tparam
p
the property we are going to write
* \tparam
i
the property we are going to write
*
*/
...
...
src/VTKWriter_grids.hpp
0 → 100644
View file @
219f53f0
/*
* VTKWriter_grids.hpp
*
* Created on: May 5, 2015
* Author: Pietro Incardona
*/
#ifndef VTKWRITER_GRIDS_HPP_
#define VTKWRITER_GRIDS_HPP_
#include <boost/mpl/pair.hpp>
#include "VTKWriter_grids_util.hpp"
template
<
typename
Grid
,
typename
St
>
class
ele_g
{
public:
typedef
Grid
value_type
;
ele_g
(
const
Grid
&
g
,
Point
<
Grid
::
dims
,
St
>
&
offset
,
Point
<
Grid
::
dims
,
St
>
&
spacing
,
Box
<
Grid
::
dims
,
St
>
dom
)
:
g
(
g
),
offset
(
offset
),
spacing
(
spacing
),
dom
(
dom
)
{}
std
::
string
dataset
;
//! Grid
const
Grid
&
g
;
//! offset where it start
Point
<
Grid
::
dims
,
St
>
offset
;
// spacing of the grid
Point
<
Grid
::
dims
,
St
>
spacing
;
// Part of the grid that is real domain
Box
<
Grid
::
dims
,
St
>
dom
;
};
/*! \brief This class specialize functions in the case the type T
* has not defined attributes
*
* In C++ partial specialization of a function is not allowed so we have to
* encapsulate this function in a class
*
* \tparam has_attributes parameter that specialize the function in case the vertex
* define or not attributes name
*
* \tparam i id of the property we are going to write
*
*/
template
<
typename
ele_g
,
typename
St
,
unsigned
int
i
>
class
prop_output_g
<
false
,
St
,
ele_g
,
i
>
{
public:
/*! \brief Given a Graph return the point data header for a typename T
*
* \tparam T type to write
* \param n_node number of the node
*
*/
static
std
::
string
get_point_property_header
()
{
//! vertex node output string
std
::
string
v_out
;
// Check if T is a supported format
// for now we support only scalar of native type
std
::
string
type
=
getType
<
typename
boost
::
fusion
::
result_of
::
at
<
typename
ele_g
::
value_type
::
value_type
::
type
,
boost
::
mpl
::
int_
<
i
>>::
type
>
();
// if the type is not supported return
if
(
type
.
size
()
==
0
)
{
return
v_out
;}
// Create point data properties
v_out
+=
"SCALARS "
+
get_attributes
()
+
" "
+
type
+
"
\n
"
;
// Default lookup table
v_out
+=
"LOOKUP_TABLE default
\n
"
;
// return the vertex list
return
v_out
;
}
/*! \brief Get the attributes name
*
*/
static
std
::
string
get_attributes
()
{
return
std
::
string
(
"attr"
+
std
::
to_string
(
i
));
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* 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
*
*/
template
<
typename
ele_g
,
typename
St
>
struct
prop_out_g
{
// property output string
std
::
string
&
v_out
;
// grid that we are processing
const
openfpm
::
vector_std
<
ele_g
>
&
vg
;
/*! \brief constructor
*
* \param v_out string to fill with the vertex properties
*
*/
prop_out_g
(
std
::
string
&
v_out
,
const
openfpm
::
vector_std
<
ele_g
>
&
vg
)
:
v_out
(
v_out
),
vg
(
vg
)
{};
//! It produce an output for each property
template
<
typename
T
>
void
operator
()(
T
&
t
)
const
{
typedef
typename
boost
::
mpl
::
at
<
typename
ele_g
::
value_type
::
value_type
::
type
,
boost
::
mpl
::
int_
<
T
::
value
>>::
type
ptype
;
meta_prop
<
boost
::
mpl
::
int_
<
T
::
value
>
,
ele_g
,
St
,
ptype
>
m
(
vg
,
v_out
);
}
};
/*!
*
* It write a VTK format file in case of grids defined on a space
*
* \tparam boost::mpl::pair<G,S>
*
* where G is the type of grid S is the type of space, float, double ...
*
*/
template
<
typename
pair
>
class
VTKWriter
<
pair
,
VECTOR_GRIDS
>
{
//! Vector of grids
openfpm
::
vector
<
ele_g
<
typename
pair
::
first
,
typename
pair
::
second
>
>
vg
;
/*! \brief Get the total number of points
*
* \return the total number
*
*/
size_t
get_total
()
{
size_t
tot
=
0
;
//! Calculate the full number of vertices
for
(
size_t
i
=
0
;
i
<
vg
.
size
()
;
i
++
)
{
tot
+=
vg
.
get
(
i
).
g
.
size
();
}
return
tot
;
}
/*! \brief It get the vertex properties list
*
* It get the vertex properties list of the vertex defined as VTK header
*
* \return a string that define the vertex properties in graphML format
*
*/
std
::
string
get_vertex_properties_list
()
{
//! vertex property output string
std
::
string
v_out
;
// write the number of vertex
v_out
+=
"VERTICES "
+
std
::
to_string
(
get_total
())
+
" "
+
std
::
to_string
(
vg
.
size
()
*
2
)
+
"
\n
"
;
// return the vertex properties string
return
v_out
;
}
/*! \brief It get the vertex properties list
*
* It get the vertex properties list of the vertex defined as a VTK header
*
* \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
"
;
// return the vertex properties string
return
v_out
;
}
/*! \brief Create the VTK point definition
*
* \tparam s_type spatial type of the data
* \tparam attr false x,y,z are set to 0 for each vertex
*
*/
template
<
bool
attr
>
std
::
string
get_point_list
()
{
//! vertex node output string
std
::
stringstream
v_out
;
//! For each defined grid
for
(
size_t
i
=
0
;
i
<
vg
.
size
()
;
i
++
)
{
//! Get the iterator
auto
it
=
vg
.
get
(
i
).
g
.
getIterator
();
//! Where the grid is defined
Box
<
pair
::
first
::
dims
,
typename
pair
::
second
>
dom
;
// if there is the next element
while
(
it
.
isNext
())
{
Point
<
pair
::
first
::
dims
,
typename
pair
::
second
>
p
;
p
=
it
.
get
().
toPoint
();
p
=
p
*
vg
.
get
(
i
).
spacing
+
vg
.
get
(
i
).
offset
;
v_out
<<
p
.
toString
()
<<
"
\n
"
;
// increment the iterator and counter
++
it
;
}
}
// return the vertex list
return
v_out
.
str
();
}
/*! \brief Create the VTK vertex definition
*
* \tparam s_type spatial type of the data
* \tparam attr false x,y,z are set to 0 for each vertex
*
*/
std
::
string
get_vertex_list
()
{
//! vertex node output string
std
::
string
v_out
;
size_t
k
=
0
;
for
(
size_t
i
=
0
;
i
<
vg
.
size
()
;
i
++
)
{
//! For each grid point create a vertex
auto
it
=
vg
.
get
(
i
).
g
.
getIterator
();
while
(
it
.
isNext
())
{
v_out
+=
"1 "
+
std
::
to_string
(
k
)
+
"
\n
"
;
++
k
;
++
it
;
}
}
// return the vertex list
return
v_out
;
}
/*! \brief Get the point data header
*
* \return a string with the point data header for VTK format
*
*/
std
::
string
get_point_data_header
()
{
std
::
string
v_out
;
v_out
+=
"POINT_DATA "
+
std
::
to_string
(
get_total
())
+
"
\n
"
;
return
v_out
;
}
public:
/*!
*
* VTKWriter constructor
*