00001 /***************************************************************************** 00002 * Copyright (C) 2007 Herve Lombaert <herve.lombaert@polymtl.ca> 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the 00016 * Free Software Foundation, Inc., 00017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 ****************************************************************************/ 00019 00020 00027 #ifndef DISPLAYTRAPEZOID_H 00028 #define DISPLAYTRAPEZOID_H 00029 00030 00031 #if __APPLE__ 00032 #include <OpenGL/gl.h> 00033 #else 00034 #include <GL/gl.h> 00035 #endif 00036 00037 00038 namespace Tools { namespace TransferFunction 00039 { 00062 class Trapezoid 00063 { 00064 public: 00065 Trapezoid(); 00066 Trapezoid(float low0, float high0, float high1, float low1, float opacity=1); 00067 ~Trapezoid(); 00068 00069 /* update ramp */ 00070 void update(float low0, float high0, float high1, float low1, float opacity); 00071 00072 /* update border (visualize only portion of the ramp) */ 00073 void clamp(float left, float right); 00074 00075 /* display ramp line and squares */ 00076 void display() const; 00077 00078 /* did mouse pick a ramp feature (xy normalized 0..1) */ 00079 bool mouse(float x, float y); 00080 00081 /* handle mouse motion after a mouse pick (xy normalized 0..1) */ 00082 bool motion(float x, float y); 00083 00084 /* get the ramp value (rgba 0..1) for a given intensity */ 00085 void get(float i, float &r, float &g, float &b, float &a) const; 00086 00087 /* set color of the selected feature */ 00088 void setColor(float r, float g, float b); 00089 00090 /* update aspect ratio (w/h) so square appears as square */ 00091 void reshape(int w, int h); 00092 00093 private: 00094 float m_low0; 00095 float m_low1; 00096 float m_high0; 00097 float m_high1; 00098 float m_opacity; 00099 float m_left; 00100 float m_right; 00101 float m_low0_u; 00102 float m_low1_u; 00103 float m_high0_u; 00104 float m_high1_u; 00105 float m_aspectratio; 00106 float m_low0_color[3]; 00107 float m_low1_color[3]; 00108 float m_high0_color[3]; 00109 float m_high1_color[3]; 00110 float m_middle0_color[3]; 00111 float m_middle1_color[3]; 00112 00113 // trapezoid features 00114 // LOW0 is the first ramp lowest value 00115 // HIGH1 is the first ramp highest value 00116 // LOW1 is the second ramp lowest value 00117 // HIGH1 is the second ramp highest value 00118 // MIDDLE0 is a dragrable square of the first ramp, change translate the ramp 00119 // MIDDLE1 is a dragrable square of the first ramp, change translate the ramp 00120 enum feature { NONE, LOW0, LOW1, HIGH0, HIGH1, MIDDLE0, MIDDLE1 }; 00121 feature m_feature; 00122 }; 00123 00124 00125 }} // namespaces 00126 00127 #endif