Blender V4.3
AdvancedFunctions1D.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10#include "AdvancedFunctions1D.h"
11#include "Canvas.h"
12
14
15#include "BLI_sys_types.h"
16
18
20{
22 Interface0DIterator it = inter.pointsBegin(_sampling);
23 Interface0DIterator itnext = it;
24 ++itnext;
25 FEdge *fe;
26 uint nSVM;
27 vector<float> values;
28
29 while (!itnext.isEnd()) {
30 Interface0D &i0D = (*it);
31 Interface0D &i0Dnext = (*itnext);
32 fe = i0D.getFEdge(i0Dnext);
33 if (fe == nullptr) {
34 cerr << "GetSteerableViewMapDensityF1D warning: no FEdge between " << i0D.getId() << " and "
35 << i0Dnext.getId() << endl;
36 // compute the direction between these two ???
37 Vec2f dir = i0Dnext.getPoint2D() - i0D.getPoint2D();
38 nSVM = svm->getSVMNumber(dir);
39 }
40 else {
41 nSVM = svm->getSVMNumber(fe->getId().getFirst());
42 }
43 Vec2r m((i0D.getProjectedX() + i0Dnext.getProjectedX()) / 2.0,
44 (i0D.getProjectedY() + i0Dnext.getProjectedY()) / 2.0);
45 values.push_back(svm->readSteerableViewMapPixel(nSVM, _level, int(m[0]), int(m[1])));
46 ++it;
47 ++itnext;
48 }
49
50 float res, res_tmp;
51 vector<float>::iterator v = values.begin(), vend = values.end();
52 uint size = 1;
53 switch (_integration) {
54 case MIN:
55 res = *v;
56 ++v;
57 for (; v != vend; ++v) {
58 res_tmp = *v;
59 if (res_tmp < res) {
60 res = res_tmp;
61 }
62 }
63 break;
64 case MAX:
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 FIRST:
75 res = *v;
76 break;
77 case LAST:
78 --vend;
79 res = *vend;
80 break;
81 case MEAN:
82 default:
83 res = *v;
84 ++v;
85 for (; v != vend; ++v, ++size) {
86 res += *v;
87 }
88 res /= (size ? size : 1);
89 break;
90 }
91 result = res;
92 return 0;
93}
94
96{
97 // soc uint size;
98 result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
99 return 0;
100}
101
103{
104 // soc uint size;
105 // Id id = inter.getId(); /* UNUSED */
106 result = integrate(_fun, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
107 return 0;
108}
109
111{
112 result = integrate(
113 _func, inter.pointsBegin(_sampling), inter.pointsEnd(_sampling), _integration);
114 return 0;
115}
116
117} // namespace Freestyle::Functions1D
Functions taking 1D input.
unsigned int uint
Class to define a canvas designed to draw style modules.
Convenient access to the steerable ViewMap to which any element of the ViewMap belongs to.
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
static Canvas * getInstance()
Definition Canvas.h:57
SteerableViewMap * getSteerableViewMap()
Definition Canvas.h:165
virtual Id getId() const
Definition Silhouette.h:485
id_type getFirst() const
Definition Id.h:64
virtual bool isEnd() const
virtual real getProjectedX() const
virtual Geometry::Vec2r getPoint2D() const
virtual FEdge * getFEdge(Interface0D &)
virtual Id getId() const
virtual real getProjectedY() const
virtual Interface0DIterator pointsEnd(float t=0.0f)
virtual Interface0DIterator pointsBegin(float t=0.0f)
float readSteerableViewMapPixel(uint iOrientation, int iLevel, int x, int y)
T integrate(UnaryFunction0D< T > &fun, Interface0DIterator it, Interface0DIterator it_end, IntegrationType integration_type=MEAN)
Definition Interface1D.h:75