17#ifndef __gui_mrview_displayable_h__
18#define __gui_mrview_displayable_h__
52 namespace Tool {
class Connectome; }
53 namespace Tool {
class Tractogram; }
73 const std::string& get_filename ()
const {
77 float scaling_min ()
const {
78 return display_midpoint - 0.5f * display_range;
81 float scaling_max ()
const {
82 return display_midpoint + 0.5f * display_range;
85 float scaling_min_thresholded ()
const {
86 return std::max(scaling_min(), lessthan);
89 float scaling_max_thresholded ()
const {
90 return std::min(scaling_max(), greaterthan);
93 float scaling_rate ()
const {
97 float intensity_min ()
const {
101 float intensity_max ()
const {
105 void set_min_max (
float min,
float max) {
111 void set_windowing (
float min,
float max) {
112 display_range = max - min;
113 display_midpoint = 0.5 * (min + max);
116 void adjust_windowing (
const QPoint& p) {
117 adjust_windowing (p.x(), p.y());
120 void reset_windowing () {
124 void adjust_windowing (
float brightness,
float contrast) {
125 display_midpoint -= 0.0005f * display_range * brightness;
126 display_range *= std::exp (-0.002f * contrast);
130 uint32_t flags ()
const {
return flags_; }
132 void set_allowed_features (
bool thresholding,
bool transparency,
bool lighting) {
141 void set_colour (std::array<GLubyte,3> &c) {
145 void set_use_discard_lower (
bool yesno) {
146 if (!discard_lower_enabled())
return;
150 void set_use_discard_upper (
bool yesno) {
151 if (!discard_upper_enabled())
return;
155 void set_use_transparency (
bool yesno) {
156 if (!transparency_enabled())
return;
160 void set_use_lighting (
bool yesno) {
161 if (!lighting_enabled())
return;
165 void set_invert_scale (
bool yesno) {
169 bool scale_inverted ()
const {
173 bool discard_lower_enabled ()
const {
177 bool discard_upper_enabled ()
const {
181 bool transparency_enabled ()
const {
185 bool lighting_enabled ()
const {
189 bool use_discard_lower ()
const {
193 bool use_discard_upper ()
const {
197 bool use_transparency ()
const {
201 bool use_lighting ()
const {
208 virtual std::string fragment_shader_source (
const Displayable&
object) = 0;
209 virtual std::string geometry_shader_source (
const Displayable&) {
return std::string(); }
210 virtual std::string vertex_shader_source (
const Displayable&
object) = 0;
212 virtual bool need_update (
const Displayable&
object)
const;
216 if (*
this == 0 || need_update (
object))
234 attach (vertex_shader);
235 if((GLuint)geometry_shader)
236 attach (geometry_shader);
237 attach (fragment_shader);
243 std::string declare_shader_variables (
const std::string& with_prefix =
"")
const {
245 "uniform float " + with_prefix+
"offset;\n"
246 "uniform float " + with_prefix+
"scale;\n";
247 if (use_discard_lower())
248 source +=
"uniform float " + with_prefix+
"lower;\n";
249 if (use_discard_upper())
250 source +=
"uniform float " + with_prefix+
"upper;\n";
251 if (use_transparency()) {
253 "uniform float " + with_prefix+
"alpha_scale;\n"
254 "uniform float " + with_prefix+
"alpha_offset;\n"
255 "uniform float " + with_prefix+
"alpha;\n";
258 source +=
"uniform vec3 " + with_prefix +
"colourmap_colour;\n";
262 void start (Shader& shader_program,
float scaling = 1.0,
const std::string& with_prefix =
"") {
263 shader_program.start (*
this);
264 set_shader_variables (shader_program, scaling, with_prefix);
267 void set_shader_variables (Shader& shader_program,
float scaling = 1.0,
const std::string& with_prefix =
"") {
268 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"offset").c_str()), (display_midpoint - 0.5f * display_range) / scaling);
269 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"scale").c_str()), scaling / display_range);
270 if (use_discard_lower())
271 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"lower").c_str()), lessthan / scaling);
272 if (use_discard_upper())
273 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"upper").c_str()), greaterthan / scaling);
274 if (use_transparency()) {
275 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"alpha_scale").c_str()), scaling / (opaque_intensity - transparent_intensity));
276 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"alpha_offset").c_str()), transparent_intensity / scaling);
277 gl::Uniform1f (gl::GetUniformLocation (shader_program, (with_prefix+
"alpha").c_str()), alpha);
280 gl::Uniform3f (gl::GetUniformLocation (shader_program, (with_prefix+
"colourmap_colour").c_str()),
281 colour[0]/255.0, colour[1]/255.0, colour[2]/255.0);
284 void stop (Shader& shader_program) {
285 shader_program.stop();
288 float lessthan, greaterthan;
289 float display_midpoint, display_range;
290 float transparent_intensity, opaque_intensity, alpha;
291 std::array<GLubyte,3> colour;
294 bool show_colour_bar;
307 if (
value) field |= bit;
320 if (!std::isfinite (transparent_intensity))
322 if (!std::isfinite (opaque_intensity))
324 if (!std::isfinite (alpha))
326 if (!std::isfinite (lessthan))
328 if (!std::isfinite (greaterthan))
void set_bit(uint32_t bit, bool value)
void set_bit(uint32_t &field, uint32_t bit, bool value)
virtual void render_image_colourbar(const Image &)
virtual void render_fixel_colourbar(const Tool::BaseFixel &)
virtual void render_tractogram_colourbar(const Tool::Tractogram &)
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
const uint32_t InvertScale
const uint32_t TransparencyEnabled
const uint32_t DiscardLower
const uint32_t DiscardLowerEnabled
const uint32_t DiscardUpperEnabled
const uint32_t Transparency
const uint32_t DiscardUpper
const uint32_t LightingEnabled