| #include <iostream> |
| #include <iomanip> |
| #include <algorithm> /* std::copy() */ |
| #include "igs_maxmin_slrender.h" |
| #include "igs_maxmin_lens_matrix.h" |
| |
| void igs::maxmin::slrender::resize(const int odd_diameter, const int width, |
| const bool alpha_ref_sw, |
| std::vector<std::vector<double>> &tracks, |
| std::vector<double> &alpha_ref, |
| std::vector<double> &result) { |
| tracks.resize(odd_diameter); |
| for (int yy = 0; yy < odd_diameter; ++yy) { |
| tracks.at(yy).resize(width + odd_diameter - 1); |
| } |
| if (alpha_ref_sw) { |
| alpha_ref.resize(width); |
| } |
| result.resize(width); |
| } |
| void igs::maxmin::slrender::clear(std::vector<std::vector<double>> &tracks, |
| std::vector<double> &alpha_ref, |
| std::vector<double> &result) { |
| result.clear(); |
| alpha_ref.clear(); |
| tracks.clear(); |
| } |
| void igs::maxmin::slrender::shift(std::vector<std::vector<double>> &tracks) { |
| |
| std::rotate(tracks.begin(), tracks.end() - 1, tracks.end()); |
| } |
| |
| namespace { |
| double maxmin_(const double src, const bool min_sw, |
| const std::vector<const double *> &begin_ptr, |
| const std::vector<int> &lens_sizes, |
| const std::vector<std::vector<double>> &lens_ratio) { |
| if (min_sw) { |
| |
| double val = 1.0 - src; |
| const double rev_src = 1.0 - src; |
| for (unsigned yy = 0; yy < begin_ptr.size(); ++yy) { |
| const int sz = lens_sizes.at(yy); |
| if (sz <= 0) { |
| continue; |
| } |
| |
| const double *xptr = begin_ptr.at(yy); |
| const double *rptr = &lens_ratio.at(yy).at(0); |
| for (int xx = 0; xx < sz; ++xx, ++xptr, ++rptr) { |
| double crnt = 1.0 - (*xptr); |
| |
| |
| if (crnt <= rev_src) { |
| continue; |
| } |
| |
| |
| crnt = rev_src + (crnt - rev_src) * (*rptr); |
| |
| if (val < crnt) { |
| val = crnt; |
| } |
| } |
| } |
| return 1.0 - val; |
| } |
| |
| double val = src; |
| for (unsigned yy = 0; yy < begin_ptr.size(); ++yy) { |
| const int sz = lens_sizes.at(yy); |
| if (sz <= 0) { |
| continue; |
| } |
| |
| const double *xptr = begin_ptr.at(yy); |
| const double *rptr = &lens_ratio.at(yy).at(0); |
| for (int xx = 0; xx < sz; ++xx, ++xptr, ++rptr) { |
| |
| if ((*xptr) <= src) { |
| continue; |
| } |
| |
| |
| const double crnt = src + ((*xptr) - src) * (*rptr); |
| |
| if (val < crnt) { |
| val = crnt; |
| } |
| } |
| } |
| return val; |
| } |
| void set_begin_ptr_(const std::vector<std::vector<double>> &tracks, |
| const std::vector<int> &lens_offsets, const int offset, |
| std::vector<const double *> &begin_ptr) { |
| for (unsigned ii = 0; ii < lens_offsets.size(); ++ii) { |
| begin_ptr.at(ii) = (0 <= lens_offsets.at(ii)) |
| ? &tracks.at(ii).at(offset + lens_offsets.at(ii)) |
| : 0; |
| } |
| } |
| } |
| |
| void igs::maxmin::slrender::render( |
| const double radius, const double smooth_outer_range, |
| const int polygon_number, const double roll_degree |
| |
| , |
| const bool min_sw |
| |
| , |
| std::vector<int> &lens_offsets, std::vector<int> &lens_sizes, |
| std::vector<std::vector<double>> &lens_ratio |
| |
| , |
| const std::vector<std::vector<double>> &tracks |
| , |
| const std::vector<double> &alpha_ref |
| , |
| std::vector<double> &result |
| ) { |
| |
| std::vector<const double *> begin_ptr(lens_offsets.size()); |
| set_begin_ptr_(tracks, lens_offsets, 0, begin_ptr); |
| |
| |
| if (0 < alpha_ref.size()) { |
| double before_radius = 0.0; |
| for (unsigned xx = 0; xx < result.size(); ++xx) { |
| |
| const double radius2 = alpha_ref.at(xx) * radius; |
| |
| |
| if (0.0 < alpha_ref.at(xx)) { |
| |
| if (radius2 != before_radius) { |
| igs::maxmin::reshape_lens_matrix( |
| radius2, igs::maxmin::outer_radius_from_radius( |
| radius2, smooth_outer_range), |
| igs::maxmin::diameter_from_outer_radius(radius + |
| smooth_outer_range), |
| polygon_number, roll_degree, lens_offsets, lens_sizes, |
| lens_ratio); |
| set_begin_ptr_(tracks, lens_offsets, xx, begin_ptr); |
| } |
| |
| result.at(xx) = |
| maxmin_(result.at(xx), min_sw, begin_ptr, lens_sizes, lens_ratio); |
| } |
| |
| |
| for (unsigned ii = 0; ii < begin_ptr.size(); ++ii) { |
| if (begin_ptr.at(ii) != 0) { |
| ++begin_ptr.at(ii); |
| } |
| } |
| if (radius2 != before_radius) { |
| before_radius = radius2; |
| } |
| } |
| } |
| |
| else { |
| for (unsigned xx = 0; xx < result.size(); ++xx) { |
| |
| result.at(xx) = |
| maxmin_(result.at(xx), min_sw, begin_ptr, lens_sizes, lens_ratio); |
| |
| |
| for (unsigned ii = 0; ii < begin_ptr.size(); ++ii) { |
| if (begin_ptr.at(ii) != 0) { |
| ++begin_ptr.at(ii); |
| } |
| } |
| } |
| } |
| } |