Blender V4.3
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
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#ifdef WITH_CXX_GUARDEDALLOC
21# include "MEM_guardedalloc.h"
22#endif
23
24namespace Freestyle {
25
26using namespace Geometry;
27
28class AppView {
29 public:
30 AppView(const char *iName = 0);
31 virtual ~AppView();
32
33 public:
34 // inherited
35 inline uint width()
36 {
37 return _width;
38 }
39 inline uint height()
40 {
41 return _height;
42 }
44 {
45 return _border;
46 }
47 inline float thickness()
48 {
49 return _thickness;
50 }
51 inline void setWidth(uint width)
52 {
53 _width = width;
54 }
55 inline void setHeight(uint height)
56 {
58 }
59 inline void setBorder(int xmin, int ymin, int xmax, int ymax)
60 {
61 _border = BBox<Vec2i>(Vec2i(xmin, ymin), Vec2i(xmax, ymax));
62 }
63 inline void setThickness(float thickness)
64 {
66 }
67
68 protected:
72
73 public:
78 inline void setModel(NodeGroup *iModel)
79 {
80 if (0 != _ModelRootNode->numberOfChildren()) {
83 }
84
85 AddModel(iModel);
86 }
87
89 inline void AddModel(NodeGroup *iModel)
90 {
91 _ModelRootNode->AddChild(iModel);
93
94 _minBBox = std::min(
95 std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
96 _ModelRootNode->bbox().getMin()[2]);
97 _maxBBox = std::max(
98 std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
99 _ModelRootNode->bbox().getMax()[2]);
100
101 _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
102 _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
103 }
104
105 inline void AddSilhouette(NodeGroup *iSilhouette)
106 {
107 _SilhouetteRootNode->AddChild(iSilhouette);
108 }
109
110 inline void Add2DSilhouette(NodeGroup * /*iSilhouette*/)
111 {
112 //_pFENode->AddChild(iSilhouette);
113 }
114
115 inline void Add2DVisibleSilhouette(NodeGroup * /*iVSilhouette*/)
116 {
117 //_pVisibleSilhouetteNode->AddChild(iVSilhouette);
118 }
119
120 inline void setDebug(NodeGroup *iDebug)
121 {
122 if (0 != _DebugRootNode->numberOfChildren()) {
125 }
126
127 AddDebug(iDebug);
128 }
129
130 inline void AddDebug(NodeGroup *iDebug)
131 {
132 _DebugRootNode->AddChild(iDebug);
133 }
134
135 inline void DetachModel(Node *iModel)
136 {
139
140 _minBBox = std::min(
141 std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
142 _ModelRootNode->bbox().getMin()[2]);
143 _maxBBox = std::max(
144 std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
145 _ModelRootNode->bbox().getMax()[2]);
146
147 _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
148 _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
149 }
150
151 inline void DetachModel()
152 {
155
156#if 0
157 // 2D Scene
159 _pFENode->DetachChildren();
160 _pVisibleSilhouetteNode->DetachChildren();
161#endif
162 }
163
164 inline void DetachSilhouette()
165 {
167#if 0
168 _pFENode->DetachChildren();
169 _pVisibleSilhouetteNode->DetachChildren();
170#endif
172 }
173
175 {
176 //_pVisibleSilhouetteNode->DetachChildren();
178 }
179
180 inline void DetachDebug()
181 {
183 }
184
187
188 inline real GetAspect() const
189 {
190 return ((real)_width / (real)_height);
191 }
192
193 void setHorizontalFov(float hfov)
194 {
195 _Fovy = 2.0 * atan(tan(hfov / 2.0) / GetAspect());
196 }
197
198 inline real GetFovyRadian() const
199 {
200 return _Fovy;
201 }
202
203 inline real GetFovyDegrees() const
204 {
205 return _Fovy * 180.0 / M_PI; /* TODO: Use RAD2DEG here too? */
206 }
207
209 {
210 return _ModelRootNode->bbox();
211 }
212
213 real znear();
214 real zfar();
215
216 public:
218 void DrawScene(SceneVisitor *iRenderer);
219
221 void Draw2DScene(SceneVisitor *iRenderer);
222
223 protected:
225 inline int rabs(int x)
226 {
227 return abs(x);
228 }
229 inline real rabs(real x)
230 {
231 return fabs(x);
232 }
233
234 protected:
235 float _Fovy;
236
237 // The root node container
242
244
249
250 // 2D Scene
255
256#ifdef WITH_CXX_GUARDEDALLOC
257 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:AppView")
258#endif
259};
260
261} /* 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:89
void setHorizontalFov(float hfov)
Definition AppView.h:193
real GetFovyDegrees() const
Definition AppView.h:203
void AddDebug(NodeGroup *iDebug)
Definition AppView.h:130
real rabs(real x)
Definition AppView.h:229
AppView(const char *iName=0)
Definition AppView.cpp:39
NodeGroup _Light
Definition AppView.h:243
void DetachVisibleSilhouette()
Definition AppView.h:174
BBox< Vec2i > _border
Definition AppView.h:70
void setWidth(uint width)
Definition AppView.h:51
void Draw2DScene(SceneVisitor *iRenderer)
virtual ~AppView()
Definition AppView.cpp:81
real GetAspect() const
Definition AppView.h:188
void AddSilhouette(NodeGroup *iSilhouette)
Definition AppView.h:105
void setBorder(int xmin, int ymin, int xmax, int ymax)
Definition AppView.h:59
void setDebug(NodeGroup *iDebug)
Definition AppView.h:120
void Add2DSilhouette(NodeGroup *)
Definition AppView.h:110
void setThickness(float thickness)
Definition AppView.h:63
NodeDrawingStyle * _ModelRootNode
Definition AppView.h:239
NodeDrawingStyle * _DebugRootNode
Definition AppView.h:241
int rabs(int x)
Definition AppView.h:225
NodeDrawingStyle * _p2DSelectionNode
Definition AppView.h:254
NodeGroup _p2DNode
Definition AppView.h:253
void setModel(NodeGroup *iModel)
Definition AppView.h:78
BBox< Vec2i > border()
Definition AppView.h:43
real GetFovyRadian() const
Definition AppView.h:198
NodeGroup _RootNode
Definition AppView.h:238
void setHeight(uint height)
Definition AppView.h:55
float thickness()
Definition AppView.h:47
void AddModel(NodeGroup *iModel)
Definition AppView.h:89
NodeDrawingStyle * _SilhouetteRootNode
Definition AppView.h:240
void Add2DVisibleSilhouette(NodeGroup *)
Definition AppView.h:115
BBox< Vec3r > scene3DBBox() const
Definition AppView.h:208
void DetachModel(Node *iModel)
Definition AppView.h:135
void DetachSilhouette()
Definition AppView.h:164
void DrawScene(SceneVisitor *iRenderer)
virtual int numberOfChildren()
Definition NodeGroup.h:56
virtual void DetachChildren()
Definition NodeGroup.cpp:69
virtual void AddChild(Node *iChild)
Definition NodeGroup.cpp:16
virtual const BBox< Vec3r > & UpdateBBox()
virtual int destroy()
Definition NodeGroup.cpp:26
virtual void DetachChild(Node *iChild)
Definition NodeGroup.cpp:80
virtual const BBox< Vec3r > & bbox() const
Definition Node.h:51
virtual void clearBBox()
Definition Node.h:84
ccl_device_inline float2 fabs(const float2 a)
VecMat::Vec2< int > Vec2i
Definition Geom.h:21
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
ccl_device_inline int abs(int x)
Definition util/math.h:120