Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iwr
dune-vtk
Commits
8b76686c
Commit
8b76686c
authored
Dec 12, 2020
by
Praetorius, Simon
Browse files
Store IDs of DataArrays using section name and Name attribute
parent
756c0f7b
Changes
2
Hide whitespace changes
Inline
Side-by-side
dune/vtk/vtkreader.hh
View file @
8b76686c
...
...
@@ -43,6 +43,7 @@ namespace Dune
// Type storing information about read data
struct
DataArrayAttributes
{
std
::
string
name
;
Vtk
::
DataTypes
type
;
unsigned
int
components
=
1
;
std
::
uint64_t
offset
=
0
;
...
...
@@ -105,11 +106,11 @@ namespace Dune
/// NOTE: requires an aforgoing call to \ref read()
GridFunction
<
Vtk
::
PointContext
>
getPointData
(
std
::
string
const
&
name
)
const
{
auto
const
&
data
=
dataArray_
.
at
(
name
);
auto
const
&
data
=
dataArray_
.
at
(
"PointData."
+
name
);
VTK_ASSERT_MSG
(
data
.
section
==
POINT_DATA
,
"The data to extract is not point-data. Use `getCellData()` instead!"
);
return
{
*
creator_
,
pointData_
.
at
(
name
),
data
.
components
,
return
{
*
creator_
,
pointData_
.
at
(
"PointData."
+
name
),
data
.
components
,
vec_types
,
vec_offsets
,
vec_connectivity
};
}
...
...
@@ -117,11 +118,11 @@ namespace Dune
/// NOTE: requires an aforgoing call to \ref read()
GridFunction
<
Vtk
::
CellContext
>
getCellData
(
std
::
string
const
&
name
)
const
{
auto
const
&
data
=
dataArray_
.
at
(
name
);
auto
const
&
data
=
dataArray_
.
at
(
"CellData."
+
name
);
VTK_ASSERT_MSG
(
data
.
section
==
CELL_DATA
,
"The data to extract is not cell-data. Use `getPointData()` instead!"
);
return
{
*
creator_
,
cellData_
.
at
(
name
),
data
.
components
,
return
{
*
creator_
,
cellData_
.
at
(
"CellData."
+
name
),
data
.
components
,
vec_types
,
vec_offsets
,
vec_connectivity
};
}
...
...
@@ -206,6 +207,9 @@ namespace Dune
return
result
;
}
// Convert a section into a string
std
::
string
toString
(
Sections
s
)
const
;
// Find beginning of appended binary data
std
::
uint64_t
findAppendedDataPosition
(
std
::
ifstream
&
input
)
const
;
...
...
@@ -237,10 +241,11 @@ namespace Dune
std
::
size_t
numberOfPoints_
=
0
;
//< Number of vertices in the grid
// offset information for appended data
// map
Name -> {
DataType,NumberOfComponents,Offset}
// map
: id -> {Name,
DataType,NumberOfComponents,Offset}
std
::
map
<
std
::
string
,
DataArrayAttributes
>
dataArray_
;
// storage for internal point and cell data
// map: id -> vector of data entries per point/cell
std
::
map
<
std
::
string
,
std
::
vector
<
FieldType
>>
pointData_
;
std
::
map
<
std
::
string
,
std
::
vector
<
FieldType
>>
cellData_
;
...
...
dune/vtk/vtkreader.impl.hh
View file @
8b76686c
...
...
@@ -110,10 +110,17 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
data_type
=
Vtk
::
Map
::
to_datatype
[
attr
[
"type"
]];
if
(
!
attr
[
"Name"
].
empty
())
data_name
=
Vtk
::
to_lower
(
attr
[
"Name"
]);
else
if
(
section
==
POINTS
)
data_name
=
"points"
;
if
(
section
==
POINTS
)
// In the Points section must only be one DataArray with id=Points
data_name
=
toString
(
section
);
else
if
(
section
==
CELLS
)
// All DataArrays in the Cells sections are identified by lower case Cells.name
data_name
=
toString
(
section
)
+
"."
+
Vtk
::
to_lower
(
attr
[
"Name"
]);
else
if
(
!
attr
[
"Name"
].
empty
())
// Use Section.Name as key
data_name
=
toString
(
section
)
+
"."
+
attr
[
"Name"
];
else
data_name
=
toString
(
section
)
+
"."
+
"_Unknown_"
;
data_components
=
1
;
if
(
!
attr
[
"NumberOfComponents"
].
empty
())
...
...
@@ -135,7 +142,7 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
}
// Store attributes of DataArray
dataArray_
[
data_name
]
=
{
data_type
,
data_components
,
data_offset
,
section
};
dataArray_
[
data_name
]
=
{
attr
[
"Name"
],
data_type
,
data_components
,
data_offset
,
section
};
// Skip section in appended mode
if
(
data_format
==
"appended"
)
{
...
...
@@ -179,7 +186,7 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
VTK_ASSERT_MSG
(
attr
[
"encoding"
]
==
"raw"
,
"base64 encoding not supported"
);
offset0_
=
findAppendedDataPosition
(
input
);
if
(
dataArray_
[
"
p
oints"
].
type
==
Vtk
::
FLOAT32
)
if
(
dataArray_
[
"
P
oints"
].
type
==
Vtk
::
FLOAT32
)
readPointsAppended
<
float
>
(
input
);
else
readPointsAppended
<
double
>
(
input
);
...
...
@@ -187,18 +194,18 @@ void VtkReader<Grid,Creator,Field>::readSerialFileFromStream (std::ifstream& inp
readCellsAppended
(
input
);
// read point an cell data
for
(
auto
const
&
[
name
,
data
]
:
dataArray_
)
{
for
(
auto
const
&
[
id
,
data
]
:
dataArray_
)
{
if
(
data
.
section
==
POINT_DATA
)
{
if
(
data
.
type
==
Vtk
::
FLOAT32
)
readPointDataAppended
<
float
>
(
input
,
name
);
readPointDataAppended
<
float
>
(
input
,
id
);
else
readPointDataAppended
<
double
>
(
input
,
name
);
readPointDataAppended
<
double
>
(
input
,
id
);
}
else
if
(
data
.
section
==
CELL_DATA
)
{
if
(
data
.
type
==
Vtk
::
FLOAT32
)
readCellDataAppended
<
float
>
(
input
,
name
);
readCellDataAppended
<
float
>
(
input
,
id
);
else
readCellDataAppended
<
double
>
(
input
,
name
);
readCellDataAppended
<
double
>
(
input
,
id
);
}
}
...
...
@@ -337,13 +344,13 @@ Sections skipRestOfDataArray (IStream& input, Sections section, Sections parent_
// Read values stored on the cells with name `name`
template
<
class
Grid
,
class
Creator
,
class
Field
>
typename
VtkReader
<
Grid
,
Creator
,
Field
>::
Sections
VtkReader
<
Grid
,
Creator
,
Field
>::
readCellData
(
std
::
ifstream
&
input
,
std
::
string
name
)
VtkReader
<
Grid
,
Creator
,
Field
>::
readCellData
(
std
::
ifstream
&
input
,
std
::
string
id
)
{
VTK_ASSERT
(
numberOfCells_
>
0
);
unsigned
int
components
=
dataArray_
[
name
].
components
;
unsigned
int
components
=
dataArray_
[
id
].
components
;
Sections
sec
;
std
::
vector
<
Field
>&
values
=
cellData_
[
name
];
std
::
vector
<
Field
>&
values
=
cellData_
[
id
];
sec
=
readDataArray
(
input
,
values
,
components
*
numberOfCells_
,
CD_DATA_ARRAY
,
CELL_DATA
);
if
(
sec
!=
CELL_DATA
)
sec
=
skipRestOfDataArray
(
input
,
CD_DATA_ARRAY
,
CELL_DATA
);
...
...
@@ -356,29 +363,29 @@ VtkReader<Grid,Creator,Field>::readCellData (std::ifstream& input, std::string n
template
<
class
Grid
,
class
Creator
,
class
Field
>
template
<
class
T
>
void
VtkReader
<
Grid
,
Creator
,
Field
>::
readCellDataAppended
(
std
::
ifstream
&
input
,
std
::
string
name
)
void
VtkReader
<
Grid
,
Creator
,
Field
>::
readCellDataAppended
(
std
::
ifstream
&
input
,
std
::
string
id
)
{
VTK_ASSERT
(
numberOfCells_
>
0
);
unsigned
int
components
=
dataArray_
[
name
].
components
;
unsigned
int
components
=
dataArray_
[
id
].
components
;
std
::
vector
<
T
>
values
;
readAppended
(
input
,
values
,
dataArray_
[
name
].
offset
);
readAppended
(
input
,
values
,
dataArray_
[
id
].
offset
);
VTK_ASSERT
(
values
.
size
()
==
components
*
numberOfCells_
);
cellData_
[
name
].
resize
(
values
.
size
());
std
::
copy
(
values
.
begin
(),
values
.
end
(),
cellData_
[
name
].
begin
());
cellData_
[
id
].
resize
(
values
.
size
());
std
::
copy
(
values
.
begin
(),
values
.
end
(),
cellData_
[
id
].
begin
());
}
template
<
class
Grid
,
class
Creator
,
class
Field
>
typename
VtkReader
<
Grid
,
Creator
,
Field
>::
Sections
VtkReader
<
Grid
,
Creator
,
Field
>::
readPointData
(
std
::
ifstream
&
input
,
std
::
string
name
)
VtkReader
<
Grid
,
Creator
,
Field
>::
readPointData
(
std
::
ifstream
&
input
,
std
::
string
id
)
{
VTK_ASSERT
(
numberOfPoints_
>
0
);
unsigned
int
components
=
dataArray_
[
name
].
components
;
unsigned
int
components
=
dataArray_
[
id
].
components
;
Sections
sec
;
std
::
vector
<
Field
>&
values
=
pointData_
[
name
];
std
::
vector
<
Field
>&
values
=
pointData_
[
id
];
sec
=
readDataArray
(
input
,
values
,
components
*
numberOfPoints_
,
PD_DATA_ARRAY
,
POINT_DATA
);
if
(
sec
!=
POINT_DATA
)
sec
=
skipRestOfDataArray
(
input
,
PD_DATA_ARRAY
,
POINT_DATA
);
...
...
@@ -391,27 +398,27 @@ VtkReader<Grid,Creator,Field>::readPointData (std::ifstream& input, std::string
template
<
class
Grid
,
class
Creator
,
class
Field
>
template
<
class
T
>
void
VtkReader
<
Grid
,
Creator
,
Field
>::
readPointDataAppended
(
std
::
ifstream
&
input
,
std
::
string
name
)
void
VtkReader
<
Grid
,
Creator
,
Field
>::
readPointDataAppended
(
std
::
ifstream
&
input
,
std
::
string
id
)
{
VTK_ASSERT
(
numberOfPoints_
>
0
);
unsigned
int
components
=
dataArray_
[
name
].
components
;
unsigned
int
components
=
dataArray_
[
id
].
components
;
std
::
vector
<
T
>
values
;
readAppended
(
input
,
values
,
dataArray_
[
name
].
offset
);
readAppended
(
input
,
values
,
dataArray_
[
id
].
offset
);
VTK_ASSERT
(
values
.
size
()
==
components
*
numberOfPoints_
);
pointData_
[
name
].
resize
(
values
.
size
());
std
::
copy
(
values
.
begin
(),
values
.
end
(),
pointData_
[
name
].
begin
());
pointData_
[
id
].
resize
(
values
.
size
());
std
::
copy
(
values
.
begin
(),
values
.
end
(),
pointData_
[
id
].
begin
());
}
template
<
class
Grid
,
class
Creator
,
class
Field
>
typename
VtkReader
<
Grid
,
Creator
,
Field
>::
Sections
VtkReader
<
Grid
,
Creator
,
Field
>::
readPoints
(
std
::
ifstream
&
input
,
std
::
string
name
)
VtkReader
<
Grid
,
Creator
,
Field
>::
readPoints
(
std
::
ifstream
&
input
,
std
::
string
id
)
{
using
T
=
typename
GlobalCoordinate
::
value_type
;
VTK_ASSERT
(
numberOfPoints_
>
0
);
VTK_ASSERT
(
dataArray_
[
"
p
oints"
].
components
==
3u
);
VTK_ASSERT
(
dataArray_
[
"
P
oints"
].
components
==
3u
);
Sections
sec
;
...
...
@@ -442,9 +449,9 @@ template <class Grid, class Creator, class Field>
void
VtkReader
<
Grid
,
Creator
,
Field
>::
readPointsAppended
(
std
::
ifstream
&
input
)
{
VTK_ASSERT
(
numberOfPoints_
>
0
);
VTK_ASSERT
(
dataArray_
[
"
p
oints"
].
components
==
3u
);
VTK_ASSERT
(
dataArray_
[
"
P
oints"
].
components
==
3u
);
std
::
vector
<
T
>
point_values
;
readAppended
(
input
,
point_values
,
dataArray_
[
"
p
oints"
].
offset
);
readAppended
(
input
,
point_values
,
dataArray_
[
"
P
oints"
].
offset
);
VTK_ASSERT
(
point_values
.
size
()
==
3
*
numberOfPoints_
);
// extract points from continuous values
...
...
@@ -462,20 +469,20 @@ void VtkReader<Grid,Creator,Field>::readPointsAppended (std::ifstream& input)
template
<
class
Grid
,
class
Creator
,
class
Field
>
typename
VtkReader
<
Grid
,
Creator
,
Field
>::
Sections
VtkReader
<
Grid
,
Creator
,
Field
>::
readCells
(
std
::
ifstream
&
input
,
std
::
string
name
)
VtkReader
<
Grid
,
Creator
,
Field
>::
readCells
(
std
::
ifstream
&
input
,
std
::
string
id
)
{
Sections
sec
=
CELLS_DATA_ARRAY
;
VTK_ASSERT
(
numberOfCells_
>
0
);
if
(
name
==
"types"
)
{
if
(
id
==
"
Cells.
types"
)
{
sec
=
readDataArray
(
input
,
vec_types
,
numberOfCells_
,
CELLS_DATA_ARRAY
,
CELLS
);
VTK_ASSERT
(
vec_types
.
size
()
==
numberOfCells_
);
}
else
if
(
name
==
"offsets"
)
{
}
else
if
(
id
==
"
Cells.
offsets"
)
{
sec
=
readDataArray
(
input
,
vec_offsets
,
numberOfCells_
,
CELLS_DATA_ARRAY
,
CELLS
);
VTK_ASSERT
(
vec_offsets
.
size
()
==
numberOfCells_
);
}
else
if
(
name
==
"connectivity"
)
{
}
else
if
(
id
==
"
Cells.
connectivity"
)
{
sec
=
readDataArray
(
input
,
vec_connectivity
,
std
::
size_t
(
-
1
),
CELLS_DATA_ARRAY
,
CELLS
);
}
else
if
(
name
==
"global_point_ids"
)
{
}
else
if
(
id
==
"
Cells.
global_point_ids"
)
{
sec
=
readDataArray
(
input
,
vec_point_ids
,
numberOfPoints_
,
CELLS_DATA_ARRAY
,
CELLS
);
VTK_ASSERT
(
vec_point_ids
.
size
()
==
numberOfPoints_
);
}
...
...
@@ -488,9 +495,9 @@ template <class Grid, class Creator, class Field>
void
VtkReader
<
Grid
,
Creator
,
Field
>::
readCellsAppended
(
std
::
ifstream
&
input
)
{
VTK_ASSERT
(
numberOfCells_
>
0
);
auto
types_data
=
dataArray_
[
"types"
];
auto
offsets_data
=
dataArray_
[
"offsets"
];
auto
connectivity_data
=
dataArray_
[
"connectivity"
];
auto
types_data
=
dataArray_
[
"
Cells.
types"
];
auto
offsets_data
=
dataArray_
[
"
Cells.
offsets"
];
auto
connectivity_data
=
dataArray_
[
"
Cells.
connectivity"
];
VTK_ASSERT
(
types_data
.
type
==
Vtk
::
UINT8
);
readAppended
(
input
,
vec_types
,
types_data
.
offset
);
...
...
@@ -518,8 +525,8 @@ void VtkReader<Grid,Creator,Field>::readCellsAppended (std::ifstream& input)
else
{
DUNE_THROW
(
Dune
::
NotImplemented
,
"Unsupported DataType in Cell connectivity."
);
}
VTK_ASSERT
(
vec_connectivity
.
size
()
==
std
::
size_t
(
vec_offsets
.
back
()));
if
(
dataArray_
.
count
(
"global_point_ids"
)
>
0
)
{
auto
point_id_data
=
dataArray_
[
"global_point_ids"
];
if
(
dataArray_
.
count
(
"
Cells.
global_point_ids"
)
>
0
)
{
auto
point_id_data
=
dataArray_
[
"
Cells.
global_point_ids"
];
VTK_ASSERT
(
point_id_data
.
type
==
Vtk
::
UINT64
);
readAppended
(
input
,
vec_point_ids
,
point_id_data
.
offset
);
VTK_ASSERT
(
vec_point_ids
.
size
()
==
numberOfPoints_
);
...
...
@@ -628,6 +635,39 @@ void VtkReader<Grid,Creator,Field>::fillGridCreator (bool insertPieces)
creator_
->
insertPieces
(
pieces_
);
}
// Convert section into string
template
<
class
Grid
,
class
Creator
,
class
Field
>
std
::
string
VtkReader
<
Grid
,
Creator
,
Field
>::
toString
(
Sections
s
)
const
{
switch
(
s
)
{
case
VTK_FILE
:
return
"VTKFile"
;
case
UNSTRUCTURED_GRID
:
return
"UnstructuredGrid"
;
case
PIECE
:
return
"Piece"
;
case
POINT_DATA
:
return
"PointData"
;
case
CELL_DATA
:
return
"CellData"
;
case
POINTS
:
return
"Points"
;
case
CELLS
:
return
"Cells"
;
case
APPENDED_DATA
:
return
"AppendedData"
;
case
PD_DATA_ARRAY
:
case
CD_DATA_ARRAY
:
case
POINTS_DATA_ARRAY
:
case
CELLS_DATA_ARRAY
:
return
"DataArray"
;
default:
return
"Unknown"
;
}
}
// Assume input already read the line <AppendedData ...>
template
<
class
Grid
,
class
Creator
,
class
Field
>
std
::
uint64_t
VtkReader
<
Grid
,
Creator
,
Field
>::
findAppendedDataPosition
(
std
::
ifstream
&
input
)
const
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment