cgv
Loading...
Searching...
No Matches
clipped_view.cxx
1#include <cgv/base/base.h>
2#include "clipped_view.h"
3
4namespace cgv {
5 namespace render {
6
8{
9 z_near = 0.0001;
10 z_far = 100;
11}
12
14{
15 return z_near;
16}
17
19{
20 z_near = z;
21}
22
24{
25 return z_far;
26}
27
29{
30 z_far = z;
31}
32
35{
36 scene_extent = _box;
37}
38
41{
42 if (scene_extent.is_valid())
43 return scene_extent;
44 return dbox3(dbox3::pnt_type(-1, -1, -1), dbox3::pnt_type(1, 1, 1));
45}
46
48{
49 set_view_dir(0, 0, -1);
50 set_view_up_dir(0, 1, 0);
51 set_focus(get_scene_extent().get_center());
52 set_y_extent_at_focus(get_scene_extent().get_extent().length());
53}
54
56double clipped_view::get_z_D(double z_eye, double z_near, double z_far)
57{
58 double C = -(z_far + z_near) / (z_far - z_near);
59 double D = -2.0*z_far*z_near / (z_far - z_near);
60 return 0.5 - 0.5*(D + C*z_eye) / z_eye;
61}
62
63void clipped_view::compute_clipping_planes(double& z_near_derived, double& z_far_derived, bool clip_relative_to_extent) const
64{
65 compute_clipping_planes(*this, z_near_derived, z_far_derived, clip_relative_to_extent);
66}
67
69void clipped_view::compute_clipping_planes(const cgv::render::view& view, double& z_near_derived, double& z_far_derived, bool clip_relative_to_extent) const
70{
71 compute_clipping_planes(view.get_eye(), view.get_view_dir(), z_near_derived, z_far_derived, clip_relative_to_extent);
72}
73
75void clipped_view::compute_clipping_planes(const dvec3& eye, const dvec3& view_dir, double& z_near_derived, double& z_far_derived, bool clip_relative_to_extent) const
76{
77 double z_eye = dot(eye, view_dir);
78
79 // compute the clipping planes based on the eye and scene extent
80 z_near_derived = z_near;
81 z_far_derived = z_far;
82 if (scene_extent.is_valid()) {
83 dvec3 sc = scene_extent.get_center();
84 dbox3 B(1.25*(scene_extent.get_min_pnt() - sc) + sc,
85 1.25*(scene_extent.get_max_pnt() - sc) + sc);
86
87 double z_min = dot(B.get_corner(0), view_dir);
88 double z_max = z_min;
89 for (unsigned int i = 1; i<8; ++i) {
90 double new_z = dot(B.get_corner(i), view_dir);
91 if (new_z< z_min)
92 z_min = new_z;
93 if (new_z > z_max)
94 z_max = new_z;
95 }
96 z_min -= z_eye;
97 z_max -= z_eye;
98 if (z_min > z_near)
99 z_near_derived = z_min;
100 if (z_max > z_near)
101 z_far_derived = z_max;
102
103 if (clip_relative_to_extent) {
104 z_near_derived *= z_near;
105 z_far_derived *= z_far;
106 }
107 }
108 else if (clip_relative_to_extent) {
109 z_near_derived = y_extent_at_focus*z_near;
110 z_far_derived = y_extent_at_focus*z_far;
111 }
112}
113
114
115 }
116}
A column vector class.
Definition vec.h:28
fpnt_type get_center() const
return the center of the box
fpnt_type get_corner(int i) const
return the i-th corner where the lower N bits of i are used to select between min (bit = 0) and max (...
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
bool is_valid() const
check if aab is valid
virtual void set_scene_extent(const dbox3 &_box)
set the extent of the scene in world coordinates used by the compute_clipping_planes functions to ada...
dbox3 get_scene_extent() const
return the currently set scene extent
double get_z_far() const
return the currently set z-value for the z-far clipping plane
virtual void set_z_near(double z)
set the z-value for the z-near clipping plane
static double get_z_D(double z_eye, double z_near, double z_far)
transform a z value in eye-coordinates (should be negative!) to device coordinate
void compute_clipping_planes(double &z_near_derived, double &z_far_derived, bool clip_relative_to_extent=false) const
compute clipping planes adapted to the current scene extent, z_near_derived is at least z_near and as...
double get_z_near() const
return the currently set z-value for the z-near clipping plane
clipped_view()
construct a parallel view with focus in the world origin looking in negative z-direction and the y-di...
virtual void set_default_view()
reset view with focus and y-extent based on current scene extent
virtual void set_z_far(double z)
set the z-value for the z-far clipping plane
defines a symmetric view with the following quantities:
Definition view.h:22
const dvec3 get_eye() const
query the eye point, which is computed from focus, view dir, y extent at focus and y view angle
Definition view.cxx:123
virtual void set_view_dir(const dvec3 &vd)
set view direction without ensuring orthogonality to view up direction
Definition view.cxx:98
virtual void set_y_extent_at_focus(double ext)
set y extent of viewing window at focus point keeping y view angle resulting in a zoom
Definition view.cxx:104
virtual void set_view_up_dir(const dvec3 &vud)
set view up direction without ensuring orthogonality to view direction
Definition view.cxx:92
const dvec3 & get_view_dir() const
query current view direction
Definition view.cxx:58
virtual void set_focus(const dvec3 &foc)
set a new focus point keeping y extent at focus and y view angle fix, such that the eye position is a...
Definition view.cxx:85
the cgv namespace
Definition print.h:11
cgv::media::axis_aligned_box< double, 3 > dbox3
declare type of 3d double precision floating point axis-aligned boxes