Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

vuMarchingCubes.cpp

Go to the documentation of this file.
00001 
00012 #include "vuMarchingCubes.h"
00013 
00014 #include <fstream.h>
00015 #include <assert.h>
00016 
00017 #include "vuColourRGBa.h"
00018 #include "vuPreviewWin.h"
00019 #include "vuMatrix.h"
00020 
00021 #include "../../wxUIElements/vuTransferDialog.h"
00022 
00023 // Actual Mod: 7
00024 #define DEBUG_MODE 99
00025 //#define DEBUG_CONST
00026 //#define DEBUG_DEST
00027 #include "General/vuMarchingCubes/debug.h"
00028 
00029 #include "gl-24x24.xpm"
00030 
00031 
00032 // {{{ class vuMCWidget:
00033 
00034 IMPLEMENT_DYNAMIC_CLASS(vuMCWidget, wxPanel);
00035 
00036 BEGIN_EVENT_TABLE(vuMCWidget, wxPanel) // {{{
00037 END_EVENT_TABLE(); // }}}
00038 
00039 vuMCWidget::vuMCWidget(wxWindow* p, int orient, int type, int cols, int hgap, int vgap) // {{{
00040 : wxPanel(p, -1)
00041 {
00042         DEBUGC("vuMCWidget::vuMCWidget(wxWindow* p="<<p<<", int orient="<<orient<<", int type="<<type<<", "
00043                <<"int cols="<<cols<<", int hgap="<<hgap<<", int vgap="<<vgap<<")\n");
00044         _sizer = 0;
00045         switch (type) {
00046                 case typeBox:
00047                         _sizer = new wxBoxSizer(orient);
00048                         break;
00049                 case typeStaticBox:
00050                         _sizer = new wxStaticBoxSizer(new wxStaticBox(this, -1, _T("No title!")), orient);
00051                         break;
00052                 case typeGrid:
00053                         _sizer = new wxGridSizer(cols, vgap, hgap);
00054                         break;
00055         }
00056         SetSizer(_sizer);
00057 } // }}} vuMCWidget::vuMCWidget(wxWindow* p, int orient, int type, int cols, int hgap, int vgap)
00058 
00062 vuMCWidget::~vuMCWidget() // {{{
00063 {
00064         DEBUGC("virtual vuMCWidget::~vuMCWidget()\n");
00065         DEBUG4("_sizer = "<<_sizer<<"\n");
00066         //delete _sizer;
00067 } /* }}} vuMCWidget::~vuMCWidget() */
00068 
00069 wxSizer* vuMCWidget::Sizer() // {{{
00070 {
00071         DEBUG0("wxSizer* vuMCWidget::Sizer()\n");
00072         return _sizer;
00073 } // }}} wxSizer* vuMCWidget::Sizer()
00074 
00075 // }}} vuMCWidget
00076 
00077 
00078 // {{{ class vuMCKeyValue:
00079 
00080 IMPLEMENT_DYNAMIC_CLASS(vuMCKeyValue, vuMCWidget);
00081 
00082 BEGIN_EVENT_TABLE(vuMCKeyValue, vuMCWidget) // {{{
00083 END_EVENT_TABLE(); // }}}
00084 
00089 vuMCKeyValue::vuMCKeyValue(wxWindow* p, const char* key, const char* format, GLfloat val) // {{{
00090 : vuMCWidget(p, wxHORIZONTAL), _value(0), _format(format)
00091 {
00092         DEBUGC("vuMCKeyValue<t>::vuMCKeyValue(wxWindow* p="<<p<<", "
00093                <<"const char* key="<<key<<", const char* format="<<format<<")\n");
00094         _key = new wxStaticText(this, -1, key, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
00095         Sizer()->Add(_key, 1, wxGROW, 5);
00096         _valueText = new wxStaticText(this, -1, wxString::Format(format, 0.0f));
00097         Sizer()->Add(_valueText, 1, wxGROW, 5);
00098         Fit();
00099 } /* }}} vuMCKeyValue::vuMCKeyValue(wxWindow* p, const char* key, const char* format) */
00100 
00101 vuMCKeyValue::~vuMCKeyValue() // {{{
00102 {
00103         DEBUGD("virtual vuMCKeyValue::~vuMCKeyValue()\n");
00104         delete _valueText;
00105         delete _key;
00106 } /* }}} vuMCKeyValue::~vuMCKeyValue() */
00107 
00108 void vuMCKeyValue::operator=(GLfloat v) // {{{
00109 {
00110         DEBUG0("void vuMCKeyValue::operator=(GLfloat v="<<v<<")\n");
00111         DEBUG3("v = "<<v<<"\n");
00112         _value = v;
00113         _valueText->SetLabel(wxString::Format(_format, _value));
00114 } /* }}} void vuMCKeyValue::operator=(GLfloat v) */
00115 
00116 void vuMCKeyValue::operator+=(GLfloat v) // {{{
00117 {
00118         DEBUG0("void vuMCKeyValue::operator+=(GLfloat v="<<v<<")\n");
00119         _value += v;
00120         _valueText->SetLabel(wxString::Format(_format, _value));
00121 } /* }}} void vuMCKeyValue::operator+=(GLfloat v) */
00122 
00123 void vuMCKeyValue::operator-=(GLfloat v) // {{{
00124 {
00125         DEBUG0("void vuMCKeyValue::operator-=(GLfloat v="<<v<<")\n");
00126         _value -= v;
00127         _valueText->SetLabel(wxString::Format(_format, _value));
00128 } /* }}} void vuMCKeyValue::operator-=(GLfloat v) */
00129 
00130 void vuMCKeyValue::Label(wxString txt) // {{{
00131 {
00132         DEBUG0("void vuMCKeyValue::Label(wxString txt="<<txt<<")\n");
00133         _valueText->SetLabel(txt);
00134 } /* }}} void vuMCKeyValue::Label(wxString txt) */
00135 
00136 inline vuMCKeyValue::operator GLfloat() // {{{
00137 {
00138         DEBUG0("vuMCKeyValue::operator GLfloat()\n");
00139         return _value;
00140 } /* }}} vuMCKeyValue::operator GLfloat() */
00141 
00142 // }}} vuMCKeyValue
00143 
00144 
00145 // {{{ class vuMCKeyVector:
00146 
00147 IMPLEMENT_DYNAMIC_CLASS(vuMCKeyVector, vuMCKeyValue);
00148 
00149 BEGIN_EVENT_TABLE(vuMCKeyVector, vuMCKeyValue) // {{{
00150 END_EVENT_TABLE(); // }}}
00151 
00152 vuMCKeyVector::vuMCKeyVector(wxWindow* p, const char* key, int size, const char* format) // {{{
00153 : vuMCKeyValue(p, key, format), _size(size), _pos(-1)
00154 {
00155         DEBUGC("vuMCKeyVector::vuMCKeyVector(wxWindow* p="<<p<<", "
00156                <<"const char* key="<<key<<", int size="<<size<<", "
00157                <<"const char* format="<<format<<")\n");
00158         for(int i = 0; i < size; ++i) _vector[i] = 0.0f;
00159         _updateLabel();
00160         Fit();
00161 } /* }}} vuMCKeyVector::vuMCKeyVector(wxWindow* p, const char* key, const char* format) */
00162 
00163 vuMCKeyVector::~vuMCKeyVector() // {{{
00164 {
00165         DEBUGD("virtual vuMCKeyVector::~vuMCKeyVector()\n");
00166 } /* }}} vuMCKeyVector::~vuMCKeyVector() */
00167 
00168 void vuMCKeyVector::_updateLabel() // {{{
00169 {
00170         DEBUG0("wxString vuMCKeyVector::_updateLabel()\n");
00171         wxString label = "[";
00172         label << wxString::Format(_format, _vector[0]);
00173         for(int i=1; i<_size; ++i) label << ", " << wxString::Format(_format, _vector[i]);
00174         label << "]";
00175         DEBUG1("label = "<<label<<"\n");
00176         Label(label);
00177 } /* }}} wxString vuMCKeyVector::_updateLabel() */
00178 
00179 void vuMCKeyVector::operator()(int n, GLfloat val) // {{{
00180 {
00181         DEBUG0("void vuMCKeyVector<t, size>::operator()(int n="<<n<<", GLfloat val"<<val<<")\n");
00182         assert(0 <= n && n < _size);
00183         _vector[n] = val;
00184         _updateLabel();
00185 } /* }}} void vuMCKeyVector::operator()(int n, GLfloat val) */
00186 
00187 GLfloat vuMCKeyVector::Get(int pos) // {{{
00188 {
00189         DEBUG0("GLfloat vuMCKeyVector::Get(int pos)\n");
00190         assert(0 <= pos && pos < _size);
00191         return _vector[pos];
00192 } // }}} t vuMCKeyVector::Get(int pos)
00193 
00194 vuMCKeyVector::operator const GLfloat*() // {{{
00195 {
00196         DEBUG0("vuMCKeyVector::operator const GLfloat*()\n");
00197         return _vector;
00198 } /* }}} vuMCKeyVector::operator const GLfloat*(int n) */
00199 
00200 void vuMCKeyVector::Inc(int n, GLfloat val) // {{{
00201 {
00202         DEBUG0("void vuMCKeyVector::Inc(int n="<<n<<", GLfloat val="<<val<<")\n");
00203         assert(0 <= n && n < _size);
00204         _vector[n] += val;
00205         _updateLabel();
00206 } /* }}} void vuMCKeyVector::Inc(int n, GLfloat val) */
00207 
00211 vuMCKeyVector& vuMCKeyVector::operator[](int n) // {{{
00212 {
00213         DEBUG0("vuMCKeyVector& vuMCKeyVector::operator[](int n="<<n<<")\n");
00214         assert(0 <= n && n < _size);
00215         _pos = n;
00216         return *this;
00217 } /* }}} vuMCKeyVector& vuMCKeyVector::operator[](int n) */
00218 
00219 void vuMCKeyVector::operator=(GLfloat val) // {{{
00220 {
00221         DEBUG0("void vuMCKeyVector::operator=(GLfloat val="<<val<<")\n");
00222         assert(_pos != -1);
00223         _vector[_pos] = val;
00224         _updateLabel();
00225 } /* }}} void vuMCKeyVector::operator=(GLfloat val) */
00226 
00227 void vuMCKeyVector::operator+=(GLfloat val) // {{{
00228 {
00229         DEBUG0("void vuMCKeyVector::operator+=(GLfloat val = "<<val<<")\n");
00230         assert(_pos != -1);
00231         _vector[_pos] += val;
00232         _updateLabel();
00233 } /* }}} void vuMCKeyVector::operator+=(GLfloat val) */
00234 
00235 void vuMCKeyVector::operator-=(GLfloat val) // {{{
00236 {
00237         DEBUG0("void vuMCKeyVector::operator-=(GLfloat val = "<<val<<")\n");
00238         assert(_pos != -1);
00239         _vector[_pos] -= val;
00240         _updateLabel();
00241 } /* }}} void vuMCKeyVector::operator-=(GLfloat val) */
00242 
00243 // }}} vuMCKeyVector
00244 
00245 
00246 // {{{ class vuMCBitField:
00247 
00248 IMPLEMENT_DYNAMIC_CLASS(vuMCBitField, vuMCWidget);
00249 
00250 BEGIN_EVENT_TABLE(vuMCBitField, vuMCWidget) // {{{
00251         EVT_COMMAND_RANGE (vuMCBitField::idMCBFCheckboxes, vuMCBitField::idMCBFCheckboxes+(VU_MCBF_MAX_SIZE),
00252                            wxEVT_COMMAND_CHECKBOX_CLICKED, vuMCBitField::OnCheckboxClicked)
00253         EVT_COMMAND_SCROLL(vuMCBitField::idMCBFSlider,     vuMCBitField::OnScroll)
00254 END_EVENT_TABLE(); // }}}
00255 
00256 vuMCBitField::vuMCBitField(wxWindow* p, const char* title, vuMCDecorator<int>* cb, int size, int init) // {{{
00257 : vuMCWidget(p), _callback(cb), _titleString(title), _size(size), _pos(-1)
00258 {
00259         DEBUGC("vuMCBitField::vuMCBitField(wxWindow* p="<<p<<", const char* title="<<title<<", "
00260                <<"vuMCDecorator<int>* dec="<<cb<<", int size="<<size<<", int init="<<init<<")\n");
00261         assert(size <= VU_MCBF_MAX_SIZE);
00263         _title = new wxStaticText(this, -1, wxString(""));
00264         _setTitle(init);
00265         Sizer()->Add(_title, 0, wxGROW, 5);
00266         wxSizer* sz = new wxGridSizer(4, 0, 5);
00267         Sizer()->Add(sz, 0, wxGROW, 5);
00268         for(int i = 0; i < VU_MCBF_MAX_SIZE; ++i) _checkboxes[i] = 0;
00269         for(int i = 0; i < size; ++i) {
00270                 _checkboxes[i] = new wxCheckBox(this, idMCBFCheckboxes+i, wxString("")<<i);
00271                 _checkboxes[i]->SetValue((1<<i)&init);
00272                 sz->Add(_checkboxes[i], 0, wxGROW, 5);
00273         }
00274         _slider = new wxSlider(this, idMCBFSlider, init, 0, (1<<size)-1);
00275         Sizer()->Add(_slider, 0, wxGROW, 5);
00276         Fit();
00277 } // }}} vuMCBitField::vuMCBitField(wxWindow* p, vuMCDecorator<int>* dec, int size, int init)
00278 
00279 vuMCBitField::~vuMCBitField() // {{{
00280 {
00281         DEBUGD("virtual vuMCBitField::~vuMCBitField()\n");
00282         if (_callback) delete _callback;
00283         delete _slider;
00284         for(int i = 0; i < VU_MCBF_MAX_SIZE; ++i)
00285                 if (_checkboxes[i]) delete _checkboxes[i];
00286         delete _title;
00287 } // }}} vuMCBitField::~vuMCBitField()
00288 
00289 void vuMCBitField::_setTitle(int val) // {{{
00290 {
00291         DEBUG0("void vuMCBitField::_setTitle(int val)\n");
00292         _title->SetLabel(wxString(_titleString)<<" ("<<val<<"):");
00293 } // }}} void vuMCBitField::_setTitle(int val)
00294 
00295 void vuMCBitField::_setCheckboxes(int val) // {{{
00296 {
00297         DEBUG0("void vuMCBitField::_setCheckboxes(int val)\n");
00298         for(int i = 0; i < _size; ++i) {
00299                 _checkboxes[i]->SetValue((1<<i) & val);
00300         }
00301 } // }}} void vuMCBitField<size>::_setCheckboxes(int val)
00302 
00303 void vuMCBitField::operator=(int val) // {{{
00304 {
00305         DEBUG0("void vuMCBitField::operator=(int val)\n");
00306         _setTitle(val);
00307         _setCheckboxes(val);
00308         _slider->SetValue(val);
00309 } // }}} void vuMCBitField<size>::operator=(int val)
00310 
00311 void vuMCBitField::operator()(int n, bool val) // {{{
00312 {
00313         DEBUG0("void vuMCBitField::operator()(int n="<<n<<", bool val="<<val<<")\n");
00314         assert(0 <= n && n < _size);
00315         int bit = 1<<n;
00316         int bitfield = _slider->GetValue();
00317         if (val && !(bit&bitfield)) {
00319                 this->operator = (bitfield+bit);
00320         } else if (!val && bit&bitfield) {
00322                 this->operator = (bitfield-bit);
00323         }
00324 } // }}} void vuMCBitField::operator()(int n, bool val)
00325 
00326 vuMCBitField::operator int() // {{{
00327 {
00328         DEBUG0("int vuMCBitField::operator()()\n");
00329         return _slider->GetValue();
00330 } // }}} int vuMCBitField<size>::operator()()
00331 
00332 vuMCBitField& vuMCBitField::operator[](int n) // {{{
00333 {
00334         DEBUG0("vuMCBitField& vuMCBitField::operator[](int n)\n");
00335         assert(0 <= n && n < _size);
00336         _pos = n;
00337         return *this;
00338 } /* }}} vuMCBitField& vuMCBitField::operator[](int n) */
00339 
00340 void vuMCBitField::operator=(bool val) // {{{
00341 {
00342         DEBUG0("void vuMCBitField::operator=(bool val)\n");
00343         assert(_pos != -1);
00344         int bit = 1<<_pos;
00345         int bitfield = _slider->GetValue();
00346         if (val && !(bit&bitfield)) {
00348                 this->operator = (bitfield-bit);
00349         } else if (!val && bit&bitfield) {
00351                 this->operator = (bitfield-bit);
00352         }
00354 } // }}} void vuMCBitField<size>::operator=(bool val)
00355 
00356 void vuMCBitField::OnCheckboxClicked(wxCommandEvent& event) // {{{
00357 {
00358         DEBUG0("void vuMCBitField::OnCheckboxClicked(wxCommandEvent& event)\n");
00359         int pos = event.GetId() - idMCBFCheckboxes;
00360         DEBUG1("pos = "<<pos<<"\n");
00361         assert(0 <= pos && pos < _size);
00362         DEBUG1("_checkboxes["<<pos<<"] = "<<_checkboxes[pos]<<"\n");
00363         (*this)(pos, _checkboxes[pos]->GetValue());
00364         if (_callback) (*_callback)(_slider->GetValue());
00365 } // }}} void vuMCBitField<size>::OnCheckboxClicked(wxCommandEvent& event)
00366 
00367 void vuMCBitField::OnScroll(wxScrollEvent& event) // {{{
00368 {
00369         DEBUG0("void vuMCBitField::OnScroll(wxScrollEvent& event)\n");
00370         DEBUG1("_slider = "<<_slider<<"\n");
00371         _setTitle(_slider->GetValue());
00372         _setCheckboxes(_slider->GetValue());
00373         if (_callback) (*_callback)(_slider->GetValue());
00374 } // }}} void vuMCBitField<size>::OnScroll(wxScrollEvent& event)
00375 
00376 // }}} vuMCBitField
00377 
00378 
00379 // {{{ class vuMCGrayColor:
00380 
00381 IMPLEMENT_DYNAMIC_CLASS(vuMCGrayColor, vuMCWidget);
00382 
00383 BEGIN_EVENT_TABLE(vuMCGrayColor, vuMCWidget) // {{{
00384         EVT_COMMAND_SCROLL(vuMCGrayColor::idMCGCSlider, vuMCGrayColor::OnScroll)
00385 END_EVENT_TABLE(); // }}}
00386 
00387 vuMCGrayColor::vuMCGrayColor(wxWindow* p, const char* title, vuMCDecorator<float>* cb, float color) // {{{
00388 : vuMCWidget(p), _callback(cb)
00389 {
00390         DEBUGC("vuMCGrayColor::vuMCGrayColor(wxWindow* p="<<p<<", const char* title="<<title<<", "
00391                <<"vuMCDecorator<float>* cb="<<cb<<", float color="<<color<<")\n");
00392         _title = new wxStaticText(this, -1, wxString(title));
00393         Sizer()->Add(_title, 0, 0, 5);
00394         wxSizer* sz = new wxBoxSizer(wxHORIZONTAL);
00395         Sizer()->Add(sz, 1, wxGROW, 0);
00396         _color = new wxPanel(this, -1, wxDefaultPosition, wxSize(20, 20));
00397         sz->Add(_color, 0, 0, 5);
00398         _slider = new wxSlider(this, idMCGCSlider, (int)((float)VU_MCGC_SLIDER_MAX*color),
00399                                0, VU_MCGC_SLIDER_MAX);
00400         sz->Add(_slider, 1, wxGROW, 5);
00401         _colorText = new wxStaticText(this, -1, wxString("0.00"));
00402         sz->Add(_colorText, 0, 0, 5);
00403         _setColor(color);
00404         Fit();
00405 } // }}} vuMCGrayColor::vuMCGrayColor(wxWindow* p, const char* title, vuMCDecorator<float>* cb, float color)
00406 
00407 vuMCGrayColor::~vuMCGrayColor() // {{{
00408 {
00409         DEBUGD("virtual vuMCGrayColor::~vuMCGrayColor()\n");
00410         if (_callback) delete _callback;
00411         delete _colorText;
00412         delete _slider;
00413         delete _color;
00414         delete _title;
00415 } // }}} vuMCGrayColor::~vuMCGrayColor()
00416 
00417 void vuMCGrayColor::_setColor(float col) // {{{
00418 {
00419         DEBUG0("void vuMCGrayColor::_setColor(float col="<<col<<")\n");
00420         assert(0.0f <= col && col <= 1.0f);
00421         _glColor[0] = _glColor[1] = _glColor[2] = col;
00422         _glColor[3] = 1.0;
00423         _color->SetBackgroundColour(wxColour((unsigned char)(255.0*col),
00424                                              (unsigned char)(255.0*col),
00425                                              (unsigned char)(255.0*col)));
00426         _color->Refresh();
00427         _colorText->SetLabel(wxString::Format("%0.2f", col));
00430 } // }}} void vuMCGrayColor::_setColor(float col)
00431 
00432 vuMCGrayColor::operator float*() // {{{
00433 {
00434         DEBUG0("vuMCGrayColor::operator float*()\n");
00435         return _glColor;
00436 } // }}} vuMCGrayColor::operator float*()
00437 
00438 void vuMCGrayColor::OnScroll(wxScrollEvent& event) // {{{
00439 {
00440         DEBUG0("void vuMCGrayColor::OnScroll(wxScrollEvent& event)\n");
00441         _setColor((float)event.GetPosition()/(float)VU_MCGC_SLIDER_MAX);
00442         (*_callback)(0);
00443 } // }}} void vuMCGrayColor::OnScroll(wxCommandEvent& event)
00444 
00445 // }}} vuMCGrayColor
00446 
00447 
00448 // {{{ class vuMCRGBColor:
00449 
00450 IMPLEMENT_DYNAMIC_CLASS(vuMCRGBColor, vuMCWidget);
00451 
00452 BEGIN_EVENT_TABLE(vuMCRGBColor, vuMCWidget) // {{{
00453         EVT_COMMAND_SCROLL(vuMCRGBColor::idMCRGBSlider, vuMCRGBColor::OnScroll)
00454         EVT_BUTTON        (vuMCRGBColor::idMCRGBButton, vuMCRGBColor::OnButton)
00455 END_EVENT_TABLE(); // }}}
00456 
00457 vuMCRGBColor::vuMCRGBColor(wxWindow* p, const char* title, // {{{
00458                            vuMCDecorator<float>* cb, wxColour c, float a)
00459 : vuMCWidget(p), _callback(cb)
00460 {
00461         DEBUGC("vuMCRGBColor::vuMCRGBColor(wxWindow* p="<<p<<", const char* title="<<title<<", "
00462                <<"vuMCDecorator<float>* cb="<<cb<<", wxColour c="<<&c<<", float a="<<a<<")\n");
00463         _title = new wxStaticText(this, -1, wxString(title));
00464         Sizer()->Add(_title, 0, 0, 5);
00465         wxSizer* sz = new wxBoxSizer(wxHORIZONTAL);
00466         Sizer()->Add(sz, 1, wxGROW, 0);
00467         _color = new wxButton(this, idMCRGBButton, _T(""), wxDefaultPosition, wxSize(20, 20));
00468         sz->Add(_color, 0, 0, 5);
00469         _slider = new wxSlider(this, idMCRGBSlider, (int)(a*(float)VU_MCRGB_SLIDER_MAX), 0, VU_MCRGB_SLIDER_MAX);
00470         sz->Add(_slider, 1, wxGROW, 5);
00471         _colorText = new wxStaticText(this, -1, wxString("0.00"));
00472         sz->Add(_colorText, 0, 0, 5);
00473         _setColor(c);
00474         _setText();
00475         Fit();
00476 } // vuMCRGBColor::vuMCRGBColor(wxWindow* p, const char* title,
00477   // }}}                        vuMCDecorator<float>* cb, wxColour c, float a)
00478 
00479 vuMCRGBColor::~vuMCRGBColor() // {{{
00480 {
00481         DEBUGD("virtual vuMCRGBColor::~vuMCRGBColor()\n");
00482         if (_callback) delete _callback;
00483         delete _colorText;
00484         delete _slider;
00485         delete _color;
00486         delete _title;
00487 } // }}} vuMCRGBColor::~vuMCRGBColor()
00488 
00489 void vuMCRGBColor::_setColor(wxColour& col) // {{{
00490 {
00491         DEBUG0("void vuMCRGBColor::_setColor(wxColour& col)\n");
00492         _color->SetBackgroundColour(col);
00493         _glColor[0] = ((float)col.Red()/255.0f)*((float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX);
00494         _glColor[1] = ((float)col.Green()/255.0f)*((float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX);
00495         _glColor[2] = ((float)col.Blue()/255.0f)*((float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX);
00496         _glColor[3] = 1.0;
00497 } // }}} void vuMCRGBColor::_setColor(wxColour& col)
00498 
00499 void vuMCRGBColor::_setColor() // {{{
00500 {
00501         DEBUG0("void vuMCRGBColor::_setColor()\n");
00502         wxColour col = _color->GetBackgroundColour();
00503         _glColor[0] = ((float)col.Red()/255.0f)*((float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX);
00504         _glColor[1] = ((float)col.Green()/255.0f)*((float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX);
00505         _glColor[2] = ((float)col.Blue()/255.0f)*((float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX);
00506         _glColor[3] = 1.0;
00507 } // }}} void vuMCRGBColor::_setColor(wxColour& col)
00508 
00509 void vuMCRGBColor::_setText() // {{{
00510 {
00511         DEBUG0("void vuMCRGBColor::_setText()\n");
00512         _colorText->SetLabel(wxString::Format("%0.2f", (float)_slider->GetValue()/(float)VU_MCRGB_SLIDER_MAX));
00513 } // }}} void vuMCRGBColor::_setText()
00514 
00515 void vuMCRGBColor::operator=(wxColour& c) // {{{
00516 {
00517         DEBUG0("void vuMCRGBColor::operator=(wxColour& c)\n");
00518         _setColor(c);
00519 } // }}} void vuMCRGBColor::operator=(wxColour& c)
00520 
00521 vuMCRGBColor::operator GLfloat*() // {{{
00522 {
00523         DEBUG0("vuMCRGBColor::operator GLfloat*()\n");
00524         return _glColor;
00525 } // }}} vuMCRGBColor::operator GLfloat*()
00526 
00527 vuVector vuMCRGBColor::tovuVector() // {{{
00528 {
00529         DEBUG0("vuVector vuMCRGBColor::tovuVector()\n");
00530         return vuVector(_glColor[0], _glColor[1], _glColor[2]);
00531 } // }}} vuVector vuMCRGBColor::tovuVector()
00532 
00533 void vuMCRGBColor::OnButton(wxCommandEvent& event) // {{{
00534 {
00535         DEBUG0("void vuMCRGBColor::OnButton(wxCommandEvent& event)\n");
00536         wxColourData cd;
00537         cd.SetColour(_color->GetBackgroundColour());
00538         wxColourDialog dialog(this, &cd);
00539         dialog.ShowModal();
00540         cd = dialog.GetColourData();
00541         wxColour c = cd.GetColour();
00542         _color->SetBackgroundColour(c);
00543         _color->Refresh();
00544         _setColor();
00545         (*_callback)(0);
00546 } // }}} void vuMCRGBColor::OnButton(wxCommandEvent& event)
00547 
00548 void vuMCRGBColor::OnScroll(wxScrollEvent& event) // {{{
00549 {
00550         DEBUG0("void vuMCRGBColor::OnScroll(wxScrollEvent& event)\n");
00551         _setColor();
00552         _setText();
00553         (*_callback)(0);
00554 } // }}} void vuMCRGBColor::OnScroll(wxScrollEvent& event)
00555 
00556 GLfloat vuMCRGBColor::Red() // {{{
00557 {
00558         DEBUG0("GLfloat vuMCRGBColor::Red()\n");
00559         return _glColor[0];
00560 } // }}} GLfloat vuMCRGBColor::Red()
00561 
00562 GLfloat vuMCRGBColor::Green() // {{{
00563 {
00564         DEBUG0("GLfloat vuMCRGBColor::Green()\n");
00565         return _glColor[1];
00566 } // }}} GLfloat vuMCRGBColor::Green()
00567 
00568 GLfloat vuMCRGBColor::Blue() // {{{
00569 {
00570         DEBUG0("GLfloat vuMCRGBColor::Blue()\n");
00571         return _glColor[2];
00572 } // }}} GLfloat vuMCRGBColor::Blue()
00573 
00574 GLfloat vuMCRGBColor::Alpha() // {{{
00575 {
00576         DEBUG0("GLfloat vuMCRGBColor::Alpha()\n");
00577         return _glColor[3];
00578 } // }}} GLfloat vuMCRGBColor::Alpha()
00579 
00580 // }}} vuMCRGBColor
00581 
00582 
00583 // {{{ class vuMCSlider:
00584 
00585 IMPLEMENT_DYNAMIC_CLASS(vuMCSlider, vuMCWidget);
00586 
00587 BEGIN_EVENT_TABLE(vuMCSlider, vuMCWidget) // {{{
00588         EVT_COMMAND_SCROLL(vuMCSlider::idMCSSlider, vuMCSlider::OnScroll)
00589 END_EVENT_TABLE(); // }}}
00590 
00591 vuMCSlider::vuMCSlider(wxWindow* p, const char* title, const char *format, // {{{
00592                        vuMCDecorator<float>* cb, float min, float max, float val, int slMax, bool cont)
00593 : vuMCWidget(p, wxHORIZONTAL), _min(min), _max(max), _slMax(slMax), _format(format), _callback(cb), _updateMode(cont)
00594 {
00595         DEBUGC("vuMCSlider::vuMCSlider(wxWindow* p="<<p<<", const char* title="<<title<<", "
00596                <<"const char* format="<<format<<", vuMCDecorator<float>* cb="<<cb<<", "
00597                <<"float min="<<min<<", float max="<<max<<", float val="<<val<<", int slMax="<<slMax<<", bool cont)\n");
00598         assert(val >= _min);
00599         DEBUG6("title = "<<title<<", _min = "<<_min<<", _max = "<<_max<<", _slMax = "<<_slMax
00600                <<", val = "<<val<<", position = "<<(int)((float)(val-min)*(float)slMax/(float)(max-min))<<"\n");
00601         _title = new wxStaticText(this, -1, wxString(title));
00602         Sizer()->Add(_title, 0, 0, 5);
00603         _slider = new wxSlider(this, idMCSSlider, 0, 0, slMax);
00604         Sizer()->Add(_slider, 1, wxGROW, 5);
00605         _value = new wxStaticText(this, -1, wxString::Format(format, max), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
00606         Sizer()->Add(_value, 0, 0, 5);
00607         _setText(val);
00608         _setValue(val);
00609         Fit();
00610 } // vuMCSlider::vuMCSlider(wxWindow* p, const char* title, const char* format, vuMCDecorator<float>* cb,
00611   // }}}                    float min, float max, float val, int slMax, bool cont)
00612 
00613 vuMCSlider::~vuMCSlider() // {{{
00614 {
00615         DEBUGD("virtual vuMCSlider::~vuMCSlider()\n");
00616         if (_callback) delete _callback;
00617         delete _value;
00618         delete _slider;
00619         delete _title;
00620 } // }}} virtual vuMCSlider::~vuMCSlider()
00621 
00622 void vuMCSlider::_setText(float val) // {{{
00623 {
00624         DEBUG0("void vuMCSlider::_setText(float val)\n");
00625         _value->SetLabel(wxString::Format(_format, val));
00626 } // }}} void vuMCSlider::_setText(float val)
00627 
00628 void vuMCSlider::_setValue(float val) // {{{
00629 {
00630         DEBUG0("void vuMCSlider::_setValue(float val)\n");
00631         DEBUG6("setting slider for '"<<_title->GetLabel()<<"' to: "<<val<<", pos: "<<(int)((val-_min)*(float)_slMax/(_max-_min))<<"\n");
00632         assert(_slider != 0);
00633         _slider->SetValue((int)((val-_min)*(float)_slMax/(_max-_min)));
00634 } // }}} void vuMCSlider::_setValue(float val)
00635 
00636 float vuMCSlider::_getValue() // {{{
00637 {
00638         DEBUG0("float vuMCSlider::_getValue()\n");
00639         return _min+((float)_slider->GetValue()*(_max-_min)/(float)_slMax);
00640 } // }}} float vuMCSlider::_getValue()
00641 
00642 vuMCSlider::operator float() // {{{
00643 {
00644         DEBUG0("vuMCSlider::operator float()\n");
00645         return _getValue();
00646 } // }}} vuMCSlider::operator float()
00647 
00648 void vuMCSlider::operator=(float val) // {{{
00649 {
00650         DEBUG0("void vuMCSlider::operator=(float val="<<val<<")\n");
00651         _setText(val);
00652         _setValue(val);
00653 } // }}} void vuMCSlider::operator=(float val)
00654 
00655 float vuMCSlider::Min() // {{{
00656 {
00657         DEBUG0("float vuMCSlider::Min()\n");
00658         return _min;
00659 } // }}} float vuMCSlider::Min()
00660 
00661 void vuMCSlider::Min(float min) // {{{
00662 {
00663         DEBUG0("void vuMCSlider::Min(float min="<<min<<")\n");
00664         assert(min < _max);
00665         float val = _getValue();
00666         _min = min;
00667         if (val < _min) {
00668                 _setValue(_min);
00669                 _setText(_min);
00670         } else {
00671                 _setValue(val);
00672         }
00673 } // }}} void vuMCSlider::Min(float min)
00674 
00675 float vuMCSlider::Max() // {{{
00676 {
00677         DEBUG0("float vuMCSlider::Max()\n");
00678         return _max;
00679 } // }}} float vuMCSlider::Max()
00680 
00681 void vuMCSlider::Max(float max) // {{{
00682 {
00683         DEBUG0("void vuMCSlider::Max(float max)\n");
00684         assert(_min < max);
00685         float val = _getValue();
00686         _max = max;
00687         if (_max < val) {
00688                 _setValue(_max);
00689                 _setText(_max);
00690         } else {
00691                 _setValue(val);
00692         }
00693 } // }}} void vuMCSlider::Max(float max)
00694 
00695 const char* vuMCSlider::Format() // {{{
00696 {
00697         DEBUG0("const char* vuMCSlider::Format()\n");
00698         return _format;
00699 } // }}} const char* vuMCSlider::Format()
00700 
00701 void vuMCSlider::Format(const char* f) // {{{
00702 {
00703         DEBUG0("void vuMCSlider::Format(const char* f)\n");
00704         _format = f;
00705 } // }}} void vuMCSlider::Format(const char* f)
00706 
00707 bool vuMCSlider::UpdateMode() // {{{
00708 {
00709         DEBUG0("bool vuMCSlider::UpdateMode()\n");
00710         return _updateMode;
00711 } // }}} bool vuMCSlider::UpdateMode()
00712 
00713 void vuMCSlider::UpdateMode(bool mode) // {{{
00714 {
00715         DEBUG0("void vuMCSlider::UpdateMode(bool mode)\n");
00716         _updateMode = mode;
00717 } // }}} void vuMCSlider::UpdateMode(bool mode)
00718 
00719 void vuMCSlider::OnScroll(wxScrollEvent& event) // {{{
00720 {
00721         DEBUG0("static void vuMCSlider::OnScroll(wxScrollEvent& event)\n");
00722         wxEventType eventType = event.GetEventType();
00723         float val = _getValue();
00724         _setText(val);
00725         if (_updateMode == VU_MCS_END_UPDATE && eventType != wxEVT_SCROLL_ENDSCROLL) return;
00726         DEBUG2("Doing the update\n");
00727         if (_callback) (*_callback)(val);
00728 } // }}} static void vuMCSlider::OnScroll(wxScrollEvent& event)
00729 
00730 // }}} vuMCSlider
00731 
00732 
00733 // {{{ class vuMCHistogram:
00734 
00735 IMPLEMENT_DYNAMIC_CLASS(_HistoCanvas, wxPanel)
00736 
00737 BEGIN_EVENT_TABLE(_HistoCanvas, wxPanel) // {{{
00738         EVT_PAINT (_HistoCanvas::OnPaint)
00739         EVT_MOTION(_HistoCanvas::OnMotion)
00740         EVT_MOUSE_EVENTS(_HistoCanvas::OnMouse)
00741 END_EVENT_TABLE(); // }}}
00742 
00743 _HistoCanvas::_HistoCanvas() // {{{
00744 : _selected(-1)
00745 {
00746         DEBUGC("_HistoCanvas::_HistoCanvas()\n");
00747 } // }}} _HistoCanvas::_HistoCanvas()
00748 
00749 _HistoCanvas::_HistoCanvas(vuMCHistogram* parent, wxWindowID id, // {{{
00750                            const wxPoint& pos, const wxSize& size)
00751 : wxPanel(parent, id, pos, size), _min(-1), _max(-1), _vmax(0), _vpp(0.0), _ppe(0.0),
00752   _callback(parent), _updateCounter(0), _delayedUpdate(true), _idx(-1)
00753 {
00754         DEBUGC("_HistoCanvas::_HistoCanvas(vuMCHistogram* parent, "
00755                <<"wxWindowID id, const wxPoint& pos, const wxSize& size)\n");
00756 } // _HistoCanvas::_HistoCanvas(vuMCHistogram* parent, wxWindowID id,
00757   // }}}                        const wxPoint& pos, const wxSize& size)
00758 
00759 _HistoCanvas::~_HistoCanvas() // {{{
00760 {
00761         DEBUGD("_HistoCanvas::~_HistoCanvas()\n");
00762 } // }}} _HistoCanvas::~_HistoCanvas()
00763 
00764 void _HistoCanvas::Reset() // {{{
00765 {
00766         DEBUG0("void _HistoCanvas::Reset()\n");
00767         _min = -1;
00768         _max = -1;
00769         _vmax = 0;
00770         _histo.clear();
00771         _updateCounter = 0;
00772         Refresh();
00773 } // }}} void _HistoCanvas::Reset()
00774 
00775 void _HistoCanvas::Inc(int n, int val) // {{{
00776 {
00777         DEBUG0("void _HistoCanvas::Inc(int n="<<n<<", int val="<<val<<")\n");
00778         if (_min==-1 && _max==-1) {
00779                 DEBUG2("Initial change at "<<n<<" ...\n");
00780                 _min = n;
00781                 _max = n;
00782                 _histo[n] = 0;
00783         } else if (n > _max) {
00784                 DEBUG2("Moving _max from "<<_max<<" to "<<n<<" ...\n");
00785                 for(int i = _max+1; i <= n; ++i) _histo[i] = 0;
00786                 _max = n;
00787         } else if (n < _min) {
00788                 DEBUG2("Movint _min from "<<_min<<" to "<<n<<" ... \n");
00789                 for(int i = n; i < _min; ++i) _histo[i] = 0;
00790                 _min = n;
00791         }
00792         _histo[n] += val;
00793         if (_histo[n] > _vmax) {
00794                 _vmax = _histo[n];
00795                 DEBUG2("Increasing _vmax to "<<_vmax<<" ... \n");
00796         }
00797         if (_delayedUpdate) {
00798                 ++_updateCounter;
00799                 if (_updateCounter < HC_UPDATE_WATERMARK) return;
00800                 _updateCounter = 0;
00801                 Refresh();
00802         }
00803 } // }}} void _HistoCanvas::Inc(int n, int val)
00804 
00805 void _HistoCanvas::SetSelColor(wxColour &c) // {{{
00806 {
00807         DEBUG0("void _HistoCanvas::SetSelColor(wxColour &c)\n");
00808         float max = (c.Red()>c.Blue()) ? c.Red() : c.Blue();
00809         max = (max>c.Green()) ? max : c.Green();
00810         _selColor = wxColour(int((float)c.Red()*255.0/max),
00811                              int((float)c.Green()*255.0/max),
00812                              int((float)c.Blue()*255.0/max));
00813 } // }}} void _HistoCanvas::SetSelColor(wxColour &c)
00814 
00815 void _HistoCanvas::Select(int idx) // {{{
00816 {
00817         DEBUG0("void _HistoCanvas::Select(int type)\n");
00818         _selected = idx;
00819 } // }}} void _HistoCanvas::Select(int type)
00820 
00821 void _HistoCanvas::DelayedUpdate(bool m) // {{{
00822 {
00823         DEBUG0("void _HistoCanvas::DelayedUpdate(bool m)\n");
00824         _delayedUpdate = m;
00825         _updateCounter = 0;
00826         DEBUG3("_delayedUpdate = "<<_delayedUpdate<<"\n");
00827 } // }}} void _HistoCanvas::DelayedUpdate(bool m)
00828 
00829 bool _HistoCanvas::DelayedUpdate() // {{{
00830 {
00831         DEBUG0("bool _HistoCanvas::DelayedUpdate()\n");
00832         return _delayedUpdate;
00833 } // }}} bool _HistoCanvas::DelayedUpdate()
00834 
00835 void _HistoCanvas::OnPaint(wxPaintEvent& event) // {{{
00836 {
00837         DEBUG0("void _HistoCanvas::OnPaint(wxPaintEvent& event)\n");
00840         DEBUG3("Painting ...\n");
00841         wxPaintDC dc(this);
00842         PrepareDC(dc);
00843         dc.SetBackground(wxBrush(wxColour(255, 255, 255), wxSOLID));
00845         dc.Clear();
00847         if (_callback) {
00848                 wxString txt("min: ");
00849                 txt<<_min<<", max: "<<_max;
00850                 _callback->OnTextChange(txt);
00851         }
00853         if (_min==-1 || _max==-1) return;
00854         wxPen pen;
00855         pen.SetColour(wxColour(50, 50, 50));
00856         wxBrush brush;
00857         brush.SetColour(wxColour(50, 50, 50));
00858         wxPen spen;
00859         spen.SetColour(_selColor);
00860         wxBrush sbrush;
00861         sbrush.SetColour(_selColor);
00862         dc.SetPen(pen);
00863         dc.SetBrush(brush);
00865         int width;
00866         int height;
00867         GetClientSize(&width, &height);
00868         _vpp = (float)height / (float)_vmax;
00869         _ppe = (float)(_max-_min+1) / (float)width;
00870         DEBUG2("_ppe = "<<_ppe<<", _vpp = "<<_vpp<<"\n");
00871         if (_ppe < 1.0) {
00874                 float bw = 1.0f/_ppe;
00875                 DEBUG2("bw = "<<bw<<", width = "<<width<<", calc width = "<<bw*(_max-_min)<<"\n");
00876                 float pos = 0.0;
00877                 for(int i=_min; i<=_max; ++i) {
00878                         int h = (int)(_histo[i]*_vpp);
00879                         if (i == _selected) {
00880                                 dc.SetPen(spen);
00881                                 dc.SetBrush(sbrush);
00882                         }
00883                         dc.DrawRectangle((int)pos, height-h, (int)(bw+0.99f), h);
00884                         pos += bw;
00885                         dc.SetPen(pen);
00886                         dc.SetBrush(brush);
00887                 }
00888         } else {
00891                 int idx = _min;
00892                 for(int i=1; i<=width; ++i) {
00893                         int val = 0;
00894                         int cnt = 0;
00895                         while(idx<=(_min+_ppe*i) && idx<=_max) {
00896                                 cnt++;
00897                                 val += _histo[idx++];
00898                                 if (i == _selected) {
00899                                         dc.SetPen(spen);
00900                                         dc.SetBrush(sbrush);
00901                                 }
00902                         }
00903                         int h = (int)(((float)val/(float)cnt)*_vpp);
00904                         dc.DrawLine(i, height-h, i, height);
00905                         dc.SetPen(pen);
00906                         dc.SetBrush(brush);
00907                 }
00908         }
00909 } // }}} void _HistoCanvas::OnPaint(wxPaintEvent& event)
00910 
00911 void _HistoCanvas::OnMotion(wxMouseEvent& event) // {{{
00912 {
00913         DEBUG0("void _HistoCanvas::OnMotion(wxMouseEvent& event)\n");
00914         wxString txt("min: ");
00915         txt<<_min<<", max: "<<_max<<", ";
00916         DEBUG2("x = "<<event.m_x<<", y = "<<event.m_y<<", _ppe = "<<_ppe<<"\n");
00917         float idx;
00918         if (_ppe < 1.0) {
00919                 idx = (float)_min+(float)event.m_x*_ppe;
00920                 DEBUG2("element = "<<idx<<"\n");
00921                 txt<<"["<<(int)idx<<"]="<<_histo[(int)idx];
00922         } else {
00923                 idx = (float)_min+((float)event.m_x-0.99)*_ppe;
00924                 DEBUG2("first element = "<<idx<<"\n");
00925                 while(idx<=(_min+_ppe*(float)event.m_x) && idx<=_max) {
00926                         txt<<"["<<(int)idx<<"]="<<_histo[(int)idx]<<" ";
00927                         idx += 1;
00928                 }
00929                 DEBUG2("last element = "<<_idx<<"\n");
00930         }
00931         _idx = (int)idx;
00932         if (_callback) _callback->OnTextChange(txt);
00933 } // }}} void _HistoCanvas::OnMotion(wxMouseEvent& event)
00934 
00935 void _HistoCanvas::OnMouse(wxMouseEvent& event) // {{{
00936 {
00937         DEBUG0("void _HistoCanvas::OnMouse(wxMouseEvent& event)\n");
00938         if (event.LeftUp()) {
00939                 _selected = _idx;
00940                 _callback->OnClicked(_idx);
00941         }
00942 } // }}} void _HistoCanvas::OnMouse(wxMouseEvent& event)
00943 
00944 IMPLEMENT_DYNAMIC_CLASS(vuMCHistogram, vuMCWidget)
00945 
00946 BEGIN_EVENT_TABLE(vuMCHistogram, vuMCWidget) // {{{
00947         EVT_CHECKBOX(vuMCHistogram::idCbxDelayedUpdate, vuMCHistogram::OnDelayedUpdateChecked)
00948         //EVT_COMMAND_LEFT_CLICK(vuMCHistogram::idClkHistogram, vuMCHistogram::OnHistogramClick)
00949         EVT_TOOL(vuMCHistogram::idClkHistogram, vuMCHistogram::OnClicked)
00950 END_EVENT_TABLE(); // }}}
00951 
00952 vuMCHistogram::vuMCHistogram(wxWindow* p, wxSize size, vuMCDecorator<int>* cb) // {{{
00953 : vuMCWidget(p), _parent(p), _callback(cb)
00954 {
00955         DEBUGC("vuMCHistogram::vuMCHistogram(wxWindow* p, wxSize size, vuMCDecorator<int>* cb)\n");
00956         _delayedUpdate = new wxCheckBox(this, idCbxDelayedUpdate, "Delayed update");
00957         Sizer()->Add(_delayedUpdate, 0, wxGROW, 5);
00958         _histoDC = new _HistoCanvas(this, idClkHistogram, wxDefaultPosition, size);
00959         Sizer()->Add(_histoDC, 1, wxGROW, 5);
00960         _delayedUpdate->SetValue(_histoDC->DelayedUpdate());
00961         _histoDC->SetHelpText("Nasenhelptext");
00962         _desc = new wxStaticText(this, -1, _T("No elements"));
00963         Sizer()->Add(_desc, 0, wxGROW, 5);
00964         Fit();
00965 } // }}} vuMCHistogram::vuMCHistogram(wxWindow* p, wxSize size, vuMCDecorator<int>* cb)
00966 
00967 vuMCHistogram::~vuMCHistogram() // {{{
00968 {
00969         DEBUGD("virtual vuMCHistogram::~vuMCHistogram()\n");
00970         delete _desc;
00971         delete _histoDC;
00972         delete _delayedUpdate;
00973 } // }}} vuMCHistogram::~vuMCHistogram()
00974 
00975 void vuMCHistogram::Clear() // {{{
00976 {
00977         DEBUG0("void vuMCHistogram::Clear()\n");
00978         _histoDC->Reset();
00979 } // }}} void vuMCHistogram::Clear()
00980 
00981 void vuMCHistogram::Flush() // {{{
00982 {
00983         DEBUG0("void vuMCHistogram::Flush()\n");
00984         wxPaintEvent ev;
00985         _histoDC->OnPaint(ev);
00986         //_histoDC->Update();
00987 } // }}} void vuMCHistogram::Flush()
00988 
00989 void vuMCHistogram::Inc(int i, int val) // {{{
00990 {
00991         DEBUG0("void vuMCHistogram::Inc(int i="<<i<<", int val="<<val<<")\n");
00992         _histoDC->Inc(i, val);
00993 } // }}} void vuMCHistogram::Inc(int i, int val)
00994 
00995 void vuMCHistogram::SetSelColor(vuVector c) // {{{
00996 {
00997         DEBUG0("void vuMCHistogram::SetSelColor(vuVector c)\n");
00998         wxColour col(int(255.0*c[0]), int(255.0*c[1]), int(255.0*c[2]));
00999         _histoDC->SetSelColor(col);
01000 } // }}} void vuMCHistogram::SetSelColor(vuVector c)
01001 
01002 void vuMCHistogram::SetSelColor(wxColour &c) // {{{
01003 {
01004         DEBUG0("void vuMCHistogram::SetSelColor(wxColour &c)\n");
01005         _histoDC->SetSelColor(c);
01006 } // }}} void vuMCHistogram::SetSelColor(wxColour &c)
01007 
01008 void vuMCHistogram::Select(int type) // {{{
01009 {
01010         DEBUG0("void vuMCHistogram::Select(int type)\n");
01011         _histoDC->Select(type);
01012         Flush();
01013 } // }}} void vuMCHistogram::Select(int type)
01014 
01015 void vuMCHistogram::OnTextChange(wxString txt) // {{{
01016 {
01017         DEBUG0("void vuMCHistogram::OnTextChange(wxString txt)\n");
01018         _desc->SetLabel(txt);
01019 } // }}} void vuMCHistogram::OnTextChange(wxString txt)
01020 
01021 void vuMCHistogram::OnClicked(int idx) // {{{
01022 {
01023         DEBUG0("void vuMCHistogram::OnClicked(wxCommandEvent &event)\n");
01024         if (0 < idx && idx < 255) {
01025                 DEBUG5("idx = "<<idx<<"\n");
01026                 _histoDC->Select(idx);
01027                 Flush();
01028                 if (_callback) (*_callback)(idx);
01029         }
01030 } // }}} void vuMCHistogram::OnClicked(wxCommandEvent &event)
01031 
01032 void vuMCHistogram::OnDelayedUpdateChecked(wxCommandEvent &event) // {{{
01033 {
01034         DEBUG0("void vuMCHistogram::OnDelayedUpdateChecked(wxCommandEvent &event)\n");
01035         _histoDC->DelayedUpdate(_delayedUpdate->IsChecked());
01036 } // }}} void vuMCHistogram::OnDelayedUpdateChecked(wxCommandEvent &event)
01037 
01038 // }}} vuMCHistogram
01039 
01040 // >>>
01041 // {{{ class vuMarchingCubes:
01042 
01043 //----------------------------------------------------------------------------
01044 //------------------------- The wxWindows event table ------------------------
01045 //----------------------------------------------------------------------------
01046 BEGIN_EVENT_TABLE(vuMarchingCubes, vuBasicUtility) // {{{
01047         EVT_CHECKBOX (vuMarchingCubes::idMCCbxCubeEnabled,   vuMarchingCubes::OnCubeEnabledChecked)
01048         EVT_CHECKBOX (vuMarchingCubes::idMCCbxLight1Enabled, vuMarchingCubes::OnLight1Checked)
01049         EVT_CHECKBOX (vuMarchingCubes::idMCCbxDrawFrame,     vuMarchingCubes::OnFrameChecked)
01050         EVT_RADIOBOX (vuMarchingCubes::idMCRbxRotate,        vuMarchingCubes::OnRotateChecked)
01051         EVT_CHECKBOX (vuMarchingCubes::idMCCbxCullLinesFrontBack,
01052                                                              vuMarchingCubes::OnCullLinesFrontBackChecked)
01053         EVT_CHECKBOX (vuMarchingCubes::idMCCbxUpdateMode,    vuMarchingCubes::OnUpdateModeChecked)
01054 #ifdef LINUX
01055         EVT_BUTTON   (vuMarchingCubes::idMCBtnUpdate,        vuMarchingCubes::OnUpdateClicked)
01056 #endif
01057         EVT_CHECKBOX (vuMarchingCubes::idMCCbxDrawNormals,   vuMarchingCubes::OnDrawNormalsChecked)
01058 END_EVENT_TABLE(); // }}}
01059 
01060 //----------------------------------------------------------------------------
01061 //------------------------- The constructor ----------------------------------
01062 //----------------------------------------------------------------------------
01063 vuMarchingCubes::vuMarchingCubes() // {{{
01064 : m_Data(0),
01065   m_imageList(0),
01066   m_thres(0),
01067 #if defined(LINUX)
01068   m_update(0),
01069 #endif
01070   m_cubesTotal(0),
01071   m_cube0(0),
01072   m_cube255(0),
01073   m_cubeOther(0),
01074   m_cubeHist(0),
01075   m_size(0),
01076   m_angle(0),
01077   m_pos(0),
01078   m_zoom(0),
01079   m_light0Pos(0),
01080   m_light1Enabled(0),
01081   m_light1Pos(0),
01082   m_numTriangles(0),
01083   m_numVertices(0),
01084   m_numIndices(0),
01085   m_statusText(0),
01086   m_status(0),
01087   m_backColor(0),
01088   m_lightColor(0),
01089   m_lightDiffuse(0),
01090   m_lightSpecular(0),
01091   m_lightShiny(0),
01092   m_frameColor(0),
01093   m_lineColor(0),
01094   m_selectColor(0),
01095   m_objectColor(0),
01096   m_objectDiffuse(0),
01097   m_objectSpecular(0),
01098   m_objectShiny(0),
01099   m_mouseSpeed(0),
01100   m_drawFrame(0),
01101   m_cullBack(0),
01102   m_cullFront(0),
01103   m_linesBack(0),
01104   m_linesFront(0),
01105   m_frameRadius(0),
01106   m_rotateX(0),
01107   m_rotateY(0),
01108   m_rotateZ(0),
01109   m_updateMode(0),
01110   m_cubeEnabled(0),
01111   m_cube(0),
01112   m_drawNormals(0),
01113   m_drawNormalsSize(0),
01114   m_cubeSizeX(0),
01115   m_cubeSizeY(0),
01116   m_cubeSizeZ(0),
01117   m_fpsTime(0),
01118   m_fpsCount(0),
01119   m_fpsWatermark(0),
01120   m_fps(1.0),
01121   m_avgFps(1.0),
01122   x1(0.0), y1(0.0), z1(0.0),
01123   x2(1.0), y2(1.0), z2(1.0)
01124 {
01125         DEBUGC("vuMarchingCubes::vuMarchingCubes()\n");
01126         m_Data = NULL;
01127 } // }}}
01128 
01129 //----------------------------------------------------------------------------
01130 //------------------------- The destructor -----------------------------------
01131 //----------------------------------------------------------------------------
01132 vuMarchingCubes::~vuMarchingCubes() // {{{
01133 {
01134         DEBUGD("virtual vuMarchingCubes::~vuMarchingCubes()\n");
01135         if (m_Data)             delete m_Data;
01136         if (m_imageList)        delete m_imageList;
01137         if (m_thres)            delete m_thres;
01138 #if defined(LINUX)
01139         if (m_update)           delete m_update;
01140 #endif
01141         if (m_cubesTotal)       delete m_cubesTotal;
01142         if (m_cube0)            delete m_cube0;
01143         if (m_cube255)          delete m_cube255;
01144         if (m_cubeOther)        delete m_cubeOther;
01145         if (m_cubeHist)         delete m_cubeHist;
01146         if (m_size)             delete m_size;
01147         if (m_angle)            delete m_angle;
01148         if (m_pos)              delete m_pos;
01149         if (m_zoom)             delete m_zoom;
01150         if (m_light0Pos)        delete m_light0Pos;
01151         if (m_light1Enabled)    delete m_light1Enabled;
01152         if (m_light1Pos)        delete m_light1Pos;
01153         if (m_numTriangles)     delete m_numTriangles;
01154         if (m_numVertices)      delete m_numVertices;
01155         if (m_numIndices)       delete m_numIndices;
01156         if (m_statusText)       delete m_statusText;
01157         if (m_status)           delete m_status;
01158         if (m_backColor)        delete m_backColor;
01159         if (m_lightColor)       delete m_lightColor;
01160         if (m_lightDiffuse)     delete m_lightDiffuse;
01161         if (m_lightSpecular)    delete m_lightSpecular;
01162         if (m_lightShiny)       delete m_lightShiny;
01163         if (m_frameColor)       delete m_frameColor;
01164         if (m_lineColor)        delete m_lineColor;
01165         if (m_selectColor)      delete m_selectColor;
01166         if (m_objectColor)      delete m_objectColor;
01167         if (m_objectDiffuse)    delete m_objectDiffuse;
01168         if (m_objectSpecular)   delete m_objectSpecular;
01169         if (m_objectShiny)      delete m_objectShiny;
01170         if (m_mouseSpeed)       delete m_mouseSpeed;
01171         if (m_drawFrame)        delete m_drawFrame;
01172         if (m_cullBack)         delete m_cullBack;
01173         if (m_cullFront)        delete m_cullFront;
01174         if (m_linesBack)        delete m_linesBack;
01175         if (m_linesFront)       delete m_linesFront;
01176         if (m_frameRadius)      delete m_frameRadius;
01177         if (m_rotateX)          delete m_rotateX;
01178         if (m_rotateY)          delete m_rotateY;
01179         if (m_rotateZ)          delete m_rotateZ;
01180         if (m_updateMode)       delete m_updateMode;
01181         if (m_cubeEnabled)      delete m_cubeEnabled;
01182         if (m_cube)             delete m_cube;
01183         if (m_drawNormals)      delete m_drawNormals;
01184         if (m_drawNormalsSize)  delete m_drawNormalsSize;
01185         if (m_cubeSizeX)        delete m_cubeSizeX;
01186         if (m_cubeSizeY)        delete m_cubeSizeY;
01187         if (m_cubeSizeZ)        delete m_cubeSizeZ;
01188         if (m_fpsWatermark)     delete m_fpsWatermark;
01189 } // }}}
01190 
01191 //----------------------------------------------------------------------------
01192 //------------------------- public: getFileType() ----------------------------
01193 //----------------------------------------------------------------------------
01194 const char* vuMarchingCubes::getFileType() // {{{
01195 {
01196         DEBUG0("const char* vuMarchingCubes::getFileType()\n");
01197         return "1112211 1112212";
01198 } // }}}
01199 
01200 typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
01201 typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
01202 typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
01203 typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
01204 
01205 PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
01206 PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
01207 PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
01208 PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;
01209 
01210 //----------------------------------------------------------------------------
01211 //------------------------- public: init() -----------------------------------
01212 //----------------------------------------------------------------------------
01213 bool vuMarchingCubes::init(const char* DataFile) // {{{
01214 {
01215         DEBUG0("bool vuMarchingCubes::init(" << DataFile << ")\n");
01216         assert(m_size != NULL);
01217         SetEvtHandlerEnabled(true);
01218 
01219         // Set up the window
01220         SetTitle("RGB Marching Cubes");
01221         CreateStatusBar();
01222 
01223         // Read in the data.
01224         m_Data = new vu1112211;
01225         m_base = (MarchingCubesBase*)((vu1112211*)m_Data);
01226         m_base->setGlobalData(&m_gd);
01227         m_base->SetProgressCallback(new vuMCMCBProgressCallback(this));
01228         m_base->SetHistoCallback(new vuMCMCBHistoCallback(this));
01229         m_Data->setFileName(DataFile);
01230         bool success = m_Data->read();
01231         if (!success) return false;
01232         m_base->marchCubes();
01233         doThresChange();
01234         DEBUG1("m_base->Size1() = "<<m_base->Size1()<<"\n");
01235         DEBUG1("m_base->Size2() = "<<m_base->Size2()<<"\n");
01236         DEBUG1("m_base->Size3() = "<<m_base->Size3()<<"\n");
01237 
01238         // GUI setup taht depends on the volume.
01239         (*m_size)[0] = m_base->Size1();
01240         (*m_size)[1] = m_base->Size2();
01241         (*m_size)[2] = m_base->Size3();
01242         (*m_pos)[2] = -m_base->maxSize()*2;
01243         (*m_light0Pos)[0] = -m_base->maxSize();
01244         (*m_light0Pos)[1] =  m_base->maxSize();
01245         (*m_light0Pos)[2] =  m_base->maxSize();
01246         (*m_light1Pos)[0] =  m_base->maxSize();
01247         (*m_light1Pos)[1] =  m_base->maxSize();
01248         (*m_light1Pos)[2] =  m_base->maxSize();
01249         m_frameRadius->Min(0.0);
01250         m_frameRadius->Max((float)m_base->maxSize() / 200.0);
01251         m_frameRadius->Min((float)m_base->maxSize() / 1000.0);
01252         *m_frameRadius = m_gd.frameRadius;
01253         m_frameRadius->Format("%0.3f");
01254         *m_cubesTotal = float((m_base->Size1()-1)*(m_base->Size2()-1)*(m_base->Size3()-1));
01255         *m_cubeOther = (float)*m_cubesTotal;
01256         m_drawNormals->SetValue(m_gd.drawNormals);
01257         m_drawNormalsSize->Min(1.0);
01258         m_drawNormalsSize->Max((float)m_base->maxSize() / 2.0);
01259         *m_drawNormalsSize = m_gd.normalsLength;
01260         *m_meshSize = m_gd.meshSize;
01261         m_cubeHist->SetSelColor(m_selectColor->tovuVector());
01262 
01263         // Some tests:
01264         /*
01265         const GLubyte *name = (const GLubyte*)"glGenBuffersARB";
01266         glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)glXGetProcAddress(name);
01267         DEBUG8("glGenBuffersARB = "<<glGenBuffersARB<<"\n");
01268         name = (const GLubyte*)"glBindBufferARB";
01269         glBindBufferARB = (PFNGLBINDBUFFERARBPROC)glXGetProcAddress(name);
01270         DEBUG8("glBindBufferARB = "<<glBindBufferARB<<"\n");
01271         glBindBufferARB(0x8892, 1);
01272         */
01273 
01274         return success;
01275 } // }}}
01276 
01277 //----------------------------------------------------------------------------
01278 //------------------------- public: getCamera() ------------------------------
01279 //----------------------------------------------------------------------------
01280 vuCamera* vuMarchingCubes::getCamera() // {{{
01281 {
01282         DEBUG0("vuCamera* vuMarchingCubes::getCamera()\n");
01283         return 0;       // we have no camera!
01284 } // }}}
01285 
01286 //----------------------------------------------------------------------------
01287 //------------------------- public: setCamera() ------------------------------
01288 //----------------------------------------------------------------------------
01289 void vuMarchingCubes::setCamera(vuCamera* cam) // {{{
01290 {
01291         DEBUG0("void vuMarchingCubes::setCamera(vuCamera* cam)\n");
01292         //m_Data->setCamera(cam);
01293 } // }}}
01294 
01295 //----------------------------------------------------------------------------
01296 //------------------------- public: getCurrentImage() ------------------------
01297 //----------------------------------------------------------------------------
01298 vuImage* vuMarchingCubes::getCurrentImage() // {{{
01299 {
01300         DEBUG0("vuImage* vuMarchingCubes::getCurrentImage()\n");
01301         return NULL;
01302 } // }}}
01303 
01304 //----------------------------------------------------------------------------
01305 //------------------------- public: DrawFromImage() --------------------------
01306 //----------------------------------------------------------------------------
01307 void vuMarchingCubes::DrawFromImage() // {{{
01308 {
01309         DEBUG0("void vuMarchingCubes::DrawFromImage()\n");
01310 } // }}}
01311 
01312 //----------------------------------------------------------------------------
01313 //------------------------- public: getCamera() ------------------------------
01314 //----------------------------------------------------------------------------
01315 void vuMarchingCubes::DrawAgain() // {{{
01316 {
01317         DEBUG0("void vuMarchingCubes::DrawAgain()\n");
01318 } // }}}
01319 
01320 //----------------------------------------------------------------------------
01321 //------------------------- public: addTop() ---------------------------------
01322 //----------------------------------------------------------------------------
01323 void vuMarchingCubes::addTop(wxSizer *sizer) // {{{
01324 {
01325         DEBUG0("void vuMarchingCubes::addTop(" << sizer << ")\n");
01326         m_thres = new vuMCSlider(this, "Threshold: ", "%5.0f", new vuMCThresChange(this),
01327                                  m_gd.valueMin, m_gd.valueMax, m_gd.thres,
01328                                  4095, VU_MCS_END_UPDATE);
01329         sizer->Add(m_thres, 1, wxALL, 5);
01330 #if defined LINUX
01331         m_update = new wxButton(this, idMCBtnUpdate, "update");
01332         m_update->Enable(!m_thres->UpdateMode());
01333         sizer->Add(m_update, 0, wxGROW, 5);
01334 #endif
01335         SetAutoLayout(TRUE);
01336         sizer->Fit(this);
01337 } // }}}
01338 
01339 //----------------------------------------------------------------------------
01340 //------------------------- public: addRight() -------------------------------
01341 //----------------------------------------------------------------------------
01342 void vuMarchingCubes::addRight(wxSizer *sizer) // {{{
01343 {
01344         DEBUG0("void vuMarchingCubes::addRight(" << sizer << ")\n");
01345 
01346         // First let's create some icons for the tabs:
01347         m_imageList = new wxImageList(16, 16);
01348         wxSize size(16, 16);
01349         m_imageList->Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, size));
01350         m_imageList->Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, size));
01351         m_imageList->Add(wxBitmap(opengl_logo_xpm));
01352 
01353         // Notebook setup:
01354         wxNotebook* notebook = new wxNotebook(this, -1);
01355         sizer->Add(new wxNotebookSizer(notebook), 1, wxGROW, 5);
01356         notebook->SetImageList(m_imageList);
01357 
01358         // Adding the info page to the notebook:
01359         notebook->AddPage(createInfoNotebook(notebook), _T("Info"), TRUE, 0);
01360 
01361         // Adding the settings page to the notebook:
01362         notebook->AddPage(createSettingsNotebook(notebook), _T("Settings"), FALSE, 1);
01363 
01364         // Adding the OpenGL page to the notebook:
01365         notebook->AddPage(createGLNotebook(notebook), _T("GL"), FALSE, 2);
01366 
01367         // Adding the Help page to the notebook:
01368         notebook->AddPage(createHelpNotebook(notebook), _T("Help"), FALSE, 0);
01369 
01370         sizer->SetMinSize(250, 10);
01371 } // }}}
01372 
01373 //----------------------------------------------------------------------------
01374 //------------------------- protected: createInfoNotebook() ------------------
01375 //----------------------------------------------------------------------------
01376 wxPanel* vuMarchingCubes::createInfoNotebook(wxNotebook* nb) // {{{
01377 {
01378         DEBUG0("wxPanel* vuMarchingCubes::createInfoNotebook(wxNotebook* nb)\n");
01379         wxPanel*     page;
01380         wxSizer*     szPage;
01381         wxSizer*     szSB;
01382         //wxGridSizer* szGrid;
01383 
01384         // Setup:
01385         page = new wxPanel(nb);
01386         szPage = new wxBoxSizer(wxVERTICAL);
01387         page->SetSizer(szPage);
01388 
01389         // Cube Counter:
01390         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Cube histogram:")), wxVERTICAL);
01391         szPage->Add(szSB, 0, wxGROW, 5);
01392         m_cubesTotal = new vuMCKeyValue(page, "Cubes total: ", "%1.0f");
01393         (*m_cubesTotal) = 0.0f;
01394         szSB->Add(m_cubesTotal, 0, wxGROW, 5);
01395         m_cube0 = new vuMCKeyValue(page, "Cubes of type 0: ", "%1.0f");
01396         (*m_cube0) = 0.0f;
01397         szSB->Add(m_cube0, 0, wxGROW, 5);
01398         m_cube255 = new vuMCKeyValue(page, "Cubes of type 255: ", "%1.0f");
01399         (*m_cube255) = 0.0f;
01400         szSB->Add(m_cube255, 0, wxGROW, 5);
01401         m_cubeOther = new vuMCKeyValue(page, "Cubes of other types: ", "%1.0f");
01402         (*m_cubeOther) = 0.0f;
01403         szSB->Add(m_cubeOther, 0, wxGROW, 5);
01404         m_cubeHist = new vuMCHistogram(page, wxSize(200, 100), new vuMCSelectType(this));
01405         szSB->Add(m_cubeHist, 0, wxGROW, 5);
01406 
01407         // States:
01408         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Internal States:")), wxVERTICAL);
01409         szPage->Add(szSB, 0, wxGROW, 5);
01410         m_size = new vuMCKeyVector(page, "Data Size: ", 3, "%1.0f");
01411         (*m_size)[0] = 0.0;
01412         (*m_size)[1] = 0.0;
01413         (*m_size)[2] = 0.0;
01414         szSB->Add(m_size, 0, wxGROW, 5);
01415         m_angle = new vuMCKeyVector(page, "Angle: ", 3, "%0.1f");
01416         szSB->Add(m_angle, 0, wxGROW, 5);
01417         m_pos = new vuMCKeyVector(page, "Position: ", 4, "%0.1f");
01418         (*m_pos)[3] = 1.0;      // Last element must be one.
01419         szSB->Add(m_pos, 0, wxGROW, 5);
01420         m_zoom = new vuMCKeyValue(page, "Zoom: ", "%0.3f");
01421         (*m_zoom) = 0.5f;
01422         szSB->Add(m_zoom, 0, wxGROW, 5);
01423         m_light0Pos = new vuMCKeyVector(page, "Pos Light 0: ", 4, "%0.1f");
01424         (*m_light0Pos)[3] = 1.0;
01425         szSB->Add(m_light0Pos, 0, wxGROW, 5);
01426         m_light1Pos = new vuMCKeyVector(page, "Pos Light 1: ", 4, "%0.1f");
01427         (*m_light1Pos)[3] = 1.0;
01428         szSB->Add(m_light1Pos, 0, wxGROW, 5);
01429         m_light1Pos->Enable(MC_DEFAULT_LIGHT1_ENABLED);
01430         m_numTriangles = new vuMCKeyValue(page, "Number of Triangles: ", "%1.0f");
01431         (*m_numTriangles) = 0.0;
01432         szSB->Add(m_numTriangles, 0, wxGROW, 5);
01433         m_numVertices = new vuMCKeyValue(page, "Number of Vertices: ", "%1.0f");
01434         (*m_numVertices) = 0.0;
01435         szSB->Add(m_numVertices, 0, wxGROW, 5);
01436         m_numIndices = new vuMCKeyValue(page, "Number of Indices: ", "%1.0f");
01437         (*m_numIndices) = 0.0;
01438         szSB->Add(m_numIndices, 0, wxGROW, 5);
01439         m_meshSize = new vuMCKeyValue(page, "Memory usage: ", "%1.0f");
01440         szSB->Add(m_meshSize, 0, wxGROW, 5);
01441 
01442         // States:
01443         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Progress:")), wxVERTICAL);
01444         szPage->Add(szSB, 0, wxGROW, 5);
01445         m_statusText = new wxStaticText(page, -1, "No status:");
01446         m_statusText->Disable();
01447         szSB->Add(m_statusText, 0, wxGROW, 5);
01448         m_status = new wxGauge(page, -1, 100, wxDefaultPosition, wxSize(-1, 10));
01449         m_status->Disable();
01450         szSB->Add(m_status, 0, wxGROW, 5);
01451 
01452         return page;
01453 } /* }}} wxPanel* vuMarchingCubes::createInfoNotebook(wxNotebook* nb) */
01454 
01455 //----------------------------------------------------------------------------
01456 //------------------------- protected: createSettingsNotebook() --------------------
01457 //----------------------------------------------------------------------------
01458 wxPanel* vuMarchingCubes::createSettingsNotebook(wxNotebook* nb) // {{{
01459 {
01460         wxPanel*     page;
01461         wxSizer*     szPage;
01462         wxSizer*     szSB;
01463         wxString     choices[3];
01464 
01465         // Page Setup:
01466         page = new wxPanel(nb);
01467         szPage = new wxBoxSizer(wxVERTICAL);
01468         page->SetSizer(szPage);
01469 
01470         // Mousing:
01471         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Mouse:")), wxVERTICAL);
01472         szPage->Add(szSB, 0, wxGROW, 5);
01473         //m_mouseSpeed = new vuMCSlider(page, "Speed ", "%3.0f" , new vuMCRender(this), 1.0, 100.0, 85.0);
01474         m_mouseSpeed = new vuMCSlider(page, "Speed ", "%3.0f" , NULL, 1.0, 100.0, 85.0);
01475         szSB->Add(m_mouseSpeed, 0, wxGROW, 20);
01476 
01477         // Frame:
01478         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Frame:")), wxVERTICAL);
01479         szPage->Add(szSB, 0, wxGROW, 5);
01480         //   Should frame be drawn:
01481         m_drawFrame = new wxCheckBox(page, idMCCbxDrawFrame, "Draw Frame");
01482         m_drawFrame->SetValue(MC_DEFAULT_DRAW_FRAME);
01483         szSB->Add(m_drawFrame, 0, wxGROW, 5);
01484         //   Frame radius:
01485         m_frameRadius = new vuMCSlider(page, "Radius: ", "%1.2f",
01486                                        new vuMCFrameChange(this), 1.0, 100.0, 10.0);
01487         m_frameRadius->Enable(MC_DEFAULT_DRAW_FRAME);
01488         szSB->Add(m_frameRadius, 0, wxGROW, 5);
01489 
01490         // Rotate Object:
01491         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Rotate Object:")), wxVERTICAL);
01492         szPage->Add(szSB, 0, wxGROW, 5);
01493         choices[0] = wxString("-90°");
01494         choices[1] = wxString("0°");
01495         choices[2] = wxString("90°");
01496         m_rotateX = new wxRadioBox(page, idMCRbxRotate, "Rotate arround x-axis:",
01497                                    wxDefaultPosition, wxDefaultSize,
01498                                    3, choices, 3, wxRA_SPECIFY_COLS);
01499         m_rotateX->SetSelection(1);
01500         szSB->Add(m_rotateX, 1, wxGROW, 5);
01501         m_rotateY = new wxRadioBox(page, idMCRbxRotate, "Rotate arround y-axis:",
01502                                    wxDefaultPosition, wxDefaultSize,
01503                                    3, choices, 3, wxRA_SPECIFY_COLS);
01504         m_rotateY->SetSelection(1);
01505         szSB->Add(m_rotateY, 1, wxGROW, 5);
01506         m_rotateZ = new wxRadioBox(page, idMCRbxRotate, "Rotate arround z-axis:",
01507                                    wxDefaultPosition, wxDefaultSize,
01508                                    3, choices, 3, wxRA_SPECIFY_COLS);
01509         m_rotateZ->SetSelection(1);
01510         szSB->Add(m_rotateZ, 1, wxGROW, 5);
01511 
01512         // Other:
01513         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Other:")), wxVERTICAL);
01514         szPage->Add(szSB, 0, wxGROW, 5);
01515         m_cullBack = new wxCheckBox(page, idMCCbxCullLinesFrontBack, "Cull Back Faces");
01516         m_cullBack->SetValue(false);
01517         szSB->Add(m_cullBack, 0, wxGROW, 5);
01518         m_cullFront = new wxCheckBox(page, idMCCbxCullLinesFrontBack, "Cull Front Faces");
01519         m_cullFront->SetValue(false);
01520         szSB->Add(m_cullFront, 0, wxGROW, 5);
01521         m_linesBack = new wxCheckBox(page, idMCCbxCullLinesFrontBack, "Lines on Back Faces");
01522         m_linesBack->SetValue(false);
01523         szSB->Add(m_linesBack, 0, wxGROW, 5);
01524         m_linesFront = new wxCheckBox(page, idMCCbxCullLinesFrontBack, "Lines on Front Faces");
01525         m_linesFront->SetValue(false);
01526         szSB->Add(m_linesFront, 0, wxGROW, 5);
01527         m_fpsWatermark = new vuMCSlider(page, "FPS wm: ", "%3.0f", NULL, 1.0, 1000.0,
01528                                         (float)MC_DEFAULT_FPS_WATERMARK, 1000);
01529         szSB->Add(m_fpsWatermark, 0, wxGROW, 5);
01530         m_updateMode = new wxCheckBox(page, idMCCbxUpdateMode, "Continuous Update on threshold change");
01531         m_updateMode->SetValue(m_thres->UpdateMode());
01532         szSB->Add(m_updateMode, 0, wxGROW, 5);
01533         m_doMeshStatistics = new wxCheckBox(page, idMCCbxMeshStatisitcs,
01534                                             "Do memory statistics on the mesh (slower)");
01535         m_doMeshStatistics->SetValue(m_gd.doMeshStatistics);
01536         szSB->Add(m_doMeshStatistics, 0, wxGROW, 5);
01537 
01538         // Cube Browser:
01539         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Cube Setup Browser:")), wxVERTICAL);
01540         szPage->Add(szSB, 0, wxGROW, 5);
01541         m_cubeEnabled = new wxCheckBox(page, idMCCbxCubeEnabled, "Enable Cube Browser");
01542         m_cubeEnabled->SetValue(m_gd.cubeBrowser);
01543         szSB->Add(m_cubeEnabled, 0, 0, 5);
01544         m_cube = new vuMCBitField(page, "Cube", new vuMCCubeChange(this), 8, 255);
01545         m_cube->Enable(m_gd.cubeBrowser);
01546         szSB->Add(m_cube, 0, wxGROW, 5);
01547 
01548         // Drawing Normals:
01549         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Drawing Normals:")), wxVERTICAL);
01550         szPage->Add(szSB, 0, wxGROW, 5);
01551         m_drawNormals = new wxCheckBox(page, idMCCbxDrawNormals, "Draw Normals");
01552         m_drawNormals->SetValue(m_gd.drawNormals);
01553         szSB->Add(m_drawNormals, 0, 0, 5);
01554         m_drawNormalsSize = new vuMCSlider(page, "Length: ", "%2.1f", new vuMCNormalLengthChange(this), 0.1, 5.0, m_gd.normalsLength);
01555         m_drawNormalsSize->Enable(m_gd.drawNormals);
01556         szSB->Add(m_drawNormalsSize, 0, wxGROW, 5);
01557 
01558         // Cube Size:
01559         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Cube size:")), wxVERTICAL);
01560         szPage->Add(szSB, 0, wxGROW, 5);
01561         m_cubeSizeX = new vuMCSlider(page, "Size X: ", "%2.1f", new vuMCCubeSizeChange(this), 0.1, 5.0, 1.0);
01562         szSB->Add(m_cubeSizeX, 0, wxGROW, 5);
01563         m_cubeSizeY = new vuMCSlider(page, "Size Y: ", "%2.1f", new vuMCCubeSizeChange(this), 0.1, 5.0, 1.0);
01564         szSB->Add(m_cubeSizeY, 0, wxGROW, 5);
01565         m_cubeSizeZ = new vuMCSlider(page, "Size Z: ", "%2.1f", new vuMCCubeSizeChange(this), 0.1, 5.0, 1.0);
01566         szSB->Add(m_cubeSizeZ, 0, wxGROW, 5);
01567 
01568         // fire it back:
01569         return page;
01570 } /* }}} wxPanel* vuMarchingCubes::createSettingsNotebook(wxNotebook* nb) */
01571 
01572 //----------------------------------------------------------------------------
01573 //------------------------- protected: createGLNotebook() --------------------
01574 //----------------------------------------------------------------------------
01575 wxPanel* vuMarchingCubes::createGLNotebook(wxNotebook* nb) // {{{
01576 {
01577         wxPanel*    page;
01578         wxSizer*    szPage;
01579         wxSizer*    szSB;
01580 
01581         // Page setup:
01582         page = new wxPanel(nb);
01583         szPage = new wxBoxSizer(wxVERTICAL);
01584         page->SetSizer(szPage);
01585 
01586         // Some Colors:
01587         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Light:")), wxVERTICAL);
01588         szPage->Add(szSB, 0, wxGROW, 5);
01589         m_light1Enabled = new wxCheckBox(page, idMCCbxLight1Enabled, "Enable Light 1");
01590         m_light1Enabled->SetValue(MC_DEFAULT_LIGHT1_ENABLED);
01591         szSB->Add(m_light1Enabled, 0, wxGROW, 5);
01592         m_backColor = new vuMCRGBColor(page, "Background:", new vuMCBackgroundChange(this),
01593                                        wxColour(255, 255, 255), 0.45);
01594         szSB->Add(m_backColor, 0, wxGROW, 5);
01595         setBackground();
01596         m_lightColor = new vuMCRGBColor(page, "Color:", new vuMCRender(this),
01597                                         wxColour(255, 255, 255), 1.0);
01598         szSB->Add(m_lightColor, 0, wxGROW, 5);
01599         m_lightDiffuse = new vuMCGrayColor(page, "Diffuse:", new vuMCRender(this), 0.4);
01600         szSB->Add(m_lightDiffuse, 0, wxGROW, 5);
01601         m_lightSpecular = new vuMCGrayColor(page, "Specular:", new vuMCRender(this), 0.6);
01602         szSB->Add(m_lightSpecular, 0, wxGROW, 5);
01603         m_lightShiny = new vuMCGrayColor(page, "Shinyness:", new vuMCRender(this), 0.8);
01604         szSB->Add(m_lightShiny, 0, wxGROW, 5);
01605 
01606         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Objects:")), wxVERTICAL);
01607         szPage->Add(szSB, 0, wxGROW, 5);
01608         m_frameColor = new vuMCRGBColor(page, "Frame:", new vuMCRender(this),
01609                                         wxColour(128, 64, 64), 0.8);
01610         szSB->Add(m_frameColor, 0, wxGROW, 5);
01611         m_lineColor = new vuMCRGBColor(page, "Line:", new vuMCLineColorChange(this),
01612                                        wxColour(0, 128, 0), 0.4);
01613         m_gd.lineColor = m_lineColor->tovuVector();
01614         szSB->Add(m_lineColor, 0, wxGROW, 5);
01615         m_selectColor = new vuMCRGBColor(page, "Selection:", new vuMCObjectColorChange(this),
01616                                        wxColour(0, 0, 128), 0.4);
01617         szSB->Add(m_selectColor, 0, wxGROW, 5);
01618         m_objectColor = new vuMCRGBColor(page, "Object:", new vuMCObjectColorChange(this),
01619                                          wxColour(128, 128, 0), 0.4);
01620         for(int i = 0; i < 256; ++i) {
01621                 m_gd.objectColor[i] = m_objectColor->tovuVector();
01622         }
01623         szSB->Add(m_objectColor, 0, wxGROW, 5);
01624         m_objectDiffuse = new vuMCGrayColor(page, "Diffuse:", new vuMCRender(this), 0.8);
01625         szSB->Add(m_objectDiffuse, 0, wxGROW, 5);
01626         m_objectSpecular = new vuMCGrayColor(page, "Specular:", new vuMCRender(this), 0.9);
01627         szSB->Add(m_objectSpecular, 0, wxGROW, 5);
01628         m_objectShiny = new vuMCGrayColor(page, "Shinyness:", new vuMCRender(this), 0.85);
01629         szSB->Add(m_objectShiny, 0, wxGROW, 5);
01630 
01631         // Fire it back:
01632         return page;
01633 } /* }}} wxPanel* vuMarchingCubes::createGLNotebook(wxNotebook* nb) */
01634 
01635 //----------------------------------------------------------------------------
01636 //------------------------- protected: createHelpNotebook() --------------------
01637 //----------------------------------------------------------------------------
01638 wxPanel* vuMarchingCubes::createHelpNotebook(wxNotebook* nb) // {{{
01639 {
01640         wxPanel*      page;
01641         wxSizer*      szPage;
01642         wxSizer*      szSB;
01643         wxStaticText* text;
01644 
01645         // Page setup:
01646         page = new wxPanel(nb);
01647         szPage = new wxBoxSizer(wxVERTICAL);
01648         page->SetSizer(szPage);
01649 
01650         // Moving the Object:
01651         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Moving the object:")), wxVERTICAL);
01652         szPage->Add(szSB, 0, wxGROW, 5);
01653         text = new wxStaticText(page, -1, "Left mouse: Rotate object");
01654         szSB->Add(text, 0, wxGROW, 5);
01655         text = new wxStaticText(page, -1, "Shift left mouse: Move object along the x- and y-axis");
01656         szSB->Add(text, 0, wxGROW, 5);
01657         text = new wxStaticText(page, -1, "Ctrl left mouse: Move object along the z-axis");
01658         szSB->Add(text, 0, wxGROW, 5);
01659 
01660         // Other movements:
01661         szSB = new wxStaticBoxSizer(new wxStaticBox(page, -1, _T("Other movements:")), wxVERTICAL);
01662         szPage->Add(szSB, 0, wxGROW, 5);
01663         text = new wxStaticText(page, -1, "Alt left mouse: Zoom (down = in, up = out)");
01664         szSB->Add(text, 0, wxGROW, 5);
01665         text = new wxStaticText(page, -1, "Ctrl right mouse: Move light 0 along the x- and z-axis");
01666         szSB->Add(text, 0, wxGROW, 5);
01667         text = new wxStaticText(page, -1, "Alt right mouse: Move light 1 along the x- and z-axis");
01668         szSB->Add(text, 0, wxGROW, 5);
01669 
01670         // Fire it back:
01671         return page;
01672 } /* }}} wxPanel* vuMarchingCubes::createGLNotebook(wxNotebook* nb) */
01673 
01674 //----------------------------------------------------------------------------
01675 //------------------------- protected: getVolume() ---------------------------
01676 //----------------------------------------------------------------------------
01677 vu1 *vuMarchingCubes::getVolume() // {{{
01678 {
01679         DEBUG0("vu1 *vuMarchingCubes::getVolume()\n");
01680         return (vu1 *)m_Data;
01681         //return NULL;
01682 } // }}}
01683 
01684 //----------------------------------------------------------------------------
01685 //------------------------- protected: glInit() ------------------------------
01686 //----------------------------------------------------------------------------
01687 bool vuMarchingCubes::glInit() // {{{
01688 {
01689         DEBUG0("bool vuMarchingCubes::glInit(void)\n");
01690         if (m_Data == 0) return false;
01691         assert(m_size != NULL);
01692         glClearColor(m_backColor->Red(), m_backColor->Green(), m_backColor->Blue(), m_backColor->Alpha());
01693 
01694         glEnable(GL_LIGHTING);
01695         glEnable(GL_LIGHT0);
01696         glShadeModel(GL_SMOOTH);
01697         glEnable(GL_LINE_SMOOTH);
01698         glEnable(GL_DEPTH_TEST);
01699         //glEnable(GL_COLOR_MATERIAL);
01700 
01701         glEnable(GL_CULL_FACE);
01702         glCullFace(GL_BACK);
01703         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
01704 
01705         glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
01706         glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
01707         //glDepthFunc(GL_LESS);
01708         //m_Data->initOpenGL();
01709         
01710         return true;
01711 }; // }}}
01712 
01713 //----------------------------------------------------------------------------
01714 //------------------------- protected: glResize() ----------------------------
01715 //----------------------------------------------------------------------------
01716 void vuMarchingCubes::glResize() // {{{
01717 {
01718         DEBUG0("void vuMarchingCubes::glResize()\n");
01719 
01720         GLint w = (GLint)m_glCanvas->getWidth();
01721         GLint h = (GLint)m_glCanvas->getHeight();
01722         float ratio = (float)w/(float)h;
01723         float maxCS = (m_gd.cubeSize[0]>m_gd.cubeSize[1]) ? m_gd.cubeSize[0] : m_gd.cubeSize[1];
01724         maxCS = (maxCS>m_gd.cubeSize[2]) ? maxCS : m_gd.cubeSize[2];
01725         float size = (float)m_base->maxSize()*maxCS;
01726         float zoom = *m_zoom;
01727         DEBUG7("size = "<<size<<", zoom = "<<zoom<<"\n");
01728         glViewport(0, 0, w, h);
01729 
01730         glMatrixMode(GL_PROJECTION);
01731         glLoadIdentity();
01732         if (ratio > 1.0) {
01733                 glFrustum(-zoom*ratio, zoom*ratio,
01734                           -zoom, zoom,
01735                           1.0, size*10.0);
01736         } else {
01737                 glFrustum(-zoom, zoom,
01738                           -zoom/ratio, zoom/ratio,
01739                           1.0, size*10.0);
01740         }
01741 
01742         glMatrixMode(GL_MODELVIEW);
01743         glLoadIdentity();
01744 } /* }}} void vuMarchingCubes::glResize(void) */
01745 
01746 //----------------------------------------------------------------------------
01747 //------------------------- public: glRender() -------------------------------
01748 //----------------------------------------------------------------------------
01754 void vuMarchingCubes::glRender() // {{{
01755 {
01756         DEBUG0("void vuMarchingCubes::glRender()\n");
01757         wxStopWatch watch;
01758         watch.Start();
01759 
01760         DEBUGGL("================ Begin frame ================\n");
01761         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
01762         glLoadIdentity();
01763 
01766         glLightfv(GL_LIGHT0, GL_POSITION,  *m_light0Pos);
01767         glLightfv(GL_LIGHT0, GL_AMBIENT,   *m_lightColor);
01768         glLightfv(GL_LIGHT0, GL_DIFFUSE,   *m_lightDiffuse);
01769         glLightfv(GL_LIGHT0, GL_SPECULAR,  *m_lightSpecular);
01770         glLightfv(GL_LIGHT0, GL_SHININESS, *m_lightShiny);
01771         if (m_light1Enabled->IsChecked()) {
01772                 glLightfv(GL_LIGHT1, GL_POSITION,  *m_light1Pos);
01773                 glLightfv(GL_LIGHT1, GL_AMBIENT,   *m_lightColor);
01774                 glLightfv(GL_LIGHT1, GL_DIFFUSE,   *m_lightDiffuse);
01775                 glLightfv(GL_LIGHT1, GL_SPECULAR,  *m_lightSpecular);
01776                 glLightfv(GL_LIGHT1, GL_SHININESS, *m_lightShiny);
01777         }
01778         glTranslatef(m_pos->Get(0), m_pos->Get(1), m_pos->Get(2));
01779         glRotatef(m_angle->Get(0), 1.0, 0.0, 0.0);
01780         glRotatef(m_angle->Get(1), 0.0, 1.0, 0.0);
01781         if (m_rotateX->GetSelection() == 0) {
01782                 glRotatef(-90.0, 1.0, 0.0, 0.0);
01783         } else if (m_rotateX->GetSelection() == 2) {
01784                 glRotatef(90.0, 1.0, 0.0, 0.0);
01785         }
01786         if (m_rotateY->GetSelection() == 0) {
01787                 glRotatef(-90.0, 0.0, 1.0, 0.0);
01788         } else if (m_rotateY->GetSelection() == 2) {
01789                 glRotatef(90.0, 0.0, 1.0, 0.0);
01790         }
01791         if (m_rotateZ->GetSelection() == 0) {
01792                 glRotatef(-90.0, 0.0, 0.0, 1.0);
01793         } else if (m_rotateZ->GetSelection() == 2) {
01794                 glRotatef(90.0, 0.0, 0.0, 1.0);
01795         }
01796 
01797         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE,   *m_objectDiffuse);
01798         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,  *m_objectSpecular);
01799         glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, *m_objectShiny);
01800 
01801         if (m_drawFrame->IsChecked()) {
01802                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, *m_frameColor);
01803                 m_base->glRenderFrame();
01804         }
01805         glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, *m_objectColor);
01806         m_base->glRender();
01807 
01808 #if DEBUG_LEVEL <= 7
01809         GLfloat matWhite[4] = { 1.0, 1.0, 1.0, 1.0 };
01810         glBegin(GL_LINES);
01811                 DEBUG7("Drawin line from: "<<x1<<", "<<y1<<", "<<z1<<"\n");
01812                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, *m_backColor);
01813                 glVertex3d(x1 * *m_cubeSizeX, y1 * *m_cubeSizeY, z1 * *m_cubeSizeZ);
01814                 DEBUG7("to: "<<x2<<", "<<y2<<", "<<z2<<"\n");
01815                 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matWhite);
01816                 glVertex3d(x2 * *m_cubeSizeX, y2 * *m_cubeSizeY, z2 * *m_cubeSizeZ);
01817         glEnd();
01818 #endif
01819 
01820         DEBUGGL("================ End frame ================\n");
01821 
01822         //watch.Pause();
01823         int time = watch.Time();
01824         DEBUG5("time used: "<<m_fpsTime<<"\n");
01825         if (m_gd.drawObject) {
01826                 m_fpsTime += time;
01827                 m_fpsCount++;
01828                 DEBUG2("m_fpsCount = "<<m_fpsCount<<"\n");
01829                 if (m_fpsCount >= (*m_fpsWatermark)) {
01830                         DEBUG2("calcing fps ...\n");
01831                         if (m_fpsTime != 0) m_avgFps = (float)m_fpsCount*1000.0f/(float)m_fpsTime;
01832                         m_fpsCount = 0;
01833                         m_fpsTime = 0;
01834                 }
01835         }
01836         m_fps = (time>0) ? 1000.0/(float)time : 1000;
01837         SetStatusText(wxString("")<<"avg: "<<format(m_avgFps)<<" ("
01838                       <<(int)(*m_fpsWatermark)-m_fpsCount<<") / fps "<<format(m_fps)<<" fps");
01839 } // }}}
01840 
01841 //----------------------------------------------------------------------------
01842 //------------------------- protected: OnChar() ------------------------------
01843 //----------------------------------------------------------------------------
01844 void vuMarchingCubes::OnChar(wxKeyEvent& event) // {{{
01845 {
01846         DEBUG0("void vuMarchingCubes::OnChar(wxKeyEvent& event)\n");
01847         DEBUG7("char code = " << (int)event.GetKeyCode() << "\n");
01848         switch(event.GetKeyCode()) {
01849                 case 13:
01850                         m_cubeHist->Flush();
01851                         break;
01852                 case 27:
01853                         exit(0);
01854                         break;
01855         }
01856 } /* }}} void vuMarchingCubes::OnChar(wxKeyEvent& event) */
01857 
01858 //----------------------------------------------------------------------------
01859 //------------------------- protected: onMouse() -----------------------------
01860 //----------------------------------------------------------------------------
01861 void vuMarchingCubes::glOnMouse(wxMouseEvent &event) // {{{
01862 {
01863         DEBUG0("void vuMarchingCubes::onMouse(wxMouseEvent &event)\n");
01864         if (event.LeftDClick())
01865                 onDblClick(event);
01866         else if (event.LeftDown() || event.RightDown())
01867                 onMouseDown(event);
01868         //else if (event.LeftIsDown() && event.Moving())
01869         else if (event.LeftIsDown())
01870                 onMouseLeftMoving(event);
01871         //else if (event.RightIsDown() && event.Moving())
01872         else if (event.RightIsDown())
01873                 onMouseRightMoving(event);
01874         else if (event.LeftUp() || event.RightUp())
01875                 onMouseUp(event);
01876 } // }}}
01877 
01878 //----------------------------------------------------------------------------
01879 //------------------------- protected: onMouseLeftMoving() -------------------
01880 //----------------------------------------------------------------------------
01881 void vuMarchingCubes::onMouseLeftMoving(wxMouseEvent &event) // {{{
01882 {
01883         DEBUG0("void vuMarchingCubes::onMouseLeftMoving(wxMouseEvent &event)\n");
01884         float difX = ((float)event.GetX()-(float)m_MouseX);
01885         float difY = ((float)event.GetY()-(float)m_MouseY);
01886         storeMousePosition(event);
01887         DEBUG1("difX = "<<difX<<", difY = "<<difY<<"\n");
01888 #ifdef _WIN32
01889         if (fabs(difX) > 10.0 || fabs(difY) > 10.0) return;
01890 #endif
01891         difX *= (*m_mouseSpeed)/100.0f;
01892         difY *= (*m_mouseSpeed)/100.0f;
01893         float size = m_base->maxSize();
01894         if (event.ShiftDown()) {
01895                 (*m_pos)[0] += (difX*size/100.0f);
01896                 (*m_pos)[1] -= (difY*size/100.0f);
01897                 m_glCanvas->redraw();
01898         } else if (event.ControlDown()) {
01899                 (*m_pos)[2] += (difY*size/100.0f);
01900                 m_glCanvas->redraw();
01901         } else if (event.AltDown()) {
01902                 (*m_zoom) -= difY/100.0;
01903                 glResize();
01904                 m_glCanvas->redraw();
01905         } else {
01906                 (*m_angle)[0] += difY;
01907                 if (m_angle->Get(0) >  180.0f) (*m_angle)[0]  =  180.0f;
01908                 if (m_angle->Get(0) < -180.0f) (*m_angle)[0]  = -180.0f;
01909                 (*m_angle)[1] += difX;
01910                 if (m_angle->Get(1) >  360.0f) (*m_angle)[1] -=  360.0f;
01911                 if (m_angle->Get(1) <    0.0f) (*m_angle)[1] +=  360.0f;
01912                 //m_cubeHist->Inc((int)(m_angle->Get(1)*10.0f));
01913                 //m_cubeHist->Inc((int)(m_angle->Get(1)));
01914                 m_glCanvas->redraw();
01915         }
01916 } /* }}} void vuMarchingCubes::onMouseLeftMoving(wxMouseEvent &event) */
01917 
01918 //----------------------------------------------------------------------------
01919 //------------------------- protected: onMouseRightMoving() ------------------
01920 //----------------------------------------------------------------------------
01921 void vuMarchingCubes::onMouseRightMoving(wxMouseEvent &event) // {{{
01922 {
01923         DEBUG0("void vuMarchingCubes::onMouseRightMoving(wxMouseEvent &event)\n");
01924         float difX = ((float)event.GetX()-(float)m_MouseX)*(*m_mouseSpeed)/100.0f;
01925         float difY = ((float)event.GetY()-(float)m_MouseY)*(*m_mouseSpeed)/100.0f;
01926         storeMousePosition(event);
01927         float size = m_base->maxSize();
01928         if (event.ShiftDown()) {
01929         } else if (event.ControlDown()) {
01930                 (*m_light0Pos)[0] += difX*size/100.0f;
01931                 (*m_light0Pos)[2] += difY*size/100.0f;
01932                 m_glCanvas->redraw();
01933         } else if (event.AltDown()) {
01934                 if (m_light1Enabled->IsChecked()) {
01935                         (*m_light1Pos)[0] += difX*size/100.0f;
01936                         (*m_light1Pos)[2] += difY*size/100.0f;
01937                         m_glCanvas->redraw();
01938                 }
01939         }
01940 } /* }}} void vuMarchingCubes::onMouseRightMoving(wxMouseEvent &event) */
01941 
01942 //----------------------------------------------------------------------------
01943 //------------------------- protected: onMouseDown() -------------------------
01944 //----------------------------------------------------------------------------
01945 void vuMarchingCubes::onMouseDown(wxMouseEvent &event) // {{{
01946 {
01947         DEBUG0("void vuMarchingCubes::onMouseDown(wxMouseEvent &event)\n");
01948         storeMousePosition(event);
01949         if (m_fps < m_gd.fpsThres && m_base) m_gd.drawObject = false;
01950 } // }}} void vuMarchingCubes::onMouseDown(wxMouseEvent &event)
01951 
01952 //----------------------------------------------------------------------------
01953 //------------------------- protected: onMouseUp() ---------------------------
01954 //----------------------------------------------------------------------------
01955 void vuMarchingCubes::onMouseUp(wxMouseEvent &event) // {{{
01956 {
01957         DEBUG0("void vuMarchingCubes::onMouseUp(wxMouseEvent &event)\n");
01958         if (m_base) m_gd.drawObject = true;
01959         m_glCanvas->redraw();
01960 } // }}} void vuMarchingCubes::onMouseUp(wxMouseEvent &event)
01961 
01962 //----------------------------------------------------------------------------
01963 //------------------------- protected: onDblClick() --------------------------
01964 //----------------------------------------------------------------------------
01965 void vuMarchingCubes::onDblClick(wxMouseEvent &event) // {{{
01966 {
01967         DEBUG0("void vuMarchingCubes::onDblClick(wxMouseEvent &event)\n");
01968         DEBUG7("Double clicked the window\n");
01969         GLdouble modelview[16];
01970         GLdouble projection[16];
01971         GLint viewport[16];
01972         glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
01973         glGetDoublev(GL_PROJECTION_MATRIX, projection);
01974         glGetIntegerv(GL_VIEWPORT, viewport);
01975         gluProject(0.0, 0.0, 0.0, modelview, projection, viewport, &x1, &y1, &z1);
01976         DEBUG7("projected (0.0, 0.0, 0.0) to ("<<x1<<", "<<y1<<", "<<z1<<")\n");
01977         GLdouble winX = event.m_x;
01978         GLdouble winY = m_glCanvas->getHeight()-event.m_y;
01979         GLdouble winZ = z1;
01980         gluUnProject(winX, winY, 0.0, modelview, projection, viewport, &x1, &y1, &z1);
01981         DEBUG7("unprojected ("<<winX<<", "<<winY<<", 0.0) to ("<<x1<<", "<<y1<<", "<<z1
01982                <<"), i.e. eye point.\n");
01983         gluUnProject(winX, winY, winZ, modelview, projection, viewport, &x2, &y2, &z2);
01984         DEBUG7("unprojected ("<<winX<<", "<<winY<<", "<<winZ<<") to ("<<x2<<", "<<y2<<", "<<z2
01985                <<"), i.e. unprojected area through the center.\n");
01986 
01987         vuVector start(x2 / *m_cubeSizeX, y2 / *m_cubeSizeY, z2 / *m_cubeSizeZ);
01988         vuVector eye(x1 / *m_cubeSizeX, y1 / *m_cubeSizeY, z1 / *m_cubeSizeZ);
01989         vuVector viewdir = (eye-start).makeUnit();
01990         double size2[3] = {
01991                 (double)m_base->Size1() / 2.0,
01992                 (double)m_base->Size2() / 2.0,
01993                 (double)m_base->Size3() / 2.0
01994         };
01995 
01996         double max;
01997         int dir;
01998         if (fabs(viewdir[0])>fabs(viewdir[1])) {
01999                 max = fabs(viewdir[0]);
02000                 dir = 0;
02001         } else {
02002                 max = fabs(viewdir[1]);
02003                 dir = 1;
02004         }
02005         if (fabs(viewdir[2])>max) {
02006                 max = fabs(viewdir[2]);
02007                 dir = 2;
02008         }
02009         DEBUG7("Calculated direction: "<<dir<<"\n");
02010         int cnt = 0;
02011         vuVector p = start;
02012         while (dir >= 0 && cnt < 3) {
02013                 DEBUG7("We are outside the borders in direction "<<dir
02014                        <<", vector: "<<p[0]<<", "<<p[1]<<", "<<p[2]<<"\n");
02015                 double theSize = (viewdir[dir]>0) ? size2[dir] : -size2[dir];
02016                 double length = (theSize-p[dir])/viewdir[dir];
02017                 DEBUG7("distance to the border in main direction ("<<dir<<"): "<<length<<"\n");
02018                 p = p + viewdir*length;
02019                 x1 = p[0]; y1 = p[1]; z1 = p[2];
02020                 dir = outside(p, size2);
02021                 cnt++;
02022         }
02023         int mySize[3] = { m_base->Size1(), m_base->Size2(), m_base->Size3() };
02024         double size[3] = { (double)mySize[0]-1.0, (double)mySize[1]-1.0, (double)mySize[2]-1.0 };
02025         int count = m_base->maxSize();
02026         vuVector step = viewdir*(-1.0/max);
02028         p += vuVector(size2[0], size2[1], size2[2]);
02029         if (outside(p, size)!=-1) p+= step;
02030         DEBUG7("start point: ("<<p[0]<<", "<<p[1]<<", "<<p[2]<<")\n");
02032         p += (step*0.001);
02033         float value = m_base->valueAt(p[0], p[1], p[2]);
02034         bool below = value < *m_thres;
02035         DEBUG7("stepping vector: ("<<step[0]<<", "<<step[1]<<", "<<step[2]<<")\n");
02036         DEBUG7("start point: ("<<p[0]<<", "<<p[1]<<", "<<p[2]<<")\n");
02037         DEBUG7("value = "<<value<<"\n");
02038         while (fabs(*m_thres-value)>0.001 && count--) {
02039                 if (outside(p, size)!=-1) {
02040                         // As soon as we are outside the first time, the challange is over!
02041                         DEBUG7("We are outside, so we stop the algorithm!\n");
02042                         return;
02043                 }
02044                 DEBUG7("bevor estimation: below = "<<below<<", step = "
02045                        <<step[0]<<", "<<step[1]<<", "<<step[2]<<"\n");
02046                 if (below && (value>*m_thres)) {
02047                         step *= -0.5;
02048                         below = false;
02049                 } else if (!below && (value<*m_thres)) {
02050                         step *= -0.5;
02051                         below = true;
02052                 }
02053                 DEBUG7("after estimation: below = "<<below<<", step = "
02054                        <<step[0]<<", "<<step[1]<<", "<<step[2]<<"\n");
02055                 p += step;
02056                 value = m_base->valueAt(p[0], p[1], p[2]);
02057                 DEBUG7("value = "<<value<<", p = "<<p[0]<<", "<<p[1]<<", "<<p[2]
02058                        <<", dist = "<<fabs(*m_thres-value)<<"\n");
02059                 DEBUG7("---------------------------------------\n");
02060         }
02061         DEBUG7("New position is: "<<p[0]<<", "<<p[1]<<", "<<p[2]<<"\n");
02062         x2 = (p[0]-size2[0]); y2 = (p[1]-size2[1]); z2 = (p[2]-size2[2]);
02063         if (outside(p, size) == -1) {
02064                 int x = int(p[0]);
02065                 int y = int(p[1]);
02066                 int z = int(p[2]);
02067                 int type = m_base->getCubeType(x, y, z);
02068                 if (type != 0 && type != 255) {
02069                         m_cubeHist->Select(type);
02070                         OnSelectType(type);
02071                         m_glCanvas->redraw();
02072                         return;
02073                 }
02074         }
02075 } // }}} void vuMarchingCubes::onDblClick(wxMouseEvent &event)
02076 
02077 //----------------------------------------------------------------------------
02078 //------------------------- protected: OnLight1Checked() ---------------------
02079 //----------------------------------------------------------------------------
02080 void vuMarchingCubes::OnLight1Checked(wxCommandEvent& event) // {{{
02081 {
02082         DEBUG0("void vuMarchingCubes::OnLight1Checked(wxCommandEvent& event)\n");
02083         wxCheckBox* cb = (wxCheckBox*)event.GetEventObject();
02084         m_light1Pos->Enable(cb->IsChecked());
02085         if (cb->IsChecked()) {
02086                 glEnable(GL_LIGHT1);
02087         } else {
02088                 glDisable(GL_LIGHT1);
02089         }
02090         m_glCanvas->redraw();
02091 } // }}} void vuMarchingCubes::OnLight1Checked(wxCommandEvent& event)
02092 
02093 //----------------------------------------------------------------------------
02094 //------------------------- protected: OnRotateChecked() ---------------------
02095 //----------------------------------------------------------------------------
02096 void vuMarchingCubes::OnRotateChecked(wxCommandEvent &event) // {{{
02097 {
02098         DEBUG0("void vuMarchingCubes::OnRotateChecked(wxCommandEvent &event)\n");
02099         DEBUG4("rotating ...\n");
02100         m_glCanvas->redraw();
02101 } // }}} void vuMarchingCubes::OnRotateChecked(wxCommandEvent &event)
02102 
02103 //----------------------------------------------------------------------------
02104 //------------------------- protected: OnCubeEnabledChecked() ----------------
02105 //----------------------------------------------------------------------------
02106 void vuMarchingCubes::OnCubeEnabledChecked(wxCommandEvent& event) // {{{
02107 {
02108         DEBUG0("void vuMarchingCubes::OnCubeEnabledChecked(wxCommandEvent& event)\n");
02109         wxCheckBox* cb = (wxCheckBox*)event.GetEventObject();
02110         m_cube->Enable(cb->IsChecked());
02111         m_gd.cubeBrowser = cb->IsChecked();
02112         m_glCanvas->redraw();
02113 } // }}} void vuMarchingCubes::OnCubeEnabledChecked(wxCommandEvent& event)
02114 
02115 //----------------------------------------------------------------------------
02116 //------------------------- protected: OnFrameChecked() ---------------------
02117 //----------------------------------------------------------------------------
02118 void vuMarchingCubes::OnFrameChecked(wxCommandEvent& event) // {{{
02119 {
02120         DEBUG0("void vuMarchingCubes::OnFrameChecked(wxCommandEvent& event)\n");
02121         m_glCanvas->redraw();
02122 } // }}} void vuMarchingCubes::OnFrameChecked(wxCommandEvent& event)
02123 
02124 //----------------------------------------------------------------------------
02125 //------------------------- protected: OnCullLinesBackFrontFacesChecked() ------------------
02126 //----------------------------------------------------------------------------
02127 void vuMarchingCubes::OnCullLinesFrontBackChecked(wxCommandEvent &event) // {{{
02128 {
02129         DEBUG0("void vuMarchingCubes::OnCullLinesFrontBackChecked(wxCommandEvent &event)\n");
02130         assert(m_base != NULL);
02131         DEBUG4("setting lines and culling ...\n");
02132         m_gd.cullMode = m_gd.linesMode = 0;
02133         if (m_cullBack->IsChecked()) m_gd.cullMode = GL_BACK;
02134         if (m_cullFront->IsChecked()) m_gd.cullMode = GL_FRONT;
02135         if (m_cullBack->IsChecked() && m_cullFront->IsChecked()) m_gd.cullMode = GL_FRONT_AND_BACK;
02136         if (m_linesBack->IsChecked()) m_gd.linesMode = GL_BACK;
02137         if (m_linesFront->IsChecked()) m_gd.linesMode = GL_FRONT;
02138         if (m_linesBack->IsChecked() && m_linesFront->IsChecked()) m_gd.linesMode = GL_FRONT_AND_BACK;
02139         m_glCanvas->redraw();
02140 } // }}} void vuMarchingCubes::OnCullLinesFrontBackChecked(wxCommandEvent &event)
02141 
02142 //----------------------------------------------------------------------------
02143 //------------------------- protected: OnUpdateModeChecked() -----------------
02144 //----------------------------------------------------------------------------
02145 void vuMarchingCubes::OnUpdateModeChecked(wxCommandEvent& event) // {{{
02146 {
02147         DEBUG0("void vuMarchingCubes::OnUpdateModeChecked(wxCommandEvent& event)\n");
02148         if (m_thres) m_thres->UpdateMode(m_updateMode->GetValue());
02149 #ifdef LINUX
02150         m_update->Enable(!m_thres->UpdateMode());
02151 #endif
02152 } // }}} void vuMarchingCubes::OnUpdateModeChecked(wxCommandEvent& event)
02153 
02154 //----------------------------------------------------------------------------
02155 //------------------------- public: redraw() ---------------------------------
02156 //----------------------------------------------------------------------------
02157 #ifdef LINUX
02158 void vuMarchingCubes::OnUpdateClicked(wxCommandEvent &event) // {{{
02159 {
02160         DEBUG0("void vuMarchingCubes::OnUpdateClicked(wxCommandEvent &event)\n");
02161         OnThresChange();
02162 } // }}} void vuMarchingCubes::OnUpdateClicked(wxCommandEvent &event)
02163 #endif
02164 
02165 //----------------------------------------------------------------------------
02166 //------------------------- public: OnDrawNormalsChecked() -------------------
02167 //----------------------------------------------------------------------------
02168 void vuMarchingCubes::OnDrawNormalsChecked(wxCommandEvent &event) // {{{
02169 {
02170         DEBUG0("void vuMarchingCubes::OnDrawNormalsChecked(wxCommandEvent &event)\n");
02171         m_gd.drawNormals = m_drawNormals->GetValue();
02172         m_drawNormalsSize->Enable(m_drawNormals->GetValue());
02173         m_glCanvas->redraw();
02174 } // }}} void vuMarchingCubes::OnDrawNormalsChecked(wxCommandEvent &event)
02175 
02176 //----------------------------------------------------------------------------
02177 //------------------------- public: redraw() ---------------------------------
02178 //----------------------------------------------------------------------------
02179 void vuMarchingCubes::redraw() // {{{
02180 {
02181         DEBUG0("void vuMarchingCubes::redraw()\n");
02182         m_glCanvas->redraw();
02183 } // }}} void vuMarchingCubes::redraw()
02184 
02185 //----------------------------------------------------------------------------
02186 //------------------------- public: resize() ---------------------------------
02187 //----------------------------------------------------------------------------
02188 void vuMarchingCubes::resize() // {{{
02189 {
02190         DEBUG0("void vuMarchingCubes::resize()\n");
02191         glResize();
02192         m_glCanvas->redraw();
02193 } // }}} void vuMarchingCubes::resize()
02194 
02195 //----------------------------------------------------------------------------
02196 //------------------------- public: OnCubeChange() ---------------------------
02197 //----------------------------------------------------------------------------
02198 void vuMarchingCubes::OnCubeChange(int val) // {{{
02199 {
02200         DEBUG0("void vuMarchingCubes::OnCubeChange(int val)\n");
02201         m_gd.objectColor[m_gd.cube] = m_objectColor->tovuVector();
02202         m_gd.isObjectColor[m_gd.cube] = true;
02203         m_gd.cube = *m_cube;
02204         m_gd.objectColor[m_gd.cube] = m_selectColor->tovuVector();
02205         m_gd.isObjectColor[m_gd.cube] = false;
02206         m_cubeHist->Select(m_gd.cube);
02207         m_cubeHist->Flush();
02208         m_glCanvas->redraw();
02209 } // }}} void vuMarchingCubes::OnCubeChange(int val)
02210 
02211 //----------------------------------------------------------------------------
02212 //------------------------- public: setBackground() --------------------------
02213 //----------------------------------------------------------------------------
02214 void vuMarchingCubes::setBackground() // {{{
02215 {
02216         DEBUG0("void vuMarchingCubes::setBackground()\n");
02217         glClearColor(m_backColor->Red(), m_backColor->Green(), m_backColor->Blue(), m_backColor->Alpha());
02218         m_glCanvas->redraw();
02219 } // }}} void vuMarchingCubes::setBackground()
02220 
02221 //----------------------------------------------------------------------------
02222 //------------------------- public: OnProgress() -----------------------------
02223 //----------------------------------------------------------------------------
02224 void vuMarchingCubes::OnProgress(float v) // {{{
02225 {
02226         DEBUG0("void vuMarchingCubes::OnProgress(float v="<<v<<")\n");
02227         if (0.0 <= v && v <= 100.0) {
02228                 m_statusText->Enable();
02229                 m_status->Enable();
02230                 m_status->SetValue((int)v);
02231         } else {
02232                 m_statusText->Disable();
02233                 m_status->Disable();
02234         }
02235 } // }}} void vuMarchingCubes::OnProgress(float v)
02236 
02237 //----------------------------------------------------------------------------
02238 //------------------------- public: OnChangeFrame() --------------------------
02239 //----------------------------------------------------------------------------
02240 void vuMarchingCubes::OnChangeFrame() // {{{
02241 {
02242         DEBUG0("void vuMarchingCubes::OnChangeFrame()\n");
02243         m_gd.frameRadius = (*m_frameRadius);
02244         DEBUG1("r = "<<m_gd.frameRadius<<"\n");
02245         m_glCanvas->redraw();
02246 } // }}} void vuMarchingCubes::OnChangeFrame()
02247 
02248 //----------------------------------------------------------------------------
02249 //------------------------- public: OnThresChange() --------------------------
02250 //----------------------------------------------------------------------------
02251 void vuMarchingCubes::OnThresChange() // {{{
02252 {
02253         DEBUG0("void vuMarchingCubes::OnThresChange()\n");
02254         m_gd.thres = *m_thres;
02255         doResetThres();
02256         m_base->marchCubes();
02257         doThresChange();
02258         m_cubeHist->Flush();
02259         m_glCanvas->redraw();
02260 } // }}} void vuMarchingCubes::OnThresChange()
02261 
02262 //----------------------------------------------------------------------------
02263 //------------------------- public: OnThresChange() --------------------------
02264 //----------------------------------------------------------------------------
02265 void vuMarchingCubes::OnNormalLengthChange(float l) // {{{
02266 {
02267         DEBUG0("void vuMarchingCubes::OnNormalLengthChange(float l)\n");
02268         m_gd.normalsLength = l;
02269         m_gd.compileNormals = true;
02270         m_glCanvas->redraw();
02271 } // }}} void vuMarchingCubes::OnNormalLengthChange(float l)
02272 
02273 //----------------------------------------------------------------------------
02274 //------------------------- public: OnThresChange() --------------------------
02275 //----------------------------------------------------------------------------
02276 void vuMarchingCubes::OnSetObjectColor() // {{{
02277 {
02278         DEBUG0("void vuMarchingCubes::OnSetObjectColor()\n");
02279         for(int i = 0; i < 256; ++i) {
02280                 if (m_gd.isObjectColor[i]) {
02281                         m_gd.objectColor[i] = m_objectColor->tovuVector();
02282                 } else {
02283                         m_gd.objectColor[i] = m_selectColor->tovuVector();
02284                         m_cubeHist->SetSelColor(m_gd.objectColor[i]);
02285                 }
02286         }
02287         m_glCanvas->redraw();
02288 } // }}} void vuMarchingCubes::OnSetObjectColor()
02289 
02290 //----------------------------------------------------------------------------
02291 //------------------------- public: OnThresChange() --------------------------
02292 //----------------------------------------------------------------------------
02293 void vuMarchingCubes::OnSetLineColor() // {{{
02294 {
02295         DEBUG0("void vuMarchingCubes::OnSetLineColor()\n");
02296         m_gd.lineColor = m_lineColor->tovuVector();
02297         m_glCanvas->redraw();
02298 } // }}} void vuMarchingCubes::OnSetLineColor()
02299 
02300 //----------------------------------------------------------------------------
02301 //------------------------- public: OnCubeSizeChange() -----------------------
02302 //----------------------------------------------------------------------------
02304 void vuMarchingCubes::OnCubeSizeChange() // {{{
02305 {
02306         DEBUG0("void vuMarchingCubes::OnCubeSizeChange()\n");
02307         m_gd.cubeSize[0] = *m_cubeSizeX;
02308         m_gd.cubeSize[1] = *m_cubeSizeY;
02309         m_gd.cubeSize[2] = *m_cubeSizeZ;
02310         m_base->Origin((float)m_base->Size1()*m_gd.cubeSize[0]/-2.0,
02311                        (float)m_base->Size2()*m_gd.cubeSize[1]/-2.0,
02312                        (float)m_base->Size3()*m_gd.cubeSize[2]/-2.0);
02313         glResize();
02314         m_gd.compileData = true;
02315         m_gd.compileNormals = true;
02316         m_glCanvas->redraw();
02317 } // }}} void vuMarchingCubes::OnCubeSizeChange()
02318 
02319 //----------------------------------------------------------------------------
02320 //------------------------- public: OnSelectType() ---------------------------
02321 //----------------------------------------------------------------------------
02322 void vuMarchingCubes::OnSelectType(int n) // {{{
02323 {
02324         DEBUG0("void vuMarchingCubes::OnSelectType(int n)\n");
02325         DEBUG5("Setting color for type = "<<n<<"\n");
02326         assert(0 < n && n < 255);
02327         int type = *m_cube;
02328         if (0 < type && type < 255) {
02329                 m_gd.objectColor[type] = m_objectColor->tovuVector();
02330                 m_gd.isObjectColor[type] = true;
02331         }
02332         *m_cube = n;
02333         m_gd.cube = n;
02334         m_gd.objectColor[n] = m_selectColor->tovuVector();
02335         m_gd.isObjectColor[n] = false;
02336         m_glCanvas->redraw();
02337 } // }}} void vuMarchingCubes::OnSelectType(int n)
02338 
02339 //----------------------------------------------------------------------------
02340 //------------------------- protected: rotate() ------------------------------
02341 //----------------------------------------------------------------------------
02345 void vuMarchingCubes::rotate(float ax, float ay) // {{{
02346 {
02347         glPopMatrix();
02348         glRotatef(ax, 1.0, 0.0, 0.0);
02349         glRotatef(ay, 0.0, 1.0, 0.0);
02350         glPushMatrix();
02351         glTranslatef(0.0, 0.0, 0.0);
02352 } /* }}} void vuMarchingCubes::rotate(float ax, float ay) */
02353 
02354 //----------------------------------------------------------------------------
02355 //------------------------- protected: doThresChage() ------------------------
02356 //----------------------------------------------------------------------------
02357 void vuMarchingCubes::doThresChange() // {{{
02358 {
02359         DEBUG0("void vuMarchingCubes::doThresChange()\n");
02360         if (m_thres) {
02361                 DEBUG3("thres min = "<<m_gd.valueMin<<", thres max = "<<m_gd.valueMax<<"\n");
02362                 m_thres->Min(m_gd.valueMin);
02363                 m_thres->Max(m_gd.valueMax);
02364         }
02365         if (m_numTriangles) {
02366                 DEBUG3("number of triangles: "<<m_base->numTriangles()<<"\n");
02367                 *m_numTriangles = m_base->numTriangles();
02368         }
02369         if (m_numVertices) {
02370                 DEBUG3("number of vertices: "<<m_base->numVertices()<<"\n");
02371                 *m_numVertices = m_base->numVertices();
02372         }
02373         if (m_numIndices) {
02374                 DEBUG3("number of indices: "<<m_base->numIndices()<<"\n");
02375                 *m_numIndices = m_base->numIndices();
02376         }
02377         if (m_meshSize) {
02378                 *m_meshSize = m_gd.meshSize;
02379         }
02380 } // }}} void vuMarchingCubes::doThresChange()
02381 
02382 //----------------------------------------------------------------------------
02383 //------------------------- protected: doThresChage() ------------------------
02384 //----------------------------------------------------------------------------
02385 void vuMarchingCubes::doResetThres() // {{{
02386 {
02387         DEBUG0("void vuMarchingCubes::doResetThres()\n");
02388         if (m_numTriangles) {
02389                 *m_numTriangles = 0.0;
02390         }
02391         if (m_numVertices) {
02392                 *m_numVertices = 0.0;
02393         }
02394         if (m_numIndices) {
02395                 *m_numIndices = 0.0;
02396         }
02397 } // }}} void vuMarchingCubes::doResetThres()
02398 
02399 //----------------------------------------------------------------------------
02400 //------------------------- protected: doThresChage() ------------------------
02401 //----------------------------------------------------------------------------
02402 inline int vuMarchingCubes::outside(vuVector &point, double *size) // {{{
02403 {
02404         DEBUG0("inline int vuMarchingCubes::outside(vuVector &point, double *size)\n");
02405         int dir = -1;
02406         for(int i = 0; i <3; ++i) {
02407                 if (fabs(point[i]) > size[i]) {
02408                         dir = i;
02409                         break;
02410                 }
02411         }
02412         return dir;
02413 } // }}} inline int vuMarchingCubes::outside(vuVector &point, double *size)
02414 
02415 // }}}
02416 // <<<
02417 
02418 // {{{ class vuMCMCBProgressCallback:
02419 
02420 vuMCMCBProgressCallback::vuMCMCBProgressCallback(vuMarchingCubes* mc) // {{{
02421 : _mc(mc)
02422 {
02423         DEBUGC("vuMCMCBProgressCallback::vuMCMCBProgressCallback(vuMarchingCubes* mc)\n");
02424 } // }}} vuMCMCBProgressCallback::vuMCMCBProgressCallback(vuMarchingCubes* mc)
02425 
02426 void vuMCMCBProgressCallback::SetText(const char* txt) // {{{
02427 {
02428         DEBUG0("void vuMCMCBProgressCallback::SetText(const char* txt)\n");
02429         assert(_mc != NULL);
02430         _mc->m_statusText->SetLabel(txt);
02431 } // }}} void vuMCMCBProgressCallback::SetText(const char* txt)
02432 
02433 void vuMCMCBProgressCallback::Start() // {{{
02434 {
02435         DEBUG0("void vuMCMCBProgressCallback::Start()\n");
02436         assert(_mc != NULL);
02437         _mc->m_statusText->Enable();
02438         _mc->m_status->Enable();
02439 } // }}} void vuMCMCBProgressCallback::Start()
02440 
02441 void vuMCMCBProgressCallback::Update(int val) // {{{
02442 {
02443         DEBUG0("void vuMCMCBProgressCallback::Update(int val)\n");
02444         assert(_mc != NULL);
02445         _mc->m_status->SetValue(val);
02446 } // }}} void vuMCMCBProgressCallback::Update(int val)
02447 
02449 void vuMCMCBProgressCallback::End() // {{{
02450 {
02451         DEBUG0("void vuMCMCBProgressCallback::End()\n");
02452         assert(_mc != NULL);
02453         _mc->m_status->SetValue(0);
02454         _mc->m_statusText->Disable();
02455         _mc->m_status->Disable();
02456 } // }}} void vuMCMCBProgressCallback::End()
02457 
02458 // }}} vuMCMCBProgressCallback
02459 
02460 
02461 // {{{ class vuMCMCBHistoCallback:
02462 
02463 vuMCMCBHistoCallback::vuMCMCBHistoCallback(vuMarchingCubes *mc) // {{{
02464 : _mc(mc)
02465 {
02466         DEBUGC("vuMCMCBHistoCallback::vuMCMCBHistoCallback(vuMarchingCubes *mc)\n");
02467 } // }}} vuMCMCBHistoCallback::vuMCMCBHistoCallback(vuMarchingCubes *mc)
02468 
02469 void vuMCMCBHistoCallback::Clear() // {{{
02470 {
02471         DEBUG0("void vuMCMCBHistoCallback::Clear()\n");
02472         *(_mc->m_cube0) = 0.0;
02473         *(_mc->m_cube255) = 0.0;
02474         *(_mc->m_cubeOther) = (float)*(_mc->m_cubesTotal);
02475         _mc->m_cubeHist->Clear();
02476 } // }}} void vuMCMCBHistoCallback::Clear()
02477 
02478 void vuMCMCBHistoCallback::Inc(int idx, int val) // {{{
02479 {
02480         DEBUG0("void vuMCMCBHistoCallback::Inc(int idx="<<idx<<", int val="<<val<<")\n");
02481         assert(_mc != NULL);
02482         if (idx == 0 || idx == 255) {
02483                 *(_mc->m_cubeOther) -= (float)val;
02484                 *(_mc->m_meshSize) = _mc->m_gd.meshSize;
02485         }
02486         if (idx == 0)   {
02487                 *(_mc->m_cube0) += (float)val;
02488                 return;
02489         }
02490         if (idx == 255) {
02491                 *(_mc->m_cube255) += (float)val;
02492                 return;
02493         }
02494         _mc->m_cubeHist->Inc(idx, val);
02495 } // }}} void vuMCMCBHistoCallback::Inc(int idx, int val = 1)
02496 
02497 void vuMCMCBHistoCallback::Flush() // {{{
02498 {
02499         DEBUG0("void vuMCMCBHistoCallback::Flush()\n");
02500         _mc->m_cubeHist->Flush();
02501 } // }}} void vuMCMCBHistoCallback::Flush()
02502 
02503 // }}} vuMCMCBHistoCallback
02504 
02505 
02506 // {{{ class vuMCCubeDecorator:
02507 
02508 vuMCCubeChange::vuMCCubeChange(vuMarchingCubes* mc) // {{{
02509 : _mc(mc)
02510 {
02511         DEBUGC("vuMCCubeChange::vuMCCubeChange(vuMarchingCubes* mc="<<mc<<")\n");
02512 } /* }}} vuMCCubeChange::vuMCCubeChange(vuMarchingCubes* mc) */
02513 
02514 void vuMCCubeChange::operator()(int c) // {{{
02515 {
02516         DEBUG0("void vuMCCubeChange::operator()(int c="<<c<<")\n");
02517         _mc->OnCubeChange(c);
02518 } /* }}} void vuMCCubeChange::operator()(int c) */
02519 
02520 // }}} vuMCCubeDecorator
02521 
02522 
02523 // {{{ class vuMCRender:
02524 
02525 vuMCRender::vuMCRender(vuMarchingCubes* mc) // {{{
02526 : _mc(mc)
02527 {
02528         DEBUGC("vuMCRender::vuMCRender(vuMarchingCubes* mc)\n");
02529 } // }}} vuMCRender::vuMCRender(vuMarchingCubes* mc)
02530 
02531 void vuMCRender::operator()(float) // {{{
02532 {
02533         DEBUG0("virtual void vuMCRender::operator()(float)\n");
02534         _mc->redraw();
02535 } // }}} virtual void vuMCRender::operator()(float)
02536 
02537 // }}} vuMCRender
02538 
02539 
02540 // {{{ class vuMCResize:
02541 
02542 vuMCResize::vuMCResize(vuMarchingCubes* mc) // {{{
02543 : _mc(mc)
02544 {
02545         DEBUGC("vuMCResize::vuMCResize(vuMarchingCubes* mc)\n");
02546 } // }}} vuMCResize::vuMCResize(vuMarchingCubes* mc)
02547 
02548 void vuMCResize::operator()(int) // {{{
02549 {
02550         DEBUG0("virtual void vuMCResize::operator()(int)\n");
02551         _mc->resize();
02552 } // }}} virtual void vuMCResize::operator()(int)
02553 
02554 // }}} vuMCResize
02555 
02556 
02557 // {{{ class vuMCBackgroundChange:
02558 
02559 vuMCBackgroundChange::vuMCBackgroundChange(vuMarchingCubes* mc) // {{{
02560 : _mc(mc)
02561 {
02562         DEBUGC("vuMCBackgroundChange::vuMCBackgroundChange(vuMarchingCubes* mc)\n");
02563 } // }}} vuMCBackgroundChange::vuMCBackgroundChange(vuMarchingCubes* mc)
02564 
02565 void vuMCBackgroundChange::operator()(float) // {{{
02566 {
02567         DEBUG0("virtual void vuMCBackgroundChange::operator()(float)\n");
02568         _mc->setBackground();
02569         _mc->redraw();
02570 } // }}} virtual void vuMCBackgroundChange::operator()(float)
02571 
02572 // }}} vuMCBackgroundChange
02573 
02574 
02575 // {{{ class vuMCProgress:
02576 
02577 vuMCProgress::vuMCProgress(vuMarchingCubes* mc) // {{{
02578 : _mc(mc)
02579 {
02580         DEBUGC("vuMCProgress::vuMCProgress(vuMarchingCubes* mc)\n");
02581 } // }}} vuMCProgress::vuMCProgress(vuMarchingCubes* mc)
02582 
02583 void vuMCProgress::operator()(float v) // {{{
02584 {
02585         DEBUG0("void vuMCProgress::operator()(float)\n");
02586         _mc->OnProgress(v);
02587 } // }}} void vuMCProgress::operator()(float)
02588 
02589 // }}} vuMCProgress
02590 
02591 
02592 // {{{ class vuMCFrameChange:
02593 
02594 vuMCFrameChange::vuMCFrameChange(vuMarchingCubes* mc) // {{{
02595 : _mc(mc)
02596 {
02597         DEBUGC("vuMCFrameChange::vuMCFrameChange(vuMarchingCubes* mc)\n");
02598 } // }}} vuMCFrameChange::vuMCFrameChange(vuMarchingCubes* mc)
02599 
02600 void vuMCFrameChange::operator()(float) // {{{
02601 {
02602         DEBUG0("void vuMCFrameChange::operator()(float)\n");
02603         _mc->OnChangeFrame();
02604 } // }}} void vuMCFrameChange::operator()(float)
02605 
02606 // }}} vuMCFrameChange
02607 
02608 
02609 // {{{ class vuMCThresChange:
02610 
02611 vuMCThresChange::vuMCThresChange(vuMarchingCubes* mc) // {{{
02612 : _mc(mc)
02613 {
02614         DEBUGC("vuMCThresChange::vuMCThresChange(vuMarchingCubes* mc)\n");
02615 } // }}} vuMCThresChange::vuMCThresChange(vuMarchingCubes* mc)
02616 
02617 void vuMCThresChange::operator()(float) // {{{
02618 {
02619         DEBUG0("void vuMCThresChange::operator()(float)\n");
02620         _mc->OnThresChange();
02621 } // }}} void vuMCThresChange::operator()(float)
02622 
02623 // }}} vuMCThresChange
02624 
02625 
02626 // {{{ class vuMCNormalLengthChange:
02627 
02628 vuMCNormalLengthChange::vuMCNormalLengthChange(vuMarchingCubes* mc) // {{{
02629 : _mc(mc)
02630 {
02631         DEBUGC("vuMCNormalLengthChange::vuMCNormalLengthChange(vuMarchingCubes* mc)\n");
02632 } // }}} vuMCNormalLengthChange::vuMCNormalLengthChange(vuMarchingCubes* mc)
02633 
02634 void vuMCNormalLengthChange::operator()(float l) // {{{
02635 {
02636         DEBUG0("void vuMCNormalLengthChange::operator()(float l)\n");
02637         _mc->OnNormalLengthChange(l);
02638         _mc->redraw();
02639 } // }}} void vuMCNormalLengthChange::operator()(float l)
02640 
02641 // }}} vuMCNormalLengthChange
02642 
02643 
02644 // {{{ class vuMCObjectColorChange:
02645 
02646 vuMCObjectColorChange::vuMCObjectColorChange(vuMarchingCubes* mc) // {{{
02647 : _mc(mc)
02648 {
02649         DEBUGC("vuMCObjectColorChange::vuMCObjectColorChange(vuMarchingCubes* mc)\n");
02650 } // }}} vuMCObjectColorChange::vuMCObjectColorChange(vuMarchingCubes* mc)
02651 
02652 void vuMCObjectColorChange::operator()(float l) // {{{
02653 {
02654         DEBUG0("void vuMCObjectColorChange::operator()(float l)\n");
02655         _mc->OnSetObjectColor();
02656 } // }}} void vuMCObjectColorChange::operator()(float l)
02657 
02658 // }}} vuMCObjectColorChange
02659 
02660 
02661 // {{{ class vuMCLineColorChange:
02662 
02663 vuMCLineColorChange::vuMCLineColorChange(vuMarchingCubes* mc) // {{{
02664 : _mc(mc)
02665 {
02666         DEBUGC("vuMCLineColorChange::vuMCLineColorChange(vuMarchingCubes* mc)\n");
02667 } // }}} vuMCLineColorChange::vuMCLineColorChange(vuMarchingCubes* mc)
02668 
02669 void vuMCLineColorChange::operator()(float l) // {{{
02670 {
02671         DEBUG0("void vuMCLineColorChange::operator()(float l)\n");
02672         _mc->OnSetLineColor();
02673 } // }}} void vuMCLineColorChange::operator()(float l)
02674 
02675 // }}} vuMCLineColorChange
02676 
02677 
02678 // {{{ class vuMCCubeSizeChange:
02679 
02680 vuMCCubeSizeChange::vuMCCubeSizeChange(vuMarchingCubes* mc) // {{{
02681 : _mc(mc)
02682 {
02683         DEBUGC("vuMCCubeSizeChange::vuMCCubeSizeChange(vuMarchingCubes* mc)\n");
02684 } // }}} vuMCCubeSizeChange::vuMCCubeSizeChange(vuMarchingCubes* mc)
02685 
02686 void vuMCCubeSizeChange::operator()(float l) // {{{
02687 {
02688         DEBUG0("void vuMCCubeSizeChange::operator()(float l)\n");
02689         _mc->OnCubeSizeChange();
02690 } // }}} void vuMCCubeSizeChange::operator()(float l)
02691 
02692 // }}} vuMCCubeSizeChange
02693 
02694 
02695 // {{{ class vuMCSelectType:
02696 
02697 vuMCSelectType::vuMCSelectType(vuMarchingCubes* mc) // {{{
02698 : _mc(mc)
02699 {
02700         DEBUGC("vuMCSelectType::vuMCSelectType(vuMarchingCubes* mc)\n");
02701 } // }}} vuMCSelectType::vuMCSelectType(vuMarchingCubes* mc)
02702 
02703 void vuMCSelectType::operator()(int n) // {{{
02704 {
02705         DEBUG0("virtual void vuMCSelectType::operator()(int n)\n");
02706         _mc->OnSelectType(n);
02707 } // }}} virtual void vuMCSelectType::operator()(int n)
02708 
02709 // }}} vuMCSelectType
02710 
02711 
02712 // vim:fdm=syntax:fdc=3:tw=100

Generated on Wed Dec 15 21:20:35 2004 for vuVolume by  doxygen 1.3.9.1