Blender V5.0
GridDensityProvider.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11
12#include <algorithm>
13#include <memory>
14#include <stdexcept>
15
16#include "AutoPtrHelper.h"
17#include "OccluderSource.h"
18
19#include "../geometry/BBox.h"
20
21#include "BKE_global.hh"
22
23#include "MEM_guardedalloc.h"
24
25namespace Freestyle {
26
27class GridDensityProvider {
28 // Disallow copying and assignment
29 GridDensityProvider(const GridDensityProvider &other);
30 GridDensityProvider &operator=(const GridDensityProvider &other);
31
32 public:
34
36
37 float cellSize()
38 {
39 return _cellSize;
40 }
41
43 {
44 return _cellsX;
45 }
46
48 {
49 return _cellsY;
50 }
51
52 float cellOrigin(int index)
53 {
54 if (index < 2) {
55 return _cellOrigin[index];
56 }
57 else {
58 throw new out_of_range("GridDensityProvider::cellOrigin can take only indexes of 0 or 1.");
59 }
60 }
61
63 {
64 source.begin();
65 if (source.isValid()) {
66 const Vec3r &initialPoint = source.getGridSpacePolygon().getVertices()[0];
67 proscenium[0] = proscenium[1] = initialPoint[0];
68 proscenium[2] = proscenium[3] = initialPoint[1];
69 while (source.isValid()) {
70 GridHelpers::expandProscenium(proscenium, source.getGridSpacePolygon());
71 source.next();
72 }
73 }
74 if (G.debug & G_DEBUG_FREESTYLE) {
75 cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
76 << ", " << proscenium[3] << ")" << endl;
77 }
78 }
79
81 const BBox<Vec3r> &bbox,
82 real proscenium[4])
83 {
84 // Transform the coordinates of the 8 corners of the 3D bounding box
85 real xm = bbox.getMin()[0], xM = bbox.getMax()[0];
86 real ym = bbox.getMin()[1], yM = bbox.getMax()[1];
87 real zm = bbox.getMin()[2], zM = bbox.getMax()[2];
88 Vec3r p1 = transform(Vec3r(xm, ym, zm));
89 Vec3r p2 = transform(Vec3r(xm, ym, zM));
90 Vec3r p3 = transform(Vec3r(xm, yM, zm));
91 Vec3r p4 = transform(Vec3r(xm, yM, zM));
92 Vec3r p5 = transform(Vec3r(xM, ym, zm));
93 Vec3r p6 = transform(Vec3r(xM, ym, zM));
94 Vec3r p7 = transform(Vec3r(xM, yM, zm));
95 Vec3r p8 = transform(Vec3r(xM, yM, zM));
96 // Determine the proscenium face according to the min and max values of the transformed x and y
97 // coordinates
98 proscenium[0] = std::min(std::min(std::min(p1.x(), p2.x()), std::min(p3.x(), p4.x())),
99 std::min(std::min(p5.x(), p6.x()), std::min(p7.x(), p8.x())));
100 proscenium[1] = std::max(std::max(std::max(p1.x(), p2.x()), std::max(p3.x(), p4.x())),
101 std::max(std::max(p5.x(), p6.x()), std::max(p7.x(), p8.x())));
102 proscenium[2] = std::min(std::min(std::min(p1.y(), p2.y()), std::min(p3.y(), p4.y())),
103 std::min(std::min(p5.y(), p6.y()), std::min(p7.y(), p8.y())));
104 proscenium[3] = std::max(std::max(std::max(p1.y(), p2.y()), std::max(p3.y(), p4.y())),
105 std::max(std::max(p5.y(), p6.y()), std::max(p7.y(), p8.y())));
106 if (G.debug & G_DEBUG_FREESTYLE) {
107 cout << "Proscenium: " << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
108 << ", " << proscenium[3] << endl;
109 }
110 }
111
112 protected:
116 float _cellOrigin[2];
117
118 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProvider")
119};
120
121class GridDensityProviderFactory {
122 // Disallow copying and assignment
123 GridDensityProviderFactory(const GridDensityProviderFactory &other);
124 GridDensityProviderFactory &operator=(const GridDensityProviderFactory &other);
125
126 public:
128
130 const real proscenium[4]) = 0;
131
133 OccluderSource &source,
134 const BBox<Vec3r> &bbox,
136
138
140
141 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProviderFactory")
142};
143
144} /* namespace Freestyle */
Utility header for auto_ptr/unique_ptr selection.
A class to hold a bounding box.
@ G_DEBUG_FREESTYLE
unsigned int uint
Read Guarded memory(de)allocation.
Class to define a cell grid surrounding the projected image of a scene.
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
const Point & getMin() const
Definition BBox.h:67
const Point & getMax() const
Definition BBox.h:72
virtual AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source, const real proscenium[4])=0
virtual AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source)=0
virtual AutoPtr< GridDensityProvider > newGridDensityProvider(OccluderSource &source, const BBox< Vec3r > &bbox, const GridHelpers::Transform &transform)=0
static void calculateOptimalProscenium(OccluderSource &source, real proscenium[4])
GridDensityProvider(OccluderSource &source)
static void calculateQuickProscenium(const GridHelpers::Transform &transform, const BBox< Vec3r > &bbox, real proscenium[4])
value_type x() const
Definition VecMat.h:489
value_type y() const
Definition VecMat.h:499
#define G(x, y, z)
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
void expandProscenium(real proscenium[4], const Polygon3r &polygon)
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14