2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - 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
15 #include "NgonGeneralData.hxx"
16 #include "DataProperties.hxx"
23 #include "graphicObjectProperties.h"
26 NgonGeneralData::NgonGeneralData(void)
29 numVerticesPerGon = 0;
37 NgonGeneralData::~NgonGeneralData(void)
39 if (numGons * numVerticesPerGon > 0)
41 delete [] coordinates;
46 delete [] colorValues;
50 int NgonGeneralData::getPropertyFromName(int propertyName)
54 case __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__ :
55 return NUM_ELEMENTS_ARRAY;
56 case __GO_DATA_MODEL_COORDINATES__ :
58 case __GO_DATA_MODEL_X__ :
60 case __GO_DATA_MODEL_Y__ :
62 case __GO_DATA_MODEL_Z__ :
64 case __GO_DATA_MODEL_COLORS__ :
66 case __GO_DATA_MODEL_NUM_COLORS__ :
69 return NgonData::getPropertyFromName(propertyName);
73 int NgonGeneralData::setDataProperty(int property, void const* value, int numElements)
76 if (property == NUM_ELEMENTS_ARRAY)
78 return setNumElementsArray((int const*) value);
80 else if (property == COORDINATES)
82 setData((double const*) value, numElements);
84 else if (property == X_COORDINATES)
86 setDataX((double const*) value, numElements);
88 else if (property == Y_COORDINATES)
90 setDataY((double const*) value, numElements);
92 else if (property == Z_COORDINATES)
94 setDataZ((double const*) value, numElements);
96 else if (property == COLORS)
98 setColors((double const*) value, numElements);
102 return NgonData::setDataProperty(property, value, numElements);
108 void NgonGeneralData::getDataProperty(int property, void **_pvData)
110 if (property == NUM_ELEMENTS_ARRAY)
112 /* Not implemented yet */
113 // getNumElementsArray();
115 else if (property == COORDINATES)
117 *_pvData = getData();
119 else if (property == X_COORDINATES)
121 *_pvData = getDataX();
123 else if (property == Y_COORDINATES)
125 *_pvData = getDataY();
127 else if (property == Z_COORDINATES)
129 *_pvData = getDataZ();
131 else if (property == COLORS)
133 *_pvData = getColors();
135 else if (property == NUM_COLORS)
137 ((int *) *_pvData)[0] = getNumColors();
141 NgonData::getDataProperty(property, _pvData);
146 double* NgonGeneralData::getData()
151 double* NgonGeneralData::getDataX(void)
156 double* NgonGeneralData::getDataY(void)
158 return &coordinates[numGons * numVerticesPerGon];
161 double* NgonGeneralData::getDataZ(void)
163 return &coordinates[2 * numGons * numVerticesPerGon];
167 * Only partially implemented
168 * Must be made consistent with setNumElementsArray
170 void NgonGeneralData::setData(double const* data, int numElements)
172 if (numElements != numGons * numVerticesPerGon)
174 delete [] coordinates;
176 numVerticesPerGon = numElements / numGons;
177 coordinates = new double[3 * numElements];
180 memcpy(coordinates, data, 3 * numElements * sizeof(double));
183 void NgonGeneralData::setDataX(double const* data, int numElements)
185 double* xCoordinates = NULL;
187 xCoordinates = coordinates;
188 memcpy(xCoordinates, data, numElements * sizeof(double));
191 void NgonGeneralData::setDataY(double const* data, int numElements)
193 double* yCoordinates;
195 yCoordinates = &coordinates[numGons * numVerticesPerGon];
196 memcpy(yCoordinates, data, numElements * sizeof(double));
199 void NgonGeneralData::setDataZ(double const* data, int numElements)
201 double* zCoordinates = NULL;
203 zCoordinates = &coordinates[2 * numGons * numVerticesPerGon];
204 memcpy(zCoordinates, data, numElements * sizeof(double));
207 int NgonGeneralData::getNumElements(void)
212 int NgonGeneralData::setNumElementsArray(int const* numElementsArray)
214 double* newCoordinates = NULL;
215 double* newColorValues = NULL;
218 /* Test whether the number of colors is valid */
219 if ((numElementsArray[2] != numElementsArray[0]*numElementsArray[1]) &&
220 (numElementsArray[2] != numElementsArray[0]) &&
221 (numElementsArray[2] != 0))
226 if (numGons * numVerticesPerGon != numElementsArray[0]*numElementsArray[1])
230 newCoordinates = new double[3 * numElementsArray[0]*numElementsArray[1]];
232 catch (const std::exception& e)
241 if (numElementsArray[2] != this->numColors)
243 if (numElementsArray[2] > 0)
247 newColorValues = new double[numElementsArray[2]];
249 catch (const std::exception& e)
260 if (newCoordinates != NULL)
262 if (numGons * numVerticesPerGon > 0)
264 delete [] coordinates;
267 coordinates = newCoordinates;
269 numGons = numElementsArray[0];
270 numVerticesPerGon = numElementsArray[1];
273 if (newColorValues != NULL || numElementsArray[2] == 0)
275 if (this->numColors > 0)
277 delete [] colorValues;
280 colorValues = newColorValues;
281 this->numColors = numElementsArray[2];
286 if (newCoordinates != NULL)
288 delete [] newCoordinates;
291 if (newColorValues != NULL)
293 delete [] newColorValues;
300 double* NgonGeneralData::getColors(void)
305 void NgonGeneralData::setColors(double const* colors, int numElements)
307 if (numElements > numColors)
311 memcpy(colorValues, colors, numElements * sizeof(double));
314 int NgonGeneralData::getNumColors(void)