Blender  V2.93
AdvancedFunctions1D.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "AdvancedFunctions1D.h"
23 #include "Canvas.h"
24 
25 #include "../view_map/SteerableViewMap.h"
26 
28 
30 {
32  Interface0DIterator it = inter.pointsBegin(_sampling);
33  Interface0DIterator itnext = it;
34  ++itnext;
35  FEdge *fe;
36  unsigned nSVM;
37  vector<float> values;
38 
39  while (!itnext.isEnd()) {
40  Interface0D &i0D = (*it);
41  Interface0D &i0Dnext = (*itnext);
42  fe = i0D.getFEdge(i0Dnext);
43  if (fe == nullptr) {
44  cerr << "GetSteerableViewMapDensityF1D warning: no FEdge between " << i0D.getId() << " and "
45  << i0Dnext.getId() << endl;
46  // compute the direction between these two ???
47  Vec2f dir = i0Dnext.getPoint2D() - i0D.getPoint2D();
48  nSVM = svm->getSVMNumber(dir);
49  }
50  else {
51  nSVM = svm->getSVMNumber(fe->getId().getFirst());
52  }
53  Vec2r m((i0D.getProjectedX() + i0Dnext.getProjectedX()) / 2.0,
54  (i0D.getProjectedY() + i0Dnext.getProjectedY()) / 2.0);
55  values.push_back(svm->readSteerableViewMapPixel(nSVM, _level, (int)m[0], (int)m[1]));
56  ++it;
57  ++itnext;
58  }
59 
60  float res, res_tmp;
61  vector<float>::iterator v = values.begin(), vend = values.end();
62  unsigned size = 1;
63  switch (_integration) {
64  case MIN:
65  res = *v;
66  ++v;
67  for (; v != vend; ++v) {
68  res_tmp = *v;
69  if (res_tmp < res) {
70  res = res_tmp;
71  }
72  }
73  break;
74  case MAX:
75  res = *v;
76  ++v;
77  for (; v != vend; ++v) {
78  res_tmp = *v;
79  if (res_tmp > res) {
80  res = res_tmp;
81  }
82  }
83  break;
84  case FIRST:
85  res = *v;
86  break;
87  case LAST:
88  --vend;
89  res = *vend;
90  break;
91  case MEAN:
92  default:
93  res = *v;
94  ++v;
95  for (; v != vend; ++v, ++size) {
96  res += *v;
97  }
98  res /= (size ? size : 1);
99  break;
100  }
101  result = res;
102  return 0;
103 }
104 
106 {
107  // soc unsigned size;
108  result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
109  return 0;
110 }
111 
113 {
114  // soc unsigned size;
115  /* Id id = inter.getId(); */ /* UNUSED */
116  result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
117  return 0;
118 }
119 
121 {
122  result = integrate(
123  _func, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
124  return 0;
125 }
126 
127 } // namespace Freestyle::Functions1D
Functions taking 1D input.
Class to define a canvas designed to draw style modules.
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
SteerableViewMap * getSteerableViewMap()
Definition: Canvas.h:177
static Canvas * getInstance()
Definition: Canvas.h:69
virtual Id getId() const
Definition: Silhouette.h:497
id_type getFirst() const
Definition: Id.h:76
virtual bool isEnd() const
Definition: Interface0D.h:296
virtual real getProjectedX() const
Definition: Interface0D.cpp:55
virtual Geometry::Vec2r getPoint2D() const
Definition: Interface0D.cpp:73
virtual FEdge * getFEdge(Interface0D &)
Definition: Interface0D.cpp:79
virtual Id getId() const
Definition: Interface0D.cpp:85
virtual real getProjectedY() const
Definition: Interface0D.cpp:61
virtual Interface0DIterator pointsEnd(float t=0.0f)
Definition: Interface1D.cpp:47
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition: Interface1D.cpp:41
float readSteerableViewMapPixel(unsigned iOrientation, int iLevel, int x, int y)
unsigned getSVMNumber(Vec2f dir)
T integrate(UnaryFunction0D< T > &fun, Interface0DIterator it, Interface0DIterator it_end, IntegrationType integration_type=MEAN)
Definition: Interface1D.h:72