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