cgv
Loading...
Searching...
No Matches
drawable.cxx
1#include <cgv/base/base.h>
2#include <cgv/base/node.h>
3#include <cgv/render/drawable.h>
4#include <cgv/base/find_action.h>
5
6namespace cgv {
7 namespace render {
8
10{
11 ctx = _ctx;
12}
14drawable::drawable() : base::traverse_policy(base::TP_ALL)
15{
16 ctx = 0;
17}
18
19
22{
23 active = false;
24}
27{
28 active = true;
29}
32{
33 return active;
34}
35
38{
39 return ctx;
40}
41
44{
45 if(ctx)
46 ctx->post_redraw();
47}
48
49view* drawable::find_view_as_node(size_t view_idx) const
50{
51 cgv::base::node* node_ptr = const_cast<cgv::base::node*>(dynamic_cast<const cgv::base::node*>(this));
52 std::vector<view*> views;
54 if (views.empty() || view_idx > views.size())
55 return 0;
56 return views[view_idx];
57}
58
59bool drawable::get_world_location(int x, int y, const view& V, dvec3& world_location, double* window_z_ptr) const
60{
61 if (!get_context())
62 return false;
63 // analyze the mouse location
64 context& ctx = *get_context();
65 const dmat4* DPV_ptr, *DPV_other_ptr;
66 int x_other, y_other, vp_col_idx, vp_row_idx, vp_width, vp_height;
67 int eye_panel = V.get_modelview_projection_window_matrices(x, y, ctx.get_width(), ctx.get_height(), &DPV_ptr, &DPV_other_ptr, &x_other, &y_other, &vp_col_idx, &vp_row_idx, &vp_width, &vp_height);
68
69 // get the possibly two (if stereo is enabled) different device z-values
70 double z = ctx.get_window_z(x, y);
71 double z_other = ctx.get_window_z(x_other, y_other);
72 // unproject to world coordinates with smaller (closer to eye) z-value one
73 if (z <= z_other) {
74 if (DPV_ptr->ncols() != 4)
75 return false;
76 // use conversion to (double*) operator to map cgv::math::vec<double> to cgv::math::fvec<float,3>
77 world_location = ctx.get_model_point(x, y, z, *DPV_ptr);
78 if (window_z_ptr)
79 *window_z_ptr = z;
80 }
81 else {
82 if (DPV_other_ptr->ncols() != 4)
83 return false;
84 world_location = ctx.get_model_point(x_other, y_other, z_other, *DPV_other_ptr);
85 if (window_z_ptr)
86 *window_z_ptr = z_other;
87 }
88 return true;
89}
90
93{
94 if (ctx)
95 ctx->force_redraw();
96}
97
100{
101 return true;
102}
104void drawable::resize(unsigned int, unsigned int)
105{
106}
113{
114}
123
128
131{
132}
133
136{
137 current_render_pass = -1;
138 render_pass_recursion_depth = 0;
139}
142{
143 if (current_render_pass != -1)
144 return false;
145 render_pass_recursion_depth = ctx.get_render_pass_recursion_depth();
146 return true;
147}
149void multi_pass_drawable::perform_render_pass(context& ctx, int rp_idx, RenderPass rp, int excluded_flags, int included_flags)
150{
151 current_render_pass = rp_idx;
152 unsigned rpf = (ctx.get_render_pass_flags() & ~excluded_flags) | included_flags;
153 ctx.render_pass(rp, RenderPassFlags(rpf), this);
154}
157{
158 current_render_pass = rp_idx;
159}
162{
163 if (current_render_pass == -1)
164 return true;
165 if (ctx.get_render_pass_user_data() != this)
166 if (render_pass_recursion_depth != ctx.get_render_pass_recursion_depth())
167 return true;
168 return false;
169}
172{
173 if (render_pass_recursion_depth != ctx.get_render_pass_recursion_depth())
174 return false;
175 current_render_pass = -1;
176 return true;
177}
178
179 } // namespace render
180} // namespace cgv
The node class keeps a pointer to its parent.
Definition node.h:19
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
matrix of fixed size dimensions
Definition fmat.h:23
static constexpr unsigned ncols()
number of columns
Definition fmat.h:71
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual void render_pass(RenderPass render_pass=RP_MAIN, RenderPassFlags render_pass_flags=RPF_ALL, void *user_data=0)
perform the given render task
Definition context.cxx:791
vec3 get_model_point(int x_window, int y_window) const
compute model space 3D point from the given opengl pixel location (window location)
Definition context.h:1423
virtual unsigned int get_width() const =0
return the width of the window
virtual RenderPassFlags get_render_pass_flags() const
return the current render pass flags
Definition context.cxx:758
virtual unsigned int get_height() const =0
return the height of the window
virtual double get_window_z(int x_window, int y_window) const =0
read the window z-coordinate from the depth buffer for the given opengl x- and y-coordinates
virtual void * get_render_pass_user_data() const
return the current render pass user data
Definition context.cxx:779
virtual void force_redraw()=0
the context will be redrawn right now. This method cannot be called inside the following methods of a...
virtual void post_redraw()=0
the context will be redrawn when the system is idle again
unsigned get_render_pass_recursion_depth() const
return current render pass recursion depth
Definition context.cxx:745
bool get_world_location(int x, int y, const view &V, dvec3 &world_location, double *window_z_ptr=0) const
use given view together with depth buffer of context in order to compute the world location of the po...
Definition drawable.cxx:59
context * get_context() const
access the current context. The context will be available latestly in the init method but not in the ...
Definition drawable.cxx:37
virtual void init_frame(context &)
this method is called in one pass over all drawables before the draw method
Definition drawable.cxx:108
void set_context(context *_ctx)
set the current focus context, this should only be called by the context itself
Definition drawable.cxx:9
virtual void finish_draw(context &)
this method is called when the current drawable is left in a tree traversal that calls the draw metho...
Definition drawable.cxx:116
virtual void draw(context &)
overload to draw the content of this drawable
Definition drawable.cxx:112
void force_redraw()
forces a redraw right now. This cannot be called from init, init_frame, draw, finish_draw,...
Definition drawable.cxx:92
virtual void resize(unsigned int w, unsigned int h)
callback to announce resizing of the output window
Definition drawable.cxx:104
void hide()
hide the drawable
Definition drawable.cxx:21
virtual void after_finish(context &)
this method is called in one pass over all drawables after finish frame
Definition drawable.cxx:125
virtual void finish_frame(context &)
this method is called in one pass over all drawables after drawing
Definition drawable.cxx:120
drawable()
default construction
Definition drawable.cxx:14
virtual bool init(context &)
this method is called after creation or recreation of the context, return whether all necessary funct...
Definition drawable.cxx:99
virtual void clear(context &)
clear all objects living in the context like textures or display lists
Definition drawable.cxx:130
view * find_view_as_node(size_t view_idx=0) const
convenience function to find the view control in the current hierarchy
Definition drawable.cxx:49
void show()
show the drawable
Definition drawable.cxx:26
void post_redraw()
posts a redraw event to the current context if one is available
Definition drawable.cxx:43
bool is_visible() const
check whether the drawable is visible
Definition drawable.cxx:31
bool multi_pass_terminate(const context &ctx)
check in after_finish method, whether this was the terminating render pass
Definition drawable.cxx:171
void perform_render_pass(context &ctx, int rp_idx, RenderPass rp=RP_USER_DEFINED, int excluded_flags=RPF_HANDLE_SCREEN_SHOT, int included_flags=0)
call to initiate a render pass in the init_frame method after initiate_render_pass_recursion() has su...
Definition drawable.cxx:149
bool initiate_render_pass_recursion(context &ctx)
call in init_frame method to check whether the recursive render passes need to be initiated
Definition drawable.cxx:141
bool multi_pass_ignore_finish(const context &ctx)
check in after_finish method, whether this should be directly exited with a return statement
Definition drawable.cxx:161
void initiate_terminal_render_pass(int rp_idx)
call after last recursive render pass to use current render pass for last render pass
Definition drawable.cxx:156
multi_pass_drawable()
construct to be not inside of a render pass
Definition drawable.cxx:135
defines a symmetric view with the following quantities:
Definition view.h:22
virtual int get_modelview_projection_window_matrices(int x, int y, int width, int height, const dmat4 **MPW_pptr, const dmat4 **MPW_other_pptr=0, int *x_other_ptr=0, int *y_other_ptr=0, int *vp_col_idx_ptr=0, int *vp_row_idx_ptr=0, int *vp_width_ptr=0, int *vp_height_ptr=0, int *vp_center_x_ptr=0, int *vp_center_y_ptr=0, int *vp_center_x_other_ptr=0, int *vp_center_y_other_ptr=0) const
given an opengl pixel location and the size in pixels of the opengl window, return the modelview_proj...
Definition view.cxx:277
RenderPass
Enumeration of different render passes, which can be queried from the context and used to specify a n...
Definition context.h:77
RenderPassFlags
available flags that can be queried from the context and set for a new render pass
Definition context.h:93
the cgv namespace
Definition print.h:11