Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
848b2fd5
Commit
848b2fd5
authored
Jan 23, 2013
by
André Reichenbach
Browse files
[ADD] vtk reader now actually gets used and can now also load tensor data
parent
9192db66
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
569 additions
and
431 deletions
+569
-431
src/modules/data/WMData.cpp
src/modules/data/WMData.cpp
+6
-0
src/modules/data/io/WReaderVTK.cpp
src/modules/data/io/WReaderVTK.cpp
+466
-391
src/modules/data/io/WReaderVTK.h
src/modules/data/io/WReaderVTK.h
+96
-39
src/qt4gui/qt4/WMainWindow.cpp
src/qt4gui/qt4/WMainWindow.cpp
+1
-1
No files found.
src/modules/data/WMData.cpp
View file @
848b2fd5
...
...
@@ -47,6 +47,7 @@
#include "io/WReaderELC.h"
#include "io/WReaderFiberVTK.h"
#include "io/WReaderLibeep.h"
#include "io/WReaderVTK.h"
#include "io/WPagerEEGLibeep.h"
#include "WMData.h"
...
...
@@ -285,6 +286,11 @@ void WMData::moduleMain()
WReaderFiberVTK
fibReader
(
fileName
);
m_dataSet
=
fibReader
.
read
();
}
else
if
(
suffix
==
".vtk"
)
{
WReaderVTK
vtkReader
(
fileName
);
m_dataSet
=
vtkReader
.
read
();
}
else
{
throw
WDHException
(
std
::
string
(
"Could not load
\"
"
+
fileName
+
"
\"
. Reason: unknown file type:
\"
"
+
suffix
+
"
\"
"
)
);
...
...
src/modules/data/io/WReaderVTK.cpp
View file @
848b2fd5
This diff is collapsed.
Click to expand it.
src/modules/data/io/WReaderVTK.h
View file @
848b2fd5
...
...
@@ -44,7 +44,8 @@
* Currently only a subset of the legacy format is supported.
*
* Formats read: Original ASCII and BINARY. The xml format is not supported.
* Grids read are: STRUCTURED_POINTS
* Grids read are: STRUCTURED_POINTS, RECTILINEAR_GRID is interpreted as a grid with
* equal spacing per coordinate axis
* Data types read: SCALARS, VECTORS, TENSORS
*
* Endianess is kept as on the platform, so for intel hosts, most files,
...
...
@@ -55,8 +56,10 @@
*/
class
WReaderVTK
:
public
WReader
// NOLINT
{
//! allow member access by the test class
friend
class
WReaderVTKTest
;
public:
public:
/**
* Constructs and makes a new VTK reader for separate thread start.
*
...
...
@@ -71,30 +74,42 @@ class WReaderVTK : public WReader // NOLINT
virtual
~
WReaderVTK
()
throw
();
/**
* Reads the
fiber
file and creates a dataset out of it.
* Reads the
data
file and creates a dataset out of it.
*
* \return Reference to the dataset.
*/
virtual
boost
::
shared_ptr
<
WDataSet
>
read
();
protected:
protected:
/**
* Read VTK header from file.
* Read VTK header from file.
Sets the m_isASCII member accordingly.
*
* \return The offset where header ends, so we may skip this next operation.
* \throws WDHIOFailure, WDHParseError
* \return true, if the header was valid
*/
void
readHeader
();
bool
readHeader
();
/**
* Read VTK POINT_DATA field from input stream.
* Read VTK Domain specification and create a matching grid.
*
* \return The constructed grid or an invalid pointer if any problem occurred.
*/
void
rea
dPoint
Data
();
boost
::
shared_ptr
<
WGridRegular3D
>
readStructure
dPoint
s
();
/**
* Read VTK STRUCTURED_POINTS field
* Read VTK Domain specification and create a matching grid.
*
* \return The constructed grid or an invalid pointer if any problem occurred.
*/
void
readStructuredPoints
();
boost
::
shared_ptr
<
WGridRegular3D
>
readRectilinearGrid
();
/**
* Read domain information for structured points.
*
* \param grid The grid constructed from the domain information.
*
* \return The value set containing the values read from the file or an invalid pointer if anything went wrong.
*/
boost
::
shared_ptr
<
WValueSetBase
>
readData
(
boost
::
shared_ptr
<
WGridRegular3D
>
const
&
grid
);
/**
* Read VTK SCALARS field
...
...
@@ -104,8 +119,10 @@ class WReaderVTK : public WReader // NOLINT
* the number of scalars to read
* \param name
* the name of the data set that may be overwritten by information in the scalars line
*
* \return The resulting value set.
*/
void
readScalars
(
size_t
nbScalars
,
const
std
::
string
&
name
);
boost
::
shared_ptr
<
WValueSetBase
>
readScalars
(
size_t
nbScalars
,
const
std
::
string
&
name
);
/**
* Read VTK SCALARS field
...
...
@@ -115,8 +132,10 @@ class WReaderVTK : public WReader // NOLINT
* the number of vectors to read
* \param name
* the name of the data set that may be overwritten by information in the vectors line
*/
void
readVectors
(
size_t
nbVectors
,
const
std
::
string
&
name
);
*
* \return The resulting value set.
*/
boost
::
shared_ptr
<
WValueSetBase
>
readVectors
(
size_t
nbVectors
,
const
std
::
string
&
name
);
/**
* Read VTK TENSORS field
...
...
@@ -126,33 +145,49 @@ class WReaderVTK : public WReader // NOLINT
* the number of tensors to read
* \param name
* the name of the data set that may be overwritten by information in the tensors line
*/
void
readTensors
(
size_t
nbTensors
,
const
std
::
string
&
name
);
*
* \return The resulting value set.
*/
boost
::
shared_ptr
<
WValueSetBase
>
readTensors
(
size_t
nbTensors
,
const
std
::
string
&
name
);
std
::
vector
<
std
::
string
>
m_header
;
//!< VTK header of the read file
/**
* Stores for every point its x,y and z float value successivley.
* \note The i'th point starts at the 3*i index since every point consumes
* 3 elements.
*/
boost
::
shared_ptr
<
std
::
vector
<
float
>
>
m_points
;
boost
::
shared_ptr
<
std
::
ifstream
>
m_ifs
;
//!< Pointer to the input file stream reader.
//boost::shared_ptr< std::vector< size_t > > m_fiberStartIndices; //!< Stores the start indices (in the point array) for every fiber
private:
//boost::shared_ptr< std::vector< size_t > > m_fiberLengths; //!< Stores the length of every fiber
//! The types of domains supported so far.
enum
DomainType
{
//! structured points
STRUCTURED_POINTS
,
/**
* Stores for every point the fiber where it belongs to.
* \note This vector has as many components as there are points, hence its
* length is just a third of the length of the points vector.
*/
//boost::shared_ptr< std::vector< size_t > > m_pointFiberMapping;
//! rectilinear grid
RECTILINEAR_GRID
,
boost
::
shared_ptr
<
std
::
ifstream
>
m_ifs
;
//!< Pointer to the input file stream reader.
//! anything else
UNSUPPORTED_DOMAIN
};
//! The types of attributes supported so far.
enum
AttributeType
{
//! scalar data
SCALARS
,
//! vector data
VECTORS
,
//! tensor data
TENSORS
,
//! array data
ARRAYS
,
//! anything else
UNSUPPORTED_ATTRIBUTE
};
private:
/**
* Reads the next line from current position in stream of the fiber VTK file.
*
...
...
@@ -163,6 +198,23 @@ class WReaderVTK : public WReader // NOLINT
*/
std
::
string
getLine
(
const
std
::
string
&
desc
);
/**
* Read the coordinates of the dataset's domain.
*
* \param name The name to look for in the first line.
* \param dim The number of coordinates.
* \param coords The resulting vector of coordinates.
*/
void
readCoords
(
std
::
string
const
&
name
,
std
::
size_t
dim
,
std
::
vector
<
float
>&
coords
);
/**
* Read values from the file. The m_isASCII flag must be initialized accordingly.
*
* \param values The values read from the file.
* \param numValues The number of values to read.
*/
void
readValuesFromFile
(
std
::
vector
<
float
>&
values
,
std
::
size_t
numValues
);
/**
* Try to cast from the given string to the template value T. If the cast fails a
* WDHParseError is thrown.
...
...
@@ -174,22 +226,26 @@ class WReaderVTK : public WReader // NOLINT
*/
template
<
typename
T
>
T
getLexicalCast
(
std
::
string
stringValue
,
const
std
::
string
&
errMsg
)
const
;
/**
* reference to the currently loading data set
*/
boost
::
shared_ptr
<
WDataSet
>
newDataSet
;
boost
::
shared_ptr
<
WDataSet
>
m_
newDataSet
;
/**
* reference to the currently loading grid
*/
boost
::
shared_ptr
<
WGridRegular3D
>
newGrid
;
boost
::
shared_ptr
<
WGridRegular3D
>
m_
newGrid
;
/**
* internal flag whether we read ascii or binary
*/
bool
isAscii
;
bool
m_isASCII
;
//! The type of domain specified in the file.
DomainType
m_domainType
;
//! The type of the attributes first read from the file.
AttributeType
m_attributeType
;
};
template
<
typename
T
>
inline
T
WReaderVTK
::
getLexicalCast
(
std
::
string
stringValue
,
const
std
::
string
&
errMsg
)
const
...
...
@@ -206,4 +262,5 @@ template< typename T > inline T WReaderVTK::getLexicalCast( std::string stringVa
return
result
;
}
#endif // WREADERVTK_H
src/qt4gui/qt4/WMainWindow.cpp
View file @
848b2fd5
...
...
@@ -672,7 +672,7 @@ void WMainWindow::openLoadDialog()
fd
.
setFileMode
(
QFileDialog
::
ExistingFiles
);
QStringList
filters
;
filters
<<
"Known file types (*.cnt *.edf *.asc *.nii *.nii.gz *.fib *.owproj *.owp)"
filters
<<
"Known file types (*.cnt *.edf *.asc *.nii *.nii.gz
*.vtk
*.fib *.owproj *.owp)"
<<
"Simple Project File (*.owproj *.owp)"
<<
"EEG files (*.cnt *.edf *.asc)"
<<
"NIfTI (*.nii *.nii.gz)"
...
...
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