~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/freestyle/intern/application/AppView.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * ***** END GPL LICENSE BLOCK *****
 
19
 */
 
20
 
 
21
/** \file blender/freestyle/intern/application/AppView.cpp
 
22
 *  \ingroup freestyle
 
23
 */
 
24
 
 
25
/* This header file needs to be included first, in order to avoid a
 
26
   compilation with MinGW (see the commit log of revision 28253) */
 
27
extern "C" {
 
28
#include "BLI_jitter.h"
 
29
}
 
30
 
 
31
#include <iostream>
 
32
 
 
33
#include "Controller.h"
 
34
#include "AppConfig.h"
 
35
#include "AppView.h"
 
36
#include "../view_map/Silhouette.h"
 
37
#include "../view_map/ViewMap.h"
 
38
#include "../scene_graph/LineRep.h"
 
39
#include "../scene_graph/NodeLight.h"
 
40
#include "../scene_graph/NodeShape.h"
 
41
#include "../scene_graph/VertexRep.h"
 
42
#include "../stroke/Canvas.h"
 
43
#include "../system/StringUtils.h"
 
44
 
 
45
extern "C" {
 
46
#include "BLI_blenlib.h"
 
47
 
 
48
#include "IMB_imbuf.h"
 
49
#include "IMB_imbuf_types.h"
 
50
 
 
51
#if 1 // FRS_antialiasing
 
52
#  include "BKE_global.h"
 
53
#  include "DNA_scene_types.h"
 
54
#endif
 
55
 
 
56
#include "FRS_freestyle.h"
 
57
}
 
58
 
 
59
namespace Freestyle {
 
60
 
 
61
AppView::AppView(const char *iName)
 
62
{
 
63
        _Fovy = DEG2RADF(30.0f);
 
64
        _ModelRootNode = new NodeDrawingStyle;
 
65
        _SilhouetteRootNode = new NodeDrawingStyle;
 
66
        _DebugRootNode = new NodeDrawingStyle;
 
67
 
 
68
        _RootNode.AddChild(_ModelRootNode);
 
69
        _SilhouetteRootNode->setStyle(DrawingStyle::LINES);
 
70
        _SilhouetteRootNode->setLightingEnabled(false);
 
71
        _SilhouetteRootNode->setLineWidth(2.0f);
 
72
        _SilhouetteRootNode->setPointSize(3.0f);
 
73
 
 
74
        _RootNode.AddChild(_SilhouetteRootNode);
 
75
 
 
76
        _DebugRootNode->setStyle(DrawingStyle::LINES);
 
77
        _DebugRootNode->setLightingEnabled(false);
 
78
        _DebugRootNode->setLineWidth(1.0f);
 
79
 
 
80
        _RootNode.AddChild(_DebugRootNode);
 
81
 
 
82
        _minBBox = std::min(std::min(_ModelRootNode->bbox().getMin()[0], _ModelRootNode->bbox().getMin()[1]),
 
83
                            _ModelRootNode->bbox().getMin()[2]);
 
84
        _maxBBox = std::max(std::max(_ModelRootNode->bbox().getMax()[0], _ModelRootNode->bbox().getMax()[1]),
 
85
                            _ModelRootNode->bbox().getMax()[2]);
 
86
 
 
87
        _maxAbs = std::max(rabs(_minBBox), rabs(_maxBBox));
 
88
        _minAbs = std::min(rabs(_minBBox), rabs(_maxBBox));
 
89
 
 
90
        _p2DSelectionNode = new NodeDrawingStyle;
 
91
        _p2DSelectionNode->setLightingEnabled(false);
 
92
        _p2DSelectionNode->setStyle(DrawingStyle::LINES);
 
93
        _p2DSelectionNode->setLineWidth(5.0f);
 
94
 
 
95
        _p2DNode.AddChild(_p2DSelectionNode);
 
96
 
 
97
        NodeLight *light = new NodeLight;
 
98
        _Light.AddChild(light);
 
99
}
 
100
 
 
101
AppView::~AppView()
 
102
{
 
103
        /*int ref =*/ /* UNUSED */ _RootNode.destroy();
 
104
 
 
105
        _Light.destroy();
 
106
        /*ref =*/ /* UNUSED */ _p2DNode.destroy();
 
107
}
 
108
 
 
109
real AppView::distanceToSceneCenter()
 
110
{
 
111
        BBox<Vec3r> bbox = _ModelRootNode->bbox();
 
112
 
 
113
        Vec3r v(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
 
114
        v -= 0.5 * (bbox.getMin() + bbox.getMax());
 
115
 
 
116
        return v.norm();
 
117
}
 
118
 
 
119
real AppView::znear()
 
120
{
 
121
        BBox<Vec3r> bbox = _ModelRootNode->bbox();
 
122
        Vec3r u = bbox.getMin();
 
123
        Vec3r v = bbox.getMax();
 
124
        Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
 
125
 
 
126
        Vec3r w1(u[0], u[1], u[2]);
 
127
        Vec3r w2(v[0], u[1], u[2]);
 
128
        Vec3r w3(u[0], v[1], u[2]);
 
129
        Vec3r w4(v[0], v[1], u[2]);
 
130
        Vec3r w5(u[0], u[1], v[2]);
 
131
        Vec3r w6(v[0], u[1], v[2]);
 
132
        Vec3r w7(u[0], v[1], v[2]);
 
133
        Vec3r w8(v[0], v[1], v[2]);
 
134
 
 
135
        real _znear = std::min((w1 - cameraCenter).norm(),
 
136
                               std::min((w2 - cameraCenter).norm(),
 
137
                                        std::min((w3 - cameraCenter).norm(),
 
138
                                                 std::min((w4 - cameraCenter).norm(),
 
139
                                                          std::min((w5 - cameraCenter).norm(),
 
140
                                                                   std::min((w6 - cameraCenter).norm(),
 
141
                                                                            std::min((w7 - cameraCenter).norm(),
 
142
                                                                                     (w8 - cameraCenter).norm()
 
143
                                                                                    )
 
144
                                                                           )
 
145
                                                                  )
 
146
                                                         )
 
147
                                                )
 
148
                                       )
 
149
                              );
 
150
 
 
151
        return std::max(_znear, 0.001);
 
152
}
 
153
 
 
154
real AppView::zfar()
 
155
{
 
156
        BBox<Vec3r> bbox = _ModelRootNode->bbox();
 
157
        Vec3r u = bbox.getMin();
 
158
        Vec3r v = bbox.getMax();
 
159
        Vec3r cameraCenter(freestyle_viewpoint[0], freestyle_viewpoint[1], freestyle_viewpoint[2]);
 
160
 
 
161
        Vec3r w1(u[0], u[1], u[2]);
 
162
        Vec3r w2(v[0], u[1], u[2]);
 
163
        Vec3r w3(u[0], v[1], u[2]);
 
164
        Vec3r w4(v[0], v[1], u[2]);
 
165
        Vec3r w5(u[0], u[1], v[2]);
 
166
        Vec3r w6(v[0], u[1], v[2]);
 
167
        Vec3r w7(u[0], v[1], v[2]);
 
168
        Vec3r w8(v[0], v[1], v[2]);
 
169
 
 
170
        real _zfar = std::max((w1 - cameraCenter).norm(),
 
171
                              std::max((w2 - cameraCenter).norm(),
 
172
                                       std::max((w3 - cameraCenter).norm(),
 
173
                                                std::max((w4 - cameraCenter).norm(),
 
174
                                                         std::max((w5 - cameraCenter).norm(),
 
175
                                                                  std::max((w6 - cameraCenter).norm(),
 
176
                                                                           std::max((w7 - cameraCenter).norm(),
 
177
                                                                                    (w8 - cameraCenter).norm()
 
178
                                                                                   )
 
179
                                                                          )
 
180
                                                                 )
 
181
                                                        )
 
182
                                               )
 
183
                                      )
 
184
                             );
 
185
 
 
186
        return _zfar;
 
187
}
 
188
 
 
189
real AppView::GetFocalLength()
 
190
{
 
191
        real Near = std::max(0.1, (real)(-2.0f * _maxAbs + distanceToSceneCenter()));
 
192
        return Near;
 
193
}
 
194
 
 
195
} /* namespace Freestyle */