HyperspaceExplorer 0.7.1
Realm.h
00001 /*
00002 Hyperspace Explorer - visualizing higher-dimensional geometry
00003 Copyright (C) 2009-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 
00027 
00028 #ifndef REALM_H
00029 #define REALM_H
00030 
00031 //#include "uintvec.h"
00032 #include "Vector.h"
00033 
00034 #include <string>
00035 #include <list>
00036 #include <vector>
00037 
00038 class Rotope;
00039 
00041 
00063 class Realm {
00064 
00065 public:
00066 
00068     typedef std::vector<VecMath::Vector<4> > vertex_container_type;
00070     typedef std::vector<Realm> realm_container_type;
00071 
00073     Realm(): _dimension(0), _subrealm(), _index(0) { }
00074 
00076 
00078     Realm(unsigned i): _dimension(0), _subrealm(), _index(i) { }
00079 
00081 
00083     Realm(const realm_container_type &sr): _subrealm(sr), _index() {
00084         if(sr.empty()) _dimension = 0;
00085         else _dimension = sr[0].dimension()+1;
00086     }
00087 
00089     ~Realm() { }
00090 
00092     unsigned size() const { return _subrealm.size(); }
00094     void clear();
00096     void push_back(const Realm &r);
00098     realm_container_type::iterator begin() { return _subrealm.begin(); }
00100     realm_container_type::const_iterator cbegin() const { return _subrealm.begin(); }
00101 
00103     realm_container_type::iterator end() { return _subrealm.end(); }
00105     realm_container_type::const_iterator cend() const { return _subrealm.end(); }
00106 
00108     realm_container_type::reverse_iterator rbegin() { return _subrealm.rbegin(); }
00109 
00111     realm_container_type::reverse_iterator rend() { return _subrealm.rend(); }
00112 
00114     unsigned dimension() const { return _dimension; }
00116     void setDimension(unsigned d) { _dimension = d; }
00117 
00119     unsigned toIndex() const;
00120 
00122     Realm extruded(unsigned delta) const;
00123 
00125     Realm tapered(unsigned taper_index) const;
00126 
00128     Realm rotated(unsigned num_segments, unsigned size) const;
00129 
00131     void merge(const Realm &r);
00132 
00134     const realm_container_type &getSubrealms() const { return _subrealm; }
00135 
00137     void setSubrealms(realm_container_type sr) { _subrealm = sr; }
00138 
00140     bool operator==(const Realm &other) const;
00141 
00143     bool contains(const Realm &other) const;
00144 
00146     std::string toString() const;
00147 
00149 
00152     void addOffset(unsigned delta);
00153 
00154 private:
00155 
00157     Realm extrudedPoint(unsigned delta) const;
00159     Realm extrudedLine(unsigned delta) const;
00161     Realm extrudedPolygon(unsigned delta) const;
00163     Realm extrudedRealm(unsigned delta) const;
00164 
00166     Realm taperedLine(unsigned taper_index) const;
00168     Realm taperedPolygon(unsigned taper_index) const;
00170     Realm taperedRealm(unsigned taper_index) const;
00171 
00173     Realm rotatedLine(unsigned num_segments, unsigned size) const;
00174 
00176     std::list<realm_container_type> generateListOfPointsToAdd(
00177         std::list<Realm> original_list,
00178         unsigned num_segments, unsigned size) const;
00180     void insertNewPoints(std::list<Realm> &original_list,
00181                          const std::list<Realm::realm_container_type> &new_points) const;
00182 
00184     Realm rotatedPolygon(unsigned num_segments, unsigned size) const;
00186     Realm rotatedPolygonCap(const realm_container_type &temp_subrealms) const;
00188     Realm rotatedRealm(unsigned num_segments, unsigned size) const;
00189 
00191     Realm rotateStep(unsigned index, unsigned base, unsigned delta) const;
00193     Realm generateStripBetweenGreatCircles(unsigned base, unsigned delta) const;
00194 
00196     realm_container_type rectsBetweenGreatCircles(unsigned base, unsigned delta) const;
00198     Realm reorderRectsBetweenGreatCircles(Realm::realm_container_type subrealms, unsigned int index) const;
00200     Realm generateRectSegment(unsigned i, unsigned base, unsigned delta) const;
00201 
00203     void addRotationStrip(Realm &all_strips, unsigned rotation_step, unsigned num_segments) const;
00205     void addStayingWithinSameStrip(unsigned total_vertices, unsigned rotation_step);
00207     void checkArgumentsForAddStayingWithinSameStrip() const;
00209     std::pair<unsigned, unsigned> wrapToStayWithinStrip(unsigned base, unsigned extruded,
00210                                                         unsigned num_segments, unsigned rotation_step) const;
00211 
00213     static Realm generateEmpty3DRealm();
00214 
00216     unsigned _dimension;
00218     realm_container_type _subrealm;
00220     unsigned _index;
00221 
00223     const static bool DEBUG_ROTATE = false;
00225     static const unsigned OFFSET_BETWEEN_NEIGHBORING_INDICES = 2;
00226 
00228     class RealmPrinter {
00229 
00231         static const std::string PRINT_DIMENSION_SPACER;
00232 
00233     public:
00234 
00236         RealmPrinter(const Realm *realm): _realm(realm) { }
00237 
00239         void print(std::ostream &out) const;
00240 
00241     private:
00243         void printHeader(std::ostream &out) const;
00245         void printFooter(std::ostream &out) const;
00247         void printPoint(std::ostream &out) const;
00249         void printSubrealms(std::ostream &out) const;
00251         void indentNextLine(std::ostream &out) const;
00252 
00254         const Realm * _realm;
00255 
00259         static unsigned _max_dimension;
00260 
00261     };
00262 
00263 };
00264 
00265 #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