HyperspaceExplorer 0.7.1
|
00001 /* 00002 Hyperspace Explorer - visualizing higher-dimensional geometry 00003 Copyright (C) 2010 Lene Preuss <lene.preuss@gmail.com> 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 */ 00020 00021 #ifndef GRID_DRAWER_IMPL_H 00022 #define GRID_DRAWER_IMPL_H 00023 00024 #undef PERFORM_TIMING 00025 00026 #include "GridDrawer.h" 00027 00028 #include "Globals.h" 00029 00030 #include "Vector.impl.h" 00031 00032 #ifdef PERFORM_TIMING 00033 # include "ScopedTimer.h" 00034 #endif 00035 00036 // template <unsigned P, typename NUM, unsigned D> 00037 // GridDrawer<P, NUM, D>::GridDrawer(const VecMath::MultiDimensionalVector< VecMath::Vector<D, NUM>, P > &x_scr, 00038 // UI::View *view): 00039 // _x(), _x_scr(x_scr), _view(view) { } 00040 00041 template <unsigned P, typename NUM, unsigned D> 00042 GridDrawer<P, NUM, D>::GridDrawer(const VecMath::MultiDimensionalVector< VecMath::Vector<4, NUM>, P > &x, 00043 const VecMath::MultiDimensionalVector< VecMath::Vector<D, NUM>, P > &x_scr, 00044 UI::View *view): 00045 _x(x), _x_scr(x_scr), _view(view) { } 00046 00047 template <unsigned P, typename NUM, unsigned D> 00048 void GridDrawer<P, NUM, D>::execute() { 00049 for (unsigned i = 0; i < _x_scr.size(); ++i) { 00050 GridDrawer<P-1, NUM, D> sub_drawer(_x[i], _x_scr[i], _view); 00051 sub_drawer.execute(); 00052 } 00053 _view->commitDraw(); 00054 } 00055 00056 template<typename NUM, unsigned D> 00057 GridDrawer<3, NUM, D>::GridDrawer(const VecMath::MultiDimensionalVector< VecMath::Vector<4, NUM>, 3 > &x, 00058 const VecMath::MultiDimensionalVector< VecMath::Vector<D, NUM>, 3 > &x_scr, 00059 UI::View *view): 00060 x_(x), x_scr_(x_scr), view_(view) { } 00061 00062 template<typename NUM, unsigned D> 00063 void GridDrawer<3, NUM, D>::execute() { 00064 unsigned size_t = x_scr_.size()-1; 00065 # ifdef PERFORM_TIMING 00066 ScopedTimer timer("GridDrawer<3, NUM, "+Util::itoa(D)+">::execute() "+Util::itoa(size_t)); 00067 # endif 00068 00069 for (unsigned t = 0; t < size_t; t++) { 00070 drawPlane (t); 00071 } 00072 00073 view_->commitDraw(); 00074 00075 } 00076 00077 template<typename NUM, unsigned D> 00078 void GridDrawer<3, NUM, D>::drawPlane(unsigned t) { 00079 unsigned size_u = x_scr_[0].size()-1; 00080 # ifdef PERFORM_TIMING 00081 ScopedTimer timer("GridDrawer<3, NUM, "+Util::itoa(D)+">::drawPlane(" + Util::itoa(t)+ ") "+Util::itoa(size_u)); 00082 # endif 00083 for (unsigned u = 0; u < size_u; u++) 00084 drawStrip (t, u); 00085 } 00086 00087 template<typename NUM, unsigned D> 00088 void GridDrawer<3, NUM, D>::drawStrip(unsigned t, unsigned u) { 00089 unsigned size_v = x_scr_[0][0].size()-1; 00090 for (unsigned v= 0; v < size_v; v++) 00091 drawCube (t, u, v); 00092 } 00093 00094 template<typename NUM, unsigned D> 00095 inline void GridDrawer<3, NUM, D>::drawCube (unsigned t, unsigned u, unsigned v) { 00096 view_->drawCube(x_, t, u, v, 00097 x_scr_[t][u][v], x_scr_[t][u][v+1], x_scr_[t][u+1][v], x_scr_[t][u+1][v+1], 00098 x_scr_[t+1][u][v], x_scr_[t+1][u][v+1], x_scr_[t+1][u+1][v], x_scr_[t+1][u+1][v+1]); 00099 00100 } 00101 00102 00103 template<typename NUM, unsigned D> 00104 GridDrawer<2, NUM, D>::GridDrawer(const VecMath::MultiDimensionalVector< VecMath::Vector<4, NUM>, 2 > &x, 00105 const VecMath::MultiDimensionalVector< VecMath::Vector<D, NUM>, 2 > &x_scr, 00106 UI::View * view): 00107 x_(x), x_scr_(x_scr), view_(view) { } 00108 00109 template<typename NUM, unsigned D> 00110 void GridDrawer<2, NUM, D>::execute() { 00111 # ifdef PERFORM_TIMING 00112 ScopedTimer timer("GridDrawer<2, NUM, "+Util::itoa(D)+">::execute() "+Util::itoa(size_t)); 00113 # endif 00114 for (unsigned t = 0; t < x_scr_.size()-1; ++t) { 00115 drawStrip(t); 00116 } 00117 00118 } 00119 00120 template<typename NUM, unsigned D> 00121 void GridDrawer<2, NUM, D>::drawStrip(unsigned t) { 00122 for (unsigned u = 0; u < x_scr_[0].size()-1; ++u) { 00123 view_->drawQuadrangle(x_[t][u], x_[t+1][u], x_[t+1][u+1], x_[t][u+1], 00124 x_scr_[t][u], x_scr_[t+1][u], x_scr_[t+1][u+1], x_scr_[t][u+1]); 00125 } 00126 } 00127 00128 00129 template<typename NUM, unsigned D> 00130 GridDrawer<1, NUM, D>::GridDrawer(const VecMath::MultiDimensionalVector< VecMath::Vector<4, NUM>, 1 > &x, 00131 const VecMath::MultiDimensionalVector< VecMath::Vector<D, NUM>, 1 > &x_scr, 00132 UI::View *view): 00133 x_(x), x_scr_(x_scr), view_(view) { } 00134 00135 template<typename NUM, unsigned D> 00136 void GridDrawer<1, NUM, D>::execute() { 00137 # ifdef PERFORM_TIMING 00138 ScopedTimer timer("GridDrawer<1, NUM, "+Util::itoa(D)+">::execute() "+Util::itoa(size_t)); 00139 # endif 00140 for (unsigned i = 0; i < x_scr_.size(); ++i) { 00141 view_->drawLine( 00142 x_[i], x_[i+1], 00143 x_scr_[i], x_scr_[i+1]); 00144 } 00145 00146 } 00147 00148 #endif