cgv
Loading...
Searching...
No Matches
cgv::render::gl::mesh_drawable Class Reference

simple implementation of a drawable for a polygonal mesh with support for materials More...

#include <mesh_drawable.h>

Inheritance diagram for cgv::render::gl::mesh_drawable:
cgv::render::drawable cgv::base::traverse_policy

Public Types

typedef cgv::media::mesh::simple_mesh< float > mesh_type
 type of mesh
 

Public Member Functions

 mesh_drawable ()
 construct from name which is necessary construction argument to node
 
void init_frame (cgv::render::context &ctx)
 init textures if the mesh has been newly loaded
 
void draw (cgv::render::context &ctx)
 default drawing implementation calls draw_mesh(ctx, true) to render opaque part
 
void finish_draw (context &ctx)
 default finish drawing implementation calls draw_mesh(ctx, false) to render transparent part
 
virtual bool read_mesh (const std::string &file_name)
 read mesh from the given file_name which is extended by model path if it does not exist
 
void clear (context &ctx)
 clear all objects living in the context like textures or display lists
 
const box3get_box () const
 return the axis aligned bounding box
 
- Public Member Functions inherited from cgv::render::drawable
 drawable ()
 default construction
 
void hide ()
 hide the drawable
 
void show ()
 show the drawable
 
bool is_visible () const
 check whether the drawable is visible
 
contextget_context () const
 access the current context. The context will be available latestly in the init method but not in the contructor.
 
void set_context (context *_ctx)
 set the current focus context, this should only be called by the context itself
 
viewfind_view_as_node (size_t view_idx=0) const
 convenience function to find the view control in the current hierarchy
 
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 point at mouse pointer location (x,y)
 
void post_redraw ()
 posts a redraw event to the current context if one is available
 
void force_redraw ()
 forces a redraw right now. This cannot be called from init, init_frame, draw, finish_draw, finish_frame and clear
 
virtual bool init (context &)
 this method is called after creation or recreation of the context, return whether all necessary functionality is supported
 
virtual void resize (unsigned int w, unsigned int h)
 callback to announce resizing of the output window
 
virtual void finish_frame (context &)
 this method is called in one pass over all drawables after drawing
 
virtual void after_finish (context &)
 this method is called in one pass over all drawables after finish frame
 
- Public Member Functions inherited from cgv::base::traverse_policy
 traverse_policy (int _policy=TP_ALL+TP_STOP_ON_SUCCESS, bool _active=true, int _focus=-1)
 construct default traverse policy that visits everything
 
int get_policy () const
 return the policy without the stop on success flag
 
bool stop_on_success () const
 return whether to stop on success
 
bool stop_on_failure () const
 return whether to stop on failure
 
void set_policy (int _policy)
 set a new policy, always add stop on success flag if needed
 
int get_focused_child () const
 return the focused child or -1 if none is focused
 
void set_focused_child (int _focused_child)
 set the focused child
 
bool get_active () const
 return whether the current node is active
 
void set_active (bool _active)
 set the active flag of the current node
 

Protected Member Functions

void draw_mesh_primitive (cgv::render::context &ctx, unsigned pi, bool opaque, bool use_materials=true)
 draw all faces belonging to the given primitive, optionally turn off the specification of materials
 
void draw_mesh (cgv::render::context &ctx, bool opaque, bool use_materials=true)
 draw the complete mesh, optionally turn off the specification of materials
 
void center_view ()
 call this to center the view after loading the mesh.
 

Protected Attributes

std::string model_path
 default path to file names
 
std::string file_name
 currently loaded file name
 
mesh_type mesh
 
mesh_render_info mesh_info
 
bool rebuild_mesh_info
 
box3 box
 the bounding box of the mesh is computed in the read_mesh method
 
- Protected Attributes inherited from cgv::base::traverse_policy
TraversePolicy policy
 
bool active
 
int focus
 

Detailed Description

simple implementation of a drawable for a polygonal mesh with support for materials

Definition at line 21 of file mesh_drawable.h.

Member Typedef Documentation

◆ mesh_type

type of mesh

Definition at line 25 of file mesh_drawable.h.

Constructor & Destructor Documentation

◆ mesh_drawable()

cgv::render::gl::mesh_drawable::mesh_drawable ( )

construct from name which is necessary construction argument to node

Definition at line 10 of file mesh_drawable.cxx.

Member Function Documentation

◆ center_view()

void cgv::render::gl::mesh_drawable::center_view ( )
protected

call this to center the view after loading the mesh.

For this to work you need to derive from at least cgv::base::node and register an instance through the object registration mechanism defined in cgv/base/register.h

Definition at line 70 of file mesh_drawable.cxx.

References box, cgv::render::drawable::find_view_as_node(), cgv::media::axis_aligned_box< T, N >::get_center(), cgv::media::axis_aligned_box< T, N >::get_extent(), cgv::media::axis_aligned_box< T, N >::get_max_extent_coord_index(), and cgv::render::drawable::post_redraw().

◆ clear()

void cgv::render::gl::mesh_drawable::clear ( context ctx)
virtual

clear all objects living in the context like textures or display lists

Reimplemented from cgv::render::drawable.

Definition at line 27 of file mesh_drawable.cxx.

References cgv::render::mesh_render_info::destruct().

◆ draw()

void cgv::render::gl::mesh_drawable::draw ( cgv::render::context ctx)
virtual

default drawing implementation calls draw_mesh(ctx, true) to render opaque part

Reimplemented from cgv::render::drawable.

Definition at line 42 of file mesh_drawable.cxx.

References draw_mesh().

◆ draw_mesh()

void cgv::render::gl::mesh_drawable::draw_mesh ( cgv::render::context ctx,
bool  opaque,
bool  use_materials = true 
)
protected

draw the complete mesh, optionally turn off the specification of materials

Definition at line 37 of file mesh_drawable.cxx.

References cgv::render::render_info::draw_all().

Referenced by draw(), and finish_draw().

◆ draw_mesh_primitive()

void cgv::render::gl::mesh_drawable::draw_mesh_primitive ( cgv::render::context ctx,
unsigned  pi,
bool  opaque,
bool  use_materials = true 
)
protected

draw all faces belonging to the given primitive, optionally turn off the specification of materials

Definition at line 32 of file mesh_drawable.cxx.

References cgv::render::mesh_render_info::draw_primitive().

◆ finish_draw()

void cgv::render::gl::mesh_drawable::finish_draw ( context ctx)
virtual

default finish drawing implementation calls draw_mesh(ctx, false) to render transparent part

Reimplemented from cgv::render::drawable.

Definition at line 47 of file mesh_drawable.cxx.

References draw_mesh().

◆ get_box()

const box3 & cgv::render::gl::mesh_drawable::get_box ( ) const

return the axis aligned bounding box

Definition at line 80 of file mesh_drawable.cxx.

References box.

◆ init_frame()

void cgv::render::gl::mesh_drawable::init_frame ( cgv::render::context ctx)
virtual

◆ read_mesh()

bool cgv::render::gl::mesh_drawable::read_mesh ( const std::string &  file_name)
virtual

read mesh from the given file_name which is extended by model path if it does not exist

Definition at line 52 of file mesh_drawable.cxx.

References box, cgv::media::mesh::simple_mesh< T >::clear(), cgv::media::mesh::simple_mesh< T >::compute_box(), file_name, cgv::base::find_data_file(), model_path, and cgv::media::mesh::simple_mesh< T >::read().

Member Data Documentation

◆ box

box3 cgv::render::gl::mesh_drawable::box
protected

the bounding box of the mesh is computed in the read_mesh method

Definition at line 38 of file mesh_drawable.h.

Referenced by center_view(), get_box(), and read_mesh().

◆ file_name

std::string cgv::render::gl::mesh_drawable::file_name
protected

currently loaded file name

Definition at line 30 of file mesh_drawable.h.

Referenced by read_mesh().

◆ mesh

mesh_type cgv::render::gl::mesh_drawable::mesh
protected

Definition at line 32 of file mesh_drawable.h.

◆ mesh_info

mesh_render_info cgv::render::gl::mesh_drawable::mesh_info
protected

Definition at line 34 of file mesh_drawable.h.

◆ model_path

std::string cgv::render::gl::mesh_drawable::model_path
protected

default path to file names

Definition at line 28 of file mesh_drawable.h.

Referenced by read_mesh().

◆ rebuild_mesh_info

bool cgv::render::gl::mesh_drawable::rebuild_mesh_info
protected

Definition at line 36 of file mesh_drawable.h.


The documentation for this class was generated from the following files: