Blender  V2.93
AppView.cpp
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 
21 #include <iostream>
22 
23 #include "AppConfig.h"
24 #include "AppView.h"
25 #include "Controller.h"
26 
27 #include "../scene_graph/LineRep.h"
28 #include "../scene_graph/NodeLight.h"
29 #include "../scene_graph/NodeShape.h"
30 #include "../scene_graph/VertexRep.h"
31 #include "../stroke/Canvas.h"
32 #include "../system/StringUtils.h"
33 #include "../view_map/Silhouette.h"
34 #include "../view_map/ViewMap.h"
35 
36 #include "BLI_blenlib.h"
37 
38 #include "IMB_imbuf.h"
39 #include "IMB_imbuf_types.h"
40 
41 #if 1 // FRS_antialiasing
42 # include "BKE_global.h"
43 # include "DNA_scene_types.h"
44 #endif
45 
46 #include "FRS_freestyle.h"
47 
48 namespace Freestyle {
49 
50 AppView::AppView(const char * /*iName*/)
51 {
52  _Fovy = DEG2RADF(30.0f);
56 
62 
64 
68 
70 
72  std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
73  _ModelRootNode->bbox().getMin()[2]);
75  std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
76  _ModelRootNode->bbox().getMax()[2]);
77 
80 
85 
87 
88  NodeLight *light = new NodeLight;
89  _Light.AddChild(light);
90 }
91 
93 {
94  /*int ref =*//* UNUSED */ _RootNode.destroy();
95 
96  _Light.destroy();
97  /*ref =*//* UNUSED */ _p2DNode.destroy();
98 }
99 
101 {
102  BBox<Vec3r> bbox = _ModelRootNode->bbox();
103 
105  v -= 0.5 * (bbox.getMin() + bbox.getMax());
106 
107  return v.norm();
108 }
109 
111 {
112  BBox<Vec3r> bbox = _ModelRootNode->bbox();
113  Vec3r u = bbox.getMin();
114  Vec3r v = bbox.getMax();
115  Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
116 
117  Vec3r w1(u[0], u[1], u[2]);
118  Vec3r w2(v[0], u[1], u[2]);
119  Vec3r w3(u[0], v[1], u[2]);
120  Vec3r w4(v[0], v[1], u[2]);
121  Vec3r w5(u[0], u[1], v[2]);
122  Vec3r w6(v[0], u[1], v[2]);
123  Vec3r w7(u[0], v[1], v[2]);
124  Vec3r w8(v[0], v[1], v[2]);
125 
126  real _znear = std::min(
127  (w1 - cameraCenter).norm(),
128  std::min((w2 - cameraCenter).norm(),
129  std::min((w3 - cameraCenter).norm(),
130  std::min((w4 - cameraCenter).norm(),
131  std::min((w5 - cameraCenter).norm(),
132  std::min((w6 - cameraCenter).norm(),
133  std::min((w7 - cameraCenter).norm(),
134  (w8 - cameraCenter).norm())))))));
135 
136  return std::max(_znear, 0.001);
137 }
138 
140 {
141  BBox<Vec3r> bbox = _ModelRootNode->bbox();
142  Vec3r u = bbox.getMin();
143  Vec3r v = bbox.getMax();
144  Vec3r cameraCenter(UNPACK3(g_freestyle.viewpoint));
145 
146  Vec3r w1(u[0], u[1], u[2]);
147  Vec3r w2(v[0], u[1], u[2]);
148  Vec3r w3(u[0], v[1], u[2]);
149  Vec3r w4(v[0], v[1], u[2]);
150  Vec3r w5(u[0], u[1], v[2]);
151  Vec3r w6(v[0], u[1], v[2]);
152  Vec3r w7(u[0], v[1], v[2]);
153  Vec3r w8(v[0], v[1], v[2]);
154 
155  real _zfar = std::max(
156  (w1 - cameraCenter).norm(),
157  std::max((w2 - cameraCenter).norm(),
158  std::max((w3 - cameraCenter).norm(),
159  std::max((w4 - cameraCenter).norm(),
160  std::max((w5 - cameraCenter).norm(),
161  std::max((w6 - cameraCenter).norm(),
162  std::max((w7 - cameraCenter).norm(),
163  (w8 - cameraCenter).norm())))))));
164 
165  return _zfar;
166 }
167 
169 {
170  real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
171  return Near;
172 }
173 
174 } /* namespace Freestyle */
Configuration file.
#define DEG2RADF(_deg)
#define UNPACK3(a)
The spinal tap of the system.
struct FreestyleGlobals g_freestyle
Contains defines and structs used throughout the imbuf module.
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition: btVector3.h:263
real distanceToSceneCenter()
Definition: AppView.cpp:100
AppView(const char *iName=0)
Definition: AppView.cpp:50
NodeGroup _Light
Definition: AppView.h:255
virtual ~AppView()
Definition: AppView.cpp:92
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
NodeGroup _RootNode
Definition: AppView.h:250
NodeDrawingStyle * _SilhouetteRootNode
Definition: AppView.h:252
real GetFocalLength()
Definition: AppView.cpp:168
const Point & getMax() const
Definition: BBox.h:86
const Point & getMin() const
Definition: BBox.h:81
void setPointSize(const float iPointSize)
void setStyle(const DrawingStyle::STYLE iStyle)
void setLineWidth(const float iLineWidth)
void setLightingEnabled(const bool iEnableLighting)
virtual void AddChild(Node *iChild)
Definition: NodeGroup.cpp:28
virtual int destroy()
Definition: NodeGroup.cpp:38
virtual const BBox< Vec3r > & bbox() const
Definition: Node.h:67
inherits from class Rep
Definition: AppCanvas.cpp:32
double real
Definition: Precision.h:26
#define min(a, b)
Definition: sort.c:51
float viewpoint[3]
Definition: FRS_freestyle.h:36
float max