Blender V5.0
AppView.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
10
11#include "AppConfig.h"
12
13#include "../geometry/BBox.h"
14#include "../geometry/Geom.h"
16#include "../system/Precision.h"
17
18#include "BLI_math_base.h"
19
20#include "MEM_guardedalloc.h"
21
22namespace Freestyle {
23
24using namespace Geometry;
25
26class AppView {
27 public:
28 AppView(const char *iName = 0);
29 virtual ~AppView();
30
31 public:
32 // inherited
33 inline uint width()
34 {
35 return _width;
36 }
37 inline uint height()
38 {
39 return _height;
40 }
42 {
43 return _border;
44 }
45 inline float thickness()
46 {
47 return _thickness;
48 }
49 inline void setWidth(uint width)
50 {
51 _width = width;
52 }
53 inline void setHeight(uint height)
54 {
56 }
57 inline void setBorder(int xmin, int ymin, int xmax, int ymax)
58 {
59 _border = BBox<Vec2i>(Vec2i(xmin, ymin), Vec2i(xmax, ymax));
60 }
61 inline void setThickness(float thickness)
62 {
64 }
65
66 protected:
70
71 public:
76 inline void setModel(NodeGroup *iModel)
77 {
78 if (0 != _ModelRootNode->numberOfChildren()) {
79 _ModelRootNode->DetachChildren();
80 _ModelRootNode->clearBBox();
81 }
82
83 AddModel(iModel);
84 }
85
87 inline void AddModel(NodeGroup *iModel)
88 {
89 _ModelRootNode->AddChild(iModel);
90 _ModelRootNode->UpdateBBox();
91
92 _minBBox = std::min(
93 std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
94 _ModelRootNode->bbox().getMin()[2]);
95 _maxBBox = std::max(
96 std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
97 _ModelRootNode->bbox().getMax()[2]);
98
99 _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
100 _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
101 }
102
103 inline void AddSilhouette(NodeGroup *iSilhouette)
104 {
105 _SilhouetteRootNode->AddChild(iSilhouette);
106 }
107
108 inline void Add2DSilhouette(NodeGroup * /*iSilhouette*/)
109 {
110 //_pFENode->AddChild(iSilhouette);
111 }
112
113 inline void Add2DVisibleSilhouette(NodeGroup * /*iVSilhouette*/)
114 {
115 //_pVisibleSilhouetteNode->AddChild(iVSilhouette);
116 }
117
118 inline void setDebug(NodeGroup *iDebug)
119 {
120 if (0 != _DebugRootNode->numberOfChildren()) {
121 _DebugRootNode->DetachChildren();
122 _DebugRootNode->clearBBox();
123 }
124
125 AddDebug(iDebug);
126 }
127
128 inline void AddDebug(NodeGroup *iDebug)
129 {
130 _DebugRootNode->AddChild(iDebug);
131 }
132
133 inline void DetachModel(Node *iModel)
134 {
135 _ModelRootNode->DetachChild(iModel);
136 _ModelRootNode->UpdateBBox();
137
138 _minBBox = std::min(
139 std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
140 _ModelRootNode->bbox().getMin()[2]);
141 _maxBBox = std::max(
142 std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
143 _ModelRootNode->bbox().getMax()[2]);
144
145 _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
146 _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
147 }
148
149 inline void DetachModel()
150 {
151 _ModelRootNode->DetachChildren();
152 _ModelRootNode->clearBBox();
153
154#if 0
155 // 2D Scene
156 _p2DNode.DetachChildren();
157 _pFENode->DetachChildren();
158 _pVisibleSilhouetteNode->DetachChildren();
159#endif
160 }
161
162 inline void DetachSilhouette()
163 {
164 _SilhouetteRootNode->DetachChildren();
165#if 0
166 _pFENode->DetachChildren();
167 _pVisibleSilhouetteNode->DetachChildren();
168#endif
169 _p2DSelectionNode->destroy();
170 }
171
173 {
174 //_pVisibleSilhouetteNode->DetachChildren();
175 _p2DSelectionNode->destroy();
176 }
177
178 inline void DetachDebug()
179 {
180 _DebugRootNode->DetachChildren();
181 }
182
185
186 inline real GetAspect() const
187 {
188 return ((real)_width / (real)_height);
189 }
190
191 void setHorizontalFov(float hfov)
192 {
193 _Fovy = 2.0 * atan(tan(hfov / 2.0) / GetAspect());
194 }
195
196 inline real GetFovyRadian() const
197 {
198 return _Fovy;
199 }
200
201 inline real GetFovyDegrees() const
202 {
203 return _Fovy * 180.0 / M_PI; /* TODO: Use RAD2DEG here too? */
204 }
205
207 {
208 return _ModelRootNode->bbox();
209 }
210
211 real znear();
212 real zfar();
213
214 public:
216 void DrawScene(SceneVisitor *iRenderer);
217
219 void Draw2DScene(SceneVisitor *iRenderer);
220
221 protected:
223 inline int rabs(int x)
224 {
225 return abs(x);
226 }
227 inline real rabs(real x)
228 {
229 return fabs(x);
230 }
231
232 protected:
233 float _Fovy;
234
235 // The root node container
240
242
247
248 // 2D Scene
253
254 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:AppView")
255};
256
257} /* namespace Freestyle */
Configuration file.
A class to hold a bounding box.
#define M_PI
unsigned int uint
Vectors and Matrices (useful type definitions).
Read Guarded memory(de)allocation.
Class to define a Drawing Style to be applied to the underlying children. Inherits from NodeGroup.
Define the float precision used in the program.
real distanceToSceneCenter()
Definition AppView.cpp:88
void setHorizontalFov(float hfov)
Definition AppView.h:191
real GetFovyDegrees() const
Definition AppView.h:201
void AddDebug(NodeGroup *iDebug)
Definition AppView.h:128
real rabs(real x)
Definition AppView.h:227
AppView(const char *iName=0)
Definition AppView.cpp:38
NodeGroup _Light
Definition AppView.h:241
void DetachVisibleSilhouette()
Definition AppView.h:172
BBox< Vec2i > _border
Definition AppView.h:68
void setWidth(uint width)
Definition AppView.h:49
void Draw2DScene(SceneVisitor *iRenderer)
virtual ~AppView()
Definition AppView.cpp:80
real GetAspect() const
Definition AppView.h:186
void AddSilhouette(NodeGroup *iSilhouette)
Definition AppView.h:103
void setBorder(int xmin, int ymin, int xmax, int ymax)
Definition AppView.h:57
void setDebug(NodeGroup *iDebug)
Definition AppView.h:118
void Add2DSilhouette(NodeGroup *)
Definition AppView.h:108
void setThickness(float thickness)
Definition AppView.h:61
NodeDrawingStyle * _ModelRootNode
Definition AppView.h:237
NodeDrawingStyle * _DebugRootNode
Definition AppView.h:239
int rabs(int x)
Definition AppView.h:223
NodeDrawingStyle * _p2DSelectionNode
Definition AppView.h:252
NodeGroup _p2DNode
Definition AppView.h:251
void setModel(NodeGroup *iModel)
Definition AppView.h:76
BBox< Vec2i > border()
Definition AppView.h:41
real GetFovyRadian() const
Definition AppView.h:196
NodeGroup _RootNode
Definition AppView.h:236
void setHeight(uint height)
Definition AppView.h:53
float thickness()
Definition AppView.h:45
void AddModel(NodeGroup *iModel)
Definition AppView.h:87
NodeDrawingStyle * _SilhouetteRootNode
Definition AppView.h:238
void Add2DVisibleSilhouette(NodeGroup *)
Definition AppView.h:113
BBox< Vec3r > scene3DBBox() const
Definition AppView.h:206
void DetachModel(Node *iModel)
Definition AppView.h:133
void DetachSilhouette()
Definition AppView.h:162
void DrawScene(SceneVisitor *iRenderer)
#define atan
#define tan
#define abs
ccl_device_inline float2 fabs(const float2 a)
VecMat::Vec2< int > Vec2i
Definition Geom.h:21
inherits from class Rep
Definition AppCanvas.cpp:20
static uint x[3]
Definition RandGen.cpp:77
double real
Definition Precision.h:14