00001 #include "vuStandardFVR.h"
00002 #include "General/vuFourier/vuFourierFilter/vuTorstensFourierFilter.h"
00003
00004 template<int SIZE>
00005 vuStandardFVR<SIZE>::vuStandardFVR()
00006 {
00007 m_Data = NULL;
00008 }
00009
00010 template<int SIZE>
00011 vuStandardFVR<SIZE>::~vuStandardFVR()
00012 {
00013 if (m_Data != NULL) {
00014 delete m_Data;
00015 m_Data = NULL;
00016 }
00017 }
00018
00019 template<int SIZE>
00020 const char *vuStandardFVR<SIZE>::_titleString()
00021 {
00022 return "Standard Fourier Volume Renderer";
00023 }
00024
00025 template<int SIZE>
00026 bool vuStandardFVR<SIZE>::init(const char* DataFile)
00027 {
00028 SetEvtHandlerEnabled(true);
00029
00030
00031 SetTitle(_titleString());
00032 CreateStatusBar();
00033
00034 m_Data = new vu1712_1<SIZE>;
00035 m_Data->setFileName(DataFile);
00036 m_Data->setFilter(vuTorstensFourierFilter::getFilter("d0_c0_1ef"));
00037
00038
00039 bool success = m_Data->read();
00040 if (success) {
00041 m_glCanvas->SetSize(512,512);
00042 vuString str;
00043 str = _titleString();
00044 str += ": [";
00045 str += m_Data->getXSize() - 2 * m_Data->getWrap();
00046 str += "x";
00047 str += m_Data->getYSize() - 2 * m_Data->getWrap();
00048 str += "x";
00049 str += m_Data->getZSize() - 2 * m_Data->getWrap();
00050 str += "] <";
00051 str += SIZE;
00052 str += " ";
00053 str += "float>";
00054 SetTitle(str.c_str());
00055 Fit();
00056 }
00057 else {
00058 wxMessageDialog dlg(this,m_Data->getErrorMessage(),
00059 _titleString(), wxOK);
00060 dlg.ShowModal();
00061 }
00062 return success;
00063 }
00064
00065 template<int SIZE>
00066 vuCamera* vuStandardFVR<SIZE>::getCamera()
00067 {
00068 return NULL;
00069 }
00070
00071 template<int SIZE>
00072 vuImage* vuStandardFVR<SIZE>::getCurrentImage()
00073 {
00074 return NULL;
00075 }
00076
00077 template<int SIZE>
00078 void vuStandardFVR<SIZE>::DrawFromImage()
00079 {
00080 }
00081
00082 template<int SIZE>
00083 void vuStandardFVR<SIZE>::DrawAgain()
00084 {
00085 }
00086
00087 template<int SIZE>
00088 wxString vuStandardFVR<SIZE>::helpText()
00089 {
00090 wxString str("");
00091
00092 str +=
00093 "\t ?\t\t\t\t this help window\n"
00094 "\t UP\t\t\t previous view\n"
00095 "\t DOWN\t\t\t next view\n"
00096 "\t LEFT\t\t\t decrease image scaling\n"
00097 "\t RIGHT\t\t\t increase image scaling\n"
00098 "\t SHIFT+LEFT\t\t slowly decrease image scaling\n"
00099 "\t SHIFT+RIGHT\t\t slowly increase image scaling\n"
00100 "\t SPACE\t\t\t set image scaling to one (same as 'fit' button)\n";
00101
00102 return str;
00103 }
00104
00105 template<int SIZE>
00106 void vuStandardFVR<SIZE>::addRight(wxSizer *sizer)
00107 {
00108 }
00109
00110 template<int SIZE>
00111 void vuStandardFVR<SIZE>::addBottom(wxSizer *sizer)
00112 {
00113 wxBoxSizer *horSpacer = new wxBoxSizer(wxHORIZONTAL);
00114 wxBoxSizer *verSpacer = new wxBoxSizer(wxVERTICAL);
00115
00116
00117
00118 wxFlexGridSizer *grid = new wxFlexGridSizer(2,5,5);
00119
00120
00121 {
00122 dword count = 0;
00123 vuString *filterNames = NULL;
00124
00125 m_CHOICEfilter =
00126 new wxChoice(this, idFILTER, wxDefaultPosition, wxSize(130,20),
00127 0, NULL, wxCAPTION, wxDefaultValidator, "Filter");
00128
00129 vuTorstensFourierFilter::getFilterNames(filterNames, count);
00130 for (dword i=0; i< count; i++) {
00131 if (filterNames[i].hasPrefix("d0"))
00132 m_CHOICEfilter->Append(filterNames[i].c_str());
00133 }
00134 m_CHOICEfilter->SetSelection(0);
00135 }
00136
00137
00138 {
00139 m_CHOICErenderMethod =
00140 new wxChoice(this, idRENDERMETHOD, wxDefaultPosition, wxSize(130,20),
00141 0, NULL, wxCAPTION, wxDefaultValidator, "RenderMethod");
00142
00143 m_CHOICErenderMethod->Append("Spatial");
00144 m_CHOICErenderMethod->Append("Freq. Amplitude ");
00145 m_CHOICErenderMethod->Append("Freq. Phase");
00146 m_CHOICErenderMethod->Append("Freq. Real");
00147 m_CHOICErenderMethod->Append("Freq. Imaginary");
00148
00149 m_CHOICErenderMethod->SetSelection(0);
00150 }
00151
00152
00153 {
00154 m_SLIDERimageScale =
00155 new wxSlider(this, idIMAGESCALE, 1, 1, 10000, wxDefaultPosition,
00156 wxSize(106,16), wxSL_HORIZONTAL,
00157 wxDefaultValidator, "imageScaleSlider");
00158 m_SLIDERimageScale->SetValue(2550);
00159 }
00160
00161
00162 {
00163 m_BUTTONfitScale = new wxButton(this,idFITSCALE,"fit",
00164 wxPoint(0,0),wxSize(20,16));
00165 }
00166
00167 wxBoxSizer *scaleSizer = new wxBoxSizer(wxHORIZONTAL);
00168 scaleSizer->Add(m_SLIDERimageScale);
00169 scaleSizer->Add(2,0);
00170 scaleSizer->Add(m_BUTTONfitScale);
00171
00172 grid->Add(80,5);
00173 grid->Add(0, 5);
00174 grid->Add(new wxStaticText(this, -1, "Filter:"), 0, wxALIGN_RIGHT);
00175 grid->Add(m_CHOICEfilter,0,wxALL|wxALIGN_LEFT,1);
00176
00177 grid->Add(new wxStaticText(this, -1, "Method:"), 0, wxALIGN_RIGHT);
00178 grid->Add(m_CHOICErenderMethod,0,wxALL|wxALIGN_LEFT,1);
00179
00180 _addChannelControls(grid);
00181
00182 grid->Add(new wxStaticText(this,-1,"Scale:"),0,wxALIGN_RIGHT|wxALIGN_BOTTOM);
00183 grid->Add(scaleSizer,0,wxALL|wxALIGN_LEFT,1);
00184
00185 grid->Add(0,3);
00186 grid->Add(0,3);
00187
00188 horSpacer->Add(0,15);
00189 horSpacer->Add(grid);
00190
00191
00192
00193 verSpacer->Add(10,0);
00194 verSpacer->Add(horSpacer);
00195 verSpacer->Add(10,0);
00196
00197 sizer->Add(verSpacer,0,wxEXPAND, 5);
00198 }
00199
00200
00201 template<int SIZE>
00202 bool vuStandardFVR<SIZE>::glInit()
00203 {
00204 if (m_Data == NULL) return false;
00205
00206 return true;
00207 }
00208
00209 template<int SIZE>
00210 void vuStandardFVR<SIZE>::glRender()
00211 {
00212 wxStopWatch watch;
00213
00214 watch.Start();
00215 m_Data->render();
00216 watch.Pause();
00217
00218 wxString statusText = "Render Time: ";
00219
00220 statusText += vuString(watch.Time()).c_str();
00221 statusText += "ms";
00222 SetStatusText(statusText);
00223
00224 m_Data->glResize(m_glCanvas->getWidth(), m_glCanvas->getHeight());
00225 }
00226
00227 template<int SIZE>
00228 void vuStandardFVR<SIZE>::glResize()
00229 {
00230 m_Data->glResize(m_glCanvas->getWidth(), m_glCanvas->getHeight());
00231 m_glCanvas->redraw();
00232 }
00233
00234 template <int SIZE>
00235 vu1 *vuStandardFVR<SIZE>::getVolume()
00236 {
00237 return m_Data;
00238 }
00239
00240
00241
00242 template <int SIZE>
00243 void vuStandardFVR<SIZE>::onKeyboard(wxKeyEvent &event)
00244 {
00245
00246 }
00247
00248 template <int SIZE>
00249 void vuStandardFVR<SIZE>::OnChoiceRenderMethod(wxCommandEvent& event)
00250 {
00251 dword idx = m_CHOICErenderMethod->GetSelection();
00252 if (idx == 0) {
00253 m_SLIDERimageScale->SetValue(255*10);
00254 }
00255 else {
00256 m_SLIDERimageScale->SetValue(1);
00257 }
00258 m_Data->setRenderMethod(idx);
00259 m_Data->setScale(1/(float)(m_SLIDERimageScale->GetValue() * 10));
00260 m_Data->setIsReRendering(true);
00261 m_glCanvas->redraw();
00262 }
00263
00264 template <int SIZE>
00265 void vuStandardFVR<SIZE>::OnChoiceFilter(wxCommandEvent& event)
00266 {
00267 vuFourierFilter *tmp = m_Data->getFilter();
00268 vuString name = m_CHOICEfilter->GetStringSelection().c_str();
00269
00270 if (tmp) if (tmp->getFilterName() == name) return;
00271
00272 m_Data->setFilter(vuTorstensFourierFilter::getFilter(name));
00273 CHECKNDELETE(tmp);
00274 m_glCanvas->redraw();
00275 }
00276
00277 template <int SIZE>
00278 void vuStandardFVR<SIZE>::OnButtonFitScale(wxCommandEvent& event)
00279 {
00280 m_Data->fitScale();
00281 m_glCanvas->redraw();
00282 }
00283
00284 template <int SIZE>
00285 void vuStandardFVR<SIZE>::OnSliderImageScale(wxScrollEvent& event)
00286 {
00287 m_Data->setScale(255.0f/(float)m_SLIDERimageScale->GetValue());
00288 m_glCanvas->redraw();
00289 }
00290
00291 template <int SIZE>
00292 void vuStandardFVR<SIZE>::OnCheckboxChannels(wxCommandEvent& event)
00293 {
00294 for (int i=0; i<SIZE; i++) {
00295 m_Data->setIsChannelActive(i, m_CHECKBOXchannels[i]->GetValue());
00296 }
00297 m_glCanvas->redraw();
00298 }
00299
00300
00301
00302
00303 template <int SIZE>
00304 void vuStandardFVR<SIZE>::_addChannelControls(wxFlexGridSizer *sizer)
00305 {
00306 vuString str;
00307
00308 if (SIZE == 1)
00309 return;
00310 else if (SIZE == 2)
00311 str = "IA";
00312 else if (SIZE == 3)
00313 str = "RGB";
00314 else
00315 return;
00316
00317 wxBoxSizer *channelSpacer = new wxBoxSizer(wxHORIZONTAL);
00318
00319 m_CHECKBOXchannels = new wxCheckBox*[SIZE];
00320
00321 for (int i=0; i<SIZE; i++) {
00322 m_CHECKBOXchannels[i] = new wxCheckBox(this, idCHANNELS, str[(dword)i],
00323 wxDefaultPosition, wxSize(130/SIZE,15));
00324 m_CHECKBOXchannels[i]->SetValue(true);
00325 channelSpacer->Add(m_CHECKBOXchannels[i]);
00326 }
00327
00328 sizer->Add(new wxStaticText(this, -1, "Channels:"), 0, wxALIGN_RIGHT);
00329 sizer->Add(channelSpacer,0,wxALL|wxALIGN_LEFT,1);
00330 }