hologram hologram_reconstructor::reconstruct(const hologram& h, const window& hw, vec3 light_direction, float_t light_distance) { hologram image(width, height); boost::timer timer; vec3 direction = normalize(output_window.direction()); std::complex<float_t> ilambda(0, wavelength); #pragma omp parallel for schedule(dynamic, 1) for (std::size_t y = 0; y < height; ++y) { for (std::size_t x = 0; x < width; ++x) { vec3 op = output_window.unproj(vec2(float_t(x) / h.width(), float_t(y) / h.height())); std::complex<float_t> wave(0); for (std::size_t hy = 0; hy < h.height(); ++hy) { for (std::size_t hx = 0; hx < h.width(); ++hx) { vec3 hp = hw.unproj(vec2(float_t(hx) / width, float_t(hy) / height)); //float_t hp_to_light = dot(hp, light_direction) + light_distance; vec3 op_to_hp = hp - op; float_t op_to_hp_len2 = cml::length_squared(op_to_hp); float_t op_to_hp_len = std::sqrt(op_to_hp_len2); wave += std::polar(h(hx, hy) / op_to_hp_len2, wavenumber * op_to_hp_len) / ilambda * dot(direction, op_to_hp); } } image(x, y) = std::abs(wave); } std::clog << (y + 1) << "/" << height << " " << int(timer.elapsed() / (y + 1) * (height - y - 1)) << " s left" << std::endl; } return image; }
// Initialize OpenGL background color and vertex/normal arrays void setupGL() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glEnable(GL_DEPTH_TEST); projection = perspective( float_t(45), float_t(WIN_WIDTH) / float_t(WIN_HEIGHT), float_t(0.1), float_t(1000.0) ); }
// Reshape function for GLUT void reshape(int w, int h) { GLUI_Master.auto_set_viewport(); WIN_WIDTH = w; WIN_HEIGHT = h; projection = perspective( float_t(45), float_t(WIN_WIDTH) / float_t(WIN_HEIGHT), float_t(0.1), float_t(1000.0) ); }
//! Portable log2() template <typename float_t> UHD_INLINE float_t log2(float_t x) { // C++11 defines std::log2(), when that's universally supported // we can switch over. return std::log(x) / std::log(float_t(2)); }
void ImageFilm::Deposite( __in pixel_descriptor_t const & value, __in float_t const fWeightingFactor) { if (fWeightingFactor <= float_t(0)) { return; } #ifdef CONFIG_CONCURRENT_LOCK if (Path::INVALID_CONSTRIBUTION != value.first) { ImageFilm::color_t const xyz(value.second * fWeightingFactor); ImageFilm::color_t & _val = m_[value.first]; union { double d; hi::qword q; } _old, _new; for (std::size_t c = 0; c < 3; ++c) { _old.d = _val[c]; do { _new.d = _old.d + xyz[c]; } while (!hi::qword_cmpxchg(reinterpret_cast<hi::qword volatile &>(_val[c]), _old.q, _new.q)); } } #else if (Path::INVALID_CONSTRIBUTION != value.first) { hi::synchronized lock(monitor_); ImageFilm::color_t const xyz(value.second * fWeightingFactor); m_[value.first] += xyz; } #endif }
void construct_regular_2d_vertices(Grid<fem_types> & grid, const ublas::fixed_vector<size_t, 2> & size, const vector_image_accessor_t & displacements) { typedef ublas::fixed_vector<float_t, 2> vertex_t; size_t n_x_vertices = size(0); size_t n_y_vertices = size(1); grid.set_regular(true); for(size_t i = 0; i < n_x_vertices; i++) for(size_t j = 0; j < n_y_vertices; ++j) { size_t vertex_index = i + j * n_x_vertices; vertex_t offset(displacements[ublas::fixed_vector<size_t, 2>(i, j)]); grid.set_vertex(vertex_index, vertex_t( .5 + float_t(i) + offset(0), .5 + float_t(j) + offset(1))); } }
void SimpleCamera::setFrustum(uint16_t width, uint16_t height, float_t fovInDegree, float_t nearPlane, float_t farPlane) { _fovInRad = DEGREES_TO_RADIANS(fovInDegree); _zNear = nearPlane; _zFar = farPlane; _screenWidth = width; _screenHeight = height; _aspectRatio = float_t(_screenWidth) / float_t(_screenHeight); MatrixPerspectiveFovRH( _projectionMatrix, _fovInRad, _aspectRatio, _zNear, _zFar, 0); _hasChangedParameters = true; }
void construct_regular_3d_vertices(Grid<fem_types> & grid, const ublas::fixed_vector<size_t, 3> & size, const vector_image_accessor_t & displacements) { typedef ublas::fixed_vector<float_t, 3> vertex_t; size_t n_x_vertices = size(0); size_t n_y_vertices = size(1); size_t n_z_vertices = size(2); grid.set_regular(false); for(size_t i = 0; i < n_x_vertices; i++) for(size_t j = 0; j < n_y_vertices; ++j) for(size_t k = 0; k < n_z_vertices; ++k) { size_t vertex_index = i + j * n_x_vertices + k * n_x_vertices * n_y_vertices; vertex_t offset(displacements[ublas::fixed_vector<size_t, 3>(i, j, k)]); grid.set_vertex(vertex_index, vertex_t(0.5 + float_t(i) + offset(0), 0.5 + float_t(j) + offset(1), 0.5 + float_t(k) + offset(2))); } }
// builder void KDTree::Build(__in std::vector<Triangle const *> const &set) { // compute bounding box [min, max) min_ = std::numeric_limits<float_t>::infinity(); max_ = -std::numeric_limits<float_t>::infinity(); for (std::size_t i = 0, size = set.size(); i < size; ++i) { set[i]->min(min_); set[i]->max(max_); } max_ += (max_ - min_) * float_t(1e-5); // 10mのスケールで1mmぐらいの幅だけ拡張する // つまりここでの max は正確には upper bound を表している Clear(); // std::tcerr << "buket"; // node_count = 0; root_ = Build(set, min_, max_, 0); }
void AppCore::updateScreenSizeRelatedConstants() { APIFactory::GetInstance().lock(OPENGL_LOCK); // Calc screensize voxel circum circle radius based on screen size and frustum // see "Rendering von Punktbasierten Oberflaechen durch Splatting auf der GPU", Koppitz 2009, page 36 // Attention: Koppitz forumular is wrong! (n missing in denomitator) float_t splatsizeFactor = float_t(_camera->getScreenHeight()) / tanf(_camera->getFieldOfViewInRad() / 2.0f); if (_voxelScreensizeCircumcircleRadius == NULL) _voxelScreensizeCircumcircleRadius = new float_t[OCTREE_LEAF_LEVEL+1]; for (uint8_t i = 0; i <= OCTREE_LEAF_LEVEL; ++i) _voxelScreensizeCircumcircleRadius[i] = _octree->getVoxelCircumcircleRadius(i) * splatsizeFactor; _octree->updateScreenSizeRelatedConstants(); APIFactory::GetInstance().unlock(OPENGL_LOCK); }
void RaiseHitToPower::operator()(MatchResults & hit) const { gsl_sf_result gsl_result; //ignore zeros if ( hit.result.score != 0.0 ) { if ( GSL_SUCCESS != gsl_sf_log_e( double( hit.result.score ), &gsl_result ) ) { throw BIO_MAKE_STRING( "Could not take logarithm of " << hit.result.score ); } if ( GSL_SUCCESS != gsl_sf_exp_e( power * gsl_result.val, &gsl_result ) ) { throw BIO_MAKE_STRING( "Could not take exponent of " << power * gsl_result.val ); } hit.result.score = float_t( gsl_result.val ); } }
void QCLuceneField::setBoost(qreal value) { d->field->setBoost(float_t(value)); }
void NelderMead::optimize() { Printer::getInstance().printStatusBegin("Optimizing (Nelder-Mead)..."); const size_t d = f.getNumberOfParameters(); xOpt.resize(0); fOpt = NAN; xHist.resize(0, d); fHist.resize(0); std::vector<base::DataVector> points(d + 1, x0); std::vector<base::DataVector> pointsNew(d + 1, x0); base::DataVector fPoints(d + 1); base::DataVector fPointsNew(d + 1); // construct starting simplex for (size_t t = 0; t < d; t++) { points[t + 1][t] = std::min(points[t + 1][t] + STARTING_SIMPLEX_EDGE_LENGTH, float_t(1.0)); fPoints[t + 1] = f.eval(points[t + 1]); } fPoints[0] = f.eval(points[0]); std::vector<size_t> index(d + 1, 0); base::DataVector pointO(d); base::DataVector pointR(d); base::DataVector pointE(d); base::DataVector pointIC(d); base::DataVector pointOC(d); size_t k = 0; size_t numberOfFcnEvals = d + 1; while (true) { // sort points by function value for (size_t i = 0; i < d + 1; i++) { index[i] = i; } std::sort(index.begin(), index.end(), [&fPoints](size_t a, size_t b) { return (fPoints[a] < fPoints[b]); }); // that could be solved more efficiently, but it suffices for now for (size_t i = 0; i < d + 1; i++) { pointsNew[i] = points[index[i]]; fPointsNew[i] = fPoints[index[i]]; } points = pointsNew; fPoints = fPointsNew; bool inDomain = true; bool shrink = false; // calculate point_o (barycenter of all points but the last) and // point_r (reflected point) simultaneously for (size_t t = 0; t < d; t++) { pointO[t] = 0.0; for (size_t i = 0; i < d; i++) { pointO[t] += points[i][t]; } pointO[t] /= static_cast<float_t>(d); pointR[t] = pointO[t] + alpha * (pointO[t] - points[d][t]); if ((pointR[t] < 0.0) || (pointR[t] > 1.0)) { inDomain = false; } } float_t fPointR = (inDomain ? f.eval(pointR) : INFINITY); numberOfFcnEvals++; if ((fPoints[0] <= fPointR) && (fPointR < fPoints[d - 1])) { points[d] = pointR; fPoints[d] = fPointR; } else if (fPointR < fPoints[0]) { bool inDomain = true; // calculate expanded point for (size_t t = 0; t < d; t++) { pointE[t] = pointO[t] + beta * (pointR[t] - pointO[t]); if ((pointE[t] < 0.0) || (pointE[t] > 1.0)) { inDomain = false; } } float_t f_point_e = (inDomain ? f.eval(pointE) : INFINITY); numberOfFcnEvals++; if (f_point_e < fPointR) { points[d] = pointE; fPoints[d] = f_point_e; } else { points[d] = pointR; fPoints[d] = fPointR; } } else if (fPointR < fPoints[d]) { bool in_domain = true; // calculate outer contracted point for (size_t t = 0; t < d; t++) { pointOC[t] = pointO[t] + gamma * (pointR[t] - pointO[t]); if ((pointOC[t] < 0.0) || (pointOC[t] > 1.0)) { in_domain = false; } } float_t fPointOC = (in_domain ? f.eval(pointOC) : INFINITY); numberOfFcnEvals++; if (fPointOC <= fPointR) { points[d] = pointOC; fPoints[d] = fPointOC; } else { shrink = true; } } else { bool in_domain = true; // calculate inner contracted point for (size_t t = 0; t < d; t++) { pointIC[t] = pointO[t] - gamma * (pointO[t] - points[d][t]); if ((pointIC[t] < 0.0) || (pointIC[t] > 1.0)) { in_domain = false; } } float_t fPointIC = (in_domain ? f.eval(pointIC) : INFINITY); numberOfFcnEvals++; if (fPointIC < fPoints[d]) { points[d] = pointIC; fPoints[d] = fPointIC; } else { shrink = true; } } if (shrink) { // shrink all points but the first for (size_t i = 1; i < d + 1; i++) { bool in_domain = true; for (size_t t = 0; t < d; t++) { points[i][t] = points[0][t] + delta * (points[i][t] - points[0][t]); if ((points[i][t] < 0.0) || (points[i][t] > 1.0)) { in_domain = false; } } fPoints[i] = (in_domain ? f.eval(points[i]) : INFINITY); } numberOfFcnEvals += d; } // status printing if (k % 10 == 0) { Printer::getInstance().printStatusUpdate(std::to_string(k) + " steps, f(x) = " + std::to_string(fPoints[0])); } if (numberOfFcnEvals + (d + 2) > N) { break; } k++; xHist.appendRow(points[0]); fHist.append(fPoints[0]); } xOpt.resize(d); xOpt = points[0]; fOpt = fPoints[0]; Printer::getInstance().printStatusUpdate(std::to_string(k) + " steps, f(x) = " + std::to_string(fPoints[0])); Printer::getInstance().printStatusEnd(); }
/// \module types constexpr float_t operator"" _f(long double val) { return float_t(static_cast<std::float_t>(val)); }