Merging r50522 through r50572 from trunk into soc-2011-tomato
[blender.git] / source / blender / compositor / intern / COM_NodeOperation.cpp
index b02bcb6676ed76a6865f7638f386da503a645ef4..4ae114bd0315145c4a443713cddc41ec60331f02 100644 (file)
  *             Monique Dewanchand
  */
 
  *             Monique Dewanchand
  */
 
-#include "COM_NodeOperation.h"
 #include <typeinfo>
 #include <typeinfo>
+#include <stdio.h>
+
+#include "COM_NodeOperation.h"
 #include "COM_InputSocket.h"
 #include "COM_SocketConnection.h"
 #include "COM_defines.h"
 #include "COM_InputSocket.h"
 #include "COM_SocketConnection.h"
 #include "COM_defines.h"
-#include "stdio.h"
 
 
-NodeOperation::NodeOperation() {
-       this->resolutionInputSocketIndex = 0;
-       this->complex = false;
-       this->width = 0;
-       this->height = 0;
-       this->openCL = false;
+NodeOperation::NodeOperation() : NodeBase()
+{
+       this->m_resolutionInputSocketIndex = 0;
+       this->m_complex = false;
+       this->m_width = 0;
+       this->m_height = 0;
+       this->m_openCL = false;
+       this->m_btree = NULL;
 }
 
 }
 
-void NodeOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) {
+void NodeOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
+{
        unsigned int temp[2];
        unsigned int temp2[2];
        unsigned int temp[2];
        unsigned int temp2[2];
-       vector<InputSocket*> &inputsockets = this->getInputSockets();
+       vector<InputSocket *> &inputsockets = this->getInputSockets();
        
        
-       for (unsigned int index = 0 ; index < inputsockets.size();index++) {
-               InputSocketinputSocket = inputsockets[index];
+       for (unsigned int index = 0; index < inputsockets.size(); index++) {
+               InputSocket *inputSocket = inputsockets[index];
                if (inputSocket->isConnected()) {
                if (inputSocket->isConnected()) {
-                       if (index == this->resolutionInputSocketIndex) {
+                       if (index == this->m_resolutionInputSocketIndex) {
                                inputSocket->determineResolution(resolution, preferredResolution);
                                temp2[0] = resolution[0];
                                temp2[1] = resolution[1];
                                inputSocket->determineResolution(resolution, preferredResolution);
                                temp2[0] = resolution[0];
                                temp2[1] = resolution[1];
@@ -51,39 +55,61 @@ void NodeOperation::determineResolution(unsigned int resolution[], unsigned int
                        }
                }
        }
                        }
                }
        }
-       for (unsigned int index = 0 ; index < inputsockets.size();index++) {
-               InputSocketinputSocket = inputsockets[index];
+       for (unsigned int index = 0; index < inputsockets.size(); index++) {
+               InputSocket *inputSocket = inputsockets[index];
                if (inputSocket->isConnected()) {
                if (inputSocket->isConnected()) {
-                       if (index != resolutionInputSocketIndex) {
+                       if (index != this->m_resolutionInputSocketIndex) {
                                inputSocket->determineResolution(temp, temp2);
                        }
                }
        }
 }
                                inputSocket->determineResolution(temp, temp2);
                        }
                }
        }
 }
-void NodeOperation::setResolutionInputSocketIndex(unsigned int index) {
-       this->resolutionInputSocketIndex = index;
+void NodeOperation::setResolutionInputSocketIndex(unsigned int index)
+{
+       this->m_resolutionInputSocketIndex = index;
 }
 }
-void NodeOperation::initExecution() {
+void NodeOperation::initExecution()
+{
+       /* pass */
 }
 
 }
 
-void NodeOperation::initMutex() {
-       BLI_mutex_init(&mutex);
+void NodeOperation::initMutex()
+{
+       BLI_mutex_init(&this->m_mutex);
 }
 }
-void NodeOperation::deinitMutex() {
-       BLI_mutex_end(&mutex);
+
+void NodeOperation::lockMutex()
+{
+       BLI_mutex_lock(&this->m_mutex);
 }
 }
-void NodeOperation::deinitExecution() {
+
+void NodeOperation::unlockMutex()
+{
+       BLI_mutex_unlock(&this->m_mutex);
+}
+
+void NodeOperation::deinitMutex()
+{
+       BLI_mutex_end(&this->m_mutex);
 }
 }
-SocketReader* NodeOperation::getInputSocketReader(unsigned int inputSocketIndex) {
+
+void NodeOperation::deinitExecution()
+{
+       /* pass */
+}
+SocketReader *NodeOperation::getInputSocketReader(unsigned int inputSocketIndex)
+{
        return this->getInputSocket(inputSocketIndex)->getReader();
 }
        return this->getInputSocket(inputSocketIndex)->getReader();
 }
-NodeOperation* NodeOperation::getInputOperation(unsigned int inputSocketIndex) {
+NodeOperation *NodeOperation::getInputOperation(unsigned int inputSocketIndex)
+{
        return this->getInputSocket(inputSocketIndex)->getOperation();
 }
 
        return this->getInputSocket(inputSocketIndex)->getOperation();
 }
 
-void NodeOperation::getConnectedInputSockets(vector<InputSocket*> *sockets) {
-       vector<InputSocket*> &inputsockets = this->getInputSockets();
-       for (vector<InputSocket*>::iterator iterator = inputsockets.begin() ; iterator!= inputsockets.end() ; iterator++) {
+void NodeOperation::getConnectedInputSockets(vector<InputSocket *> *sockets)
+{
+       vector<InputSocket *> &inputsockets = this->getInputSockets();
+       for (vector<InputSocket *>::iterator iterator = inputsockets.begin(); iterator != inputsockets.end(); iterator++) {
                InputSocket *socket = *iterator;
                if (socket->isConnected()) {
                        sockets->push_back(socket);
                InputSocket *socket = *iterator;
                if (socket->isConnected()) {
                        sockets->push_back(socket);
@@ -91,24 +117,33 @@ void NodeOperation::getConnectedInputSockets(vector<InputSocket*> *sockets) {
        }
 }
 
        }
 }
 
-bool NodeOperation::determineDependingAreaOfInterest(rcti * input, ReadBufferOperation *readOperation, rcti* output) {
+bool NodeOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
+{
        if (this->isInputNode()) {
        if (this->isInputNode()) {
-               BLI_init_rcti(output, input->xmin, input->xmax, input->ymin, input->ymax);
+               BLI_rcti_init(output, input->xmin, input->xmax, input->ymin, input->ymax);
                return false;
                return false;
-       } else {
-               unsigned int index;
-               vector<InputSocket*> &inputsockets = this->getInputSockets();
-       
-               for (index = 0 ; index < inputsockets.size() ; index++) {
-                       InputSocket* inputsocket = inputsockets[index];
-                       if (inputsocket->isConnected()) {
-                               NodeOperation* inputoperation = (NodeOperation*)inputsocket->getConnection()->getFromNode();
-                               bool result = inputoperation->determineDependingAreaOfInterest(input, readOperation, output);
-                               if (result) {
-                                       return true;
+       }
+       else {
+               rcti tempOutput;
+               bool first = true;
+               for (int i = 0 ; i < getNumberOfInputSockets() ; i ++) {
+                       NodeOperation * inputOperation = this->getInputOperation(i);
+                       if (inputOperation && inputOperation->determineDependingAreaOfInterest(input, readOperation, &tempOutput)) {
+                               if (first) {
+                                       output->xmin = tempOutput.xmin;
+                                       output->ymin = tempOutput.ymin;
+                                       output->xmax = tempOutput.xmax;
+                                       output->ymax = tempOutput.ymax;
+                                       first = false;
+                               }
+                               else {
+                                       output->xmin = MIN2(output->xmin, tempOutput.xmin);
+                                       output->ymin = MIN2(output->ymin, tempOutput.ymin);
+                                       output->xmax = MAX2(output->xmax, tempOutput.xmax);
+                                       output->ymax = MAX2(output->ymax, tempOutput.ymax);
                                }
                        }
                }
                                }
                        }
                }
-               return false;
+               return !first;
        }
 }
        }
 }