Math Node:
[blender.git] / source / blender / compositor / nodes / COM_MathNode.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor: 
19  *              Jeroen Bakker 
20  *              Monique Dewanchand
21  */
22
23 #include "COM_MathNode.h"
24 #include "COM_MathBaseOperation.h"
25 #include "COM_ExecutionSystem.h"
26
27 void MathNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
28 {
29         MathBaseOperation *operation = NULL;
30         
31         switch (this->getbNode()->custom1) {
32                 case 0: /* Add */
33                         operation = new MathAddOperation();
34                         break;
35                 case 1: /* Subtract */
36                         operation = new MathSubtractOperation();
37                         break;
38                 case 2: /* Multiply */
39                         operation = new MathMultiplyOperation();
40                         break;
41                 case 3: /* Divide */
42                         operation = new MathDivideOperation();
43                         break;
44                 case 4: /* Sine */
45                         operation = new MathSineOperation();
46                         break;
47                 case 5: /* Cosine */
48                         operation = new MathCosineOperation();
49                         break;
50                 case 6: /* Tangent */
51                         operation = new MathTangentOperation();
52                         break;
53                 case 7: /* Arc-Sine */
54                         operation = new MathArcSineOperation();
55                         break;
56                 case 8: /* Arc-Cosine */
57                         operation = new MathArcCosineOperation();
58                         break;
59                 case 9: /* Arc-Tangent */
60                         operation = new MathArcTangentOperation();
61                         break;
62                 case 10: /* Power */
63                         operation = new MathPowerOperation();
64                         break;
65                 case 11: /* Logarithm */
66                         operation = new MathLogarithmOperation();
67                         break;
68                 case 12: /* Minimum */
69                         operation = new MathMinimumOperation();
70                         break;
71                 case 13: /* Maximum */
72                         operation = new MathMaximumOperation();
73                         break;
74                 case 14: /* Round */
75                         operation = new MathRoundOperation();
76                         break;
77                 case 15: /* Less Than */
78                         operation = new MathLessThanOperation();
79                         break;
80                 case 16: /* Greater Than */
81                         operation = new MathGreaterThanOperation();
82                         break;
83                 case 17: /* Modulo */
84                         operation = new MathModuloOperation();
85                         break;
86         }
87         
88         if (operation != NULL) {
89                 bool useClamp = this->getbNode()->custom2;
90
91                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
92                 this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
93                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
94
95                 operation->setUseClamp(useClamp);
96
97                 graph->addOperation(operation);
98         }
99 }