[next] [prev] [prev-tail] [tail] [up]

### 1.4 The VMask class

The VMask class is an abstraction over the VIPS DOUBLEMASK and INTMASK types which gives convenient and safe representation of matricies.

VMask has two sub-classes, VIMask and VDMask. These represent matricies of integers and doubles respectively.

#### 1.4.1 Constructors

There are three constructors for VIMask and VDMask:

VIMask( int xsize, int ysize ); VIMask( int xsize, int ysize, int scale, int offset, ... ); VIMask( const char ⋆name ); VIMask(); VDMask( int xsize, int ysize ); VDMask( int xsize, int ysize, double scale, double offset, ... ); VDMask( const char ⋆name ); VDMask();

The first form creates an empty matrix, with the specified dimensions; the second form initialises a matrix from a varargs list; the third form reads the matrix from the named file. The final form makes a mask object with no contents yet.

#### 1.4.2 Projection functions

A set of member functions of VIMask provide access to the fields in the matrix:

int xsize() const; int ysize() const; int scale() const; int offset() const; const char ⋆filename() const;

VDMask is the same, except that the scale() and offset() members return double. VMask allows all operations that are common to VIMask and VDMask.

#### 1.4.3 Assignment

VMask defines copy and assignment with pointer-style semantics. You can write stuff like:

VIMask fred( "mask" ); VMask jim; jim = fred;

This reads the file mask, noting a pointer to the mask in fred. It then makes jim also point to it, so jim and fred are sharing the same underlying matrix values.

Internally, a VMask object is just a pointer to a reference-counting block, which in turn holds a pointer to the underlying VIPS MASK type. You can therefore efficiently pass VMask objects to functions by value, and return VMask objects as function results.

#### 1.4.4 Computing with VMask

You can use [] to get at matrix elements, numbered left-to-right, top-to-bottom. Alternatively, use () to address elements by x,y position. For example:

VIMask fred( "mask" ); for( int i = 0; i < fred.xsize(); i++ ) fred[i] = 12;

will set the first line of the matrix to 12, and:

VDMask fred( "mask" ); for( int x = 0; x < fred.xsize(); x++ ) fred(x, x) = 12.0;

will set the leading diagonal to 12.

See the member functions below for other operations on VMask.

#### 1.4.5 VIMask operations

The following operations are defined for VIMask:

// Cast to VDMask and VImage operator VDMask(); operator VImage(); // Build gaussian and log masks static VIMask gauss( double, double ); static VIMask log( double, double ); // Rotate VIMask rotate45(); VIMask rotate90(); // Transpose, invert, join and multiply VDMask trn() ; VDMask inv(); VDMask cat( VDMask ); VDMask mul( VDMask );

#### 1.4.6 VDMask operations

The following operations are defined for VDMask:

// Cast to VIMask and VImage operator VIMask(); operator VImage(); // Build gauss and log masks static VDMask gauss( double, double ); static VDMask log( double, double ); // Rotate VDMask rotate45(); VDMask rotate90(); // Scale to intmask VIMask scalei(); // Transpose, invert, join and multiply VDMask trn(); VDMask inv(); VDMask cat( VDMask ); VDMask mul( VDMask );

#### 1.4.7 Output of masks

You can output masks with the usual << operator.

[next] [prev] [prev-tail] [front] [up]