HyperspaceExplorer 0.7.1
VertexData.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 
00021 #ifndef VERTEX_DATA_H
00022 #define VERTEX_DATA_H
00023 
00024 #include "RotopeInterface.h"
00025 #include "Projector.h"
00026 
00027 #include <typeinfo>
00028 
00030 
00041 template <unsigned D>
00042     class VertexData: public RotopeInterface {
00043 
00045 
00047         static constexpr double PROJECTION_SCREEN_W = 2.;
00049 
00051         static constexpr double PROJECTION_CAMERA_W = 8.;
00052 
00053     public:
00054 
00056         virtual Realm &realm() { return _realm; }
00058         virtual const Realm &realm() const { return _realm; }
00059 
00061         const std::vector<VecMath::Vector<D> > &raw_vertices() const { return _raw_vertices; }
00062         virtual std::vector<VecMath::Vector<4> > projected_vertices();
00063 
00064         virtual unsigned dimension() const { return _dimension; }
00065         virtual unsigned &dimension() { return _dimension; }
00066 
00068         virtual std::string toString();
00069 
00070 
00071     protected:
00072 
00074         VertexData(): _dimension(0), _raw_vertices(), _transform() {
00075             raw_vertices().push_back(VecMath::Vector<D>());
00076         }
00077 
00079         virtual void addTransform(unsigned, const VecMath::RotationBase *);
00080 
00082         std::vector<VecMath::Vector<D> > &raw_vertices() { return _raw_vertices; }
00084         void set_raw_vertices(const std::vector<VecMath::Vector<D> > &new_vertices) {
00085             _raw_vertices = new_vertices;
00086         }
00087 
00088     private:
00089 
00090         unsigned _dimension;                    
00091 
00092         std::vector<VecMath::Vector<D> > _raw_vertices;    
00093 
00095         Realm _realm;
00096 
00098         std::vector<const VecMath::RotationBase *> _transform;
00099 
00101 
00102         class VertexDataPrinter {
00103 
00105             const static int PRINT_VERTICES_COLUMN_WIDTH = 40;
00107             const static int PRINT_VERTICES_NUM_COLUMNS = 2;
00108 
00109         public:
00110 
00112             VertexDataPrinter(VertexData *vertexData):
00113                 _vertexData(vertexData) { }
00114 
00116             void printToStream(std::ostream &out) const;
00117 
00118         private:
00119 
00121             std::string verticesToString(unsigned num_columns) const;
00122 
00124             void printVertices(unsigned num_columns = PRINT_VERTICES_NUM_COLUMNS,
00125                                std::ostream &out = std::cout) const;
00126 
00128 
00131             std::string verticesToStringRow(unsigned base_index, unsigned num_columns) const;
00132 
00134             void printVerticesRow(unsigned base_index,
00135                                   unsigned num_columns = PRINT_VERTICES_NUM_COLUMNS,
00136                                   std::ostream &out = std::cout) const;
00137 
00139             VertexData *_vertexData;
00140         };
00141 
00143     friend class RotopeFactory;
00144     };
00145 
00146 /*  You shouldn't use "using" directives in a header file, but the code gets
00147     nearly unreadable otherwise. I mean, just look at that:
00148     typename std::vector<VecMath::Vector<D> >::iterator i = _X.begin();
00149     And because I'm defining template classes here, code must be written in the
00150     header file anyway.
00151 */
00152 using VecMath::Vector;
00153 using std::vector;
00154 
00155 #include "VertexDataPrinter.h"
00156 
00157 template <unsigned D> std::string VertexData<D>::toString() {
00158     std::ostringstream o;
00159     VertexDataPrinter printer(this);
00160     printer.printToStream(o);
00161     o << std::ends;
00162     return o.str();
00163 }
00164 
00165 
00166 template <unsigned D>
00167     std::vector<VecMath::Vector<4> > VertexData<D>::projected_vertices() {
00168 //        Transform(VecMath::Rotation<D>(), VecMath::Vector<D>());
00169         Projector<D, 4> p;
00170         return p(raw_vertices(), PROJECTION_SCREEN_W, PROJECTION_CAMERA_W);  
00171     }
00172 
00176 template <unsigned D>
00177     void VertexData<D>::addTransform(unsigned d,
00178                                      const VecMath::RotationBase *R) {
00179     std::cerr << "vertex_data<" << D << ">::addTransform("
00180             << d << ", " << typeid(R).name() << ")\n";
00181     _transform.resize(d+1);
00182     _transform[d] = R;
00183 }
00184 
00185 #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