void PrettyPrinter::special_print(const Store* store, std::ostream& outStream, const std::string tableName, const size_t& limit, const size_t& start) { ftprinter::FTPrinter tp(tableName, outStream); tp.addColumn("#rowid", 6); const size_t columns = store->columnCount(); // TODO: how about using limit=0 as parameter to print whole table instead of strange -1 for unsigned? auto prepareLimit = (limit < (size_t) - 1) ? std::min(limit, store->size()) : store->size(); for (size_t column_index = 0; column_index < columns; ++column_index) { // Auto adjusting widths means iterating over the table twice, but we use it for // debugging purposes only, anyways, so we'll go with beauty of output here auto name = store->nameOfColumn(column_index); size_t width = std::accumulate(RangeIter(0), RangeIter(prepareLimit), // minimum width is 4 name.size() > 4 ? name.size() : 4, [&](size_t max, const size_t row)->size_t { size_t sz = generateValue(store, column_index, row).size(); return sz > max ? sz : max; }); tp.addColumn(name, width); } tp.addColumn("$tid", 6); tp.addColumn("$cidbeg", 6); tp.addColumn("$cidend", 6); if (limit < (size_t) - 1) { outStream << "(showing first " << limit << " rows)" << std::endl; } if (tableName.size() > 0) tp.printTableName(); tp.printHeader(); for (size_t row = start; row < store->size() && row < limit; ++row) { tp << row; for (size_t column = 0; column < columns; ++column) { tp << generateValue(store, column, row); } writeTid(tp, store->_tidVector[row]); writeCid(tp, store->_cidBeginVector[row]); writeCid(tp, store->_cidEndVector[row]); } tp.printFooter(); }
void PrettyPrinter::special_print(T& input, std::ostream& outStream, const std::string tableName, const size_t& limit, const size_t& start) { ftprinter::FTPrinter tp(tableName, outStream); tp.addColumn("#rowid", 6); auto prepareLimit = (limit < (size_t) - 1) ? std::min(limit, input->size()) : input->size(); const size_t columns = input->columnCount(); for (size_t column_index = 0; column_index < columns; ++column_index) { // Auto adjusting widths means iterating over the table twice, but we use it for // debugging purposes only, anyways, so we'll go with beauty of output here auto name = input->nameOfColumn(column_index); size_t width = std::accumulate(RangeIter(0), RangeIter(prepareLimit), // minimum width is 4 name.size() > 4 ? name.size() : 4, [&](size_t max, const size_t & row)->size_t { size_t sz = generateValue(input, column_index, row).size(); return sz > max ? sz : max; }); tp.addColumn(name, width); } if (limit < (size_t) - 1) { outStream << "(showing first " << limit << " of " << input->size() << " rows)" << std::endl; } if (tableName.size() > 0) tp.printTableName(); tp.printHeader(); for (size_t row = start; row < input->size() && row < limit; ++row) { tp << row; for (size_t column = 0; column < columns; ++column) { tp << generateValue(input, column, row); } } tp.printFooter(); }
float bePerlinNoise2D::GetOctave(float x, float y, int octaves, float persistence) { float total = 0.f; float frequency = 1.f; float amplitude = 1.f; float maxValue = 0.f; // Used for normalizing result to [0.0,1.0] for (int i : RangeIter(octaves)) { Unused(i); total += Get(x * frequency, y * frequency) * amplitude; maxValue += amplitude; amplitude *= persistence; frequency *= 2.f; } return total/maxValue; }
void StateRenderTest::InitGrid(beRenderInterface* renderInterface) { const int gridRadius = 100; const float gridSize = 1.f; const float xyOffset = gridSize / 2.f; // Don't draw on same spot as renderAxes const float gridOffset = ((float)gridRadius / 2.f); const int quadCount = gridRadius * gridRadius; const int vertexCount = quadCount * 8; const int triCount = quadCount * 2; const int triIndexCount = triCount * 3; const float noiseScale = 5.f; const float noiseHeight = 8.f; beRandom rng; rng.InitFromSystemTime(); bePerlinNoise2D noise; noise.Initialise(rng.Next()); beVector<beShaderColour::VertexType> vertices(vertexCount, vertexCount, 0); beVector<u32> lineIndices(vertexCount, vertexCount, 0); beVector<u32> triIndices(triIndexCount, triIndexCount, 0); for (int i : RangeIter(lineIndices.Count())) { lineIndices[i] = i; } for (int i : RangeIter(quadCount)) { const int triListIndex = i * 6; const int lineListIndex = i * 8; triIndices[triListIndex+0] = lineListIndex+0; triIndices[triListIndex+1] = lineListIndex+2; triIndices[triListIndex+2] = lineListIndex+4; triIndices[triListIndex+3] = lineListIndex+4; triIndices[triListIndex+4] = lineListIndex+6; triIndices[triListIndex+5] = lineListIndex+0; } int vertexIndex = 0; for (float x = -gridOffset; x < gridOffset; x += gridSize) { const float xPos0 = x + xyOffset; const float xPos1 = xPos0+gridSize; for (float y = -gridOffset; y < gridOffset; y += gridSize) { const float yPos0 = y + xyOffset; const float yPos1 = yPos0+gridSize; const float zPos0 = noiseHeight * noise.GetOctave(xPos0/noiseScale, yPos0/noiseScale, 4); const float zPos1 = noiseHeight * noise.GetOctave(xPos0/noiseScale, yPos1/noiseScale, 4); const float zPos2 = noiseHeight * noise.GetOctave(xPos1/noiseScale, yPos1/noiseScale, 4); const float zPos3 = noiseHeight * noise.GetOctave(xPos1/noiseScale, yPos0/noiseScale, 4); const Vec4 pos0(xPos0, yPos0, zPos0, 1.f); const Vec4 pos1(xPos0, yPos1, zPos1, 1.f); const Vec4 pos2(xPos1, yPos1, zPos2, 1.f); const Vec4 pos3(xPos1, yPos0, zPos3, 1.f); //LOG("[{},{}] 0- {}", x, y, pos0); //LOG("[{},{}] 1- {}", x, y, pos1); //LOG("[{},{}] 2- {}", x, y, pos2); //LOG("[{},{}] 3- {}", x, y, pos3); vertices[vertexIndex+0].position = pos0; vertices[vertexIndex+1].position = pos1; vertices[vertexIndex+2].position = pos1; vertices[vertexIndex+3].position = pos2; vertices[vertexIndex+4].position = pos2; vertices[vertexIndex+5].position = pos3; vertices[vertexIndex+6].position = pos3; vertices[vertexIndex+7].position = pos0; vertices[vertexIndex+0].colour = Vec4(zPos0 / noiseHeight, zPos0 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+1].colour = Vec4(zPos1 / noiseHeight, zPos1 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+2].colour = Vec4(zPos1 / noiseHeight, zPos1 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+3].colour = Vec4(zPos2 / noiseHeight, zPos2 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+4].colour = Vec4(zPos2 / noiseHeight, zPos2 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+5].colour = Vec4(zPos3 / noiseHeight, zPos3 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+6].colour = Vec4(zPos3 / noiseHeight, zPos3 / noiseHeight, 1.f, 1.f); vertices[vertexIndex+7].colour = Vec4(zPos0 / noiseHeight, zPos0 / noiseHeight, 1.f, 1.f); vertexIndex += 8; } } beRenderBuffer vertexBuffer, indexBuffer, linesIndexB; vertexBuffer.Allocate(renderInterface, ElementSize(vertices), vertexCount, D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, 0, 0, 0, vertices.begin()); beModel::Material materials[1]; materials[0].m_shader = beRendering::ShaderType::Colour; beModel::Mesh meshes[2]; meshes[0].m_name = beString("GroundFilled"); meshes[0].m_indexBuffer.Allocate(renderInterface, decltype(triIndices)::element_size, triIndices.Count(), D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, 0, 0, triIndices.begin()); meshes[0].m_materialIndex = 0; meshes[0].m_enabled = false; meshes[1].m_name = beString("GroundLines"); meshes[1].m_indexBuffer.Allocate(renderInterface, decltype(lineIndices)::element_size, vertexCount, D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, D3D11_PRIMITIVE_TOPOLOGY_LINELIST, 0, 0, lineIndices.begin()); meshes[1].m_materialIndex = 0; const bool success = m_gridModel.InitFromBuffers(&vertexBuffer, meshes, materials); if (!success) { BE_ASSERT(false); return; } }
void PrettyPrinter::printDiff(const c_atable_ptr_t& input, const TableDiff& diff, std::ostream& outStream, const std::string tableName, const size_t& limit, const size_t& start) { ftprinter::FTPrinter tp(tableName, outStream); tp.addColumn("#rowid", 6); const size_t columns = input->columnCount(); for (size_t column_index = 0; column_index < columns; ++column_index) { // Auto adjusting widths means iterating over the table twice, but we use it for // debugging purposes only, anyways, so we'll go with beauty of output here auto name = input->nameOfColumn(column_index); size_t width = std::accumulate(RangeIter(0), RangeIter(input->size()), // minimum width is 4 name.size() > 4 ? name.size() : 4, [&](size_t max, const size_t & row)->size_t { size_t sz = generateValue(input, column_index, row).size(); return sz > max ? sz : max; }); ftprinter::PrintFormat format = ftprinter::format::basic; if (diff.fields[column_index] == TableDiff::FieldWrong) format = ftprinter::format::red; else if (diff.fields[column_index] == TableDiff::FieldWrongType) format = ftprinter::format::magenta; tp.addColumn(name, width, format); } outStream << std::endl; if (limit < (size_t) - 1) { outStream << "(showing first " << limit << " rows)" << std::endl; } auto iWrong = diff.wrongRows.begin(); auto iFalsePos = diff.falsePositionRows.begin(); while (iWrong != diff.wrongRows.end() && *iWrong < start) iWrong++; while (iFalsePos != diff.falsePositionRows.end() && (*iFalsePos).first < start) iFalsePos++; if (tableName.size() > 0) tp.printTableName(); tp.printHeader(); for (size_t row = start; row < input->size() && row < limit; ++row) { tp << row; if (iWrong != diff.wrongRows.end() && *iWrong == row) { tp << ftprinter::format::red; iWrong++; } if (iFalsePos != diff.falsePositionRows.end() && (*iFalsePos).first == row) { tp << ftprinter::format::yellow; iFalsePos++; } for (field_t column = 0; column < columns; ++column) { tp << generateValue(input, column, row); } } tp.printFooter(); };