2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010-2012 - DIGITEO - Manuel Juliachs
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
13 #include "NgonGridData.hxx"
19 #include "graphicObjectProperties.h"
22 NgonGridData::NgonGridData(void)
26 /* Grid: must be set to 4 */
27 numVerticesPerGon = 4;
42 /* Set to 0 as a default */
43 zCoordinatesShift = 0.0;
46 NgonGridData::~NgonGridData(void)
50 delete [] xCoordinates;
55 delete [] yCoordinates;
58 if (xSize > 0 && ySize > 0)
60 delete [] zCoordinates;
64 int NgonGridData::getPropertyFromName(int propertyName)
68 case __GO_DATA_MODEL_NUM_X__ :
70 case __GO_DATA_MODEL_NUM_Y__ :
72 case __GO_DATA_MODEL_NUM_Z__ :
74 case __GO_DATA_MODEL_X_DIMENSIONS__ :
76 case __GO_DATA_MODEL_Y_DIMENSIONS__ :
78 case __GO_DATA_MODEL_GRID_SIZE__ :
80 case __GO_DATA_MODEL_X__ :
82 case __GO_DATA_MODEL_Y__ :
84 case __GO_DATA_MODEL_Z__ :
86 case __GO_DATA_MODEL_Z_COORDINATES_SHIFT__ :
87 return Z_COORDINATES_SHIFT;
89 return NgonData::getPropertyFromName(propertyName);
94 int NgonGridData::setDataProperty(int property, void const* value, int numElements)
96 if (property == GRID_SIZE)
98 return setGridSize((int const*) value);
100 else if (property == X_COORDINATES)
102 setDataX((double const*) value, numElements);
104 else if (property == Y_COORDINATES)
106 setDataY((double const*) value, numElements);
108 else if (property == Z_COORDINATES)
110 setDataZ((double const*) value, numElements);
112 else if (property == Z_COORDINATES_SHIFT)
114 setZCoordinatesShift((double const*) value);
118 return NgonData::setDataProperty(property, value, numElements);
124 void NgonGridData::getDataProperty(int property, void **_pvData)
126 if (property == NUM_X)
128 ((int *) *_pvData)[0] = getNumX();
130 else if (property == NUM_Y)
132 ((int *) *_pvData)[0] = getNumY();
134 else if (property == NUM_Z)
136 ((int *) *_pvData)[0] = getNumZ();
138 else if (property == X_DIMENSIONS)
140 *_pvData = getXDimensions();
142 else if (property == Y_DIMENSIONS)
144 *_pvData = getYDimensions();
146 else if (property == X_COORDINATES)
148 *_pvData = getDataX();
150 else if (property == Y_COORDINATES)
152 *_pvData = getDataY();
154 else if (property == Z_COORDINATES)
156 *_pvData = getDataZ();
158 else if (property == Z_COORDINATES_SHIFT)
160 ((double *) *_pvData)[0] = getZCoordinatesShift();
164 NgonData::getDataProperty(property, _pvData);
169 int NgonGridData::setGridSize(int const* gridSize)
178 double* newXCoordinates = NULL;
179 double* newYCoordinates = NULL;
180 double* newZCoordinates = NULL;
188 if ((gridSize[0] != 1) && (gridSize[1] != 1))
193 if ((gridSize[2] != 1) && (gridSize[3] != 1))
198 newXSize = gridSize[0] * gridSize[1];
199 newYSize = gridSize[2] * gridSize[3];
202 if (newXSize != xSize)
208 newXCoordinates = new double[newXSize];
210 catch (const std::exception& e)
217 if (newYSize != ySize)
223 newYCoordinates = new double[newYSize];
225 catch (const std::exception& e)
232 if (newXSize*newYSize != xSize * ySize)
238 newZCoordinates = new double[newXSize * newYSize];
240 catch (const std::exception& e)
253 delete [] xCoordinates;
256 xCoordinates = newXCoordinates;
260 xDimensions[0] = gridSize[0];
261 xDimensions[1] = gridSize[1];
267 delete [] yCoordinates;
270 yCoordinates = newYCoordinates;
274 yDimensions[0] = gridSize[2];
275 yDimensions[1] = gridSize[3];
279 if (xSize * ySize > 0)
281 delete [] zCoordinates;
284 zCoordinates = newZCoordinates;
286 numGons = (xSize - 1) * (ySize - 1);
292 /* Failed allocation(s) */
294 if (xModified && (newXCoordinates != NULL))
296 delete [] newXCoordinates;
299 if (yModified && (newYCoordinates != NULL))
301 delete [] newYCoordinates;
304 if (zModified && (newZCoordinates != NULL))
306 delete [] newZCoordinates;
314 int NgonGridData::getNumX(void)
319 int NgonGridData::getNumY(void)
324 int NgonGridData::getNumZ(void)
326 return xSize * ySize;
329 int* NgonGridData::getXDimensions(void)
334 int* NgonGridData::getYDimensions(void)
339 void NgonGridData::setDataX(double const* data, int numElements)
341 if (numElements > xSize)
346 for (int i = 0; i < numElements; i++)
348 xCoordinates[i] = data[i];
352 void NgonGridData::setDataY(double const* data, int numElements)
354 if (numElements > ySize)
359 for (int i = 0; i < numElements; i++)
361 yCoordinates[i] = data[i];
365 void NgonGridData::setDataZ(double const* data, int numElements)
367 if (numElements > xSize * ySize)
372 for (int i = 0; i < numElements; i++)
374 zCoordinates[i] = data[i];
378 void NgonGridData::setZCoordinatesShift(double const* data)
380 zCoordinatesShift = *data;
383 double* NgonGridData::getDataX(void)
388 double* NgonGridData::getDataY(void)
393 double* NgonGridData::getDataZ(void)
398 double NgonGridData::getZCoordinatesShift(void)
400 return zCoordinatesShift;