Blender  V2.93
AppView.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
23 #include "AppConfig.h"
24 
25 #include "../geometry/BBox.h"
26 #include "../geometry/Geom.h"
27 #include "../scene_graph/NodeDrawingStyle.h"
28 #include "../system/Precision.h"
29 
30 #include "BLI_math.h"
31 
32 #ifdef WITH_CXX_GUARDEDALLOC
33 # include "MEM_guardedalloc.h"
34 #endif
35 
36 namespace Freestyle {
37 
38 using namespace Geometry;
39 
40 class AppView {
41  public:
42  AppView(const char *iName = 0);
43  virtual ~AppView();
44 
45  public:
46  // inherited
47  inline unsigned int width()
48  {
49  return _width;
50  }
51  inline unsigned int height()
52  {
53  return _height;
54  }
56  {
57  return _border;
58  }
59  inline float thickness()
60  {
61  return _thickness;
62  }
63  inline void setWidth(unsigned int width)
64  {
65  _width = width;
66  }
67  inline void setHeight(unsigned int height)
68  {
69  _height = height;
70  }
71  inline void setBorder(int xmin, int ymin, int xmax, int ymax)
72  {
73  _border = BBox<Vec2i>(Vec2i(xmin, ymin), Vec2i(xmax, ymax));
74  }
75  inline void setThickness(float thickness)
76  {
77  _thickness = thickness;
78  }
79 
80  protected:
81  unsigned int _width, _height;
83  float _thickness;
84 
85  public:
90  inline void setModel(NodeGroup *iModel)
91  {
92  if (0 != _ModelRootNode->numberOfChildren()) {
93  _ModelRootNode->DetachChildren();
94  _ModelRootNode->clearBBox();
95  }
96 
97  AddModel(iModel);
98  }
99 
101  inline void AddModel(NodeGroup *iModel)
102  {
103  _ModelRootNode->AddChild(iModel);
104  _ModelRootNode->UpdateBBox();
105 
106  _minBBox = std::min(
107  std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
108  _ModelRootNode->bbox().getMin()[2]);
109  _maxBBox = std::max(
110  std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
111  _ModelRootNode->bbox().getMax()[2]);
112 
113  _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
114  _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
115  }
116 
117  inline void AddSilhouette(NodeGroup *iSilhouette)
118  {
119  _SilhouetteRootNode->AddChild(iSilhouette);
120  }
121 
122  inline void Add2DSilhouette(NodeGroup * /*iSilhouette*/)
123  {
124  //_pFENode->AddChild(iSilhouette);
125  }
126 
127  inline void Add2DVisibleSilhouette(NodeGroup * /*iVSilhouette*/)
128  {
129  //_pVisibleSilhouetteNode->AddChild(iVSilhouette);
130  }
131 
132  inline void setDebug(NodeGroup *iDebug)
133  {
134  if (0 != _DebugRootNode->numberOfChildren()) {
135  _DebugRootNode->DetachChildren();
136  _DebugRootNode->clearBBox();
137  }
138 
139  AddDebug(iDebug);
140  }
141 
142  inline void AddDebug(NodeGroup *iDebug)
143  {
144  _DebugRootNode->AddChild(iDebug);
145  }
146 
147  inline void DetachModel(Node *iModel)
148  {
149  _ModelRootNode->DetachChild(iModel);
150  _ModelRootNode->UpdateBBox();
151 
152  _minBBox = std::min(
153  std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
154  _ModelRootNode->bbox().getMin()[2]);
155  _maxBBox = std::max(
156  std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
157  _ModelRootNode->bbox().getMax()[2]);
158 
159  _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
160  _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
161  }
162 
163  inline void DetachModel()
164  {
165  _ModelRootNode->DetachChildren();
166  _ModelRootNode->clearBBox();
167 
168 #if 0
169  // 2D Scene
170  _p2DNode.DetachChildren();
171  _pFENode->DetachChildren();
172  _pVisibleSilhouetteNode->DetachChildren();
173 #endif
174  }
175 
176  inline void DetachSilhouette()
177  {
178  _SilhouetteRootNode->DetachChildren();
179 #if 0
180  _pFENode->DetachChildren();
181  _pVisibleSilhouetteNode->DetachChildren();
182 #endif
183  _p2DSelectionNode->destroy();
184  }
185 
187  {
188  //_pVisibleSilhouetteNode->DetachChildren();
189  _p2DSelectionNode->destroy();
190  }
191 
192  inline void DetachDebug()
193  {
194  _DebugRootNode->DetachChildren();
195  }
196 
197  real distanceToSceneCenter();
198  real GetFocalLength();
199 
200  inline real GetAspect() const
201  {
202  return ((real)_width / (real)_height);
203  }
204 
205  void setHorizontalFov(float hfov)
206  {
207  _Fovy = 2.0 * atan(tan(hfov / 2.0) / GetAspect());
208  }
209 
210  inline real GetFovyRadian() const
211  {
212  return _Fovy;
213  }
214 
215  inline real GetFovyDegrees() const
216  {
217  return _Fovy * 180.0 / M_PI; // TODO Use RAD2DEG here too?
218  }
219 
221  {
222  return _ModelRootNode->bbox();
223  }
224 
225  real znear();
226  real zfar();
227 
228  public:
230  void DrawScene(SceneVisitor *iRenderer);
231 
233  void Draw2DScene(SceneVisitor *iRenderer);
234 
235  protected:
237  inline int rabs(int x)
238  {
239  return abs(x);
240  }
241  inline real rabs(real x)
242  {
243  return fabs(x);
244  }
245 
246  protected:
247  float _Fovy;
248 
249  // The root node container
254 
256 
261 
262  // 2D Scene
267 
268 #ifdef WITH_CXX_GUARDEDALLOC
269  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:AppView")
270 #endif
271 };
272 
273 } /* namespace Freestyle */
Configuration file.
#define M_PI
Definition: BLI_math_base.h:38
_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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
Read Guarded memory(de)allocation.
void setHorizontalFov(float hfov)
Definition: AppView.h:205
void setHeight(unsigned int height)
Definition: AppView.h:67
real GetFovyDegrees() const
Definition: AppView.h:215
void AddDebug(NodeGroup *iDebug)
Definition: AppView.h:142
unsigned int _height
Definition: AppView.h:81
real rabs(real x)
Definition: AppView.h:241
NodeGroup _Light
Definition: AppView.h:255
void DetachVisibleSilhouette()
Definition: AppView.h:186
BBox< Vec2i > _border
Definition: AppView.h:82
void Draw2DScene(SceneVisitor *iRenderer)
unsigned int height()
Definition: AppView.h:51
real GetAspect() const
Definition: AppView.h:200
float _thickness
Definition: AppView.h:83
void setWidth(unsigned int width)
Definition: AppView.h:63
void AddSilhouette(NodeGroup *iSilhouette)
Definition: AppView.h:117
void setBorder(int xmin, int ymin, int xmax, int ymax)
Definition: AppView.h:71
void setDebug(NodeGroup *iDebug)
Definition: AppView.h:132
void Add2DSilhouette(NodeGroup *)
Definition: AppView.h:122
void DetachModel()
Definition: AppView.h:163
BBox< Vec2i > border()
Definition: AppView.h:55
void setThickness(float thickness)
Definition: AppView.h:75
NodeDrawingStyle * _ModelRootNode
Definition: AppView.h:251
NodeDrawingStyle * _DebugRootNode
Definition: AppView.h:253
int rabs(int x)
Definition: AppView.h:237
NodeDrawingStyle * _p2DSelectionNode
Definition: AppView.h:266
NodeGroup _p2DNode
Definition: AppView.h:265
void setModel(NodeGroup *iModel)
Definition: AppView.h:90
real GetFovyRadian() const
Definition: AppView.h:210
void DetachDebug()
Definition: AppView.h:192
NodeGroup _RootNode
Definition: AppView.h:250
float thickness()
Definition: AppView.h:59
BBox< Vec3r > scene3DBBox() const
Definition: AppView.h:220
void AddModel(NodeGroup *iModel)
Definition: AppView.h:101
NodeDrawingStyle * _SilhouetteRootNode
Definition: AppView.h:252
void Add2DVisibleSilhouette(NodeGroup *)
Definition: AppView.h:127
unsigned int width()
Definition: AppView.h:47
void DetachModel(Node *iModel)
Definition: AppView.h:147
void DetachSilhouette()
Definition: AppView.h:176
void DrawScene(SceneVisitor *iRenderer)
VecMat::Vec2< int > Vec2i
Definition: Geom.h:33
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned x[3]
Definition: RandGen.cpp:87
double real
Definition: Precision.h:26
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
#define min(a, b)
Definition: sort.c:51
float max
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
ccl_device_inline float2 fabs(const float2 &a)