OpenWalnut  1.5.0dev
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
WReaderVTK Class Reference

Reads simple VTK files. More...

#include <WReaderVTK.h>

+ Inheritance diagram for WReaderVTK:
+ Collaboration diagram for WReaderVTK:

Public Member Functions

 WReaderVTK (std::string fname)
 Constructs and makes a new VTK reader for separate thread start. More...
 
virtual ~WReaderVTK () throw ()
 Destroys this instance and closes the file. More...
 
virtual std::shared_ptr< WDataSetread ()
 Reads the data file and creates a dataset out of it. More...
 
- Public Member Functions inherited from WReader
 WReader (std::string fname)
 Creates a read object for file reading. More...
 
OW_API_DEPRECATED void setFileName (std::string fname)
 Reset the file name and checks if it exists. More...
 
void setFilename (std::string fname)
 Reset the file name and checks if it exists. More...
 

Protected Member Functions

bool readHeader ()
 Read VTK header from file. More...
 
std::shared_ptr< WGridRegular3DreadStructuredPoints ()
 Read VTK Domain specification and create a matching grid. More...
 
std::shared_ptr< WGridRegular3DreadRectilinearGrid ()
 Read VTK Domain specification and create a matching grid. More...
 
std::shared_ptr< WValueSetBasereadData (std::shared_ptr< WGridRegular3D > const &grid)
 Read domain information for structured points. More...
 
std::shared_ptr< WValueSetBasereadScalars (size_t nbScalars, const std::string &name)
 Read VTK SCALARS field. More...
 
std::shared_ptr< WValueSetBasereadVectors (size_t nbVectors, const std::string &name)
 Read VTK SCALARS field. More...
 
std::shared_ptr< WValueSetBasereadHARDI (std::size_t nbPoints, std::size_t nbGradients, const std::string &)
 Read HARDI data from the file. More...
 
std::shared_ptr< WValueSetBasereadTensors (size_t nbTensors, const std::string &name)
 Read VTK TENSORS field. More...
 

Protected Attributes

std::vector< std::string > m_header
 VTK header of the read file. More...
 
std::shared_ptr< std::ifstream > m_ifs
 Pointer to the input file stream reader. More...
 
- Protected Attributes inherited from WReader
std::string m_fname
 Absolute path of the file to read from. More...
 

Private Types

enum  DomainType { STRUCTURED_POINTS , RECTILINEAR_GRID , UNSUPPORTED_DOMAIN }
 The types of domains supported so far. More...
 
enum  AttributeType {
  SCALARS , VECTORS , TENSORS , ARRAYS ,
  UNSUPPORTED_ATTRIBUTE
}
 The types of attributes supported so far. More...
 

Private Member Functions

std::string getLine (const std::string &desc)
 Reads the next line from current position in stream of the fiber VTK file. More...
 
void readCoords (std::string const &name, std::size_t dim, std::vector< float > &coords)
 Read the coordinates of the dataset's domain. More...
 
void readValuesFromFile (std::vector< float > &values, std::size_t numValues)
 Read values from the file. More...
 
std::shared_ptr< std::vector< WVector3d > > readGradients ()
 Read gradients from a gradients file which has the same basename as the data file and ends in .bvec. More...
 
template<typename T >
getLexicalCast (std::string stringValue, const std::string &errMsg) const
 Try to cast from the given string to the template value T. More...
 

Private Attributes

std::shared_ptr< WDataSetm_newDataSet
 reference to the currently loading data set More...
 
std::shared_ptr< WGridRegular3Dm_newGrid
 reference to the currently loading grid More...
 
bool m_isASCII
 internal flag whether we read ascii or binary More...
 
DomainType m_domainType
 The type of domain specified in the file. More...
 
AttributeType m_attributeType
 The type of the attributes first read from the file. More...
 

Friends

class WReaderVTKTest
 allow member access by the test class More...
 

Detailed Description

Reads simple VTK files.

For VTK just see http://www.vtk.org. 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, 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, which are typically stored in little endian, are not readable if they are binary files.

Definition at line 56 of file WReaderVTK.h.

Member Enumeration Documentation

◆ AttributeType

The types of attributes supported so far.

Enumerator
SCALARS 

scalar data

VECTORS 

vector data

TENSORS 

tensor data

ARRAYS 

array data

UNSUPPORTED_ATTRIBUTE 

anything else

Definition at line 181 of file WReaderVTK.h.

◆ DomainType

enum WReaderVTK::DomainType
private

The types of domains supported so far.

Enumerator
STRUCTURED_POINTS 

structured points

RECTILINEAR_GRID 

rectilinear grid

UNSUPPORTED_DOMAIN 

anything else

Definition at line 168 of file WReaderVTK.h.

Constructor & Destructor Documentation

◆ WReaderVTK()

WReaderVTK::WReaderVTK ( std::string  fname)
explicit

Constructs and makes a new VTK reader for separate thread start.

Parameters
fnameFile name where to read data from
Exceptions
WDHNoSuchFile

Definition at line 49 of file WReaderVTK.cpp.

◆ ~WReaderVTK()

WReaderVTK::~WReaderVTK ( )
throw (
)
virtual

Destroys this instance and closes the file.

Definition at line 54 of file WReaderVTK.cpp.

Member Function Documentation

◆ getLexicalCast()

template<typename T >
T WReaderVTK::getLexicalCast ( std::string  stringValue,
const std::string &  errMsg 
) const
inlineprivate

Try to cast from the given string to the template value T.

If the cast fails a WDHParseError is thrown.

Exceptions
WDHParseError
Parameters
stringValueThe string to cast from
errMsgError message incase the cast fails
Returns
The casted value from the given string.

Definition at line 266 of file WReaderVTK.h.

References WReader::m_fname.

◆ getLine()

std::string WReaderVTK::getLine ( const std::string &  desc)
private

Reads the next line from current position in stream of the fiber VTK file.

Parameters
descIn case of trouble while reading, this gives information in the error message about what was tried to read
Exceptions
WDHIOFailure,WDHParseError
Returns
Next line as string.

Definition at line 545 of file WReaderVTK.cpp.

References WReader::m_fname, and m_ifs.

Referenced by readCoords(), readData(), readHARDI(), readHeader(), readRectilinearGrid(), readScalars(), readStructuredPoints(), readTensors(), readValuesFromFile(), and readVectors().

+ Here is the caller graph for this function:

◆ read()

std::shared_ptr< WDataSet > WReaderVTK::read ( )
virtual

Reads the data file and creates a dataset out of it.

Returns
Reference to the dataset.

Definition at line 58 of file WReaderVTK.cpp.

References ARRAYS, wlog::error(), m_attributeType, m_domainType, WReader::m_fname, m_ifs, readData(), readGradients(), readHeader(), readRectilinearGrid(), readStructuredPoints(), RECTILINEAR_GRID, SCALARS, STRUCTURED_POINTS, TENSORS, and VECTORS.

+ Here is the call graph for this function:

◆ readCoords()

void WReaderVTK::readCoords ( std::string const &  name,
std::size_t  dim,
std::vector< float > &  coords 
)
private

Read the coordinates of the dataset's domain.

Parameters
nameThe name to look for in the first line.
dimThe number of coordinates.
coordsThe resulting vector of coordinates.

Definition at line 316 of file WReaderVTK.cpp.

References getLine(), readValuesFromFile(), string_utils::tokenize(), and string_utils::toLower().

Referenced by readRectilinearGrid().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readData()

std::shared_ptr< WValueSetBase > WReaderVTK::readData ( std::shared_ptr< WGridRegular3D > const &  grid)
protected

Read domain information for structured points.

Parameters
gridThe grid constructed from the domain information.
Returns
The value set containing the values read from the file or an invalid pointer if anything went wrong.

Definition at line 493 of file WReaderVTK.cpp.

References ARRAYS, getLine(), m_attributeType, readHARDI(), readScalars(), readTensors(), readVectors(), SCALARS, TENSORS, string_utils::tokenize(), string_utils::toUpper(), and VECTORS.

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readGradients()

std::shared_ptr< std::vector< WVector3d > > WReaderVTK::readGradients ( )
private

Read gradients from a gradients file which has the same basename as the data file and ends in .bvec.

Returns
A pointer to a vector of gradients.

Definition at line 134 of file WReaderVTK.cpp.

References WReader::m_fname.

Referenced by read().

+ Here is the caller graph for this function:

◆ readHARDI()

std::shared_ptr< WValueSetBase > WReaderVTK::readHARDI ( std::size_t  nbPoints,
std::size_t  nbGradients,
const std::string &   
)
protected

Read HARDI data from the file.

Parameters
nbPointsThe number of voxels.
nbGradientsThe number of gradients for this HARDI dataset.
Returns
The data read as a value set of floats.

Definition at line 463 of file WReaderVTK.cpp.

References getLine(), m_ifs, readValuesFromFile(), string_utils::tokenize(), and string_utils::toUpper().

Referenced by readData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readHeader()

bool WReaderVTK::readHeader ( )
protected

Read VTK header from file.

Sets the m_isASCII member accordingly.

Returns
true, if the header was valid

Definition at line 186 of file WReaderVTK.cpp.

References wlog::error(), getLine(), m_domainType, WReader::m_fname, m_header, m_isASCII, RECTILINEAR_GRID, STRUCTURED_POINTS, and wlog::warn().

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readRectilinearGrid()

std::shared_ptr< WGridRegular3D > WReaderVTK::readRectilinearGrid ( )
protected

Read VTK Domain specification and create a matching grid.

Returns
The constructed grid or an invalid pointer if any problem occurred.

Definition at line 289 of file WReaderVTK.cpp.

References getLine(), readCoords(), string_utils::tokenize(), string_utils::toLower(), and wlog::warn().

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readScalars()

std::shared_ptr< WValueSetBase > WReaderVTK::readScalars ( size_t  nbScalars,
const std::string &  name 
)
protected

Read VTK SCALARS field.

Postcondition
the data set pointer is set to the data set constructed of the current grid and the read scalar values
Parameters
nbScalarsthe number of scalars to read
namethe name of the data set that may be overwritten by information in the scalars line
Returns
The resulting value set.

Definition at line 368 of file WReaderVTK.cpp.

References getLine(), m_ifs, readValuesFromFile(), string_utils::tokenize(), and string_utils::toUpper().

Referenced by readData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readStructuredPoints()

std::shared_ptr< WGridRegular3D > WReaderVTK::readStructuredPoints ( )
protected

Read VTK Domain specification and create a matching grid.

Returns
The constructed grid or an invalid pointer if any problem occurred.

Definition at line 245 of file WReaderVTK.cpp.

References getLine(), string_utils::tokenize(), string_utils::toLower(), and WGridTransformOrthoTemplate< T >::translate().

Referenced by read().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readTensors()

std::shared_ptr< WValueSetBase > WReaderVTK::readTensors ( size_t  nbTensors,
const std::string &  name 
)
protected

Read VTK TENSORS field.

Postcondition
the data set pointer is set to the data set constructed of the current grid and the read tensor values
Parameters
nbTensorsthe number of tensors to read
namethe name of the data set that may be overwritten by information in the tensors line
Returns
The resulting value set.

Definition at line 418 of file WReaderVTK.cpp.

References ARRAYS, getLine(), m_attributeType, m_ifs, readValuesFromFile(), string_utils::tokenize(), and string_utils::toUpper().

Referenced by readData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readValuesFromFile()

void WReaderVTK::readValuesFromFile ( std::vector< float > &  values,
std::size_t  numValues 
)
private

Read values from the file.

The m_isASCII flag must be initialized accordingly.

Parameters
valuesThe values read from the file.
numValuesThe number of values to read.

Definition at line 328 of file WReaderVTK.cpp.

References wlog::debug(), getLine(), m_ifs, m_isASCII, and string_utils::tokenize().

Referenced by readCoords(), readHARDI(), readScalars(), readTensors(), and readVectors().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readVectors()

std::shared_ptr< WValueSetBase > WReaderVTK::readVectors ( size_t  nbVectors,
const std::string &  name 
)
protected

Read VTK SCALARS field.

Postcondition
the data set pointer is set to the data set constructed of the current grid and the read vector values
Parameters
nbVectorsthe number of vectors to read
namethe name of the data set that may be overwritten by information in the vectors line
Returns
The resulting value set.

Definition at line 388 of file WReaderVTK.cpp.

References getLine(), m_ifs, readValuesFromFile(), string_utils::tokenize(), and string_utils::toUpper().

Referenced by readData().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ WReaderVTKTest

friend class WReaderVTKTest
friend

allow member access by the test class

Definition at line 59 of file WReaderVTK.h.

Member Data Documentation

◆ m_attributeType

AttributeType WReaderVTK::m_attributeType
private

The type of the attributes first read from the file.

Definition at line 263 of file WReaderVTK.h.

Referenced by read(), readData(), and readTensors().

◆ m_domainType

DomainType WReaderVTK::m_domainType
private

The type of domain specified in the file.

Definition at line 260 of file WReaderVTK.h.

Referenced by read(), and readHeader().

◆ m_header

std::vector< std::string > WReaderVTK::m_header
protected

VTK header of the read file.

Definition at line 162 of file WReaderVTK.h.

Referenced by readHeader().

◆ m_ifs

std::shared_ptr< std::ifstream > WReaderVTK::m_ifs
protected

Pointer to the input file stream reader.

Definition at line 164 of file WReaderVTK.h.

Referenced by getLine(), read(), readHARDI(), readScalars(), readTensors(), readValuesFromFile(), and readVectors().

◆ m_isASCII

bool WReaderVTK::m_isASCII
private

internal flag whether we read ascii or binary

Definition at line 257 of file WReaderVTK.h.

Referenced by readHeader(), and readValuesFromFile().

◆ m_newDataSet

std::shared_ptr< WDataSet > WReaderVTK::m_newDataSet
private

reference to the currently loading data set

Definition at line 247 of file WReaderVTK.h.

◆ m_newGrid

std::shared_ptr< WGridRegular3D > WReaderVTK::m_newGrid
private

reference to the currently loading grid

Definition at line 252 of file WReaderVTK.h.


The documentation for this class was generated from the following files: