com.tensegrity.generic.util.metric
Class Metric

java.lang.Object
  extended bycom.tensegrity.generic.util.metric.Metric

public final class Metric
extends java.lang.Object

The Metric class provides the functionality that is needed in order to work with a logical coordinate system.

* * * * * * The Metric class is not supposed to be instantiated. In order to get an instance of this class one has to call the method getInstance() * * * * * * * * * * * * * *

Version:
$Id: Metric.java,v 1.4 2006/06/08 12:11:11 MichaelKegel Exp $
Author:
MKegel
See Also:
MetricConstants, MetricExpression

Field Summary
static int FROM_METRIC
          Determining the conversion direction for conversion methods.
static double INCH_TO_CM
          Conversion factor to calculate inch to centimeters
static Metric SOLE_METRIC
          The singleton instance of this class
static int TO_METRIC
          Determining the conversion direction for conversion methods.
 
Method Summary
 double computeMeasuringUnitConversionFactor(int measuringUnitConvertTo)
          Returns the conversion factor that has to be used in order to convert a value that is given in the units of this Metric instance into the unit identified through the constant given by measuringUnitConvertTo.
static double computeMeasuringUnitConversionFactor(int measuringUnitConvertFrom, int measuringUnitConvertTo)
          Returns the conversion factor that has to be used in order to convert a value that is given in the measuring units identified through the constant given by measuringUnitConvertFrom into the measuring units identified through the constant given by measuringUNitConvertTo.
 double[] convert(double[] internPoints, int direction)
          Converts the given given array of point given in internal measurement units to the measurement unit set for this metric object.
 double convertMeasureValue(int measuringUnitConvertTo)
          Converts the measure value of this Metric instance given in the measuring unit of this Metric instance into the corresponding measure value for the measuring unit identified through the constant given by measuringUnitConvertTo.
 MetricExpression convertMetricExpression(double value, int measuringUnitConvertFrom, int measuringUnitConvertTo)
          Converts the value given by value from one measuring unit system into another measuring unit system and creates a MetricExpression instance for the converted value.
 MetricExpression convertMetricExpression(MetricExpression expression, int measuringUnitConvertTo)
          Converts the MetricExpression given by expression into another MetricExpression whose measuring unit system is identified through the constant given by measuringUnitConvertTo.
 double convertMetricExpressionValue(double value, int measuringUnitConvertFrom, int measuringUnitConvertTo)
          Converts the value given by value from one measuring unit system into another measuring unit system.
 double convertMetricExpressionValue(MetricExpression expression, int measuringUnitConvertTo)
          Converts the value of the MetricExpression given by expression from one measuring unit system into another measuring unit system.
 int getDisplayHeight()
          Returns the value that is currently set as the display height.
 int getDisplayResolutionX()
          Returns the value that is currently set as display resolution in x direction.
 int getDisplayResolutionY()
          Returns the value that is currently set as display resolution in y direction.
 int getDisplayWidth()
          Returns the value that is currently set as the display width.
static Metric getInstance()
          Returns the singleton instance of this class
 double getMeasureValue()
          Returns the current measure value.
 int getMeasuringUnit()
          Returns a constant that identifies the current measuring unit.
 void setDisplaySize(int displayWidthMM, int displayHeightMM)
          Sets the display size in millimeters to use for metric conversions
 void setScreenResolution(int screenWidth, int screenHeight)
          Sets the screen resolution to use for metric conversions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOLE_METRIC

public static final Metric SOLE_METRIC
The singleton instance of this class


INCH_TO_CM

public static final double INCH_TO_CM
Conversion factor to calculate inch to centimeters

See Also:
Constant Field Values

FROM_METRIC

public static final int FROM_METRIC
Determining the conversion direction for conversion methods.

See Also:
convert(double[], int), Constant Field Values

TO_METRIC

public static final int TO_METRIC
Determining the conversion direction for conversion methods.

See Also:
convert(double[], int), Constant Field Values
Method Detail

getInstance

public static final Metric getInstance()
Returns the singleton instance of this class

Returns:
the singleton instance of this class

setScreenResolution

public void setScreenResolution(int screenWidth,
                                int screenHeight)
Sets the screen resolution to use for metric conversions

Parameters:
screenWidth - The new screen width in pixels to use
screenHeight - The new screen height in pixels to use

setDisplaySize

public void setDisplaySize(int displayWidthMM,
                           int displayHeightMM)
Sets the display size in millimeters to use for metric conversions

Parameters:
displayWidthMM - The width of the monitor in millimeters
displayHeightMM - The height of the monitor in millimeters

getMeasureValue

public double getMeasureValue()
Returns the current measure value.

Returns:
double the current measure value

getMeasuringUnit

public int getMeasuringUnit()
Returns a constant that identifies the current measuring unit.

Returns:
int constant for the current measuring unit

getDisplayWidth

public int getDisplayWidth()
Returns the value that is currently set as the display width. The unit of the returned value is millimeter.

Returns:
the currently used display width in millimeter

getDisplayHeight

public int getDisplayHeight()
Returns the value that is currently set as the display height. The unit of the returned value is millimeter.

Returns:
the currently used display height in millimeter

getDisplayResolutionX

public int getDisplayResolutionX()
Returns the value that is currently set as display resolution in x direction. The unit of the returned value is pixel.

Returns:
the currently used display resolution for the x axis in pixel

getDisplayResolutionY

public int getDisplayResolutionY()
Returns the value that is currently set as display resolution in y direction. The unit of the returned value is pixel.

Returns:
the currently used display resolution for the y axis in pixel

computeMeasuringUnitConversionFactor

public final double computeMeasuringUnitConversionFactor(int measuringUnitConvertTo)
Returns the conversion factor that has to be used in order to convert a value that is given in the units of this Metric instance into the unit identified through the constant given by measuringUnitConvertTo.

Parameters:
measuringUnitConvertTo - the constant for the measuring unit a value should be converted into
Returns:
double the conversion factor from the measuring unit of this Metric instance into the given measuring unit

computeMeasuringUnitConversionFactor

public static final double computeMeasuringUnitConversionFactor(int measuringUnitConvertFrom,
                                                                int measuringUnitConvertTo)
Returns the conversion factor that has to be used in order to convert a value that is given in the measuring units identified through the constant given by measuringUnitConvertFrom into the measuring units identified through the constant given by measuringUNitConvertTo.

Parameters:
measuringUnitConvertFrom - constant for the measuring unit to convert from
measuringUnitConvertTo - constant for the measuring unit to convert into
Returns:
double the conversion factor between the two given measuring units

convertMetricExpression

public final MetricExpression convertMetricExpression(MetricExpression expression,
                                                      int measuringUnitConvertTo)
Converts the MetricExpression given by expression into another MetricExpression whose measuring unit system is identified through the constant given by measuringUnitConvertTo.
The measuring unit system to convert from is the one of the given MetricExpression.
The measuring unit system to convert into is identified through the constant given by measuringUnitConvertTo.
The returned MetricExpression instance is not the same as the one passed into this method.

Parameters:
expression - the MetricExpression whose value should be converted
measuringUnitConvertTo - the constant for the measuring unit system to convert to
Returns:
MetricExpression the converted MetricExpression

convertMetricExpression

public final MetricExpression convertMetricExpression(double value,
                                                      int measuringUnitConvertFrom,
                                                      int measuringUnitConvertTo)
Converts the value given by value from one measuring unit system into another measuring unit system and creates a MetricExpression instance for the converted value.
The measuring unit system to convert from, which is the measuring unit system the value is given in, is identified through the constant given by measuringUnitConvertFrom.
The measuring unit system to convert into is identified through the constant given by measuringUnitConvertTo.

Parameters:
value - the value that should be converted
measuringUnitConvertFrom - the constant for the measuring unit system to convert from
measuringUnitConvertTo - the constant for the measuring unit system to convert into
Returns:
MetricExpression an instance of MetricExpression that carries the converted value

convertMetricExpressionValue

public final double convertMetricExpressionValue(MetricExpression expression,
                                                 int measuringUnitConvertTo)
Converts the value of the MetricExpression given by expression from one measuring unit system into another measuring unit system.
The measuring unit system to convert from is the one of the given MetricExpression.
The measuring unit system to convert into is identified through the constant given by measuringUnitConvertTo.

Parameters:
expression - the MetricExpression whose value should be converted
measuringUnitConvertTo - the constant for the measuring unit system to convert to
Returns:
double the converted value

convertMetricExpressionValue

public final double convertMetricExpressionValue(double value,
                                                 int measuringUnitConvertFrom,
                                                 int measuringUnitConvertTo)
Converts the value given by value from one measuring unit system into another measuring unit system.
The measuring unit system to convert from, which is the measuring unit system the value is given in, is identified through the constant given by measuringUnitConvertFrom.
The measuring unit system to convert into is identified through the constant given by measuringUnitConvertTo.

Parameters:
value - the value that should be converted
measuringUnitConvertFrom - the constant for the measuring unit system to convert from
measuringUnitConvertTo - the constant for the measuring unit system to convert to
Returns:
double the converted value

convertMeasureValue

public final double convertMeasureValue(int measuringUnitConvertTo)
Converts the measure value of this Metric instance given in the measuring unit of this Metric instance into the corresponding measure value for the measuring unit identified through the constant given by measuringUnitConvertTo.

Parameters:
measuringUnitConvertTo - the constant for the measuring unit to convert the measuring value of the Metric instance into
Returns:
double the converted measuring value of this Metric instance

convert

public double[] convert(double[] internPoints,
                        int direction)
Converts the given given array of point given in internal measurement units to the measurement unit set for this metric object. The coordinates stored within the given aren't affected.

Parameters:
internPoints - the points to convert given in intern units.
direction - the direction to convert to. Valid values are TO_METRIC and FROM_METRIC.
Returns:
an array holding the converted points.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.