Skip to content

Commit

Permalink
Merge pull request #94 from untereiner/develop
Browse files Browse the repository at this point in the history
[volume render] ADD hexa grid specific view with clipping topo using …
  • Loading branch information
Lionel Untereiner authored Sep 27, 2019
2 parents 649cb64 + 8a5d15f commit 4b445a0
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 179 deletions.
112 changes: 96 additions & 16 deletions schnapps/plugins/volume_render/map_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <cgogn/rendering/shaders/shader_simple_color.h>
#include <cgogn/rendering/shaders/shader_point_sprite.h>
#include <cgogn/rendering/volume_drawer.h>
#include <cgogn/rendering/hexagrid_drawer.h>
#include <cgogn/rendering/frame_manipulator.h>
#include <cgogn/rendering/topo_drawer.h>
#ifdef USE_TRANSPARENCY
Expand Down Expand Up @@ -68,6 +69,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
render_topology_(false),
render_color_per_volumes_(false),
apply_clipping_plane_(false),
apply_grid_clipping_plane_(false),
clipping_plane_initialized_(false),
vertex_color_(190, 85, 168),
edge_color_(0, 0, 0),
Expand All @@ -77,6 +79,9 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
volume_explode_factor_(0.8f),
use_transparency_(false),
transparency_factor_(127),
clipping_x_(0),
clipping_y_(0),
clipping_z_(0),
color_map_(cgogn::ColorMapType::INFERNO)
{
initialize_gl();
Expand All @@ -91,6 +96,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
inline bool render_topology() const { return render_topology_; }
inline bool render_color_per_volume() const { return render_color_per_volumes_; }
inline bool apply_clipping_plane() const { return apply_clipping_plane_; }
inline bool apply_grid_clipping_plane() const { return apply_grid_clipping_plane_; }
inline const QColor& vertex_color() const { return vertex_color_; }
inline const QColor& edge_color() const { return edge_color_; }
inline const QColor& face_color() const { return face_color_; }
Expand Down Expand Up @@ -118,6 +124,9 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
update_volume_drawer();
if(render_topology_)
update_topo_drawer();

if(apply_grid_clipping_plane_)
update_hexa_drawer();
}
else
position_vbo_ = nullptr;
Expand Down Expand Up @@ -172,9 +181,6 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
color_map_ = cgogn::color_map_type(color_map.toStdString());
render_color_per_volumes_ = true;


std::cout << std::boolalpha << recompute << std::endl;

if(recompute)
update_volume_color_attribute(true);
}
Expand Down Expand Up @@ -203,6 +209,10 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
topo_drawer_->set_explode_volume(vef);
if (render_topology_)
update_topo_drawer();

hexa_drawer_rend_->set_explode_volume(volume_explode_factor_);
if(apply_grid_clipping_plane_)
update_hexa_drawer();
}

void set_transparency_enabled(bool b)
Expand Down Expand Up @@ -246,6 +256,7 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
#ifdef USE_TRANSPARENCY
volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0));
#endif
hexa_drawer_rend_->set_clipping_plane(QVector4D(0, 0, 0, 0));
}
}

Expand All @@ -271,6 +282,57 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
#ifdef USE_TRANSPARENCY
volume_transparency_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d));
#endif
hexa_drawer_rend_->set_clipping_plane(QVector4D(z_axis[0], z_axis[1], z_axis[2], d));
}

void set_apply_grid_clipping_plane(bool b)
{
apply_grid_clipping_plane_ = b;
if(apply_grid_clipping_plane_)
update_hexa_drawer();
}

void set_clipping_plane(int x, int y, int z)
{
clipping_x_ = x;
clipping_y_ = y;
clipping_z_ = z;

hexa_drawer_rend_->set_clipping_plane_topo(QVector3D(clipping_x_, clipping_y_, clipping_z_));
}

void update_hexa_drawer()
{
if (position_vbo_)
{
const CMap3::VertexAttribute<VEC3>& pos_attr = mh_->map()->get_attribute<VEC3, CMap3::Vertex::ORBIT>(position_vbo_->name());
if (!pos_attr.is_valid())
{
cgogn_log_warning("plugin_volume_render|MapParameters::update_topo_drawer") << "The attribute \"" << position_vbo_->name() << "\" is not valid. Its data should be of type " << cgogn::name_of_type(VEC3()) << ".";
position_vbo_ = nullptr;
return;
}

auto i_ = mh_->map()->get_attribute<uint32, CMap3::Volume>("i");
auto j_ = mh_->map()->get_attribute<uint32, CMap3::Volume>("j");
auto k_ = mh_->map()->get_attribute<uint32, CMap3::Volume>("k");

if(volume_attribute_.isEmpty())
{
qreal r, g, b;
face_color_.getRgbF(&r, &g, &b);
cgogn::rendering::FakeAttribute<CMap3::Volume::ORBIT, VEC3> fake_color(VEC3(r, g, b));
hexa_drawer_->update_face(*mh_->map(),pos_attr, fake_color, i_, j_, k_);
hexa_drawer_->update_edge(*mh_->map(),pos_attr,i_, j_, k_);
}
else
{
QString color_attribute = volume_attribute_ + "_color";
const CMap3::VolumeAttribute<VEC3>& color_attr = mh_->map()->get_attribute<VEC3, CMap3::Volume::ORBIT>(color_attribute.toStdString());
hexa_drawer_->update_face(*mh_->map(), pos_attr, color_attr, i_, j_, k_);
hexa_drawer_->update_edge(*mh_->map(), pos_attr, i_, j_, k_);
}
}
}

void update_topo_drawer()
Expand Down Expand Up @@ -342,16 +404,23 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
}


if(mh_->filtered())
{
//volume_drawer_color_->update_edge(*mh_->map(), *mh_->filter(), pos_attr);
volume_drawer_color_->update_face(*mh_->map(), *mh_->filter(), pos_attr, color_attr);
}
else
{
//volume_drawer_color_->update_edge(*mh_->map(), pos_attr);
volume_drawer_color_->update_face(*mh_->map(), pos_attr, color_attr);
}
if(apply_grid_clipping_plane_)
{
update_hexa_drawer();
}
else
{
if(mh_->filtered())
{
//volume_drawer_color_->update_edge(*mh_->map(), *mh_->filter(), pos_attr);
volume_drawer_color_->update_face(*mh_->map(), *mh_->filter(), pos_attr, color_attr);
}
else
{
//volume_drawer_color_->update_edge(*mh_->map(), pos_attr);
volume_drawer_color_->update_face(*mh_->map(), pos_attr, color_attr);
}
}
}
}

Expand All @@ -372,9 +441,6 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
{
QString color_attribute = volume_attribute_ + "_color";


std::cout << volume_attribute_.toStdString() << std::endl;

auto color_attr = mh_->map()->get_attribute<VEC3, CMap3::Volume::ORBIT>(color_attribute.toStdString());

if(!color_attr.is_valid())
Expand Down Expand Up @@ -656,6 +722,12 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters

frame_manip_ = cgogn::make_unique<cgogn::rendering::FrameManipulator>();

hexa_drawer_ = cgogn::make_unique<cgogn::rendering::HexaGridDrawer>();
hexa_drawer_rend_ = hexa_drawer_->generate_renderer();

hexa_drawer_rend_->set_explode_volume(volume_explode_factor_);
hexa_drawer_rend_->set_clipping_plane_topo(QVector3D(clipping_x_, clipping_y_, clipping_z_));

set_position_vbo(position_vbo_);
set_vertex_color(vertex_color_);
set_edge_color(edge_color_);
Expand Down Expand Up @@ -686,13 +758,17 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
std::unique_ptr<cgogn::rendering::VolumeDrawerColor> volume_drawer_color_;
std::unique_ptr<cgogn::rendering::VolumeDrawerColor::Renderer> volume_drawer_color_rend_;

std::unique_ptr<cgogn::rendering::HexaGridDrawer> hexa_drawer_;
std::unique_ptr<cgogn::rendering::HexaGridDrawer::Renderer> hexa_drawer_rend_;

cgogn::rendering::VBO* position_vbo_;
bool render_vertices_;
bool render_edges_;
bool render_faces_;
bool render_topology_;
bool render_color_per_volumes_;
bool apply_clipping_plane_;
bool apply_grid_clipping_plane_;
bool clipping_plane_initialized_;
QColor vertex_color_;
QColor edge_color_;
Expand All @@ -703,6 +779,10 @@ struct PLUGIN_VOLUME_RENDER_EXPORT MapParameters
bool use_transparency_;
int32 transparency_factor_;

int32 clipping_x_;
int32 clipping_y_;
int32 clipping_z_;

QString volume_attribute_;
cgogn::ColorMapType color_map_;
};
Expand Down
40 changes: 35 additions & 5 deletions schnapps/plugins/volume_render/volume_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ MapParameters& Plugin_VolumeRender::parameters(View* view, CMap3Handler* mh)
MapParameters& p = view_param_set[mh];
p.mh_ = mh;
p.set_vertex_base_size(mh->bb_diagonal_size() / (2.0f * std::sqrt(mh->map()->nb_cells<CMap3::Edge>())));

return p;
}
else
Expand Down Expand Up @@ -165,16 +166,21 @@ void Plugin_VolumeRender::draw_object(View* view, Object *o, const QMatrix4x4& p
if(p.render_color_per_volumes_)
{
if (p.render_edges_ && p.volume_explode_factor_ > 0.995f)
p.set_volume_explode_factor(0.995f);
if (!p.use_transparency_ && p.volume_drawer_rend_)
p.volume_drawer_color_rend_->draw_faces(proj, mv);
p.set_volume_explode_factor(0.995f);
if(p.apply_grid_clipping_plane_)
p.hexa_drawer_rend_->draw_faces(proj, mv);
else if (!p.use_transparency_ && p.volume_drawer_rend_)
p.volume_drawer_color_rend_->draw_faces(proj, mv);
}
else
{
if (p.render_edges_ && p.volume_explode_factor_ > 0.995f)
p.set_volume_explode_factor(0.995f);
if (!p.use_transparency_ && p.volume_drawer_rend_)
p.volume_drawer_rend_->draw_faces(proj, mv);

if(p.apply_grid_clipping_plane_)
p.hexa_drawer_rend_->draw_faces(proj, mv);
else if (!p.use_transparency_ && p.volume_drawer_rend_)
p.volume_drawer_rend_->draw_faces(proj, mv);
}
}
}
Expand Down Expand Up @@ -574,6 +580,18 @@ void Plugin_VolumeRender::set_apply_clipping_plane(View* view, CMap3Handler* mh,
}
}

void Plugin_VolumeRender::set_apply_grid_clipping_plane(View* view, CMap3Handler* mh, bool b, bool update_dock_tab)
{
if (view && view->is_linked_to_plugin(this) && mh && mh->is_linked_to_view(view))
{
MapParameters& p = parameters(view, mh);
p.set_apply_grid_clipping_plane(b);
if (update_dock_tab && view->is_selected_view() && dock_tab_->selected_map() == mh)
dock_tab_->set_apply_grid_clipping_plane(b);
view->update();
}
}

void Plugin_VolumeRender::set_vertex_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab)
{
if (view && view->is_linked_to_plugin(this) && mh && mh->is_linked_to_view(view))
Expand Down Expand Up @@ -668,6 +686,18 @@ void Plugin_VolumeRender::set_transparency_factor(View* view, CMap3Handler* mh,
}
}

void Plugin_VolumeRender::set_grid_clipping_plane(View* view, CMap3Handler* mh, int32 x, int32 y, int32 z, bool update_dock_tab)
{
if (view && view->is_linked_to_plugin(this) && mh && mh->is_linked_to_view(view))
{
MapParameters& p = parameters(view, mh);
p.set_clipping_plane(x,y,z);
if (update_dock_tab && view->is_selected_view() && dock_tab_->selected_map() == mh)
dock_tab_->set_grid_clipping_plane(x,y,z);
view->update();
}
}

} // namespace plugin_volume_render

} // namespace schnapps
3 changes: 3 additions & 0 deletions schnapps/plugins/volume_render/volume_render.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public slots:
void set_render_faces(View* view, CMap3Handler* mh, bool b, bool update_dock_tab);
void set_render_topology(View* view, CMap3Handler* mh, bool b, bool update_dock_tab);
void set_apply_clipping_plane(View* view, CMap3Handler* mh, bool b, bool update_dock_tab);
void set_apply_grid_clipping_plane(View* view, CMap3Handler* mh, bool b, bool update_dock_tab);
void set_vertex_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab);
void set_edge_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab);
void set_face_color(View* view, CMap3Handler* mh, const QColor& color, bool update_dock_tab);
Expand All @@ -130,6 +131,8 @@ public slots:
void set_transparency_enabled(View* view, CMap3Handler* mh, bool b, bool update_dock_tab);
void set_transparency_factor(View* view, CMap3Handler* mh, int32 tf, bool update_dock_tab);

void set_grid_clipping_plane(View* view, CMap3Handler* mh, int32 x, int32 y, int32 z, bool update_dock_tab);

private:

VolumeRender_DockTab* dock_tab_;
Expand Down
Loading

0 comments on commit 4b445a0

Please sign in to comment.