aboutsummaryrefslogtreecommitdiff
path: root/tools/CurveEditor/source/GraphEditorTestApp/CurveEditorTestApp.cpp
blob: 9aa42bd4d7a2ab16c6c2b864d92a7aa76bf8f0ea (plain) (blame)
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#include "CurveEditorTestApp.h"
#include "ui_CurveEditorTestApp.h"
#include "CurveEditorMainWindow.h"
#include <QtCore/QDebug>

CurveEditorTestApp::CurveEditorTestApp(QWidget *parent, Qt::WindowFlags flags)
    : QWidget(parent, flags)
	, ui(new Ui::CurveEditorTestAppClass())
	, _curveEditor(new CurveEditorMainWindow(this))
{
    ui->setupUi(this);

	bool val = connect(_curveEditor, SIGNAL(CurveAttributeChanged(nvidia::CurveEditor::CurveAttribute*)), this, SLOT(onCurveAttributeChanged(nvidia::CurveEditor::CurveAttribute*)));
    val = connect(_curveEditor, SIGNAL(ColorAttributeChanged(nvidia::CurveEditor::ColorAttribute*)), this, SLOT(onColorAttributeChanged(nvidia::CurveEditor::ColorAttribute*)) );
    val = connect(_curveEditor, SIGNAL(ReloadColorAttributeTexture(nvidia::CurveEditor::ColorAttribute*, bool, int)), this, SLOT(onReloadColorAttributeTexture(nvidia::CurveEditor::ColorAttribute*, bool, int)) );

    _curveEditor->hide();

    _fillCurveAttributes();
    _fillColorAttributes();
}

CurveEditorTestApp::~CurveEditorTestApp()
{

}

void CurveEditorTestApp::on_btnCurveEditor_clicked(void)
{
    _curveEditor->show();
}

void CurveEditorTestApp::onCurveAttributeChanged(CurveAttribute* attribute)
{
    if (attribute)
    {
        qDebug()<<"-------------------------onCurveAttributeChanged---------------------------------";
        qDebug()<< attribute->getName().c_str() <<": changed";

        size_t count = attribute->curve.getControlPointCount();
        for (int i = 0; i < count; ++i)
        {
            const ControlPoint& ctrlPnt = attribute->curve.getControlPoint(i);
            if (attribute->getName() == "Y" && i == 9 && ctrlPnt.value.y() > 2.5)
            {
                int j = 0;
                ++j;
            }
            qDebug()<< ctrlPnt.value;
        }
    }
}

void CurveEditorTestApp::onColorAttributeChanged(ColorAttribute* attribute)
{
    if (attribute)
    {
        qDebug()<<"----------------------------------------------------------";
        qDebug()<< attribute->getName().c_str() <<": changed";
    }
}

void CurveEditorTestApp::onReloadColorAttributeTexture(ColorAttribute* attribute, bool reloadColorTex, int selectedCtrlPntIndex)
{
    if (attribute)
    {
        qDebug()<<"----------------------------------------------------------";
        qDebug()<< attribute->getName().c_str() <<": reloadColorTex" << reloadColorTex<< " selectedCtrlPntIndex: "<< selectedCtrlPntIndex;
    }
}

void CurveEditorTestApp::_fillCurveAttributes()
{
    {
        std::vector<CurveAttributeBase*>   attributes;

        CurveAttributeGroup* attrGroup = new CurveAttributeGroup("Position");
        attributes.push_back(attrGroup);

        CurveAttribute* attribute = new CurveAttribute("X", false, true, true);
        //attribute->color = QColor(0x11, 0x22, 0x33, 0x44);//
        attribute->color = QColor("#FF0000");
        attrGroup->attributes.push_back(attribute);

        {
            Curve& curve = attribute->curve;
            curve.initValueRange(QPointF(-1, 0), QPointF(6, 1));
            curve.appendControlPoint(ControlPoint(-1, 1, eDiscret));
            curve.appendControlPoint(ControlPoint(0, 0, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(0.25, 0.5, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(0.5, 0, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(0.75, 0.5, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(1, 0, eCatmullRomSpline));
            {
                BezierSplineData splineData;
                splineData.inLen = 0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(2, 1, eBezierSpline, splineData));
                splineData.inLen = 0.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(3, 0, eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(4, 1, eBezierSpline, splineData));
            }
            curve.appendControlPoint(ControlPoint(5, 0, eLinear));
            curve.appendControlPoint(ControlPoint(6, 1, eLinear));
        }

        attribute = new CurveAttribute("Y", true);
        attribute->color = QColor("#FFFF00");
        attrGroup->attributes.push_back(attribute);
        {
            Curve& curve = attribute->curve;
            curve.initValueRange(QPointF(-2, 0), QPointF(8, 2));
            curve.appendControlPoint(ControlPoint(-2, 2, eDiscret));
            curve.appendControlPoint(ControlPoint(1, 0, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(1.25, 0.5, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(1.5, 0, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(1.75, 0.5, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(2, 0, eCatmullRomSpline));
            {
                BezierSplineData splineData;
                splineData.inLen = 0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(3, 1, eBezierSpline, splineData));
                splineData.inLen = 0.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(4, 0, eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(5, 1, eBezierSpline, splineData));
            }
            curve.appendControlPoint(ControlPoint(6, 0, eLinear));
            curve.appendControlPoint(ControlPoint(8, 2, eLinear));
        }

        attribute = new CurveAttribute("Z", true);
        attribute->color = QColor("#00FF00");
        attrGroup->attributes.push_back(attribute);
        {
            Curve& curve = attribute->curve;
            curve.initValueRange(QPointF(-2, 0), QPointF(8, 4));
            curve.appendControlPoint(ControlPoint(-2, 2, eDiscret));
            curve.appendControlPoint(ControlPoint(1, 0, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(1.5, 4, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(1.75, 0.5, eCatmullRomSpline));
            curve.appendControlPoint(ControlPoint(2, 1, eCatmullRomSpline));
            {
                BezierSplineData splineData;
                splineData.inLen = 0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(3, 3, eBezierSpline, splineData));
                splineData.inLen = 0.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(4, 0, eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(5, 2, eBezierSpline, splineData));
            }
            curve.appendControlPoint(ControlPoint(6, 0, eLinear));
            curve.appendControlPoint(ControlPoint(8, 4, eLinear));
        }

        attribute = new CurveAttribute("AddRemove_ChangeTangent", true, true, true);

        attributes.push_back(attribute);

        {
            Curve& curve = attribute->curve;
            curve.initValueRange(QPointF(-1, 0), QPointF(4, 255));
            curve.appendControlPoint(ControlPoint(-1, 0, eLinear));
            {
                BezierSplineData splineData;
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ControlPoint(4, 255, eBezierSpline, splineData));
            }
        }

        
        _curveAttributes = attributes;
        _curveEditor->setCurveAttributes(_curveAttributes);
    }
}

void CurveEditorTestApp::_fillColorAttributes()
{
    {
        std::vector<ColorAttribute*>   attributes;

        ColorAttribute* attribute = new ColorAttribute("Hair Color");
        attributes.push_back(attribute);

        {
            ColorCurve& colorCurve = attribute->colorCurve;
            colorCurve.initValueRange(0, 1);
            ColorCurve& alphaCurve = attribute->alphaCurve;
            alphaCurve.initValueRange(0, 1);

            colorCurve.appendControlPoint(ColorControlPoint(0, QColor(255, 0, 0, 255), eLinear));
            colorCurve.appendControlPoint(ColorControlPoint(1, QColor(0, 255, 0, 255), eLinear));

            alphaCurve.appendControlPoint(ColorControlPoint(0, QColor(0, 0, 0, 0), eLinear));
            alphaCurve.appendControlPoint(ColorControlPoint(1, QColor(0, 0, 0, 255), eLinear));
        }

        attribute = new ColorAttribute("XColor", true, true, true);
        //attribute->color = QColor(0x11, 0x22, 0x33, 0x44);//
        attributes.push_back(attribute);

        {
            ColorCurve& curve = attribute->colorCurve;
            curve.initValueRange(-1, 6);
            curve.appendControlPoint(ColorControlPoint(-1, QColor(255, 0, 0, 0), eDiscret));
            curve.appendControlPoint(ColorControlPoint(0, QColor(0, 255, 0, 255), eCatmullRomSpline));
            curve.appendControlPoint(ColorControlPoint(0.25, QColor(128, 0, 255, 128), eCatmullRomSpline));
            curve.appendControlPoint(ColorControlPoint(0.5, QColor(255, 0, 0, 255), eCatmullRomSpline));
            curve.appendControlPoint(ColorControlPoint(0.75, QColor(0, 255, 0, 128), eCatmullRomSpline));
            curve.appendControlPoint(ColorControlPoint(1, QColor(0, 0, 255, 0), eCatmullRomSpline));
            {
                BezierSplineData splineData;
                splineData.inLen = 0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ColorControlPoint(2, QColor(255, 0, 0, 255), eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ColorControlPoint(3, QColor(0, 255, 0, 128), eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                curve.appendControlPoint(ColorControlPoint(4, QColor(0, 0, 255, 0), eBezierSpline, splineData));
            }
            curve.appendControlPoint(ColorControlPoint(5, QColor(255, 0, 0, 255), eLinear));
            curve.appendControlPoint(ColorControlPoint(6, QColor(0, 255, 0, 128), eLinear));
        }

        attribute = new ColorAttribute("Color_NoAddRemove_NotChangeTangent", true, false, false);

        attributes.push_back(attribute);

        {
            ColorCurve& colorCurve = attribute->colorCurve;
            colorCurve.initValueRange(-1, 4);
            colorCurve.appendControlPoint(ColorControlPoint(-1, QColor(255, 0, 0, 0), eLinear));
            colorCurve.appendControlPoint(ColorControlPoint(0, QColor(0, 255, 0, 255), eLinear));
            colorCurve.appendControlPoint(ColorControlPoint(0.5, QColor(0, 0, 255, 255), eLinear));
            colorCurve.appendControlPoint(ColorControlPoint(1, QColor(255, 0, 0, 0), eLinear));
            {
                BezierSplineData splineData;
                splineData.inLen = 0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                colorCurve.appendControlPoint(ColorControlPoint(2, QColor(0, 255, 0, 255), eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                colorCurve.appendControlPoint(ColorControlPoint(3, QColor(0, 0, 255, 128), eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                colorCurve.appendControlPoint(ColorControlPoint(4, QColor(255, 0, 0, 0), eBezierSpline, splineData));
            }

            ColorCurve& alphaCurve = attribute->alphaCurve;
            alphaCurve.initValueRange(-1, 4);
            alphaCurve.appendControlPoint(ColorControlPoint(-1, QColor(0, 0, 0, 0), eDiscret));
            alphaCurve.appendControlPoint(ColorControlPoint(1, QColor(0, 0, 0, 255), eLinear));
            alphaCurve.appendControlPoint(ColorControlPoint(2, QColor(0, 0, 0, 80), eLinear));
            alphaCurve.appendControlPoint(ColorControlPoint(4, QColor(0, 0, 0, 255), eLinear));
        }

        attribute = new ColorAttribute("Color_AddRemove_ChangeTangent", true, true, true);

        attributes.push_back(attribute);

        {
            ColorCurve& colorCurve = attribute->colorCurve;
            colorCurve.initValueRange(-1, 4);
            colorCurve.appendControlPoint(ColorControlPoint(-1, QColor(255, 0, 0, 0), eLinear));
            //colorCurve.appendControlPoint(ColorControlPoint(0, QColor(0, 255, 0, 255), eLinear));
            //colorCurve.appendControlPoint(ColorControlPoint(0.5, QColor(0, 0, 255, 255), eLinear));
            //colorCurve.appendControlPoint(ColorControlPoint(1, QColor(255, 0, 0, 0), eLinear));
            {
                BezierSplineData splineData;
                //splineData.inLen = 0;
                //splineData.inTan = 0;
                //splineData.outLen = 1.0;
                //splineData.outTan = 0;
                //colorCurve.appendControlPoint(ColorControlPoint(2, QColor(0, 255, 0, 255), eBezierSpline, splineData));
                //splineData.inLen = 1.0;
                //splineData.inTan = 0;
                //splineData.outLen = 1.0;
                //splineData.outTan = 0;
                //colorCurve.appendControlPoint(ColorControlPoint(3, QColor(0, 0, 255, 128), eBezierSpline, splineData));
                splineData.inLen = 1.0;
                splineData.inTan = 0;
                splineData.outLen = 1.0;
                splineData.outTan = 0;
                colorCurve.appendControlPoint(ColorControlPoint(4, QColor(0, 255, 0, 0), eBezierSpline, splineData));
            }

            ColorCurve& alphaCurve = attribute->alphaCurve;
            alphaCurve.initValueRange(-1, 4);
            alphaCurve.appendControlPoint(ColorControlPoint(-1, QColor(0, 0, 0, 0), eDiscret));
            //alphaCurve.appendControlPoint(ColorControlPoint(1, QColor(0, 0, 0, 255), eLinear));
            //alphaCurve.appendControlPoint(ColorControlPoint(2, QColor(0, 0, 0, 80), eLinear));
            alphaCurve.appendControlPoint(ColorControlPoint(4, QColor(0, 0, 0, 255), eLinear));
        }

        _colorAttributes = attributes;
        _curveEditor->setColorCurveAttributes(_colorAttributes);
    }
}