soc-2008-mxcurioni: merged changes to revision 15705
[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   double 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       return 0.0;
35     RGBImage image;
36     canvas->readColorPixels((int)iter->getProjectedX() - bound,
37                             (int)iter->getProjectedY() - bound,
38                             _filter.maskSize(),
39                             _filter.maskSize(),
40                             image);
41     return _filter.getSmoothedPixel<RGBImage>(&image, (int)iter->getProjectedX(),
42                                         (int)iter->getProjectedY());
43   }
44
45
46   double LocalAverageDepthF0D::operator()(Interface0DIterator& iter) {
47     Canvas * iViewer = Canvas::getInstance();
48     int bound = _filter.getBound();
49     
50     if( (iter->getProjectedX()-bound < 0) || (iter->getProjectedX()+bound>iViewer->width())
51         || (iter->getProjectedY()-bound < 0) || (iter->getProjectedY()+bound>iViewer->height()))
52       return 0.0;
53     GrayImage image ;
54     iViewer->readDepthPixels((int)iter->getProjectedX()-bound,(int)iter->getProjectedY()-bound,_filter.maskSize(),_filter.maskSize(),image);
55     return _filter.getSmoothedPixel(&image, (int)iter->getProjectedX(), (int)iter->getProjectedY());
56   }
57
58   float ReadMapPixelF0D::operator()(Interface0DIterator& iter) {
59     Canvas * canvas = Canvas::getInstance();
60     return canvas->readMapPixel(_mapName, _level, (int)iter->getProjectedX(), (int)iter->getProjectedY());
61   }
62
63   float ReadSteerableViewMapPixelF0D::operator()(Interface0DIterator& iter) {
64     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
65     float v = svm->readSteerableViewMapPixel(_orientation, _level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
66     return v;
67   }
68
69   float ReadCompleteViewMapPixelF0D::operator()(Interface0DIterator& iter) {
70     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
71     float v = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
72     return v;
73   }
74
75   float GetViewMapGradientNormF0D::operator()(Interface0DIterator& iter){
76     SteerableViewMap *svm = Canvas::getInstance()->getSteerableViewMap();
77     float pxy = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY());
78     float gx = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX()+_step, (int)iter->getProjectedY())
79       - pxy;
80     float gy = svm->readCompleteViewMapPixel(_level,(int)iter->getProjectedX(), (int)iter->getProjectedY()+_step)
81       - pxy;
82         float f = Vec2f(gx,gy).norm();
83     return f;
84   }
85 } // end of namespace Functions0D