Blender V4.3
ArbitraryGridDensityProvider.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#include "BLI_sys_types.h"
13
14#include "BKE_global.hh"
15
16namespace Freestyle {
17
18ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource &source,
19 const real proscenium[4],
20 uint numCells)
21 : GridDensityProvider(source), numCells(numCells)
22{
23 initialize(proscenium);
24}
25
26ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource &source,
27 const BBox<Vec3r> &bbox,
28 const GridHelpers::Transform &transform,
29 uint numCells)
30 : GridDensityProvider(source), numCells(numCells)
31{
32 real proscenium[4];
33 calculateQuickProscenium(transform, bbox, proscenium);
34
35 initialize(proscenium);
36}
37
38ArbitraryGridDensityProvider::ArbitraryGridDensityProvider(OccluderSource &source, uint numCells)
39 : GridDensityProvider(source), numCells(numCells)
40{
41 real proscenium[4];
43
44 initialize(proscenium);
45}
46
47void ArbitraryGridDensityProvider::initialize(const real proscenium[4])
48{
49 float prosceniumWidth = (proscenium[1] - proscenium[0]);
50 float prosceniumHeight = (proscenium[3] - proscenium[2]);
51 real cellArea = prosceniumWidth * prosceniumHeight / numCells;
52 if (G.debug & G_DEBUG_FREESTYLE) {
53 cout << prosceniumWidth << " x " << prosceniumHeight << " grid with cells of area " << cellArea
54 << "." << endl;
55 }
56
57 _cellSize = sqrt(cellArea);
58 // Now we know how many cells make each side of our grid
59 _cellsX = ceil(prosceniumWidth / _cellSize);
60 _cellsY = ceil(prosceniumHeight / _cellSize);
61 if (G.debug & G_DEBUG_FREESTYLE) {
62 cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl;
63 }
64
65 // Make sure the grid exceeds the proscenium by a small amount
66 float safetyZone = 0.1f;
67 if (_cellsX * _cellSize < prosceniumWidth * (1.0 + safetyZone)) {
68 _cellsX = ceil(prosceniumWidth * (1.0 + safetyZone) / _cellSize);
69 }
70 if (_cellsY * _cellSize < prosceniumHeight * (1.0 + safetyZone)) {
71 _cellsY = ceil(prosceniumHeight * (1.0 + safetyZone) / _cellSize);
72 }
73 if (G.debug & G_DEBUG_FREESTYLE) {
74 cout << _cellsX << "x" << _cellsY << " cells of size " << _cellSize << " square." << endl;
75 }
76
77 // Find grid origin
78 _cellOrigin[0] = ((proscenium[0] + proscenium[1]) / 2.0) - (_cellsX / 2.0) * _cellSize;
79 _cellOrigin[1] = ((proscenium[2] + proscenium[3]) / 2.0) - (_cellsY / 2.0) * _cellSize;
80}
81
86
93
100
106
107} /* namespace Freestyle */
Class to define a cell grid surrounding the projected image of a scene.
@ G_DEBUG_FREESTYLE
sqrt(x)+1/max(0
unsigned int uint
void initialize()
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])
ccl_device_inline float3 ceil(const float3 a)
#define G(x, y, z)
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14