Blender  V2.93
Pow23GridDensityProvider.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 
23 
24 #include "BKE_global.h"
25 
26 namespace Freestyle {
27 
28 Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource &source,
29  const real proscenium[4],
30  unsigned numFaces)
31  : GridDensityProvider(source), numFaces(numFaces)
32 {
33  initialize(proscenium);
34 }
35 
36 Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource &source,
37  const BBox<Vec3r> &bbox,
39  unsigned numFaces)
40  : GridDensityProvider(source), numFaces(numFaces)
41 {
42  real proscenium[4];
43  calculateQuickProscenium(transform, bbox, proscenium);
44 
45  initialize(proscenium);
46 }
47 
48 Pow23GridDensityProvider::Pow23GridDensityProvider(OccluderSource &source, unsigned numFaces)
49  : GridDensityProvider(source), numFaces(numFaces)
50 {
51  real proscenium[4];
53 
54  initialize(proscenium);
55 }
56 
57 void Pow23GridDensityProvider::initialize(const real proscenium[4])
58 {
59  float prosceniumWidth = (proscenium[1] - proscenium[0]);
60  float prosceniumHeight = (proscenium[3] - proscenium[2]);
61  real cellArea = prosceniumWidth * prosceniumHeight / pow(numFaces, 2.0f / 3.0f);
62  if (G.debug & G_DEBUG_FREESTYLE) {
63  cout << prosceniumWidth << " x " << prosceniumHeight << " grid with cells of area " << cellArea
64  << "." << endl;
65  }
66 
67  _cellSize = sqrt(cellArea);
68  // Now we know how many cells make each side of our grid
69  _cellsX = ceil(prosceniumWidth / _cellSize);
70  _cellsY = ceil(prosceniumHeight / _cellSize);
71  if (G.debug & G_DEBUG_FREESTYLE) {
72  cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl;
73  }
74 
75  // Make sure the grid exceeds the proscenium by a small amount
76  float safetyZone = 0.1;
77  if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) {
78  _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize);
79  }
80  if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) {
81  _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize);
82  }
83  if (G.debug & G_DEBUG_FREESTYLE) {
84  cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl;
85  }
86 
87  // Find grid origin
88  _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize;
89  _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize;
90 }
91 
93  : numFaces(numFaces)
94 {
95 }
96 
98  OccluderSource &source, const real proscenium[4])
99 {
100  return AutoPtr<GridDensityProvider>(new Pow23GridDensityProvider(source, proscenium, numFaces));
101 }
102 
104  OccluderSource &source, const BBox<Vec3r> &bbox, const GridHelpers::Transform &transform)
105 {
107  new Pow23GridDensityProvider(source, bbox, transform, numFaces));
108 }
109 
111  OccluderSource &source)
112 {
114 }
115 
116 } /* namespace Freestyle */
@ G_DEBUG_FREESTYLE
Definition: BKE_global.h:140
sqrt(x)+1/max(0
Class to define a cell grid surrounding the projected image of a scene.
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
static void calculateOptimalProscenium(OccluderSource &source, real proscenium[4])
static void calculateQuickProscenium(const GridHelpers::Transform &transform, const BBox< Vec3r > &bbox, real proscenium[4])
AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source, const real proscenium[4])
inherits from class Rep
Definition: AppCanvas.cpp:32
double real
Definition: Precision.h:26
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
Definition: rall1d.h:359
ccl_device_inline float3 ceil(const float3 &a)
#define G(x, y, z)