void TextureDisplay::rebuildImage() { if (!_tex) { _image.fill(Qt::black); } else { for (int y = 0; y < _h; ++y) { Vec3c *img = reinterpret_cast<Vec3c *>(_image.scanLine(y)); for (int x = 0; x < _w; ++x) { Vec2f uv((x + 0.5f)/_w, 1.0f - (y + 0.5f)/_h); Vec3f color = std::pow((*_tex)[uv], 1.0f/2.2f); img[x] = Vec3c(clamp(Vec3i(color*255.0f), Vec3i(0), Vec3i(255))); } } } setBackgroundRole(QPalette::Base); setPixmap(QPixmap::fromImage(_image)); }
void Integrator::writeBuffers(const std::string &suffix, bool overwrite) { Vec2u res = _scene->cam().resolution(); std::unique_ptr<Vec3f[]> hdr(new Vec3f[res.product()]); std::unique_ptr<Vec3c[]> ldr(new Vec3c[res.product()]); for (uint32 y = 0; y < res.y(); ++y) for (uint32 x = 0; x < res.x(); ++x) hdr[x + y*res.x()] = _scene->cam().getLinear(x, y); for (uint32 i = 0; i < res.product(); ++i) ldr[i] = Vec3c(clamp(Vec3i(_scene->cam().tonemap(hdr[i])*255.0f), Vec3i(0), Vec3i(255))); const RendererSettings &settings = _scene->rendererSettings(); if (!settings.outputFile().empty()) ImageIO::saveLdr(incrementalFilename(settings.outputFile(), suffix, overwrite), &ldr[0].x(), res.x(), res.y(), 3); if (!settings.hdrOutputFile().empty()) ImageIO::saveHdr(incrementalFilename(settings.hdrOutputFile(), suffix, overwrite), &hdr[0].x(), res.x(), res.y(), 3); }
void YarnBuilder::buildBraid() { const real height = 20.0; const real width = 8.0; const real depth = 3.0; const int depthLevels = 3; const int vertLevels = 15; const int horizLevels = 7; const int totalPoints = 43; const Vec3c origin(0.0, 10.0, 0.0); std::vector<Vec3c> points; points.reserve(totalPoints); int vert = 14; int horiz = -3; int dep = 0; bool down = false; bool right = false; bool front = false; while (points.size() < totalPoints) { Vec3c out; out.x = dep * (depth / depthLevels); dep += front ? 1 : -1; if (dep == -depthLevels/2 || dep == depthLevels/2) front = !front; out.y = vert * (height / vertLevels); if (vert == 0 || vert == vertLevels-1) { down = !down; out.x = 0; dep = 0; front = !front; } vert += down ? -1 : 1; out.z = horiz * (width / horizLevels); if (horiz == -horizLevels/2 || horiz == horizLevels/2) { right = !right; out.x = 0; dep = 0; front = !front; } horiz += right ? 1 : -1; out += origin; points.push_back(out); } Vec3c u = (points[1] - points[0]).cross(Vec3c(1.0, 0.0, 0.0)).normalized(); std::string filename = ci::app::getAppPath().string() + "braid.yarn"; std::ofstream out(filename, std::ios::trunc); assert(out.is_open() && "Error: could not open file for output"); out << totalPoints << "\n"; for (int i=0; i<totalPoints; i++) { for (int j=0; j<3; j++) { out << points[i][j] << "\n"; } } for (int i=0; i<3; i++) { out << u[i] << "\n"; } out.close(); std::cout << "braid file written to " << filename << "\n"; }