style cleanup: braces, compositor
[blender.git] / source / blender / compositor / intern / COM_NodeOperation.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_NodeOperation.h"
24 #include <typeinfo>
25 #include "COM_InputSocket.h"
26 #include "COM_SocketConnection.h"
27 #include "COM_defines.h"
28 #include "stdio.h"
29
30 NodeOperation::NodeOperation() {
31         this->resolutionInputSocketIndex = 0;
32         this->complex = false;
33         this->width = 0;
34         this->height = 0;
35         this->openCL = false;
36 }
37
38 void NodeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) {
39         unsigned int temp[2];
40         unsigned int temp2[2];
41         vector<InputSocket*> &inputsockets = this->getInputSockets();
42         
43         for (unsigned int index = 0 ; index < inputsockets.size();index++) {
44                 InputSocket* inputSocket = inputsockets[index];
45                 if (inputSocket->isConnected()) {
46                         if (index == this->resolutionInputSocketIndex) {
47                                 inputSocket->determineResolution(resolution, preferredResolution);
48                                 temp2[0] = resolution[0];
49                                 temp2[1] = resolution[1];
50                                 break;
51                         }
52                 }
53         }
54         for (unsigned int index = 0 ; index < inputsockets.size();index++) {
55                 InputSocket* inputSocket = inputsockets[index];
56                 if (inputSocket->isConnected()) {
57                         if (index != resolutionInputSocketIndex) {
58                                 inputSocket->determineResolution(temp, temp2);
59                         }
60                 }
61         }
62 }
63 void NodeOperation::setResolutionInputSocketIndex(unsigned int index) {
64         this->resolutionInputSocketIndex = index;
65 }
66 void NodeOperation::initExecution() {
67 }
68
69 void NodeOperation::initMutex() {
70         BLI_mutex_init(&mutex);
71 }
72 void NodeOperation::deinitMutex() {
73         BLI_mutex_end(&mutex);
74 }
75 void NodeOperation::deinitExecution() {
76 }
77 SocketReader* NodeOperation::getInputSocketReader(unsigned int inputSocketIndex) {
78         return this->getInputSocket(inputSocketIndex)->getReader();
79 }
80 NodeOperation* NodeOperation::getInputOperation(unsigned int inputSocketIndex) {
81         return this->getInputSocket(inputSocketIndex)->getOperation();
82 }
83
84 void NodeOperation::getConnectedInputSockets(vector<InputSocket*> *sockets) {
85         vector<InputSocket*> &inputsockets = this->getInputSockets();
86         for (vector<InputSocket*>::iterator iterator = inputsockets.begin() ; iterator!= inputsockets.end() ; iterator++) {
87                 InputSocket *socket = *iterator;
88                 if (socket->isConnected()) {
89                         sockets->push_back(socket);
90                 }
91         }
92 }
93
94 bool NodeOperation::determineDependingAreaOfInterest(rcti * input, ReadBufferOperation *readOperation, rcti* output) {
95         if (this->isInputNode()) {
96                 BLI_init_rcti(output, input->xmin, input->xmax, input->ymin, input->ymax);
97                 return false;
98         }
99         else {
100                 unsigned int index;
101                 vector<InputSocket*> &inputsockets = this->getInputSockets();
102         
103                 for (index = 0 ; index < inputsockets.size() ; index++) {
104                         InputSocket* inputsocket = inputsockets[index];
105                         if (inputsocket->isConnected()) {
106                                 NodeOperation* inputoperation = (NodeOperation*)inputsocket->getConnection()->getFromNode();
107                                 bool result = inputoperation->determineDependingAreaOfInterest(input, readOperation, output);
108                                 if (result) {
109                                         return true;
110                                 }
111                         }
112                 }
113                 return false;
114         }
115 }