ITK  6.0.0
Insight Toolkit
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
itk::CSVArray2DFileReader< TData > Class Template Reference

#include <itkCSVArray2DFileReader.h>

Detailed Description

template<typename TData>
class itk::CSVArray2DFileReader< TData >

Parses csv files and stores the data in a itkCSVArray2DDataObject.

CSVArray2DFileReader is used for reading csv files. This reader should only be used for parsing numeric data fields. The Parse() method in this class parses the data from the file into a itkCSVArray2DDataObject. As the Array2D object only holds one data type, all the data, other than the row and column headers, will be cast to a single data type. Row and column headers will be parsed into std vectors of strings.

The user would need to specify the file name using the SetFileName() method. The field delimiter character is set to ',' by default but other field delimiter characters may be set using SetFieldDelimiterCharacter(). If there are row and column headers in the file, the user must specify whether or not they exist using the HasRowHeaders and HasColumnHeaders flags. Also, if row and/or column headers are enclosed in "" or within other string delimiter characters being used, the user can set the option of turning the string delimiter character on with the UseStringDelimiterCharacter flag. This is also especially useful if headers such as "This,Header" contain commas or other field delimiter characters within them.

If the csv file has row and column headers, they do not necessarily need to be enclosed in "" or other string delimiter characters as long as you specify that row and/or column headers exist in the file. Turning on HasColumnHeaders flags will tell the reader that the first line contains column headers and turning on HasRowHeaders will tell the reader to recognize the first field in all subsequent lines as row headers. After all the inputs have been set, the user then calls the Parse() method. The user can then get the results by instantiating a itkCSVArray2DDataObject and assigning it using the GetOutput() method.

Below is an example of how this class can be used to read and parse the data from an input file:

using ReaderType = itk::CSVArray2DFileReader<double>; auto reader = ReaderType::New();

std::string filename = "NameOfFile.csv"; reader->SetFileName( filename ); reader->SetFieldDelimiterCharacter( ',' ); reader->SetStringDelimiterCharacter( '"' ); reader->HasColumnHeadersOn(); reader->HasRowHeadersOn(); reader->UseStringDelimiterCharacterOn();

reader->Parse();

Definition at line 79 of file itkCSVArray2DFileReader.h.

+ Inheritance diagram for itk::CSVArray2DFileReader< TData >:
+ Collaboration diagram for itk::CSVArray2DFileReader< TData >:

Public Types

using Array2DDataObjectPointer = typename Array2DDataObjectType::Pointer
 
using Array2DDataObjectType = typename itk::CSVArray2DDataObject< TData >
 
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = CSVArray2DFileReader
 
using Superclass = CSVFileReaderBase
 
using ValueType = TData
 
- Public Types inherited from itk::CSVFileReaderBase
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = CSVFileReaderBase
 
using Superclass = LightProcessObject
 
- Public Types inherited from itk::LightProcessObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightProcessObject
 
using Superclass = Object
 
- Public Types inherited from itk::Object
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = Object
 
using Superclass = LightObject
 
- Public Types inherited from itk::LightObject
using ConstPointer = SmartPointer< const Self >
 
using Pointer = SmartPointer< Self >
 
using Self = LightObject
 

Public Member Functions

virtual Array2DDataObjectTypeGetModifiableArray2DDataObject ()
 
const char * GetNameOfClass () const override
 
virtual Array2DDataObjectPointer GetOutput ()
 
void Parse () override
 
virtual void Update ()
 
- Public Member Functions inherited from itk::CSVFileReaderBase
void GetDataDimension (SizeValueType &rows, SizeValueType &cols)
 
virtual char GetFieldDelimiterCharacter ()
 
virtual bool GetHasColumnHeaders () const
 
virtual bool GetHasRowHeaders () const
 
const char * GetNameOfClass () const override
 
void GetNextField (std::string &)
 
virtual char GetStringDelimiterCharacter ()
 
virtual bool GetUseStringDelimiterCharacter () const
 
virtual void Parse ()=0
 
virtual void SetFieldDelimiterCharacter (char _arg)
 
virtual void SetFileName (const char *_arg)
 
virtual void SetHasColumnHeaders (bool _arg)
 
virtual void SetHasRowHeaders (bool _arg)
 
virtual void SetStringDelimiterCharacter (char _arg)
 
virtual void SetUseStringDelimiterCharacter (bool _arg)
 
virtual void HasRowHeadersOn ()
 
virtual void HasColumnHeadersOn ()
 
virtual void UseStringDelimiterCharacterOn ()
 
template<typename TData >
TData ConvertStringToValueType (const std::string str)
 
- Public Member Functions inherited from itk::LightProcessObject
virtual void AbortGenerateDataOn ()
 
virtual const bool & GetAbortGenerateData () const
 
const char * GetNameOfClass () const override
 
virtual void SetAbortGenerateData (bool _arg)
 
virtual void UpdateOutputData ()
 
void UpdateProgress (float amount)
 
virtual void SetProgress (float _arg)
 
virtual const float & GetProgress () const
 
- Public Member Functions inherited from itk::Object
unsigned long AddObserver (const EventObject &event, Command *cmd) const
 
unsigned long AddObserver (const EventObject &event, std::function< void(const EventObject &)> function) const
 
LightObject::Pointer CreateAnother () const override
 
virtual void DebugOff () const
 
virtual void DebugOn () const
 
CommandGetCommand (unsigned long tag)
 
bool GetDebug () const
 
MetaDataDictionaryGetMetaDataDictionary ()
 
const MetaDataDictionaryGetMetaDataDictionary () const
 
virtual ModifiedTimeType GetMTime () const
 
const char * GetNameOfClass () const override
 
virtual const TimeStampGetTimeStamp () const
 
bool HasObserver (const EventObject &event) const
 
void InvokeEvent (const EventObject &)
 
void InvokeEvent (const EventObject &) const
 
virtual void Modified () const
 
void Register () const override
 
void RemoveAllObservers ()
 
void RemoveObserver (unsigned long tag) const
 
void SetDebug (bool debugFlag) const
 
void SetReferenceCount (int) override
 
void UnRegister () const noexcept override
 
void SetMetaDataDictionary (const MetaDataDictionary &rhs)
 
void SetMetaDataDictionary (MetaDataDictionary &&rrhs)
 
virtual void SetObjectName (std::string _arg)
 
virtual const std::string & GetObjectName () const
 
- Public Member Functions inherited from itk::LightObject
Pointer Clone () const
 
virtual Pointer CreateAnother () const
 
virtual void Delete ()
 
virtual const char * GetNameOfClass () const
 
virtual int GetReferenceCount () const
 
void Print (std::ostream &os, Indent indent=0) const
 
virtual void Register () const
 
virtual void SetReferenceCount (int)
 
virtual void UnRegister () const noexcept
 

Static Public Member Functions

static Pointer New ()
 
- Static Public Member Functions inherited from itk::LightProcessObject
static Pointer New ()
 
- Static Public Member Functions inherited from itk::Object
static bool GetGlobalWarningDisplay ()
 
static void GlobalWarningDisplayOff ()
 
static void GlobalWarningDisplayOn ()
 
static Pointer New ()
 
static void SetGlobalWarningDisplay (bool val)
 
- Static Public Member Functions inherited from itk::LightObject
static void BreakOnError ()
 
static Pointer New ()
 

Protected Member Functions

 CSVArray2DFileReader ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~CSVArray2DFileReader () override=default
 
- Protected Member Functions inherited from itk::CSVFileReaderBase
 CSVFileReaderBase ()
 
void PrepareForParsing ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~CSVFileReaderBase () override=default
 
- Protected Member Functions inherited from itk::LightProcessObject
virtual void GenerateData ()
 
 LightProcessObject ()
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
 ~LightProcessObject () override
 
- Protected Member Functions inherited from itk::Object
 Object ()
 
bool PrintObservers (std::ostream &os, Indent indent) const
 
void PrintSelf (std::ostream &os, Indent indent) const override
 
virtual void SetTimeStamp (const TimeStamp &timeStamp)
 
 ~Object () override
 
- Protected Member Functions inherited from itk::LightObject
virtual LightObject::Pointer InternalClone () const
 
 LightObject ()
 
virtual void PrintHeader (std::ostream &os, Indent indent) const
 
virtual void PrintSelf (std::ostream &os, Indent indent) const
 
virtual void PrintTrailer (std::ostream &os, Indent indent) const
 
virtual ~LightObject ()
 

Private Attributes

Array2DDataObjectPointer m_Array2DDataObject {}
 

Additional Inherited Members

- Protected Attributes inherited from itk::CSVFileReaderBase
int m_EndOfColumnHeadersLine {}
 
char m_FieldDelimiterCharacter {}
 
std::string m_FileName {}
 
bool m_HasColumnHeaders {}
 
bool m_HasRowHeaders {}
 
std::ifstream m_InputStream {}
 
std::string m_Line {}
 
char m_StringDelimiterCharacter {}
 
bool m_UseStringDelimiterCharacter {}
 
- Protected Attributes inherited from itk::LightObject
std::atomic< int > m_ReferenceCount {}
 

Member Typedef Documentation

◆ Array2DDataObjectPointer

template<typename TData >
using itk::CSVArray2DFileReader< TData >::Array2DDataObjectPointer = typename Array2DDataObjectType::Pointer

Definition at line 99 of file itkCSVArray2DFileReader.h.

◆ Array2DDataObjectType

template<typename TData >
using itk::CSVArray2DFileReader< TData >::Array2DDataObjectType = typename itk::CSVArray2DDataObject<TData>

DataFrame Object types

Definition at line 98 of file itkCSVArray2DFileReader.h.

◆ ConstPointer

template<typename TData >
using itk::CSVArray2DFileReader< TData >::ConstPointer = SmartPointer<const Self>

Definition at line 89 of file itkCSVArray2DFileReader.h.

◆ Pointer

template<typename TData >
using itk::CSVArray2DFileReader< TData >::Pointer = SmartPointer<Self>

Definition at line 88 of file itkCSVArray2DFileReader.h.

◆ Self

template<typename TData >
using itk::CSVArray2DFileReader< TData >::Self = CSVArray2DFileReader

Standard class type aliases

Definition at line 86 of file itkCSVArray2DFileReader.h.

◆ Superclass

template<typename TData >
using itk::CSVArray2DFileReader< TData >::Superclass = CSVFileReaderBase

Definition at line 87 of file itkCSVArray2DFileReader.h.

◆ ValueType

template<typename TData >
using itk::CSVArray2DFileReader< TData >::ValueType = TData

The value type of the dataset.

Definition at line 102 of file itkCSVArray2DFileReader.h.

Constructor & Destructor Documentation

◆ CSVArray2DFileReader()

template<typename TData >
itk::CSVArray2DFileReader< TData >::CSVArray2DFileReader ( )
protected

◆ ~CSVArray2DFileReader()

template<typename TData >
itk::CSVArray2DFileReader< TData >::~CSVArray2DFileReader ( )
overrideprotecteddefault

Member Function Documentation

◆ GetModifiableArray2DDataObject()

template<typename TData >
virtual Array2DDataObjectType * itk::CSVArray2DFileReader< TData >::GetModifiableArray2DDataObject ( )
virtual

This method can be used to get the data frame object once the data from the file has been parsed.

◆ GetNameOfClass()

template<typename TData >
const char * itk::CSVArray2DFileReader< TData >::GetNameOfClass ( ) const
overridevirtual

◆ GetOutput()

template<typename TData >
virtual Array2DDataObjectPointer itk::CSVArray2DFileReader< TData >::GetOutput ( )
virtual

Aliased to the GetDataFrameObject() method to be consistent with the rest of the pipeline

◆ New()

template<typename TData >
static Pointer itk::CSVArray2DFileReader< TData >::New ( )
static

Standard New method.

◆ Parse()

template<typename TData >
void itk::CSVArray2DFileReader< TData >::Parse ( )
overridevirtual

Parses the data from the file. Gets all the fields and parses row and column headers, if any, into std::vectors of strings and parses the numeric data into an Array2D object. The vectors and the Array2D object are part of the Array2DDataFrameobject.

Implements itk::CSVFileReaderBase.

◆ PrintSelf()

template<typename TData >
void itk::CSVArray2DFileReader< TData >::PrintSelf ( std::ostream &  os,
Indent  indent 
) const
overrideprotectedvirtual

Print the reader.

Reimplemented from itk::LightProcessObject.

◆ Update()

template<typename TData >
virtual void itk::CSVArray2DFileReader< TData >::Update ( )
virtual

Aliased to the Parse() method to be consistent with the rest of the pipeline.

Member Data Documentation

◆ m_Array2DDataObject

template<typename TData >
Array2DDataObjectPointer itk::CSVArray2DFileReader< TData >::m_Array2DDataObject {}
private

Definition at line 134 of file itkCSVArray2DFileReader.h.


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