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 #if(!defined SPONGE_H) 00022 #define SPONGE_H 00023 00024 #define USE_ALT_SPONGE 0 00025 00026 #include "ObjectImplementations.h" 00027 00029 00031 00050 class Sponge: public Hypercube { 00051 public: 00053 00063 Sponge (unsigned _level = 1, unsigned _distance = 2, double _rad = 0.8, 00064 VecMath::Vector<4> _center = VecMath::Vector<4>(0., 0.,0., 0.)); 00065 virtual ~Sponge (); 00066 virtual std::string getFunctionName() const { return "4D Menger Sponge"; } 00067 00068 virtual void Transform (const VecMath::Rotation<4> &R, 00069 const VecMath::Vector<4> &T, 00070 const VecMath::Vector<4> &scale); 00071 virtual void Project (double ScrW, double CamW, bool DepthCue4D); 00072 virtual void Draw (UI::View *view); 00073 00074 virtual void SetParameters(const ParameterMap &parms) { 00075 std::cerr << "Sponge::SetParameters(" << parms.toString() << ")\n"; 00076 # if 1 00077 for (ParameterMap::const_iterator i = parms.begin(); 00078 i != parms.end(); ++i) { 00079 if (i->second->getName() == "Level") 00080 Level = i->second->toUnsigned(); 00081 if (i->second->getName() == "Distance") 00082 distance = i->second->toInt(); 00083 if (i->second->getName() == "Size") 00084 rad = i->second->toDouble(); 00085 } 00086 # else 00087 setParameter(parms, this->Phase, "Phase"); 00088 # endif 00089 } 00090 00092 virtual void ReInit (double, double, double, 00093 double, double, double, 00094 double, double, double) { 00095 List.clear(); 00096 Object::ReInit(0,0,0,0,0,0,0,0,0); 00097 } 00098 00100 virtual std::string description () { 00101 std::ostringstream out; 00102 out << "Sponge (level = " << Level << ")" << std::ends; 00103 return out.str (); 00104 } 00105 00106 protected: 00107 virtual void Initialize(); 00108 virtual unsigned long MemRequired (unsigned); 00109 unsigned Level; 00110 00112 00113 std::vector<Hypercube *> List; 00114 00115 int distance; 00116 double rad; 00117 VecMath::Vector<4> center; 00118 }; 00119 00120 namespace { 00121 Displayable *createSponge() { return new Sponge(); } 00122 const bool registeredS = TheFunctionFactory::Instance().registerFunction(createSponge, "Object"); 00123 } 00124 00126 00128 class AltSponge: public Hypercube { 00129 public: 00131 00141 AltSponge (unsigned _level = 1, unsigned _distance = 2, double _rad = 0.8, 00142 VecMath::Vector<4> _center = VecMath::Vector<4>(0., 0.,0., 0.)); 00143 virtual ~AltSponge () { } 00144 virtual std::string getFunctionName() const { return "4D Menger Sponge (version)"; } 00145 00146 virtual void SetParameters(const ParameterMap &parms) { 00147 std::cerr << "AltSponge::SetParameters(" << parms.toString() << ")\n"; 00148 # if 1 00149 for (ParameterMap::const_iterator i = parms.begin(); 00150 i != parms.end(); ++i) { 00151 if (i->second->getName() == "Level") 00152 Level = i->second->toUnsigned(); 00153 if (i->second->getName() == "Distance") 00154 distance = i->second->toInt(); 00155 if (i->second->getName() == "Size") 00156 rad = i->second->toDouble(); 00157 } 00158 # else 00159 setParameter(parms, this->Phase, "Phase"); 00160 # endif 00161 } 00162 00164 virtual std::string description () { 00165 std::ostringstream out; 00166 out << "Alternative Sponge (level = " << Level << ")" << std::ends; 00167 return out.str (); 00168 } 00169 00170 protected: 00171 virtual void Initialize(); 00172 virtual unsigned long MemRequired (unsigned); 00173 00175 void reduceVertices(); 00177 void removeDuplicateSurfaces(); 00179 00185 void renumberSurfaces(unsigned original_vertex, unsigned duplicate_vertex); 00186 00187 void X_push_back(const VecMath::Vector<4> &x); 00188 00189 unsigned Level; 00190 int distance; 00191 double rad; 00192 VecMath::Vector<4> center; 00193 }; 00194 00195 #if USE_ALT_SPONGE 00196 namespace { 00197 Displayable *createAltSponge() { return new AltSponge(); } 00198 const bool registeredAS = TheFunctionFactory::Instance().registerFunction(createAltSponge, "Object"); 00199 } 00200 #endif 00201 00202 #endif