pslib
Class PSColourMap

java.lang.Object
  extended by pslib.PSColourMap

public class PSColourMap
extends java.lang.Object

PSColourMap Class

The PSColourMap object permits the generation of colour maps derived from either image scripts or stored values. Once generated, the resultant map may be output as a two-dimensional PSColour array, a WeightedList array. Individual layers may also be output as either a PSColour array or WeightedList.

This library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library. If not, see http://www.gnu.org/licenses/.


Constructor Summary
PSColourMap()
          Create a new object instance
 
Method Summary
 boolean generateFromScript(java.lang.String f)
          Generate the colour map from the specified script.
 int layers()
          Return the amount of layers within the stored map
 boolean read(java.lang.String f)
          Generate the colour map from the specified file
 void setMap(PSColour[][] m)
          Copy the values of the specified map into this object
 void setWeights(int[][] w)
          Set the weights for the stored colour map
 int size(int i)
          Return the size of the specified map layer
 PSColour[][] toArray()
          Return the map stored in this object as a two-dimensional PSColour array
 PSColour[] toArray(int i)
          Return the specified layer of the map stored in this object as a PSColour array
 WeightedList<PSColour>[] toWeightedList()
          Return the map stored in this object as a WeightedList array
 WeightedList<PSColour> toWeightedList(int i)
          Return the specified layer of the map stored in this object as a WeightedList object
 boolean write(java.lang.String f)
          Write the map stored in this object to file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PSColourMap

public PSColourMap()
Create a new object instance

Method Detail

generateFromScript

public final boolean generateFromScript(java.lang.String f)
Generate the colour map from the specified script.

Script lines should be in the format: layer#[index]=[file],[values]

Parameters:
f - script file
Returns:
true if the map was successfully generated

read

public final boolean read(java.lang.String f)
Generate the colour map from the specified file

File lines should be in the format: layer#[index]=[red],[green],[blue],[alpha] or weight#[index]=[v1],[v2], ... [vn]

Parameters:
f - colour map file
Returns:
true if the map was successfully generated

write

public final boolean write(java.lang.String f)
Write the map stored in this object to file

The output format of the file matches that of the input format specified by read().

Parameters:
f - file
Returns:
true if the map was successfully written

setMap

public final void setMap(PSColour[][] m)
Copy the values of the specified map into this object

The map stored within this object will be resized to match the input.

Parameters:
m - colour map

setWeights

public final void setWeights(int[][] w)
Set the weights for the stored colour map

The weight values are stored within the WeightedList output and dictate the likelihood of value selection.

If the specified array does not match the dimensions of the stored map, this will be reflected in the output file. Such invariances will however be corrected prior to WeightedList output.

Parameters:
w - weights

toArray

public final PSColour[][] toArray()
Return the map stored in this object as a two-dimensional PSColour array

If the map stored in this object is empty then a null value will be returned. If any layers within the map are empty or null then the returned array will contain null entries.

Returns:
the map stored in this object as a two-dimensional PSColour array

toArray

public final PSColour[] toArray(int i)
Return the specified layer of the map stored in this object as a PSColour array

If the map stored in this object is empty or the specified index is invalid then a null value will be returned.

Parameters:
i - layer index
Returns:
the specified layer of the map stored in this object as a PSColour array

toWeightedList

public final WeightedList<PSColour>[] toWeightedList()
Return the map stored in this object as a WeightedList array

The output WeightedList array stores all PSColour values alongside their respective weightings.

If the map stored in this object is empty then a null value will be returned. If any layers within the map are empty or null then the returned array will contain null entries.

Returns:
the map stored in this object as a WeightedList array

toWeightedList

public final WeightedList<PSColour> toWeightedList(int i)
Return the specified layer of the map stored in this object as a WeightedList object

The output WeightedList object stores all of the layer PSColour values alongside their respective weightings.

If the map stored in this object is empty or the specified index is invalid then a null value will be returned.

Parameters:
i - layer index
Returns:
the specified layer of the map stored in this object as a WeightedList object

layers

public final int layers()
Return the amount of layers within the stored map

A value of -1 will be returned if the stored map is empty

Returns:
the amount of layers within the stored map

size

public final int size(int i)
Return the size of the specified map layer

A value of -1 will be returned if the stored map is empty, the specified index is invalid, or the specified layer is empty.

Parameters:
i - layer index
Returns:
the size of the specified map layer