Blender  V3.3
AppView.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 #include "AppConfig.h"
10 
11 #include "../geometry/BBox.h"
12 #include "../geometry/Geom.h"
13 #include "../scene_graph/NodeDrawingStyle.h"
14 #include "../system/Precision.h"
15 
16 #include "BLI_math.h"
17 
18 #ifdef WITH_CXX_GUARDEDALLOC
19 # include "MEM_guardedalloc.h"
20 #endif
21 
22 namespace Freestyle {
23 
24 using namespace Geometry;
25 
26 class AppView {
27  public:
28  AppView(const char *iName = 0);
29  virtual ~AppView();
30 
31  public:
32  // inherited
33  inline unsigned int width()
34  {
35  return _width;
36  }
37  inline unsigned int height()
38  {
39  return _height;
40  }
42  {
43  return _border;
44  }
45  inline float thickness()
46  {
47  return _thickness;
48  }
49  inline void setWidth(unsigned int width)
50  {
51  _width = width;
52  }
53  inline void setHeight(unsigned int height)
54  {
55  _height = height;
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  {
63  _thickness = thickness;
64  }
65 
66  protected:
67  unsigned int _width, _height;
69  float _thickness;
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 
183  real distanceToSceneCenter();
184  real GetFocalLength();
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 #ifdef WITH_CXX_GUARDEDALLOC
255  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:AppView")
256 #endif
257 };
258 
259 } /* namespace Freestyle */
Configuration file.
#define M_PI
Definition: BLI_math_base.h:20
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
Read Guarded memory(de)allocation.
void setHorizontalFov(float hfov)
Definition: AppView.h:191
void setHeight(unsigned int height)
Definition: AppView.h:53
real GetFovyDegrees() const
Definition: AppView.h:201
void AddDebug(NodeGroup *iDebug)
Definition: AppView.h:128
unsigned int _height
Definition: AppView.h:67
real rabs(real x)
Definition: AppView.h:227
NodeGroup _Light
Definition: AppView.h:241
void DetachVisibleSilhouette()
Definition: AppView.h:172
BBox< Vec2i > _border
Definition: AppView.h:68
void Draw2DScene(SceneVisitor *iRenderer)
unsigned int height()
Definition: AppView.h:37
real GetAspect() const
Definition: AppView.h:186
float _thickness
Definition: AppView.h:69
void setWidth(unsigned int width)
Definition: AppView.h:49
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 DetachModel()
Definition: AppView.h:149
BBox< Vec2i > border()
Definition: AppView.h:41
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
real GetFovyRadian() const
Definition: AppView.h:196
void DetachDebug()
Definition: AppView.h:178
NodeGroup _RootNode
Definition: AppView.h:236
float thickness()
Definition: AppView.h:45
BBox< Vec3r > scene3DBBox() const
Definition: AppView.h:206
void AddModel(NodeGroup *iModel)
Definition: AppView.h:87
NodeDrawingStyle * _SilhouetteRootNode
Definition: AppView.h:238
void Add2DVisibleSilhouette(NodeGroup *)
Definition: AppView.h:113
unsigned int width()
Definition: AppView.h:33
void DetachModel(Node *iModel)
Definition: AppView.h:133
void DetachSilhouette()
Definition: AppView.h:162
void DrawScene(SceneVisitor *iRenderer)
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
VecMat::Vec2< int > Vec2i
Definition: Geom.h:19
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned x[3]
Definition: RandGen.cpp:73
double real
Definition: Precision.h:12
INLINE Rall1d< T, V, S > atan(const Rall1d< T, V, S > &x)
Definition: rall1d.h:375
INLINE Rall1d< T, V, S > tan(const Rall1d< T, V, S > &arg)
Definition: rall1d.h:327
T abs(const T &a)
#define min(a, b)
Definition: sort.c:35
float max