Class WindowedColourModel
- All Implemented Interfaces:
java.awt.Transparency
,java.lang.Cloneable
,XMLObject
public class WindowedColourModel extends java.awt.image.ColorModel implements java.lang.Cloneable, XMLObject
NB: This colour model is mutable, meaning that it can be changed and its changes
will be reflected in all objects that reference it. Use the clone()
method to
make a copy of a particular model state.
NB: an alpha of zero will always map to zero; this is necessary for the current implementation of Volume3DTexture, which requires a power-of-two volume, part of which will be outside the bounds of any non-power-of-two volume, and thus should be always invisible.
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Andrew Reid
-
Nested Class Summary
Nested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType
-
Field Summary
Fields Modifier and Type Field Description protected double
alpha
protected double
alphaMax
protected double
alphaMin
protected int
channels
protected ColourMap
colourMap
int
data_size
protected int
discrete_min
protected java.util.HashMap<java.lang.Integer,java.lang.Integer>
index_map
protected double
intercept
boolean
is_discrete
boolean
is_solid
protected boolean
low_is_transparent
protected int
map_size
protected byte[]
rgba
protected double
scale
protected int[]
solid_colour
protected double
window_mid
protected double
window_width
Fields inherited from class java.awt.image.ColorModel
pixel_bits, transferType
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
-
Constructor Summary
Constructors Constructor Description WindowedColourModel()
Constructor produces a greyscale model of typeDataBuffer.TYPE_DOUBLE
.WindowedColourModel(int transferType)
Constructor produces a greyscale model of typetransferType
.WindowedColourModel(ColourMap cm, double min, double max, boolean has_alpha, int transfer_type)
Constructor specifying min and max values only.WindowedColourModel(ColourMap cm, double scale, double intercept, double window_mid, double window_width, boolean has_alpha, int transferType)
Constructors specifying the full set of model parameters. -
Method Summary
Modifier and Type Method Description java.lang.Object
clone()
java.awt.image.SampleModel
createCompatibleSampleModel(int w, int h)
java.awt.image.WritableRaster
createCompatibleWritableRaster(int w, int h)
double
getAlpha()
int
getAlpha(int pixel)
int
getAlpha(java.lang.Object inData)
int
getAlphaIndex()
double
getAlphaMax()
double
getAlphaMin()
int
getBlue(int pixel)
int
getBlue(java.lang.Object inData)
int
getBlueIndex()
ColourMap
getColourMap()
java.lang.String
getDTD()
Returns the Data Type Declaration (DTD) for this object's XML representationint
getGreen(int pixel)
int
getGreen(java.lang.Object inData)
int
getGreenIndex()
boolean
getHasAlpha()
double
getIntercept()
double
getInverseMappedValue(double value)
Maps a value according to the inverse of the linear window model:double[]
getLimits()
Returns the limits of this windowed modeljava.lang.String
getLocalName()
Returns the local name associated with this XML object.boolean
getLowIsTransparent()
double
getMappedValue(double value)
Maps a value according to the linear window model:int
getRed(int pixel)
int
getRed(java.lang.Object inData)
int
getRedIndex()
int
getRGB(int pixel)
int
getRGB(java.lang.Object inData)
double
getScale()
java.lang.String
getShortXML(int tab)
Returns a short XML representation of this object.java.awt.Color
getSolidColour()
double
getWindowMid()
double
getWindowWidth()
java.lang.String
getXML()
Returns this object's XML representation as a single string.java.lang.String
getXML(int tab)
Returns this object's XML representation as a single string.java.lang.String
getXMLSchema()
Returns the XML schema for this object's XML representationstatic double
getZeroValue(int transferType)
Returns the "zero" value for the given transfer type.void
handleXMLElementEnd(java.lang.String localName)
Handles the end of an XML element.void
handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)
Handles the start of an XML element.void
handleXMLString(java.lang.String s)
Handles a string within an XML element.boolean
isCompatibleRaster(java.awt.image.Raster raster)
void
setAlpha(double alpha)
void
setAlphaMax(double alphaMax)
void
setAlphaMin(double alphaMin)
boolean
setColourMap(ColourMap cm)
void
setFromColourModel(WindowedColourModel model)
void
setHasAlpha(boolean b)
void
setIntercept(double i)
void
setIsSolidColour(boolean b)
void
setLimits(double[] limits)
Set the window from limits.void
setLimits(double min, double max)
Set the window from limits.void
setLowIsTransparent(boolean b)
void
setScale(double s)
void
setSolidColour(java.awt.Color clr)
void
setWindowMid(double mid)
void
setWindowWidth(double width)
void
writeXML(int tab, java.io.Writer writer)
Writes the XML representation of this object to file.void
writeXML(int tab, java.io.Writer writer, ProgressUpdater progress_bar)
Writes the XML representation of this object to file, asXMLType.Normal
.void
writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar)
Writes the XML representation of this object to file.Methods inherited from class java.awt.image.ColorModel
coerceData, equals, finalize, getAlphaRaster, getColorSpace, getComponents, getComponents, getComponentSize, getComponentSize, getDataElement, getDataElement, getDataElements, getDataElements, getDataElements, getNormalizedComponents, getNormalizedComponents, getNumColorComponents, getNumComponents, getPixelSize, getRGBdefault, getTransferType, getTransparency, getUnnormalizedComponents, hasAlpha, hashCode, isAlphaPremultiplied, isCompatibleSampleModel, toString
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
-
Field Details
-
rgba
protected byte[] rgba -
colourMap
-
channels
protected int channels -
data_size
public int data_size -
map_size
protected int map_size -
scale
protected double scale -
intercept
protected double intercept -
window_mid
protected double window_mid -
window_width
protected double window_width -
alphaMin
protected double alphaMin -
alphaMax
protected double alphaMax -
is_discrete
public boolean is_discrete -
is_solid
public boolean is_solid -
discrete_min
protected int discrete_min -
alpha
protected double alpha -
low_is_transparent
protected boolean low_is_transparent -
index_map
protected java.util.HashMap<java.lang.Integer,java.lang.Integer> index_map -
solid_colour
protected int[] solid_colour
-
-
Constructor Details
-
WindowedColourModel
public WindowedColourModel()Constructor produces a greyscale model of typeDataBuffer.TYPE_DOUBLE
.- Parameters:
transfer_type
-
-
WindowedColourModel
public WindowedColourModel(int transferType)Constructor produces a greyscale model of typetransferType
.- Parameters:
transferType
-
-
WindowedColourModel
public WindowedColourModel(ColourMap cm, double min, double max, boolean has_alpha, int transfer_type)Constructor specifying min and max values only.- Parameters:
cm
-min
-max
-has_alpha
-transfer_type
-
-
WindowedColourModel
public WindowedColourModel(ColourMap cm, double scale, double intercept, double window_mid, double window_width, boolean has_alpha, int transferType)Constructors specifying the full set of model parameters.- Parameters:
cm
-scale
-intercept
-window_mid
-window_width
-has_alpha
-transferType
-
-
-
Method Details
-
setIsSolidColour
public void setIsSolidColour(boolean b) -
setSolidColour
public void setSolidColour(java.awt.Color clr) -
getSolidColour
public java.awt.Color getSolidColour() -
setHasAlpha
public void setHasAlpha(boolean b) -
getHasAlpha
public boolean getHasAlpha() -
getScale
public double getScale() -
getIntercept
public double getIntercept() -
setScale
public void setScale(double s) -
setIntercept
public void setIntercept(double i) -
setWindowMid
public void setWindowMid(double mid) -
getWindowMid
public double getWindowMid() -
setWindowWidth
public void setWindowWidth(double width) -
getWindowWidth
public double getWindowWidth() -
setLowIsTransparent
public void setLowIsTransparent(boolean b) -
getLowIsTransparent
public boolean getLowIsTransparent() -
setLimits
public void setLimits(double[] limits)Set the window from limits.- Parameters:
limits
-
-
setLimits
public void setLimits(double min, double max)Set the window from limits.- Parameters:
min
-max
-
-
getLimits
public double[] getLimits()Returns the limits of this windowed model- Returns:
-
getRedIndex
public int getRedIndex() -
getGreenIndex
public int getGreenIndex() -
getBlueIndex
public int getBlueIndex() -
getAlphaIndex
public int getAlphaIndex() -
createCompatibleWritableRaster
public java.awt.image.WritableRaster createCompatibleWritableRaster(int w, int h)- Overrides:
createCompatibleWritableRaster
in classjava.awt.image.ColorModel
-
createCompatibleSampleModel
public java.awt.image.SampleModel createCompatibleSampleModel(int w, int h)- Overrides:
createCompatibleSampleModel
in classjava.awt.image.ColorModel
-
isCompatibleRaster
public boolean isCompatibleRaster(java.awt.image.Raster raster)- Overrides:
isCompatibleRaster
in classjava.awt.image.ColorModel
-
getRGB
public int getRGB(int pixel)- Overrides:
getRGB
in classjava.awt.image.ColorModel
-
getRGB
public int getRGB(java.lang.Object inData)- Overrides:
getRGB
in classjava.awt.image.ColorModel
-
getRed
public int getRed(java.lang.Object inData)- Overrides:
getRed
in classjava.awt.image.ColorModel
-
getRed
public int getRed(int pixel)- Specified by:
getRed
in classjava.awt.image.ColorModel
-
getGreen
public int getGreen(java.lang.Object inData)- Overrides:
getGreen
in classjava.awt.image.ColorModel
-
getGreen
public int getGreen(int pixel)- Specified by:
getGreen
in classjava.awt.image.ColorModel
-
getBlue
public int getBlue(java.lang.Object inData)- Overrides:
getBlue
in classjava.awt.image.ColorModel
-
getBlue
public int getBlue(int pixel)- Specified by:
getBlue
in classjava.awt.image.ColorModel
-
getAlpha
public int getAlpha(java.lang.Object inData)- Overrides:
getAlpha
in classjava.awt.image.ColorModel
-
getAlpha
public int getAlpha(int pixel)- Specified by:
getAlpha
in classjava.awt.image.ColorModel
-
getMappedValue
public double getMappedValue(double value)Maps a value according to the linear window model:Y = (value - intercept) * scale * m + b
where
m = data_size * window_width
and
b = data_size * (window_mid - 0.5)
- Parameters:
value
-- Returns:
-
getInverseMappedValue
public double getInverseMappedValue(double value)Maps a value according to the inverse of the linear window model:Y = (value - b) / (scale * m) + intercept
where
m = data_size * window_width
and
b = data_size * (window_mid - 0.5)
- Parameters:
value
-- Returns:
-
getZeroValue
public static double getZeroValue(int transferType)Returns the "zero" value for the given transfer type. This value is used to set transparency for masked pixels.- Parameters:
transferType
-- Returns:
-
setColourMap
-
getColourMap
-
setFromColourModel
-
clone
public java.lang.Object clone()- Overrides:
clone
in classjava.lang.Object
-
getAlphaMin
public double getAlphaMin() -
setAlphaMin
public void setAlphaMin(double alphaMin) -
getAlphaMax
public double getAlphaMax() -
setAlphaMax
public void setAlphaMax(double alphaMax) -
getAlpha
public double getAlpha() -
setAlpha
public void setAlpha(double alpha) -
getDTD
public java.lang.String getDTD()Description copied from interface:XMLObject
Returns the Data Type Declaration (DTD) for this object's XML representationSee http://en.wikipedia.org/wiki/Document_Type_Definition for a description.
-
getXMLSchema
public java.lang.String getXMLSchema()Description copied from interface:XMLObject
Returns the XML schema for this object's XML representation- Specified by:
getXMLSchema
in interfaceXMLObject
- Returns:
-
getXML
public java.lang.String getXML()Description copied from interface:XMLObject
Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
getXML
public java.lang.String getXML(int tab)Description copied from interface:XMLObject
Returns this object's XML representation as a single string. NOTE: this is not feasible for larger objects and containers, thus may not be implemented for these objects. Use theXMLObject.writeXML(int,java.io.Writer,mgui.io.standard.xml.XMLOutputOptions,mgui.interfaces.ProgressUpdater)
functions to write larger objects to file. -
handleXMLElementStart
public void handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles the start of an XML element.- Specified by:
handleXMLElementStart
in interfaceXMLObject
- Parameters:
localName
- Local name of the elementattributes
- Set of element attributestype
- TheXMLType
of this element- Throws:
org.xml.sax.SAXException
-
handleXMLElementEnd
public void handleXMLElementEnd(java.lang.String localName) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles the end of an XML element.- Specified by:
handleXMLElementEnd
in interfaceXMLObject
- Parameters:
localName
- Local name of the element- Throws:
org.xml.sax.SAXException
-
handleXMLString
public void handleXMLString(java.lang.String s) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles a string within an XML element.- Specified by:
handleXMLString
in interfaceXMLObject
- Parameters:
s
- String to handle- Throws:
org.xml.sax.SAXException
-
getLocalName
public java.lang.String getLocalName()Description copied from interface:XMLObject
Returns the local name associated with this XML object.- Specified by:
getLocalName
in interfaceXMLObject
- Returns:
-
writeXML
public void writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format ofXMLFormat.Ascii
will be used. -
writeXML
public void writeXML(int tab, java.io.Writer writer, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file, asXMLType.Normal
. The default format ofXMLFormat.Ascii
will be used. The basic contract for this method is that it should not write a newline character at its start or end. -
writeXML
public void writeXML(int tab, java.io.Writer writer) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format ofXMLFormat.Ascii
will be used. -
getShortXML
public java.lang.String getShortXML(int tab)Description copied from interface:XMLObject
Returns a short XML representation of this object.- Specified by:
getShortXML
in interfaceXMLObject
- Returns:
-