Class to hold values from image expression parser. More...
#include <ImageExprParse.h>
Public Member Functions | |
ImageExprParse (Bool value) | |
Construct a literal object for the given type. | |
ImageExprParse (Int value) | |
ImageExprParse (Float value) | |
ImageExprParse (Double value) | |
ImageExprParse (const Complex &value) | |
ImageExprParse (const DComplex &value) | |
ImageExprParse (const Char *value) | |
ImageExprParse (const String &value) | |
LatticeExprNode | makeFuncNode () const |
Make a LatticeExprNode for a function. | |
LatticeExprNode | makeFuncNode (const LatticeExprNode &arg1) const |
LatticeExprNode | makeFuncNode (const LatticeExprNode &arg1, const LatticeExprNode &arg2) const |
LatticeExprNode | makeFuncNode (const LatticeExprNode &arg1, const LatticeExprNode &arg2, const LatticeExprNode &arg3) const |
LatticeExprNode | makeLRNode () const |
Make a LatticeExprNode object for the lattice or region name. | |
LatticeExprNode | makeLitLRNode () const |
Make a LatticeExprNode object for the name of constant, lattice, or region. | |
LatticeExprNode | makeRegionNode () const |
Make a LatticeExprNode object for the temporary region number. | |
LatticeExprNode | makeLiteralNode () const |
Make a LatticeExprNode object for the literal value. | |
Static Public Member Functions | |
static LatticeExprNode | command (const String &str, const String &dirName=String()) |
Parse the given command. | |
static LatticeExprNode | command (const String &str, const Block< LatticeExprNode > &tempLattices, const PtrBlock< const ImageRegion * > &tempRegions, const String &dirName=String()) |
static Slice * | makeSlice (const ImageExprParse &start) |
Make a Slice object from 1-3 literals. | |
static Slice * | makeSlice (const ImageExprParse &start, const ImageExprParse &end) |
static Slice * | makeSlice (const ImageExprParse &start, const ImageExprParse &end, const ImageExprParse &incr) |
static LatticeExprNode | makeIndexinNode (const LatticeExprNode &axis, const vector< Slice > &slices) |
Make a node for the INDEXIN function. | |
static LatticeExprNode | makeValueList (const Block< LatticeExprNode > &values) |
Make an array from a value list. | |
static IPosition | makeBinning (const LatticeExprNode &values) |
Make an IPosition containing the binning values. | |
static const vector< String > & | getImageNames () |
Get the names of the images used in the expression. | |
static void | setNode (const LatticeExprNode &node) |
Set the static node object (used by the .y file). | |
static void | addNode (LatticeExprNode *node) |
Keep track of the nodes allocated while parsing the expression. | |
static void | addNode (ImageExprParse *node) |
static void | deleteNodes () |
static String | setAddDir (const String &dirName, const String &fileName) |
A function to test addDir. | |
Private Member Functions | |
Bool | tryLatticeNode (LatticeExprNode &node, const String &name) const |
Try if the name represent a lattice or image. | |
LatticeExprNode | makeImageNode (const String &name, const String &mask) const |
Make the node from the image name and a mask name. | |
Static Private Member Functions | |
static String | addDir (const String &fileName) |
If a directory was given, prepend it to the file name if relative. | |
static Table & | getRegionTable (void *, Bool) |
Callback function for RegionHandlerTable to get the table to be used. | |
static const CountedPtr < HDF5File > & | getRegionHDF5 (void *) |
Callback function for RegionHandlerHDF5 to get the file to be used. | |
Private Attributes | |
DataType | itsType |
Bool | itsBval |
Int | itsIval |
Float | itsFval |
Double | itsDval |
Complex | itsCval |
DComplex | itsDCval |
String | itsSval |
Static Private Attributes | |
static LatticeExprNode | theirNode |
static vector< String > | theirNames |
static Int | theirLevel |
Class to hold values from image expression parser.
Public interface
ImageExprParse is the class used to parse an image expression command.
ImageExprParse is used by the parser of image expression statements. The parser is written in Bison and Flex in files ImageExprGram.y and .l. The statements in there use the routines in this file to act upon a reduced rule.
The main function (and the only function to be used by a user) is the static function ImageExprParse::command which parses an expression command. It returns a LatticeExprNode object containing the expression represented as a tree. The object can be used as a Lattice(Expr)<T>
in other operations.
The syntax of the command is similar to that of expressions in C++. E.g.
The following items can be used in an expression:
image.data "~noordam/data/image.data" "~/image.data" "$HOME/image.data" $HOME\/image.data "ab'c"'d"e' results in ab'cd"e
$n
notation, where n
is the sequence number in the tempLattices
argument given to the command
function. Note that the sequence numbers start counting at 1 (to be compliant with glish indexing). When the expression is parsed, it is checked if the images and lattices involved have conforming shapes and coordinates. Note, however, that some functions (e.g. mean) reduce an image to a scalar. Such an image can have a different shape and coordinates.
The data types of the images and constants involved can be different. The data type of a subexpression is the common data type (e.g. Float and Double result in Double; Complex and Double result in DComplex). Automatic implicit conversions are done where needed. However, for performance reasons it may sometimes be better to convert explicitly. See below in the first example.
The expression evaluator (which is not part of the parser) evaluates the expression in chunks to avoid having to keep large temporary results. A scalar subexpression is evaluated only once to avoid unnecessary (possibly expensive) calculations.
Some examples:
img1 + min(float(pi()), mean(img2))
min(img1, (min(img1)+max(img1))/2)
LatticeExpr<Double> expr ("a + sin(b)");
ArrayLattice<Double> arr(expr.shape());
arr.copyData (expr);
Line 1 creates a LatticeExpr object for the given expression. Note that a
and b
are names of lattice files (e.g. PagedImage).
Line 2 creates an ArrayLattice with the same shape as the expression (which is the shape of lattice a (and b)).
Line 3 copies the result of the expression to the ArrayLattice.
It is necessary to be able to give an image expression command in ASCII. This can be used in glish to operate on lattices/images.
Definition at line 205 of file ImageExprParse.h.
casacore::ImageExprParse::ImageExprParse | ( | Bool | value | ) |
Construct a literal object for the given type.
casacore::ImageExprParse::ImageExprParse | ( | Int | value | ) |
casacore::ImageExprParse::ImageExprParse | ( | Float | value | ) |
casacore::ImageExprParse::ImageExprParse | ( | Double | value | ) |
casacore::ImageExprParse::ImageExprParse | ( | const Complex & | value | ) |
casacore::ImageExprParse::ImageExprParse | ( | const DComplex & | value | ) |
casacore::ImageExprParse::ImageExprParse | ( | const Char * | value | ) |
casacore::ImageExprParse::ImageExprParse | ( | const String & | value | ) |
If a directory was given, prepend it to the file name if relative.
static void casacore::ImageExprParse::addNode | ( | ImageExprParse * | node | ) | [static] |
static void casacore::ImageExprParse::addNode | ( | LatticeExprNode * | node | ) | [static] |
Keep track of the nodes allocated while parsing the expression.
static LatticeExprNode casacore::ImageExprParse::command | ( | const String & | str, | |
const Block< LatticeExprNode > & | tempLattices, | |||
const PtrBlock< const ImageRegion * > & | tempRegions, | |||
const String & | dirName = String() | |||
) | [static] |
static LatticeExprNode casacore::ImageExprParse::command | ( | const String & | str, | |
const String & | dirName = String() | |||
) | [static] |
Parse the given command.
It will open all lattices needed. It returns the resulting image expression.
The tempLattices/tempRegions
arguments make it possible to use temporary lattices/images and regions in the expression by means of the $n
notation.
If a directory name is given, it is used instead of the working directory for relative file names.
static void casacore::ImageExprParse::deleteNodes | ( | ) | [static] |
static const vector<String>& casacore::ImageExprParse::getImageNames | ( | ) | [inline, static] |
Get the names of the images used in the expression.
Definition at line 284 of file ImageExprParse.h.
References theirNames.
static const CountedPtr<HDF5File>& casacore::ImageExprParse::getRegionHDF5 | ( | void * | ) | [static, private] |
Callback function for RegionHandlerHDF5 to get the file to be used.
Callback function for RegionHandlerTable to get the table to be used.
static IPosition casacore::ImageExprParse::makeBinning | ( | const LatticeExprNode & | values | ) | [static] |
Make an IPosition containing the binning values.
LatticeExprNode casacore::ImageExprParse::makeFuncNode | ( | const LatticeExprNode & | arg1, | |
const LatticeExprNode & | arg2, | |||
const LatticeExprNode & | arg3 | |||
) | const |
LatticeExprNode casacore::ImageExprParse::makeFuncNode | ( | const LatticeExprNode & | arg1, | |
const LatticeExprNode & | arg2 | |||
) | const |
LatticeExprNode casacore::ImageExprParse::makeFuncNode | ( | const LatticeExprNode & | arg1 | ) | const |
LatticeExprNode casacore::ImageExprParse::makeFuncNode | ( | ) | const |
Make a LatticeExprNode for a function.
LatticeExprNode casacore::ImageExprParse::makeImageNode | ( | const String & | name, | |
const String & | mask | |||
) | const [private] |
Make the node from the image name and a mask name.
The mask name can be NOMASK (case insensitive) meaning that no mask is applied to the image.
static LatticeExprNode casacore::ImageExprParse::makeIndexinNode | ( | const LatticeExprNode & | axis, | |
const vector< Slice > & | slices | |||
) | [static] |
Make a node for the INDEXIN function.
LatticeExprNode casacore::ImageExprParse::makeLiteralNode | ( | ) | const |
Make a LatticeExprNode object for the literal value.
LatticeExprNode casacore::ImageExprParse::makeLitLRNode | ( | ) | const |
Make a LatticeExprNode object for the name of constant, lattice, or region.
LatticeExprNode casacore::ImageExprParse::makeLRNode | ( | ) | const |
Make a LatticeExprNode object for the lattice or region name.
LatticeExprNode casacore::ImageExprParse::makeRegionNode | ( | ) | const |
Make a LatticeExprNode object for the temporary region number.
static Slice* casacore::ImageExprParse::makeSlice | ( | const ImageExprParse & | start, | |
const ImageExprParse & | end, | |||
const ImageExprParse & | incr | |||
) | [static] |
static Slice* casacore::ImageExprParse::makeSlice | ( | const ImageExprParse & | start, | |
const ImageExprParse & | end | |||
) | [static] |
static Slice* casacore::ImageExprParse::makeSlice | ( | const ImageExprParse & | start | ) | [static] |
Make a Slice object from 1-3 literals.
static LatticeExprNode casacore::ImageExprParse::makeValueList | ( | const Block< LatticeExprNode > & | values | ) | [static] |
Make an array from a value list.
static String casacore::ImageExprParse::setAddDir | ( | const String & | dirName, | |
const String & | fileName | |||
) | [static] |
A function to test addDir.
It first sets the directory.
static void casacore::ImageExprParse::setNode | ( | const LatticeExprNode & | node | ) | [inline, static] |
Set the static node object (used by the .y file).
Definition at line 288 of file ImageExprParse.h.
References theirNode.
Bool casacore::ImageExprParse::tryLatticeNode | ( | LatticeExprNode & | node, | |
const String & | name | |||
) | const [private] |
Try if the name represent a lattice or image.
Return False if not.
Bool casacore::ImageExprParse::itsBval [private] |
Definition at line 330 of file ImageExprParse.h.
Complex casacore::ImageExprParse::itsCval [private] |
Definition at line 334 of file ImageExprParse.h.
DComplex casacore::ImageExprParse::itsDCval [private] |
Definition at line 335 of file ImageExprParse.h.
Double casacore::ImageExprParse::itsDval [private] |
Definition at line 333 of file ImageExprParse.h.
Float casacore::ImageExprParse::itsFval [private] |
Definition at line 332 of file ImageExprParse.h.
Int casacore::ImageExprParse::itsIval [private] |
Definition at line 331 of file ImageExprParse.h.
String casacore::ImageExprParse::itsSval [private] |
Definition at line 336 of file ImageExprParse.h.
DataType casacore::ImageExprParse::itsType [private] |
Definition at line 329 of file ImageExprParse.h.
Int casacore::ImageExprParse::theirLevel [static, private] |
Definition at line 327 of file ImageExprParse.h.
vector<String> casacore::ImageExprParse::theirNames [static, private] |
Definition at line 326 of file ImageExprParse.h.
Referenced by getImageNames().
LatticeExprNode casacore::ImageExprParse::theirNode [static, private] |
Definition at line 322 of file ImageExprParse.h.
Referenced by setNode().