1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2011-2012 - DIGITEO - Manuel Juliachs
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
*/
#ifndef NGONGRIDMATPLOTDATA_DECOMPOSER_HXX
#define NGONGRIDMATPLOTDATA_DECOMPOSER_HXX
#include <string>
#include "ColorComputer.hxx"
extern "C"
{
#include "Matplot.h"
}
/**
* NgonGridMatplotData decomposer class
* Determines the vertices and the segments indices to be rendered
* as a function of the decomposed Matplot object's properties.
*
*/
class NgonGridMatplotDataDecomposer : public NgonGridDataDecomposer
{
private :
/** NgonGridMatplotData decomposer instance */
static NgonGridMatplotDataDecomposer* decomposer;
protected :
/**
* Fills a buffer with vertex data from a grid.
* In the case of Matplot objects, vertex coordinates are computed using the coordinates of the grid's lower-left corner
* and the distances between two adjacent vertices for both the x and y axes, which we label respectively (xmin, ymin) and
* (xd, yd). The relevant values are used as the x and y coordinate arrays (see the parameter descriptions).
* @param[out] the buffer to fill.
* @param[in] the buffer length in number of elements.
* @param[in] the number of coordinates taken by one element in the buffer.
* @param[in] the byte mask specifying which coordinates are filled (1 for X, 2 for Y, 4 for Z).
* @param[in] the conversion scale factor to apply to data.
* @param[in] the conversion translation factor to apply to data.
* @param[in] the bit mask specifying whether logarithmic coordinates are used.
* @param[in] the grid x-coordinate array (2 elements: xmin, xd).
* @param[in] the grid y-coordinate array (2 elements: ymin, yd).
* @param[in] the grid z-coordinate array.
* @param[in] the grid's number of vertices along the x-axis.
* @param[in] the grid's number of vertices along the y-axis.
*/
virtual void fillGridVertices(float* buffer, int bufferLength, int elementsSize, int coordinateMask, double* scale, double* translation, int logMask,
double* x, double* y, double* z, int numX, int numY);
/**
* Determines whether a facet is valid.
* The facet is identified by its lower left-corner (i,j).
* For a Matplot object, facet (i,j)'s validity depends only on its z coordinate and its (i,j) value,
* edge validity being therefore irrelevant. The flag specifying per-node values should be 0,
* as Matplot grid values are defined per facet, although it is actually unused.
* @param[in] the grid z-coordinate array.
* @param[in] the grid value array.
* @param[in] a flag indicating whether grid values are defined per node (1) or per facet (0). Unused.
* @param[in] the grid's number of vertices along the x-axis.
* @param[in] the grid's number of vertices along the y-axis.
* @param[in] the lower-left corner's x index.
* @param[in] the lower-left corner's y index.
* @param[in] a flag specifying whether logarithmic coordinates are used. Unused.
* @param[in] (i,j) to (i,j+1) edge validity flag. Unused.
* @param[out] a pointer to the output (i+1,j) to (i+1,j+1) edge validity flag. Always set to 1.
* @return 1 if the facet is valid, 0 if it is not.
*/
virtual int isFacetValid(double* z, double* values, int perNodeValues, int numX, int numY, int i, int j, int logUsed, int currentEdgeValid, int* nextEdgeValid);
/**
* Determines whether the left edge of a facet is valid.
* For a Matplot object, edge validity is irrelevant, it is therefore always equal to 1.
* @param[in] the grid z-coordinate array.
* @param[in] the grid value array.
* @param[in] a flag indicating whether grid values are defined per node (1) or per facet (0).
* @param[in] the grid's number of vertices along the x-axis.
* @param[in] the grid's number of vertices along the y-axis.
* @param[in] the lower-left corner's x index.
* @param[in] the lower-left corner's y index.
* @param[in] a flag specifying whether logarithmic coordinates are used.
* @return Always 1.
*/
virtual int isFacetEdgeValid(double* z, double* values, int perNodeValues, int numX, int numY, int i, int j, int logUsed);
public :
/**
* Returns the class single instance.
* @return the class instance.
*/
static NgonGridMatplotDataDecomposer* get(void)
{
if (decomposer == NULL)
{
decomposer = new NgonGridMatplotDataDecomposer();
}
return decomposer;
}
/**
* Fills the given buffer with vertex data from the given object.
* @param[in] the id of the given object.
* @param[out] the buffer to fill.
* @param[in] the buffer length in number of elements.
* @param[in] the number of coordinates taken by one element in the buffer.
* @param[in] the byte mask specifying which coordinates are filled (1 for X, 2 for Y, 4 for Z).
* @param[in] the conversion scale factor to apply to data.
* @param[in] the conversion translation factor to apply to data.
* @param[in] the bit mask specifying whether logarithmic coordinates are used.
*/
static void fillVertices(int id, float* buffer, int bufferLength, int elementsSize, int coordinateMask, double* scale, double* translation, int logMask);
/**
* Fills the given buffer with color data from the given object.
* @param[in] the id of the given object.
* @param[out] the buffer to fill.
* @param[in] the buffer length in number of elements.
* @param[in] the number of components taken by one element in the buffer (3 or 4).
*/
static void fillColors(int id, float* buffer, int bufferLength, int elementsSize);
/**
* Fills the given buffer with indices data of the given object.
* @param[in] the given object id.
* @param[out] the buffer to fill.
* @param[in] the buffer length.
* @param[in] the bit mask specifying whether logarithmic coordinates are used.
* @return the number of indices actually written.
*/
static int fillIndices(int id, int* buffer, int bufferLength, int logMask);
template <typename T>
inline static void fillColorsByIndex(T * indices, float * buffer, int elementsSize, const int nbRow, const int nbCol, double * colormap, const int colormapSize)
{
float facetColor[3];
T index;
int bufferOffset = 0;
for (int j = 0; j < nbRow; j++)
{
for (int i = 0; i < nbCol; i++)
{
index = indices[nbRow - 1 + i * nbRow - j];
ColorComputer::getDirectColor(index - 1, colormap, colormapSize, facetColor);
writeFacetColorToBuffer(buffer, bufferOffset, facetColor, elementsSize);
bufferOffset += 4 * elementsSize;
}
}
}
static void getRGBAData(ImageType imagetype, DataType datatype, GLType gltype, void * data, float * buffer, int elementsSize, const int nbRow, const int nbCol, double * colormap, const int colormapSize);
};
#endif
|