Added switch in dilate/erode between old (Step) and new (Distance)
[blender.git] / source / blender / compositor / nodes / COM_DilateErodeNode.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_DilateErodeNode.h"
24 #include "DNA_scene_types.h"
25 #include "COM_ExecutionSystem.h"
26 #include "COM_DilateErodeOperation.h"
27 #include "COM_AntiAliasOperation.h"
28 #include "BLI_math.h"
29
30 DilateErodeNode::DilateErodeNode(bNode *editorNode): Node(editorNode)
31 {
32 }
33
34 void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context)
35 {
36         
37         bNode *editorNode = this->getbNode();
38         if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE) {
39                 DilateErodeDistanceOperation *operation = new DilateErodeDistanceOperation();
40                 operation->setDistance(editorNode->custom2);
41                 operation->setInset(editorNode->custom3);
42                 
43                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0));
44         
45                 if (editorNode->custom3 < 2.0f) {
46                         AntiAliasOperation * antiAlias = new AntiAliasOperation();
47                         addLink(graph, operation->getOutputSocket(), antiAlias->getInputSocket(0));
48                         this->getOutputSocket(0)->relinkConnections(antiAlias->getOutputSocket(0));
49                         graph->addOperation(antiAlias);
50                 } else {
51                         this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
52                 }
53                 graph->addOperation(operation);
54         } else {
55                 if (editorNode->custom2 > 0) {
56                         DilateStepOperation * operation = new DilateStepOperation();
57                         operation->setIterations(editorNode->custom2);
58                         this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0));
59                         this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
60                         graph->addOperation(operation);
61                 } else {
62                         ErodeStepOperation * operation = new ErodeStepOperation();
63                         operation->setIterations(-editorNode->custom2);
64                         this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0));
65                         this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
66                         graph->addOperation(operation);
67                 }
68         }
69 }