TrajectoryReader module
Module contents
-
template<typename TrajectoryT>
class TrajectoryReader : public tracktable::GenericReader<TrajectoryT> Read trajectories from files.
This reader wraps the following pipeline:
Read lines from a text file
Skip any lines that begin with a designated comment character (‘#’ by default)
Tokenize each line using specified delimiters (whitespace by default)
Create a trajectory (user-specified type) from each tokenized line
Return the resulting points via a C++ iterator
You will use set_input() to supply an input stream, set_comment_character() to configure which lines to skip, set_field_delimiter() to specify how to turn lines into fields.
Public Functions
-
inline TrajectoryReader()
Instantiate TrajectoryReader using a default configuration
Default reader configuration
If you are reading BasePoints, this sets coordinates 0 to d-1 (D is the point’s dimension) using columns 0 to d-1.
If you are reading TrajectoryPoints, column 0 is the object ID, column 1 is the timestamp, and columns 2 through D+1 (inclusive) are the coordinates.
These are the default settings. You can override any or all of them after you instantiate the reader.
-
inline TrajectoryReader(std::istream &infile)
Instantiate a TrajectoryReader using a
std::istreamand default configurationDefault reader configuration
If you are reading BasePoints, this sets coordinates 0 to d-1 (D is the point’s dimension) using columns 0 to d-1.
If you are reading TrajectoryPoints, column 0 is the object ID, column 1 is the timestamp, and columns 2 through D+1 (inclusive) are the coordinates.
These are the default settings. You can override any or all of them after you instantiate the reader.
- Parameters:
infile – [in] Stream to read input from
-
inline TrajectoryReader(TrajectoryReader const &other)
Copy contructor, create a reader with a copy of another
- Parameters:
other – [in] TrajectoryReader to copy from
-
inline virtual ~TrajectoryReader()
Destructor.
-
inline TrajectoryReader &operator=(TrajectoryReader const &other)
Assign a TrajectoryReader to the value of another.
- Parameters:
other – [in] TrajectoryReader to assign value of
- Returns:
Reader with the new assigned value
-
inline bool operator==(TrajectoryReader const &other) const
Check whether one reader is equal to another by comparing all the properties.
Two readers are equal if all of their properties are equal.
- Parameters:
other – [in] TrajectoryReader for comparison
- Returns:
Boolean indicating equivalency
-
inline bool operator!=(TrajectoryReader const &other) const
Check whether two TrajectoryReaders are unequal.
- Parameters:
other – [in] TrajectoryReader for comparison
- Returns:
Boolean indicating equivalency
-
inline void set_default_configuration()
Default reader configuration
If you are reading BasePoints, this sets coordinates 0 to d-1 (D is the point’s dimension) using columns 0 to d-1.
If you are reading TrajectoryPoints, column 0 is the object ID, column 1 is the timestamp, and columns 2 through D+1 (inclusive) are the coordinates.
These are the default settings. You can override any or all of them after you instantiate the reader.
-
inline void set_comment_character(string_type const &comment)
Specify comment character for skipping lines
A line is a comment if and only if its first non-whitespace character is the comment character (‘#’ by default). We will skip such lines entirely. We do not handle inline or trailing comments: a line will either be included in its entirety or skipped completely.
- Parameters:
comment – [in] Single character
-
inline string_type comment_character() const
Retrieve current value of comment character.
This function invalidates any outstanding iterators.
- Returns:
Current value of comment character
-
inline void set_null_value(string_type const &_null_value)
Specify string value to be interpreted as null
- Parameters:
_null_value – [in] String to interpret as null
-
inline string_type null_value() const
Get string value for nulls
- Returns:
Current string that will be interpreted as null
-
inline void set_input(std::istream &_input)
Supply input stream from delimited text source.
We read our input from C++ std::istreams. The stream you supply will be traversed exactly once.
- Parameters:
_input – [in] Stream from which we will read points
-
inline std::istream &input() const
Retrieve the current input stream.
- Bug:
We currently have no way to indicate whether the stream is valid.
- Returns:
Stream being used for input.
-
inline void set_warnings_enabled(bool onoff)
Enable/disable warnings during parsing.
We may run into type mismatches and bad casts while we’re parsing headers and data. This flag determines whether or not warnings will be printed.
- Parameters:
onoff – [in] Warnings are on / off
-
inline bool warnings_enabled() const
Check whether warnings are enable
- Returns:
Whether or not warnings are on
-
inline void set_field_delimiter(string_type const &delimiters)
Set one or more characters as field delimiters.
Each character in the argument to this function will be treated as a potential field delimiter. If you supply
",|"as your delimiter then both the comma and the exclamation point will be used to tokenize field.This function invalidates any outstanding iterators.
- Parameters:
delimiters – [in] String containing all desired delimiter characters
-
inline string_type field_delimiter() const
Retrieve the current set of delimiter characters.
- Returns:
String containing all delimiters
-
inline void set_timestamp_format(string_type const &format)
Set the format of the timestamp
- Parameters:
format – [in] String containing the format of the time stamp
-
inline string_type timestamp_format() const
Retrieve the format of the timestamp
- Returns:
The timestamp format
Private Types
-
typedef TrajectoryT trajectory_type
-
typedef trajectory_type::point_type point_type
-
typedef tracktable::LineReader line_reader_type
-
typedef tracktable::SkipCommentsReader<line_reader_type::iterator> skip_comments_reader_type
-
typedef tracktable::StringTokenizingReader<skip_comments_reader_type::iterator> string_tokenizer_type
-
typedef string_vector_type::const_iterator token_iter_type
-
typedef std::pair<token_iter_type, token_iter_type> token_range_type
-
typedef std::vector<token_range_type> token_range_vector_type
-
typedef PointFromTokensReader<point_type, token_range_vector_type::iterator> point_reader_type
Private Functions
-
inline virtual trajectory_shared_ptr_type next_item()
Increment the iterator the next item to be read in
- Returns:
The next item
-
inline trajectory_shared_ptr_type parse_trajectory(string_vector_type const &tokens)
Parse the read in trajectory
- Parameters:
tokens – Tokens that are read in and parsed
Populate the trajectorie’s points
- Parameters:
token_begin – [in] Start of tokens read in
token_end – [in] End of tokens read in
num_points – [in] Num of points expected to be in trajectory
trajectory – [in] Trajectory to populate
Populate the trajectories points from token ranges
- Parameters:
input_range_begin – [in] Start of range to read in
input_range_end – [in] End of range to read in
trajectory – [in] Trajectory to populate
Private Members
-
line_reader_type LineReader
-
point_reader_type PointReader
-
skip_comments_reader_type SkipCommentsReader
-
string_tokenizer_type StringTokenizer
-
string_type TimestampFormat
-
string_tokenizer_type::iterator TokenizedInputBegin
-
string_tokenizer_type::iterator TokenizedInputEnd
-
bool WarningsEnabled
-
int TrajectoriesRead
-
rw::detail::TrajectoryHeader ParseTrajectoryHeader