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
13 #include "TriangleMeshData.hxx"
14 #include "DataProperties.hxx"
20 #include "graphicObjectProperties.h"
23 TriangleMeshData::TriangleMeshData(void)
33 /* To be correctly implemented */
34 TriangleMeshData::TriangleMeshData(unsigned int numberVertices, unsigned int numberTriangles)
36 vertices = new double[3 * numberVertices];
38 indices = new unsigned int[3 * numberTriangles];
40 this->numberVertices = numberVertices;
41 this->numberTriangles = numberTriangles;
44 /* To be correctly implemented */
45 TriangleMeshData::~TriangleMeshData(void)
47 if (numberVertices > 0)
53 if (numberTriangles > 0)
60 int TriangleMeshData::getPropertyFromName(int propertyName)
64 case __GO_DATA_MODEL_NUM_VERTICES__ :
66 case __GO_DATA_MODEL_NUM_INDICES__ :
68 case __GO_DATA_MODEL_X__ :
70 case __GO_DATA_MODEL_Y__ :
72 case __GO_DATA_MODEL_Z__ :
74 case __GO_DATA_MODEL_COORDINATES__ :
76 case __GO_DATA_MODEL_INDICES__ :
78 case __GO_DATA_MODEL_VALUES__ :
81 return Data3D::getPropertyFromName(propertyName);
87 int TriangleMeshData::setDataProperty(int property, void const* value, int numElements)
92 return setNumVertices(*((unsigned int const*) value));
94 return setNumIndices(*((unsigned int const*) value));
96 setDataX((double const*) value, numElements);
99 setDataY((double const*) value, numElements);
102 setDataZ((double const*) value, numElements);
105 setVertices((double const*) value, numElements);
108 setIndices((unsigned int const*) value, numElements);
111 setValues((double const*) value, numElements);
114 return Data3D::setDataProperty(property, value, numElements);
120 void TriangleMeshData::getDataProperty(int property, void **_pvData)
125 ((int *)*_pvData)[0] = getNumVertices();
128 ((int *)*_pvData)[0] = getNumIndices();
131 *_pvData = getVertices();
134 *_pvData = getIndices();
137 *_pvData = getValues();
140 Data3D::getDataProperty(property, _pvData);
144 unsigned int TriangleMeshData::getNumVertices(void)
146 return numberVertices;
150 * Values are considered as being specified per-vertex for now
153 int TriangleMeshData::setNumVertices(unsigned int numVertices)
157 if (numVertices == 0 && numberVertices > 0)
167 if (numVertices != this->numberVertices)
169 double* newVertices = NULL;
170 double* newValues = NULL;
174 newVertices = new double[3 * numVertices];
176 catch (const std::exception& e)
184 newValues = new double[numVertices];
186 catch (const std::exception& e)
194 if (this->numberVertices > 0)
200 vertices = newVertices;
203 this->numberVertices = numVertices;
209 /* Failed allocation, nothing is set */
210 if (newVertices != NULL)
212 delete [] newVertices;
215 if (newValues != NULL)
226 unsigned int TriangleMeshData::getNumIndices(void)
228 return numberTriangles;
231 int TriangleMeshData::setNumIndices(unsigned int numIndices)
235 if (numIndices != this->numberTriangles)
237 unsigned int* newIndices = NULL;
241 newIndices = new unsigned int[3 * numIndices];
243 catch (const std::exception& e)
251 if (this->numberTriangles > 0)
256 indices = newIndices;
258 this->numberTriangles = numIndices;
262 /* Failed allocation, nothing is set */
263 if (newIndices != NULL)
265 delete [] newIndices;
274 double* TriangleMeshData::getVertices(void)
279 void TriangleMeshData::setVertices(double const* vertices, unsigned int numElements)
281 if (numElements <= numberVertices)
283 memcpy(this->vertices, vertices, numElements * 3 * sizeof(double));
287 unsigned int* TriangleMeshData::getIndices(void)
292 void TriangleMeshData::setIndices(unsigned int const* indices, unsigned int numElements)
294 if (numElements <= numberTriangles)
296 memcpy(this->indices, indices, numElements * 3 * sizeof(unsigned int));
300 void TriangleMeshData::setDataX(double const* data, unsigned int numElements)
302 if (numElements <= numberVertices)
304 for (unsigned int i = 0 ; i < numElements ; i++)
306 vertices[3 * i] = data[i];
311 void TriangleMeshData::setDataY(double const* data, unsigned int numElements)
313 if (numElements <= numberVertices)
315 for (unsigned int i = 0 ; i < numElements ; i++)
317 vertices[3 * i + 1] = data[i];
322 void TriangleMeshData::setDataZ(double const* data, unsigned int numElements)
324 if (numElements <= numberVertices)
326 for (unsigned int i = 0; i < numElements; i++)
328 vertices[3 * i + 2] = data[i];
333 void TriangleMeshData::setValues(double const* data, unsigned int numElements)
335 if (numElements <= numberVertices)
337 memcpy(this->values, data, numElements * sizeof(double));
341 double* TriangleMeshData::getValues(void)
346 unsigned int TriangleMeshData::scilabIndexToIndex(unsigned int scilabIndex)
348 return (scilabIndex - 1);
351 void TriangleMeshData::resetCoordinates(void)
353 for (unsigned int i = 0; i < numberVertices; i++)
355 vertices[3 * i] = 0.0;
356 vertices[3 * i + 1] = 0.0;
357 vertices[3 * i + 2] = 0.0;