summaryrefslogtreecommitdiff
path: root/modules/graphic_objects/src/cpp/createObjectData.cpp
blob: c200dd22131861349457a9929b982118e58b1c6a (plain)
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
/*
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2012 - Pedro Arthur dos S. Souza
 * Copyright (C) 2012 - Caio Lucas dos S. Souza
 *
 * 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
 *
 */
#include <stdio.h>
#include <string.h>

extern "C"
{
#include "createGraphicObject.h"
#include "deleteGraphicObject.h"
#include "returnType.h"
#include "getGraphicObjectProperty.h"
#include "setGraphicObjectProperty.h"
#include "graphicObjectProperties.h"

    int createObject3dData(int obj, int newObj, int type);

}
/*
 * Create the data object for the newObj
 * and copy the data from obj to newObj.
 */
int createObject3dData(int obj, int newObj, int type)
{
    double *pvecx, *pvecy, *pvecz;
    int dataObj = 0;
    int numElementsArray[3];
    BOOL result;
    int *ptr;

    dataObj = createDataObject(newObj, type);

    if (dataObj == 0)
    {
        return 0;
    }


    if (type == __GO_PLOT3D__ || type == __GO_GRAYPLOT__)
    {
        ptr = &numElementsArray[0];
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_NUM_X__, jni_int, (void**)&ptr);
        ptr = &numElementsArray[1];
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_NUM_Y__, jni_int, (void**)&ptr);
        ptr = &numElementsArray[2];
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_NUM_Z__, jni_int, (void**)&ptr);

        int grid[] = {1, numElementsArray[0], 1, numElementsArray[1]};
        result = setGraphicObjectProperty(newObj, __GO_DATA_MODEL_GRID_SIZE__, grid, jni_int_vector, 4);
    }
    else if (type == __GO_FAC3D__)
    {
        int ng = 0, nvg = 0;
        int *png = &ng, *pnvg = &nvg;
        int numColors;
        int *pNumColors = &numColors;
        double *Colors;
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_NUM_GONS__, jni_int, (void**) &png);
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_NUM_VERTICES_PER_GON__, jni_int, (void**) &pnvg);
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_NUM_COLORS__, jni_int, (void**)&pNumColors);
        getGraphicObjectProperty(obj, __GO_DATA_MODEL_COLORS__, jni_double_vector, (void**)&Colors);

        numElementsArray[0] = numElementsArray[1] = numElementsArray[2] = ng * nvg;

        int elements[] = {ng, nvg, numColors};
        result = setGraphicObjectProperty(newObj, __GO_DATA_MODEL_NUM_ELEMENTS_ARRAY__, &elements, jni_int_vector, 3);
        setGraphicObjectProperty(newObj, __GO_DATA_MODEL_COLORS__, Colors, jni_double_vector, numColors);
    }
    else
    {
        return 0;
    }


    if (result == 0)
    {
        deleteDataObject(dataObj);
        return 0;
    }

    getGraphicObjectProperty(obj, __GO_DATA_MODEL_X__, jni_double_vector, (void**)&pvecx);
    getGraphicObjectProperty(obj, __GO_DATA_MODEL_Y__, jni_double_vector, (void**)&pvecy);
    getGraphicObjectProperty(obj, __GO_DATA_MODEL_Z__, jni_double_vector, (void**)&pvecz);

    setGraphicObjectProperty(newObj, __GO_DATA_MODEL_X__, pvecx, jni_double_vector, numElementsArray[0]);
    setGraphicObjectProperty(newObj, __GO_DATA_MODEL_Y__, pvecy, jni_double_vector, numElementsArray[1]);
    setGraphicObjectProperty(newObj, __GO_DATA_MODEL_Z__, pvecz, jni_double_vector, numElementsArray[2]);

    return dataObj;
}