Merged changes in the trunk up to revision 28247.
[blender.git] / source / blender / freestyle / intern / stroke / AdvancedFunctions0D.cpp
1
2 //
3 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
4 //   with this source distribution. 
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 ///////////////////////////////////////////////////////////////////////////////
21
22 # include "../view_map/Functions0D.h"
23 # include "AdvancedFunctions0D.h"
24 # include "../view_map/SteerableViewMap.h"
25 # include "Canvas.h"
26
27 namespace Functions0D {
28
29   int DensityF0D::operator()(Interface0DIterator& iter) {
30     Canvas* canvas = Canvas::getInstance();
31     int bound = _filter.getBound();
32     if( (iter->getProjectedX()-bound < 0) || (iter->getProjectedX()+bound>canvas->width())
33          || (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>canvas->height())) {
34       result = 0.0;
35           return 0;
36         }
37     RGBImage image;
38     canvas->readColorPixels((int)iter->getProjectedX() - bound,
39                             (int)iter->getProjectedY() - bound,
40                             _filter.maskSize(),
41                             _filter.maskSize(),
42                             image);
43     result = _filter.getSmoothedPixel<RGBImage>(&image, (int)iter->getProjectedX(),
44                                         (int)iter->getProjectedY());
45         return 0;
46   }
47
48
49   int LocalAverageDepthF0D::operator()(Interface0DIterator& iter) {
50     Canvas * iViewer = Canvas::getInstance();
51     int bound = _filter.getBound();
52     
53     if( (iter->getProjectedX()-bound < 0) || (iter->getProjectedX()+bound>iViewer->width())
54          || (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>iViewer->height())) {
55       result = 0.0;
56           return 0;
57         }
58     GrayImage image ;
59     iViewer->readDepthPixels((int)iter->getProjectedX()-bound,(int)iter->getProjectedY()-bound,_filter.maskSize(),_filter.maskSize(),image);
60     result = _filter.getSmoothedPixel(&image, (int)iter->getProjectedX(), (int)iter->getProjectedY());
61         return 0;
62   }
63
64   int ReadMapPixelF0D::operator()(Interface0DIterator& iter) {
65     Canvas * canvas = Canvas::getInstance();
66     result = canvas->readMapPixel(_mapName, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY());
67         return 0;
68   }
69
70   int ReadSteerableViewMapPixelF0D::operator()(Interface0DIterator& iter) {
71     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
72     result = svm->readSteerableViewMapPixel(_orientation, _level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
73     return 0;
74   }
75
76   int ReadCompleteViewMapPixelF0D::operator()(Interface0DIterator& iter) {
77     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
78     result = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
79     return 0;
80   }
81
82   int GetViewMapGradientNormF0D::operator()(Interface0DIterator& iter){
83     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
84     float pxy = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
85     float gx = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX()+_step, (int)iter->getProjectedY())
86       - pxy;
87     float gy = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY()+_step)
88       - pxy;
89         result = Vec2f(gx,gy).norm();
90     return 0;
91   }
92 } // end of namespace Functions0D