cz.cuni.jagrlib.piece
Class DataMatrix

java.lang.Object
  extended by cz.cuni.jagrlib.DefaultProperty
      extended by cz.cuni.jagrlib.Piece
          extended by cz.cuni.jagrlib.piece.DataMatrix
All Implemented Interfaces:
Breakable, Property, SampleData, Template

public class DataMatrix
extends Piece
implements SampleData

Module holding N-dimensional data matrix.

Since:
0.24
See Also:
DataMatrix.java

Field Summary
protected  int[] accel
          Accelerators: submatrix sizes (accel[i] = Prod_{j=i..N} dim[j]).
protected static java.lang.String CATEGORY
          Object category.
protected  byte[] dataByte
          The data array itself (byte format).
protected  double[] dataDouble
          The data array itself (byte format).
protected  float[] dataFloat
          The data array itself (byte format).
protected  int[] dataInt
          The data array itself (byte format).
protected  long[] dataLong
          The data array itself (byte format).
protected  short[] dataShort
          The data array itself (byte format).
protected  int[] dim
          Actual dimension sizes (dim.length == dims).
protected  int dims
          Actual number of sample-array dimensions.
protected  double[] geometry
          Sample-array geometry (1 double for one dimension = uniform distance between samples).
protected  java.lang.Object map
          Data mapping (used together with integer data matrix).
static RegPiece reg
          Static registration instance for this class.
protected  int sampleType
          Actual sample type.
protected static java.lang.String TEMPLATE_NAME
          Object template identifier.
protected  int totalSize
          Total 1D packed array size (equal to accel[0]).
 
Fields inherited from class cz.cuni.jagrlib.Piece
channels, info, pl, plugs, TEMPLATE_TYPE, userBreak
 
Fields inherited from interface cz.cuni.jagrlib.iface.SampleData
FREQUENCY, SAMPLE_BYTE, SAMPLE_COMPLEX, SAMPLE_DOUBLE, SAMPLE_FLOAT, SAMPLE_INT, SAMPLE_LONG, SAMPLE_RGBA, SAMPLE_SHORT, SAMPLE_TYPE
 
Fields inherited from interface cz.cuni.jagrlib.iface.Property
LOGGING, STATISTICS, TEXT_DESCRIPTION
 
Fields inherited from interface cz.cuni.jagrlib.Template
ALL_PLUGS, C_1D, C_2D, C_3D, C_ALPHA, C_BINARY, C_BREP, C_CAMERA, C_CIRCLE, C_CLIP, C_COMPRESSION, C_CURVE, C_DATA, C_DRAW, C_EDITOR, C_ELLIPSE, C_FILL, C_FILTER, C_FLOAT, C_FUNCTION, C_IMAGE, C_INTEGER, C_IO, C_LIGHT, C_LINE, C_METRIC, C_POLYGON, C_PROJECTION, C_RADIOSITY, C_RASTER, C_RENDER, C_SAMPLE, C_SCENE, C_SET, C_SOLID, C_TEXT, C_TRANSFORM, C_VECTOR, C_VIEWER, C_WORKER, CAT_EMPTY, EMPTY, IFACE, JAGRLIB, JAGRLIB2, MANIPULATOR_COMBO, MANIPULATOR_CUSTOM, MANIPULATOR_DEFAULT, MANIPULATOR_MULTILINE, PL_ALPHAMASK, PL_BITMASK, PL_CAUSTIC, PL_CODEC, PL_COLORMAP, PL_COMPARE, PL_DATA, PL_DIRECT, PL_EDITOR, PL_FILTER, PL_FUNCTION, PL_IMAGE, PL_IMPORT, PL_INPUT, PL_INTERSECTION, PL_LIGHTSOURCE, PL_ORDER, PL_OUTPUT, PL_PALETTE, PL_PHOTON, PL_PROPERTY, PL_QUANTIZER, PL_RASTER, PL_RENDER, PL_SHADOW, PL_STREAM, PL_TRANSFORM, PL_TRIGGER, PL_VOLUME, PL_WINDOW, TYPE_BOOLEAN, TYPE_DOUBLE, TYPE_FLOAT, TYPE_INTEGER, TYPE_LONG, TYPE_OBJECT, TYPE_STRING
 
Constructor Summary
DataMatrix()
           
 
Method Summary
protected  int countIndex(int[] ind)
          Computes item index of ind[0] .. ind[dims-2] (w/o the last - fastest - index).
protected  java.lang.Object dataArray()
          Returns internal packed 1D array of the apropriate type.
 java.lang.Object get(java.lang.String key)
          Gets the given property.
protected  java.lang.Class<?> getComponentClass(java.lang.Object array)
          Determines array's component type (returns null if there is a problem).
 java.lang.Object getDataArray(int[] dim)
          Returns the original data array.
 int getDataDim(int[] dim)
          Returns actual array dimensions.
 void getSampleGeometry(double[] geom)
          Gets the sample geometry (in regular sample matrix).
 java.lang.Object getSampleMapping(java.lang.Object map, int srcFrom, int srcTo, int[] bounds)
          Retrieves the whole sample mapping (for mapped arrays only).
 int getSamples(int[] from, int[] to, double[] data)
          Reads the given sample segment (float formats: float, double, complex).
 int getSamples(int[] from, int[] to, int[] data)
          Reads the given sample segment (integer formats: byte, short, int, RGBA).
 int getSamples(int[] from, int[] to, long[] data)
          Reads the given sample segment (long format).
 int getSamplesGeneral(int[] from, int[] to, java.lang.Object data)
          Reads the given sample segment (general data format).
 int getSampleType()
          Returns actual sample type (SAMPLE_* constant).
 void resetData(int type, boolean mapped, int[] dim)
          (Re-)initialize the data array.
 void set(java.lang.String key, java.lang.Object value)
          Sets the given property.
 void setDataArray(java.lang.Object data, int srcFrom, int[] dstFrom, int[] dstTo)
          Sets data array in the raw (internal) format.
 void setSampleGeometry(double[] geom)
          Sets the sample geometry (in regular sample matrix).
 void setSampleMapping(java.lang.Object map, int srcFrom, int srcTo, int dstFrom)
          Sets (partially) the new sample mapping (for mapped arrays only).
 void setSamples(int[] from, int[] to, double[] data)
          Writes the given sample segment (float formats: float, double, complex).
 void setSamples(int[] from, int[] to, int[] data)
          Writes the given sample segment (integer formats: byte, short, int, RGBA).
 void setSamples(int[] from, int[] to, long[] data)
          Writes the given sample segment (long format).
 void setSamplesGeneral(int[] from, int[] to, java.lang.Object data)
          Writes the given sample segment (general data format).
static int setTemplate(Template t, int ord)
          General-purpose registration routine.
 
Methods inherited from class cz.cuni.jagrlib.Piece
className, connect, findPlug, findPlug, getInfo, getInterface, getInterface, getPlug, getReg, init, isCompatible, isCompatible, isConnected, logError, logWarning, myInterface, newInputPlug, newOptOutputPlug, newOutputPlug, newPlug, noTemplates, propBegin, propBounds, propDefault, propEnd, propEnum, propManipulator, propManipulator, setProgressListener, setRegStrings, setTemplateDynamic, stop
 
Methods inherited from class cz.cuni.jagrlib.DefaultProperty
booleanProperty, booleanProperty, colorDoubleProperty, colorProperty, commit, doubleProperty, doubleProperty, doubleProperty, enumProperty, floatProperty, floatProperty, floatProperty, intProperty, intProperty, intProperty, longProperty, longProperty, longProperty, set, stringProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface cz.cuni.jagrlib.iface.Property
commit
 

Field Detail

dims

protected int dims
Actual number of sample-array dimensions.


dim

protected int[] dim
Actual dimension sizes (dim.length == dims).


accel

protected int[] accel
Accelerators: submatrix sizes (accel[i] = Prod_{j=i..N} dim[j]).


totalSize

protected int totalSize
Total 1D packed array size (equal to accel[0]).


sampleType

protected int sampleType
Actual sample type. If map != null, the actual data array has to be SampleData.SAMPLE_INT.


geometry

protected double[] geometry
Sample-array geometry (1 double for one dimension = uniform distance between samples).


dataByte

protected byte[] dataByte
The data array itself (byte format).


dataShort

protected short[] dataShort
The data array itself (byte format).


dataInt

protected int[] dataInt
The data array itself (byte format).


dataLong

protected long[] dataLong
The data array itself (byte format).


dataFloat

protected float[] dataFloat
The data array itself (byte format).


dataDouble

protected double[] dataDouble
The data array itself (byte format).


map

protected java.lang.Object map
Data mapping (used together with integer data matrix).


TEMPLATE_NAME

protected static final java.lang.String TEMPLATE_NAME
Object template identifier.

See Also:
Constant Field Values

CATEGORY

protected static final java.lang.String CATEGORY
Object category.

See Also:
Constant Field Values

reg

public static final RegPiece reg
Static registration instance for this class. Automatically initialized in class-loading time.

Constructor Detail

DataMatrix

public DataMatrix()
Method Detail

dataArray

protected java.lang.Object dataArray()
Returns internal packed 1D array of the apropriate type.


getComponentClass

protected java.lang.Class<?> getComponentClass(java.lang.Object array)
Determines array's component type (returns null if there is a problem).


countIndex

protected final int countIndex(int[] ind)
Computes item index of ind[0] .. ind[dims-2] (w/o the last - fastest - index).


resetData

public void resetData(int type,
                      boolean mapped,
                      int[] dim)
(Re-)initialize the data array.

Specified by:
resetData in interface SampleData
Parameters:
type - Sample type (one of SAMPLE_* constants).
mapped - Should the array contain mapped values?
dim - Dimensions of an array.
See Also:
SampleData.SAMPLE_BYTE, SampleData.SAMPLE_SHORT, SampleData.SAMPLE_INT, SampleData.SAMPLE_LONG, SampleData.SAMPLE_FLOAT, SampleData.SAMPLE_DOUBLE, SampleData.SAMPLE_COMPLEX, SampleData.SAMPLE_RGBA

getSampleType

public int getSampleType()
Returns actual sample type (SAMPLE_* constant).

Specified by:
getSampleType in interface SampleData
Returns:
Sample type (SAMPLE_* constant).
See Also:
getDataDim(int[]), SampleData.SAMPLE_BYTE, SampleData.SAMPLE_SHORT, SampleData.SAMPLE_INT, SampleData.SAMPLE_LONG, SampleData.SAMPLE_FLOAT, SampleData.SAMPLE_DOUBLE, SampleData.SAMPLE_COMPLEX, SampleData.SAMPLE_RGBA

getDataDim

public int getDataDim(int[] dim)
Returns actual array dimensions.

Specified by:
getDataDim in interface SampleData
Parameters:
dim - Pre-allocated array to hold individual dimensions' sizes.
Returns:
Dimensionality (number of dimensions).
See Also:
getSampleType()

setSampleGeometry

public void setSampleGeometry(double[] geom)
Sets the sample geometry (in regular sample matrix).

Specified by:
setSampleGeometry in interface SampleData
Parameters:
geom - Sample periods for all dimensions.
See Also:
getSampleGeometry(double[])

getSampleGeometry

public void getSampleGeometry(double[] geom)
Gets the sample geometry (in regular sample matrix).

Specified by:
getSampleGeometry in interface SampleData
Parameters:
geom - Sample periods for all dimensions.
See Also:
setSampleGeometry(double[])

setSampleMapping

public void setSampleMapping(java.lang.Object map,
                             int srcFrom,
                             int srcTo,
                             int dstFrom)
Sets (partially) the new sample mapping (for mapped arrays only).

Specified by:
setSampleMapping in interface SampleData
Parameters:
map - Mapping array to be set (should be an array of the apropriate type).
srcFrom - First source index (map[from]).
srcTo - After the last source index.
dstFrom - First destination index.
See Also:
getSampleMapping(java.lang.Object, int, int, int[])

getSampleMapping

public java.lang.Object getSampleMapping(java.lang.Object map,
                                         int srcFrom,
                                         int srcTo,
                                         int[] bounds)
Retrieves the whole sample mapping (for mapped arrays only).

Specified by:
getSampleMapping in interface SampleData
Parameters:
map - Optional pre-allocated mapping array to be filled.
srcFrom - First index to be retrieved.
srcTo - After the last index to be retrieved.
bounds - Retrieved index bounds (bounds[0] = the 1st mapped value written in map[0], bounds[1] = index after the last value).
See Also:
setSampleMapping(java.lang.Object, int, int, int)

getDataArray

public java.lang.Object getDataArray(int[] dim)
Returns the original data array.

Specified by:
getDataArray in interface SampleData
Parameters:
dim - Returned dimensionality (array of individual dimension sizes). Can be null.
Returns:
Packed 1D sample array (read / write access) or null if the service is not available.
See Also:
setDataArray(java.lang.Object, int, int[], int[])

setDataArray

public void setDataArray(java.lang.Object data,
                         int srcFrom,
                         int[] dstFrom,
                         int[] dstTo)
Sets data array in the raw (internal) format. Can be used for data fragment or for the whole data array.

Specified by:
setDataArray in interface SampleData
Parameters:
data - Packed 1D source data array (of apropriate type - integer has to be used for mapped types).
srcFrom - Source index to begin from.
dstFrom - Start of the region to be set. Can be null (instead of [0,0,0,..]).
dstTo - End of the region to be set. Can be null (instead of dim).

getSamplesGeneral

public int getSamplesGeneral(int[] from,
                             int[] to,
                             java.lang.Object data)
Reads the given sample segment (general data format).

Specified by:
getSamplesGeneral in interface SampleData
Parameters:
from - Starting index.
to - Index after retrieved data.
data - Pre-allocated array to hold the result (packed 1D array).
Returns:
Number of returned samples.

setSamplesGeneral

public void setSamplesGeneral(int[] from,
                              int[] to,
                              java.lang.Object data)
Writes the given sample segment (general data format).

Specified by:
setSamplesGeneral in interface SampleData
Parameters:
from - Starting index.
to - Index after the written data.
data - Data to be written - in 1D array (integer indices for mapped data arrays).

getSamples

public int getSamples(int[] from,
                      int[] to,
                      int[] data)
Reads the given sample segment (integer formats: byte, short, int, RGBA).

Specified by:
getSamples in interface SampleData
Parameters:
from - Starting index.
to - Index after retrieved data.
data - Pre-allocated array to hold the result.
Returns:
Number of returned samples.

getSamples

public int getSamples(int[] from,
                      int[] to,
                      long[] data)
Reads the given sample segment (long format).

Specified by:
getSamples in interface SampleData
Parameters:
from - Starting index.
to - Index after retrieved data.
data - Pre-allocated array to hold the result.
Returns:
Number of returned samples.

getSamples

public int getSamples(int[] from,
                      int[] to,
                      double[] data)
Reads the given sample segment (float formats: float, double, complex).

Specified by:
getSamples in interface SampleData
Parameters:
from - Starting index.
to - Index after retrieved data.
data - Pre-allocated array to hold the result (complex uses double-sized array).
Returns:
Number of returned samples.

setSamples

public void setSamples(int[] from,
                       int[] to,
                       int[] data)
Writes the given sample segment (integer formats: byte, short, int, RGBA).

Specified by:
setSamples in interface SampleData
Parameters:
from - Starting index.
to - Index after written data.
data - Data to be written (1D array).

setSamples

public void setSamples(int[] from,
                       int[] to,
                       long[] data)
Writes the given sample segment (long format).

Specified by:
setSamples in interface SampleData
Parameters:
from - Starting index.
to - Index after written data.
data - Data to be written (1D array).

setSamples

public void setSamples(int[] from,
                       int[] to,
                       double[] data)
Writes the given sample segment (float formats: float, double, complex).

Specified by:
setSamples in interface SampleData
Parameters:
from - Starting index.
to - Index after written data.
data - Data to be written (1D array). Complex uses double-sized array.

set

public void set(java.lang.String key,
                java.lang.Object value)
Sets the given property.

Specified by:
set in interface Property
Overrides:
set in class DefaultProperty
Parameters:
key - Key string.
value - The new value.
See Also:
Property.commit()

get

public java.lang.Object get(java.lang.String key)
Gets the given property.

Specified by:
get in interface Property
Overrides:
get in class DefaultProperty
Parameters:
key - Key string.
Returns:
The actual value or null.

setTemplate

public static int setTemplate(Template t,
                              int ord)
General-purpose registration routine. Sets all plugs, strings, etc. to the given Template.