HyperspaceExplorer 0.7.1
Extrude.h
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 EXTRUSION_H
00022 #define EXTRUSION_H
00023 
00024 #include "Rotope.h"
00025 
00027 
00031 template <unsigned D>
00032     class extrude_base: public VertexData<D> {
00033 
00034     public:
00035 
00037         extrude_base(): VertexData<D>() { }
00039         extrude_base(const VertexData<D> &v): VertexData<D>(v) { }
00040 
00042 
00050         void extrude(unsigned d);
00051 
00052     };
00053 
00055 
00081 template <unsigned D, unsigned Dmin, unsigned Dmax>
00082     class Extrude: public Extrude<D, Dmin, Dmax-1> {
00083     public:
00085 
00091         Extrude(): Extrude<D, Dmin, Dmax-1>() {
00092             extrude_base<D>::extrude(Dmax);
00093         }
00094 
00096 
00102         Extrude(const VertexData<D> &v): Extrude<D, Dmin, Dmax-1>(v) {
00103             extrude_base<D>::extrude(Dmax);
00104         }
00105     };
00106 
00108 
00114 template <unsigned D, unsigned Dmin>
00115     class Extrude<D, Dmin, Dmin>: public extrude_base<D> {
00116     public:
00118 
00123         Extrude(): extrude_base<D>() {
00124             extrude_base<D>::extrude(Dmin);
00125         }
00126 
00128 
00132         Extrude(const VertexData<D> &v): extrude_base<D>(v) {
00133             extrude_base<D>::extrude(Dmin);
00134         }
00135     };
00136 
00137 
00138 template <unsigned D> void extrude_base<D>::extrude(unsigned d) {
00139     if (d >= D) {
00140         throw std::logic_error(
00141            "extrude_base::extrude() called on a higher dimension"
00142            " than the vector space allows");
00143     }
00144 
00145     VecMath::Vector<D> x;
00146     x[d] = 1.;
00147     unsigned xsize = VertexData<D>::raw_vertices().size();
00148     for (unsigned i = 0; i < xsize; ++i) {
00149         VertexData<D>::raw_vertices()[i] -= x;
00150         VertexData<D>::raw_vertices().push_back(VertexData<D>::raw_vertices()[i]+x*2.);
00151     }
00152 
00153     if (d == 0) VertexData<D>::realm() = Realm(0);
00154 
00155     VertexData<D>::realm() = VertexData<D>::realm().extruded(xsize);
00156 
00157     VertexData<D>::dimension()++;   //  object is now one dimension higher
00158 }
00159 
00160 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends

Generated on Mon Apr 9 2012 20:25:15 for HyperspaceExplorer 0.7.1 by doxygen 1.7.4  -  Hosted bySourceForge.net Logo