Perforce JViews TGO Sample: Image Color Tuner
Description
This sample is a utility to find the best image processing parameters to use a given image as the base of a Perforce JViews TGO predefined business object.
How to Use the Sample
- Load the image which will be used to create the new object type using the File -> Load Image... menu item.
- Customize the Carrying Traffic with alarm representations. You have to choose the gray level that will be mapped to the normal alarm color. To do so, you can either display the tab called Row 1 and use the slider or click in the zoomed view on a pixel that has the color you want to be mapped to the normal alarm color.
- Customize the No Traffic representation. You have to indicate which details of your original image should have the dark color. To do so, display the tab called Row 2 and adjust the two sliders. The first slider adjusts the threshold for bright colors: colors of the original image brighter than this threshold will be displayed in the appropriate dark color depending on the state and alarms. The second slider adjusts the threshold for dark colors: colors of the original image darker than this threshold will also be displayed in the appropriate dark color depending on the state and alarms.
- Display the sample source code using the File -> View Source... menu item. The source code needed to create your new type as it is currently represented on screen is displayed. The factory constructor contains the appropriate values. You have to note or copy these values or the entire code and paste it into your JViews TGO application to create your new type.
How to Run the Sample as an Application
This sample can
be run as an application.
The installation directory contains
an executable JAR file,
imagecolortuner.jar
,
that allows you to execute the sample with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the sample application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the sample and type:
ant run
Topics Covered
- Creating network elements.
- Creating new network element types.
- Configuring the best image parameters to use a given image as the base of a predefined business object.
Detailed Description
This sample shows how to you can find the best image processing parameters to use a given image as the base of a Perforce JViews TGO predefined business object.
The class ilog.tgo.graphic.renderer.IltNEImageBaseRendererFactory is used to create new network element types based on a single image.
Perforce JViews TGO processes images to produce various representations for a network element depending on its associated state and alarm.
If the base style is Carrying Traffic no alarms, the representation is the original image. For example:
In all other cases, the representation is automatically computed by JViews TGO, as follows:
-
Carrying Traffic with alarms: A color scale corresponding to the alarm color is applied to the original image. This color scale uses three colors: a bright alarm color, a normal alarm color, and a dark alarm color.
For example, for a major alarm JViews TGO uses the colors bright red, red, and dark red. The color scale is applied to the original image by first converting it to a normalized grayscale image (that is, gray levels in the range 0..255). Then, the normalized grayscale image is colored by mapping each gray level to a color level. The brighter gray is mapped to the bright alarm color, the darker gray is mapped to the dark alarm color, and the gray level corresponding to the third integer in the factory constructor is mapped to the normal alarm color (if this integer is not explicitly given, the default value used is 128). Any other gray level different from the brighter one, the darker one, or the one given in the factory constructor is mapped to the appropriate color in a continuous manner.
-
No Traffic (with or without alarms): The original image, which is supposed to be a relief image (according to the JViews TGO look-and-feel), is transformed to a flat image. The flat image is composed of only two colors: in the absence of alarms, one gray and one darker gray, otherwise one alarm color and one dark alarm color. Using only two colors ensures a flat visual aspect. To follow the JViews TGO look-and-feel, the whole object should be represented in the normal color with its border in the dark color, plus possibly some details of the inside of the object also in the dark color.
For example, in the image below we can see that the border is in the dark color as well as the outline of the small screen and the receiver of the phone. To indicate which details of the original image you want in the dark color and which you do not, you must use the first two integers of the factory constructor. The first integer indicates a threshold above which the bright colors of the original image should be considered as details and drawn in the dark color; if this integer is not explicitly given, the default value used will be 200. The image below shows examples where the threshold assumed is 200 (in the range 0..255). In this way, the left border of the receiver and the lower right border of the screen are drawn in the dark color. The second integer is a threshold indicating which of the dark colors of the original image should be considered as details and also drawn in the dark color; if this integer is not explicitly provided, the default value will be 50. In this example this threshold is 11 (in the range 0..255). This causes the lower right border of the receiver and the upper left border of the screen to be drawn in the dark color.
-
Out of Service and Not Installed (with or without alarms): According to the JTGO look-and-feel, the object should be represented with only two colors, a dashed border and a pattern inside, but no other details. JViews TGO uses the transparency, if any, to determine the border of the image. When there is no transparency, the rectangle of the image is considered to be the border. Then, the interior is filled with the appropriate pattern and the border is drawn as a dashed line. JViews TGO does not need any extra parameters (threshold or gray level as mentioned above) to compute these representations correctly.
The purpose of this sample is to help you find the best values for the thresholds and the gray level.
For the ilog.tgo.graphic.renderer.IltNEImageBaseRendererFactory to properly process the supported image types (GIF, PNG and JPG), the only constraint on the image itself is that the number of colors, C, be as follows: 2 <= C <= 256
Note: Transparency is preserved by the ilog.tgo.graphic.renderer.IltNEImageBaseRendererFactory and, as such, is not considered a color. Consequently, it does not color the transparent pixels of the image. For example, an image that contains the color black as the foreground, and a transparency as the background, will not have the regular coloring scheme applied as it fails to meet the requirement above.
Installation Directory
The Image Color Tuner sample is installed here.
Classes Involved
-
ilog.cpl.IlpSystem
The class that initializes a JViews TGO application.
-
ilog.cpl.IlpNetwork
The Network Component.
-
ilog.tgo.model.IltNetworkElement
The predefined business object that models network nodes.
-
ilog.tgo.graphic.renderer.IltNEImageBaseRendererFactory
The class that lets you easily create new types of network elements based on a single image.
Source Files
-
imagecolortuner.Main
The entry point of the sample.