00001 #include "vuColourRGBa.h"
00002 #include "vuSpecSplat.h"
00003 #include "../../wxUIElements/vuGLCanvas.h"
00004 #include "../../wxUIElements/vuTFDialogSpec.h"
00005 #include <wx/wx.h>
00006
00007
00008
00009
00010
00011 enum
00012 {
00013 idCANVAS
00014 };
00015
00016
00017 BEGIN_EVENT_TABLE(vuSpecSplat, vuBasicUtility)
00018 END_EVENT_TABLE();
00019
00020
00021
00022
00023
00024
00025
00026 vuSpecSplat::vuSpecSplat() : m_TFunc(32), m_TFDialog(this,m_TFunc),
00027 m_LightDial(this,m_TFunc)
00028 {
00029 m_Data = 0;
00030 m_ViewScale = 1.0f;
00031 }
00032
00033
00034
00035
00036
00037 vuSpecSplat::~vuSpecSplat()
00038 {
00039 if (m_Data != 0) delete m_Data;
00040 }
00041
00042
00043
00044
00045
00046 const char* vuSpecSplat::getFileType()
00047 {
00048 return "11121";
00049 }
00050
00051
00052
00053
00054
00055 bool vuSpecSplat::init(const char* DataFile)
00056 {
00057
00058 SetTitle("vuSpecSplat");
00059 CreateStatusBar();
00060
00061
00062 m_Data = new vu1112115;
00063 m_Data->setFileName(DataFile);
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 m_TFunc.generateFunction();
00078 m_Data->setTransferFunc(m_TFunc);
00079
00080
00081 bool success = m_Data->read();
00082 if (success)
00083 {
00084 m_glCanvas->SetSize(512,512);
00085 Fit();
00086 }
00087 else
00088 {
00089 wxMessageDialog dlg(this,m_Data->getErrorMessage(),"vuSpecSplat",wxOK);
00090 dlg.ShowModal();
00091 }
00092
00093 return success;
00094 };
00095
00096
00097
00098
00099
00100 bool vuSpecSplat::glInit(void)
00101 {
00102 if (m_Data == 0) return false;
00103
00104 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
00105
00106 glEnable(GL_LIGHTING);
00107 glEnable(GL_LIGHT0);
00108 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
00109
00110 m_Data->initOpenGL();
00111 return true;
00112 };
00113
00114
00115
00116
00117
00118
00119 void vuSpecSplat::glRender()
00120 {
00121 wxStopWatch watch;
00122 watch.Start();
00123
00124 glClear(GL_COLOR_BUFFER_BIT);
00125
00126 glLoadIdentity();
00127 m_Camera.gluLookAt();
00128 glTranslatef((float)m_Data->getDim1Size()/(-2.0f),
00129 (float)m_Data->getDim2Size()/(-2.0f),
00130 (float)m_Data->getDim3Size()/(-2.0f));
00131
00132 m_Data->setViewVectors(m_Camera.getLookAtVector(),
00133 m_Camera.getUpVector(),
00134 m_Camera.getRightVector());
00135
00136
00137 m_Data->setTransferFunc(m_TFunc);
00138
00139 m_Data->render();
00140
00141 watch.Pause();
00142 SetStatusText(wxString("Render Time: ") + vuString(watch.Time()).c_str() + "ms");
00143 };
00144
00145 void vuSpecSplat::notifyDataChanged()
00146 {
00147 m_glCanvas->redraw();
00148 }
00149
00150
00151
00152
00153
00154
00155 void vuSpecSplat::glResize()
00156 {
00157
00158 glViewport(0, 0, (GLint)m_glCanvas->getWidth(),(GLint)m_glCanvas->getHeight());
00159
00160
00161 dword max = m_Data->getDim1Size();
00162 if (m_Data->getDim2Size() > max)
00163 max = m_Data->getDim2Size();
00164 if (m_Data->getDim3Size() > max)
00165 max = m_Data->getDim3Size();
00166
00167
00168 glMatrixMode(GL_PROJECTION);
00169 glLoadIdentity();
00170 glOrtho((float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00171 (float)max/(-1.0f*m_ViewScale), (float)max/m_ViewScale,
00172 10000.0f, -10000.0f);
00173 glMatrixMode(GL_MODELVIEW);
00174 glLoadIdentity();
00175
00176
00177 float lpos[4] = {0.0, 0.0, 1024.0, 1.0};
00178 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
00179 }
00180
00181
00182
00183
00184
00185 void vuSpecSplat::glOnMouse(wxMouseEvent &ev)
00186 {
00187 if (ev.LeftDown() || ev.RightDown())
00188 {
00189
00190 m_x = (int) ev.GetX();
00191 m_y = (int) ev.GetY();
00192 }
00193 else if (ev.LeftIsDown() && ev.Moving())
00194 {
00195
00196 vuVector t = m_Camera.getPosition();
00197 float d = t.norm();
00198
00199 m_Camera.translateXYZ(0.0f, 0.0f, d);
00200 m_Camera.rotateAboutUp(ev.GetX() - m_x);
00201 m_Camera.rotateAboutRight(ev.GetY() - m_y);
00202 m_Camera.translateXYZ(0.0f, 0.0f, -d);
00203 m_glCanvas->redraw();
00204
00205
00206 m_x = (int) ev.GetX();
00207 m_y = (int) ev.GetY();
00208 }
00209 else if (ev.RightIsDown() && ev.Moving())
00210 {
00211
00212 m_ViewScale -= ((float)ev.GetY() - m_y)/500.0f;
00213 glResize();
00214 m_glCanvas->redraw();
00215
00216
00217 m_x = (int) ev.GetX();
00218 m_y = (int) ev.GetY();
00219 }
00220 else if (ev.LeftDClick())
00221 {
00222
00223 m_TFDialog.Show(true);
00224 }
00225 else if (ev.RightDClick())
00226 {
00227
00228 m_LightDial.Show(true);
00229 }
00230 }
00231
00232 void vuSpecSplat::DrawAgain ()
00233
00234 {
00235 m_glCanvas->redraw();
00236 }
00237
00238 void vuSpecSplat::DrawFromImage ()
00239
00240 {
00241 m_Data->drawPic ();
00242 }
00243
00244 vuImage* vuSpecSplat::getCurrentImage ()
00245
00246 {
00247 return m_Data->getBuffer ();
00248 }
00249
00250 vuCamera* vuSpecSplat::getCamera ()
00251
00252 {
00253 return &m_Camera;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264