Blender V4.3
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
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#ifdef WITH_CXX_GUARDEDALLOC
24# include "MEM_guardedalloc.h"
25#endif
26
27namespace Freestyle {
28
30 // Disallow copying and assignment
32 GridDensityProvider &operator=(const GridDensityProvider &other);
33
34 public:
36
38
39 float cellSize()
40 {
41 return _cellSize;
42 }
43
45 {
46 return _cellsX;
47 }
48
50 {
51 return _cellsY;
52 }
53
54 float cellOrigin(int index)
55 {
56 if (index < 2) {
57 return _cellOrigin[index];
58 }
59 else {
60 throw new out_of_range("GridDensityProvider::cellOrigin can take only indexes of 0 or 1.");
61 }
62 }
63
65 {
66 source.begin();
67 if (source.isValid()) {
68 const Vec3r &initialPoint = source.getGridSpacePolygon().getVertices()[0];
69 proscenium[0] = proscenium[1] = initialPoint[0];
70 proscenium[2] = proscenium[3] = initialPoint[1];
71 while (source.isValid()) {
73 source.next();
74 }
75 }
76 if (G.debug & G_DEBUG_FREESTYLE) {
77 cout << "Proscenium: (" << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
78 << ", " << proscenium[3] << ")" << endl;
79 }
80 }
81
83 const BBox<Vec3r> &bbox,
84 real proscenium[4])
85 {
86 // Transform the coordinates of the 8 corners of the 3D bounding box
87 real xm = bbox.getMin()[0], xM = bbox.getMax()[0];
88 real ym = bbox.getMin()[1], yM = bbox.getMax()[1];
89 real zm = bbox.getMin()[2], zM = bbox.getMax()[2];
90 Vec3r p1 = transform(Vec3r(xm, ym, zm));
91 Vec3r p2 = transform(Vec3r(xm, ym, zM));
92 Vec3r p3 = transform(Vec3r(xm, yM, zm));
93 Vec3r p4 = transform(Vec3r(xm, yM, zM));
94 Vec3r p5 = transform(Vec3r(xM, ym, zm));
95 Vec3r p6 = transform(Vec3r(xM, ym, zM));
96 Vec3r p7 = transform(Vec3r(xM, yM, zm));
97 Vec3r p8 = transform(Vec3r(xM, yM, zM));
98 // Determine the proscenium face according to the min and max values of the transformed x and y
99 // coordinates
100 proscenium[0] = std::min(std::min(std::min(p1.x(), p2.x()), std::min(p3.x(), p4.x())),
101 std::min(std::min(p5.x(), p6.x()), std::min(p7.x(), p8.x())));
102 proscenium[1] = std::max(std::max(std::max(p1.x(), p2.x()), std::max(p3.x(), p4.x())),
103 std::max(std::max(p5.x(), p6.x()), std::max(p7.x(), p8.x())));
104 proscenium[2] = std::min(std::min(std::min(p1.y(), p2.y()), std::min(p3.y(), p4.y())),
105 std::min(std::min(p5.y(), p6.y()), std::min(p7.y(), p8.y())));
106 proscenium[3] = std::max(std::max(std::max(p1.y(), p2.y()), std::max(p3.y(), p4.y())),
107 std::max(std::max(p5.y(), p6.y()), std::max(p7.y(), p8.y())));
108 if (G.debug & G_DEBUG_FREESTYLE) {
109 cout << "Proscenium: " << proscenium[0] << ", " << proscenium[1] << ", " << proscenium[2]
110 << ", " << proscenium[3] << endl;
111 }
112 }
113
114 protected:
118 float _cellOrigin[2];
119
120#ifdef WITH_CXX_GUARDEDALLOC
121 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProvider")
122#endif
123};
124
126 // Disallow copying and assignment
129
130 public:
132
134 const real proscenium[4]) = 0;
135
137 OccluderSource &source,
138 const BBox<Vec3r> &bbox,
139 const GridHelpers::Transform &transform) = 0;
140
142
144
145#ifdef WITH_CXX_GUARDEDALLOC
146 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:GridDensityProviderFactory")
147#endif
148};
149
150} /* 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
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
const Point & getMin() const
Definition BBox.h:69
const Point & getMax() const
Definition BBox.h:74
const vector< Point > & getVertices() const
Definition Polygon.h:68
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:493
value_type y() const
Definition VecMat.h:503
#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