cgv
box_renderer.h
1 #pragma once
2 
3 #include "surface_renderer.h"
4 
5 #include "gl/lib_begin.h"
6 
7 namespace cgv { // @<
8  namespace render { // @<
9  class CGV_API box_renderer;
10 
12 
15  extern CGV_API box_renderer& ref_box_renderer(context& ctx, int ref_count_change = 0);
16 
18  struct CGV_API box_render_style : public surface_render_style
19  {
26  };
27 
29  class CGV_API box_renderer : public surface_renderer
30  {
31  protected:
41  render_style* create_render_style() const;
42  public:
44  box_renderer();
46  void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
48  void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
50  void set_position_is_center(bool _position_is_center);
52  bool init(context& ctx);
54  bool enable(context& ctx);
56  template <typename T>
57  void set_extent(const context& ctx, const T& extent) { has_extents = true; ref_prog().set_attribute(ctx, ref_prog().get_attribute_location(ctx, "extent"), extent); }
59  template <typename T>
60  void set_extent_array(const context& ctx, const std::vector<T>& extents) { has_extents = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "extent"), extents); }
62  template <typename T>
63  void set_extent_array(const context& ctx, const T* extents, size_t nr_elements, unsigned stride_in_bytes = 0) { has_extents = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "extent"), extents, nr_elements, stride_in_bytes); }
65  template <typename T>
66  void set_box(const context& ctx, const cgv::media::axis_aligned_box<T, 3>& box) {
67  set_position(ctx, box.get_min_pnt());
68  set_extent(ctx, box.get_max_pnt());
69  set_position_is_center(false);
70  }
72  template <typename T>
73  void set_box_array(const context& ctx, const std::vector<cgv::media::axis_aligned_box<T, 3> >& boxes) {
74  set_composed_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "position"),
75  &boxes.front(), boxes.size(), boxes[0].get_min_pnt());
76  ref_composed_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "extent"),
77  ref_prog().get_attribute_location(ctx, "position"), &boxes.front(), boxes.size(), boxes[0].get_max_pnt());
78  has_positions = true;
79  has_extents = true;
80  set_position_is_center(false);
81  }
83  template <typename T>
84  void set_box_array(const context& ctx, const cgv::media::axis_aligned_box<T, 3>* boxes, size_t count) {
85  set_composed_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "position"),
86  boxes, count, boxes[0].get_min_pnt());
87  ref_composed_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "extent"),
88  ref_prog().get_attribute_location(ctx, "position"), boxes, count, boxes[0].get_max_pnt());
89  has_positions = true;
90  has_extents = true;
91  set_position_is_center(false);
92  }
94  template <typename T>
95  void set_translation_array(const context& ctx, const std::vector<T>& translations) { has_translations = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "translation"), translations); }
97  template <typename T>
98  void set_translation_array(const context& ctx, const T* translations, size_t nr_elements, unsigned stride_in_bytes = 0) { has_translations = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "translation"), translations, nr_elements, stride_in_bytes); }
100  template <typename T>
101  void set_rotation_array(const context& ctx, const std::vector<T>& rotations) { has_rotations = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "rotation"), rotations); }
103  template <typename T>
104  void set_rotation_array(const context& ctx, const T* rotations, size_t nr_elements, unsigned stride_in_bytes = 0) { has_rotations = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "rotation"), rotations, nr_elements, stride_in_bytes); }
106  bool disable(context& ctx);
108  void draw(context& ctx, size_t start, size_t count,
109  bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1);
110  };
111  struct CGV_API box_render_style_reflect : public box_render_style
112  {
113  bool self_reflect(cgv::reflect::reflection_handler& rh);
114  };
115  extern CGV_API cgv::reflect::extern_reflection_traits<box_render_style, box_render_style_reflect> get_reflection_traits(const box_render_style&);
116  }
117 }
118 
119 #include <cgv/config/lib_end.h>
cgv::render::box_renderer::set_extent_array
void set_extent_array(const context &ctx, const T *extents, size_t nr_elements, unsigned stride_in_bytes=0)
extent array specifies box extends in case of position_is_center=true, otherwise the maximum point of...
Definition: box_renderer.h:63
cgv::render::render_style
base class for all render styles
Definition: renderer.h:16
cgv::render::box_render_style
boxes use surface render styles
Definition: box_renderer.h:19
cgv::render::box_render_style::relative_anchor
vec3 relative_anchor
box anchor position relative to center that corresponds to the position attribute
Definition: box_renderer.h:23
cgv::render::box_renderer::set_extent_array
void set_extent_array(const context &ctx, const std::vector< T > &extents)
extent array specifies box extends in case of position_is_center=true, otherwise the maximum point of...
Definition: box_renderer.h:60
cgv::render::box_renderer
renderer that supports point splatting
Definition: box_renderer.h:30
cgv::render::surface_render_style
Definition: surface_renderer.h:26
cgv::render::box_renderer::has_translations
bool has_translations
whether array with per box translations has been specified
Definition: box_renderer.h:35
cgv::render::box_renderer::has_rotations
bool has_rotations
whether array with per box rotations has been specified
Definition: box_renderer.h:37
cgv::render::ref_box_renderer
box_renderer & ref_box_renderer(context &ctx, int ref_count_change)
reference to a singleton box renderer that is shared among drawables
Definition: box_renderer.cxx:14
cgv::render::attribute_array_manager
attribute array manager used to upload arrays to gpu
Definition: renderer.h:21
cgv::render::box_renderer::set_box
void set_box(const context &ctx, const cgv::media::axis_aligned_box< T, 3 > &box)
specify a single box. This sets position_is_center to false as well as position and extent attributes
Definition: box_renderer.h:66
cgv::media::axis_aligned_box
Definition: axis_aligned_box.h:15
cgv::reflect::reflection_handler
Definition: reflection_handler.h:63
cgv::render::box_renderer::has_extents
bool has_extents
store whether extent array has been specified
Definition: box_renderer.h:33
cgv::render::box_renderer::set_box_array
void set_box_array(const context &ctx, const cgv::media::axis_aligned_box< T, 3 > *boxes, size_t count)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
Definition: box_renderer.h:84
cgv::media::axis_aligned_box::get_max_pnt
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
Definition: axis_aligned_box.h:62
cgv::media::axis_aligned_box::get_min_pnt
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
Definition: axis_aligned_box.h:60
cgv::render::surface_renderer
base classes for renderers that support surface rendering
Definition: surface_renderer.h:43
cgv::render::box_renderer::position_is_center
bool position_is_center
whether position is box center, if not it is lower left bottom corner
Definition: box_renderer.h:39
cgv::reflect::extern_reflection_traits
this reflection traits implementation is used for external self_reflect implementations of instances ...
Definition: reflect_extern.h:28
cgv::render::box_renderer::set_box_array
void set_box_array(const context &ctx, const std::vector< cgv::media::axis_aligned_box< T, 3 > > &boxes)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
Definition: box_renderer.h:73
cgv::render::box_renderer::set_extent
void set_extent(const context &ctx, const T &extent)
specify a single extent for all boxes
Definition: box_renderer.h:57
cgv::render::box_render_style::default_extent
vec3 default_extent
extent used in case extent array is not specified
Definition: box_renderer.h:21
cgv::render::box_renderer::set_translation_array
void set_translation_array(const context &ctx, const T *translations, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
Definition: box_renderer.h:98
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::render::context
Definition: context.h:525
cgv::render::box_renderer::set_rotation_array
void set_rotation_array(const context &ctx, const T *rotations, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
Definition: box_renderer.h:104
cgv::render::box_renderer::set_rotation_array
void set_rotation_array(const context &ctx, const std::vector< T > &rotations)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
Definition: box_renderer.h:101
cgv::render::box_renderer::set_translation_array
void set_translation_array(const context &ctx, const std::vector< T > &translations)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
Definition: box_renderer.h:95