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 _VERTEXDATAPRINTER_H 00022 #define _VERTEXDATAPRINTER_H 00023 00024 #include "VertexData.h" 00025 00026 #include "Vector.impl.h" 00027 00028 #include <iomanip> 00029 #include <algorithm> 00030 00031 template <unsigned D> 00032 void VertexData<D>::VertexDataPrinter::printToStream(std::ostream &out) const { 00033 00034 out << std::string(PRINT_VERTICES_NUM_COLUMNS*PRINT_VERTICES_COLUMN_WIDTH, '-') 00035 << std::endl; 00036 out << _vertexData->dimension() << "-dimensional object"; 00037 00038 out << "\n" << _vertexData->realm().size() << " realms: \n"; 00039 for (Realm::realm_container_type::const_iterator it = _vertexData->realm().begin(); 00040 it != _vertexData->realm().end(); ++it) { 00041 out << it->toString() << " "; 00042 } 00043 out << "\n"; 00044 00045 out << verticesToString(PRINT_VERTICES_NUM_COLUMNS); 00046 00047 out << std::string(PRINT_VERTICES_NUM_COLUMNS*PRINT_VERTICES_COLUMN_WIDTH, '-') 00048 << std::endl; 00049 } 00050 00051 template <unsigned D> 00052 std::string VertexData<D>::VertexDataPrinter::verticesToString( 00053 unsigned num_columns) const { 00054 00055 std::ostringstream vertices_outstream; 00056 00057 printVertices(num_columns, vertices_outstream); 00058 vertices_outstream << std::ends; 00059 00060 return vertices_outstream.str(); 00061 } 00062 00063 template <unsigned D> 00064 void VertexData<D>::VertexDataPrinter::printVertices(unsigned num_columns, 00065 std::ostream &out) const { 00066 for (unsigned i = 0; i < _vertexData->raw_vertices().size(); i += num_columns) { 00067 out << verticesToStringRow(i, num_columns) << std::endl; 00068 } 00069 } 00070 00071 00072 template <unsigned D> 00073 std::string VertexData<D>::VertexDataPrinter::verticesToStringRow( 00074 unsigned base_index, unsigned num_columns) const { 00075 00076 std::ostringstream column_outstream; 00077 00078 printVerticesRow(base_index, num_columns, column_outstream); 00079 column_outstream << std::ends; 00080 00081 return column_outstream.str(); 00082 } 00083 00084 template <unsigned D> 00085 void VertexData<D>::VertexDataPrinter::printVerticesRow(unsigned base_index, 00086 unsigned num_columns, 00087 std::ostream& out) const { 00088 const unsigned PRINT_VERTICES_INDEX_WIDTH = 5; 00089 00090 for (unsigned column = 0; column < num_columns; ++column) { 00091 00092 if (base_index+column >= _vertexData->raw_vertices().size()) break; 00093 00094 std::string vec_as_string = _vertexData->raw_vertices()[base_index+column].toString(); 00095 00096 int fill_width = PRINT_VERTICES_COLUMN_WIDTH-PRINT_VERTICES_INDEX_WIDTH-2-vec_as_string.length(), 00097 num_fill_chars = std::max(0, fill_width); 00098 00099 out << std::setw(PRINT_VERTICES_INDEX_WIDTH) << base_index+column << ": " 00100 << vec_as_string 00101 << std::string(num_fill_chars, ' '); 00102 } 00103 00104 } 00105 00106 00107 #endif /* _VERTEXDATAPRINTER_H */