17#ifndef __gui_mrview_volume_h__
18#define __gui_mrview_volume_h__
54 void set_interpolate (
bool linear) {
interpolation = linear ? gl::LINEAR : gl::NEAREST; }
55 bool interpolate ()
const {
return interpolation == gl::LINEAR; }
57 void set_colourmap (
size_t index) {
59 if (
index != colourmap)
61 Displayable::colourmap =
index;
64 void render (Displayable::Shader& shader_program,
const Projection& projection,
float depth) {
66 projection.
set (shader_program);
70 stop (shader_program);
75 texture().
gen (gl::TEXTURE_3D);
84 Eigen::Transform<float,3,Eigen::AffineCompact> image2scanner ()
const {
85 return _header.transform().cast<
float>();
88 Eigen::Transform<float,3,Eigen::AffineCompact> scanner2image ()
const {
89 return _header.transform().inverse().cast<
float>();
92 Eigen::Transform<float,3,Eigen::AffineCompact> voxel2scanner ()
const {
94 return T.scale (Eigen::Vector3d (
_header.spacing(0),
_header.spacing(1),
_header.spacing(2))).cast<
float>();
97 Eigen::Transform<float,3,Eigen::AffineCompact> scanner2voxel ()
const {
98 auto T =
_header.transform().inverse();
99 return T.prescale (Eigen::Vector3d (1.0/
_header.spacing(0), 1.0/
_header.spacing(1), 1.0/
_header.spacing(2))).cast<
float>();
104 float focus_rate ()
const {
105 return 1.0e-3 * (std::pow (
120 if (std::isnan (display_midpoint) || std::isnan (display_range))
126 inline void upload_data (
const std::array<ssize_t,3>& x,
const std::array<ssize_t,3>& size,
const void* data) {
127 gl::TexSubImage3D (gl::TEXTURE_3D, 0,
129 size[0], size[1], size[2],
147 inline Eigen::Vector3f
div (
const Eigen::Vector3f& a,
const Eigen::Vector3f& b) {
148 return Eigen::Vector3f (a[0]/b[0], a[1]/b[1], a[2]/b[2]);
159 const auto S2V = scanner2voxel();
178 gl::EnableVertexAttribArray (0);
179 gl::VertexAttribPointer (0, 3, gl::FLOAT, gl::FALSE_, 2*
sizeof(Eigen::Vector3f), (
void*)0);
181 gl::EnableVertexAttribArray (1);
182 gl::VertexAttribPointer (1, 3, gl::FLOAT, gl::FALSE_, 2*
sizeof(Eigen::Vector3f), (
void*)(
sizeof(Eigen::Vector3f)));
189 gl::BufferData (gl::ARRAY_BUFFER, 8*
sizeof(Eigen::Vector3f), &
vertices[0][0], gl::STREAM_DRAW);
190 gl::DrawArrays (gl::TRIANGLE_FAN, 0, 4);
static bool get_bool(const std::string &key, bool default_value)
void set_interp(GLint type) const
void gen(GLenum target, GLint interp_type=gl::LINEAR)
void bind(GLenum target) const
Eigen::Vector3f vertices[8]
bool texture_mode_changed
GL::Texture * _current_texture
GL::VertexBuffer vertex_buffer
GL::VertexArrayObject vertex_array_object
void set_vertices_for_slice_render(const Projection &projection, float depth)
Eigen::Vector3f div(const Eigen::Vector3f &a, const Eigen::Vector3f &b)
Eigen::Vector3f screen_to_model(float x, float y, float depth) const
void set(GL::Shader::Program &shader_program) const