* @param[out] a pointer to the array into which the resulting color is output (its R, G, B components are written consecutively).
*/
static void getColor(double s, double smin, double srange, double indexOffset, double* colormap, int minIndex, int maxIndex,
- int colormapSize, float* returnedColor);
+ int colormapSize, float* returnedColor);
/**
* Outputs an RGB color directly mapped to a scalar value s.
* @param[in] a pointer to the colormap used.
* @param[in] the colormap's size.
* @param[out] a pointer to the array into which the resulting color is output (its R, G, B components are written consecutively).
+ * @param[in] a boolean to indicate if the color is clamped (by default true).
*/
- static void getDirectColor(double s, double* colormap, int colormapSize, float* returnedColor);
+ static void getDirectColor(double s, double* colormap, int colormapSize, float* returnedColor, bool clamped = true);
/**
* Outputs an RGB color directly mapped to a scalar value s.
* @param[in] a pointer to the colormap used.
* @param[in] the colormap's size.
* @param[out] a pointer to the array into which the resulting color is output (its R, G, B components are written consecutively).
+ * @param[in] a boolean to indicate if the color is clamped (by default true).
*/
- static void getDirectByteColor(double s, double* colormap, int colormapSize, unsigned char* returnedColor);
+ static void getDirectByteColor(double s, double* colormap, int colormapSize, unsigned char* returnedColor, bool clamped = true);
/**
* Returns a colormap index from a scalar value s.
/**
* Special color index values.
*/
-enum SpecialColorIndexValues {
+enum SpecialColorIndexValues
+{
WHITE_LOWER_INDEX = -4,
BLACK_LOWER_INDEX = -3,
BLACK_UPPER_INDEX = 0
#define COLOR_TEXTURE_OFFSET 0.5
#endif
+
else
{
value = (s - smin) / (srange);
- index = (int) ((double)(colormapSize-1)*value + indexOffset);
+ index = (int) ((double)(colormapSize - 1) * value + indexOffset);
/* Clamp */
if (index < 0)
}
returnedColor[0] = (float)colormap[index];
- returnedColor[1] = (float)colormap[colormapSize+index];
- returnedColor[2] = (float)colormap[2*colormapSize+index];
+ returnedColor[1] = (float)colormap[colormapSize + index];
+ returnedColor[2] = (float)colormap[2 * colormapSize + index];
}
}
else
{
value = (s - smin) / (srange);
- index = (int) ((double)(maxIndex - minIndex)*value + indexOffset + (double) minIndex);
+ index = (int) ((double)(maxIndex - minIndex) * value + indexOffset + (double) minIndex);
/* Clamp */
if (index < minIndex)
}
returnedColor[0] = (float)colormap[index];
- returnedColor[1] = (float)colormap[colormapSize+index];
- returnedColor[2] = (float)colormap[2*colormapSize+index];
+ returnedColor[1] = (float)colormap[colormapSize + index];
+ returnedColor[2] = (float)colormap[2 * colormapSize + index];
}
}
else
{
value = (s - smin) / (srange);
- index = (double)(maxIndex - minIndex)*value + indexOffset + (double) minIndex;
+ index = (double)(maxIndex - minIndex) * value + indexOffset + (double) minIndex;
index = floor(index);
return index;
}
-void ColorComputer::getDirectColor(double s, double* colormap, int colormapSize, float* returnedColor)
+void ColorComputer::getDirectColor(double s, double* colormap, int colormapSize, float* returnedColor, bool clamped)
{
int index = 0;
{
if (s > (double)(colormapSize - 1))
{
- s = (double) (colormapSize - 1);
+ if (clamped)
+ {
+ s = (double) (colormapSize - 1);
+ }
+ else
+ {
+ returnedColor[0] = -1;
+ return;
+ }
}
index = (int) s;
returnedColor[0] = (float)colormap[index];
- returnedColor[1] = (float)colormap[colormapSize+index];
- returnedColor[2] = (float)colormap[2*colormapSize+index];
+ returnedColor[1] = (float)colormap[colormapSize + index];
+ returnedColor[2] = (float)colormap[2 * colormapSize + index];
}
}
return index;
}
-void ColorComputer::getDirectByteColor(double s, double* colormap, int colormapSize, unsigned char* returnedColor)
+void ColorComputer::getDirectByteColor(double s, double* colormap, int colormapSize, unsigned char* returnedColor, bool clamped)
{
- float color[3];
- getDirectColor(s, colormap, colormapSize, color);
+ float color[3];
+ getDirectColor(s, colormap, colormapSize, color, clamped);
+
+ returnedColor[0] = (unsigned char)(color[0] * 255);
+ returnedColor[1] = (unsigned char)(color[1] * 255);
+ returnedColor[2] = (unsigned char)(color[2] * 255);
- returnedColor[0] = (unsigned char)(color[0] * 255);
- returnedColor[1] = (unsigned char)(color[1] * 255);
- returnedColor[2] = (unsigned char)(color[2] * 255);
+ if (!clamped && color[0] == -1)
+ {
+ returnedColor[3] = 0;
+ }
+ else
+ {
+ returnedColor[3] = 255;
+ }
}
double ColorComputer::getClampedDirectIndex(double s, int colormapSize)
index = (int) s;
returnedColor[0] = (float)colormap[index];
- returnedColor[1] = (float)colormap[colormapSize+index];
- returnedColor[2] = (float)colormap[2*colormapSize+index];
+ returnedColor[1] = (float)colormap[colormapSize + index];
+ returnedColor[2] = (float)colormap[2 * colormapSize + index];
}
}
-
int MatPlotDecomposer::getTextureWidth(char* id)
{
- int width = 0;
- int* piWidth = &width;
- getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piWidth);
- return width - 1;
+ int width = 0;
+ int* piWidth = &width;
+ getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_X__, jni_int, (void**) &piWidth);
+ return width - 1;
}
int MatPlotDecomposer::getTextureHeight(char* id)
{
- int height = 0;
- int* piHeight = &height;
- getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piHeight);
- return height - 1;
+ int height = 0;
+ int* piHeight = &height;
+ getGraphicObjectProperty(id, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**) &piHeight);
+ return height - 1;
}
int MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int bufferLength)
{
- double* value = NULL;
- getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &value);
- int textureWidth = getTextureWidth(id);
- int textureHeight = getTextureHeight(id);
- int dataSize = textureWidth * textureHeight;
- if (dataSize * 4 == bufferLength)
- {
+ double* value = NULL;
+ getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &value);
+ int textureWidth = getTextureWidth(id);
+ int textureHeight = getTextureHeight(id);
+ int dataSize = textureWidth * textureHeight;
+ if (dataSize * 4 == bufferLength)
+ {
+
+ char* parentFigure = NULL;
+ double* colormap = NULL;
+ int colormapSize = 0;
+ int* piColormapSize = &colormapSize;
- char* parentFigure = NULL;
- double* colormap = NULL;
- int colormapSize = 0;
- int* piColormapSize = &colormapSize;
+ getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure);
+ getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
+ getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
- getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure);
- getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
- getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
+ for (int i = 0 ; i < textureWidth ; i++)
+ {
+ for (int j = 0 ; j < textureHeight ; j++)
+ {
+ ColorComputer::getDirectByteColor(value[j + i * textureHeight] - 1, colormap, colormapSize, &buffer[4 * (i + j * textureWidth)], false);
+ }
+ }
- for (int i = 0 ; i < textureWidth ; i++)
+ return bufferLength;
+ }
+ else
{
- for (int j = 0 ; j < textureHeight ; j++)
- {
- ColorComputer::getDirectByteColor(value[j + i * textureHeight] - 1, colormap, colormapSize, &buffer[4 * (i + j * textureWidth)]);
- buffer[4 * (i + j * textureWidth) + 3] = 255;
- }
+ return 0;
}
-
- return bufferLength;
- }
- else
- {
- return 0;
- }
}
int MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int bufferLength, int x, int y, int width, int height)
{
- double* value = NULL;
- getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &value);
- if (width * height * 4 == bufferLength)
- {
- char* parentFigure = NULL;
- double* colormap = NULL;
- int colormapSize = 0;
- int* piColormapSize = &colormapSize;
- getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure);
- getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
- getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
- int textureHeight = getTextureHeight(id);
- int k = 0;
- for (int j = y ; j < y + height ; j++)
+ double* value = NULL;
+ getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, (void**) &value);
+ if (width * height * 4 == bufferLength)
+ {
+ char* parentFigure = NULL;
+ double* colormap = NULL;
+ int colormapSize = 0;
+ int* piColormapSize = &colormapSize;
+ getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure);
+ getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
+ getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);
+ int textureHeight = getTextureHeight(id);
+ int k = 0;
+ for (int j = y ; j < y + height ; j++)
+ {
+ for (int i = x ; i < x + width ; i++)
+ {
+ ColorComputer::getDirectByteColor(value[j + i * textureHeight] - 1, colormap, colormapSize, &buffer[k]);
+ buffer[k + 3] = 255;
+ k += 4;
+ }
+ }
+ return bufferLength;
+ }
+ else
{
- for (int i = x ; i < x + width ; i++)
- {
- ColorComputer::getDirectByteColor(value[j + i * textureHeight] - 1, colormap, colormapSize, &buffer[k]);
- buffer[k + 3] = 255;
- k += 4;
- }
+ return 0;
}
- return bufferLength;
- }
- else
- {
- return 0;
- }
}
+