|
Toshihiro Shimizu |
890ddd |
#include <cmath> // sqrt() sin() cos()</cmath>
|
|
Toshihiro Shimizu |
890ddd |
#ifndef M_PI /* only Microsoft C++ */
|
|
Toshihiro Shimizu |
890ddd |
#define M_PI 3.14159265358979323846
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
#include <iostream> // std::cout</iostream>
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_maxmin_lens_matrix.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
y
|
|
Toshihiro Shimizu |
890ddd |
^
|
|
Toshihiro Shimizu |
890ddd |
| <-
|
|
Toshihiro Shimizu |
890ddd |
| \
|
|
Toshihiro Shimizu |
890ddd |
| |
|
|
Toshihiro Shimizu |
890ddd |
<---------------+----------------> x
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
Toshihiro Shimizu |
890ddd |
|
|
|
Toshihiro Shimizu |
890ddd |
v
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
bool inside_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
double radius, int odd_diameter, double xp, double yp, int polygon_number, double roll_degree)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (polygon_number < 3) { /* equal less than 2 is circle */
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
double radian = roll_degree * M_PI / 180.0, add_radian = 2.0 * M_PI / polygon_number;
|
|
Toshihiro Shimizu |
890ddd |
double x1 = radius * cos(radian), y1 = radius * sin(radian), x2 = 0, y2 = 0, xa = odd_diameter, xb = odd_diameter;
|
|
Toshihiro Shimizu |
890ddd |
radian += add_radian;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 線分の回数loop回す */
|
|
Toshihiro Shimizu |
890ddd |
for (int ii = 0; ii < polygon_number; ++ii, radian += add_radian, x1 = x2, y1 = y2) {
|
|
Toshihiro Shimizu |
890ddd |
/* (0,0)を原点とした正多角形の各頂点
|
|
Toshihiro Shimizu |
890ddd |
数学的開始点(右)及び回転方向(CCW)とするため、
|
|
Toshihiro Shimizu |
890ddd |
内部では上下左右反転する。
|
|
Toshihiro Shimizu |
890ddd |
これをしないと左からCW回転となる
|
|
Toshihiro Shimizu |
890ddd |
計算の考えを単純にするため反転しない2013-12-10
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
x2 = radius * cos(radian);
|
|
Toshihiro Shimizu |
890ddd |
y2 = radius * sin(radian);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* scanline方向でy1とy2の間で区切った領域外なら次へ
|
|
Toshihiro Shimizu |
890ddd |
((y2==y1==yp)の場合も)しない線分なら次へ */
|
|
Toshihiro Shimizu |
890ddd |
if (!(((y1 <= yp) && (yp <= y2)) ||
|
|
Toshihiro Shimizu |
890ddd |
((y2 <= yp) && (yp <= y1)))) {
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* scanline方向でy1とy2の間で区切った領域 */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 水平線分 */
|
|
Toshihiro Shimizu |
890ddd |
if (y2 == y1) {
|
|
Toshihiro Shimizu |
890ddd |
if (((x1 <= xp) && (xp <= x2)) ||
|
|
Toshihiro Shimizu |
890ddd |
((x2 <= xp) && (xp <= x1))) {
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
} /* 水平線分上 */
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
} /* 水平範囲外 */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 水平方向の初めの交差位置(xa) */
|
|
Toshihiro Shimizu |
890ddd |
if (xa == odd_diameter) {
|
|
Toshihiro Shimizu |
890ddd |
/* (x2 - x1)/(y2 - y1)=(xa - x1)/(yp - y1);
|
|
Toshihiro Shimizu |
890ddd |
(xa - x1)=(yp - y1)*(x2 - x1)/(y2 - y1); */
|
|
Toshihiro Shimizu |
890ddd |
xa = (yp - y1) * (x2 - x1) / (y2 - y1) + x1;
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
/* 2番目の交差位置(xb) */
|
|
Toshihiro Shimizu |
890ddd |
if (xb == odd_diameter) {
|
|
Toshihiro Shimizu |
890ddd |
xb = (yp - y1) * (x2 - x1) / (y2 - y1) + x1;
|
|
Toshihiro Shimizu |
890ddd |
if (((xa <= xp) && (xp <= xb)) ||
|
|
Toshihiro Shimizu |
890ddd |
((xb <= xp) && (xp <= xa))) {
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
} /* 水平範囲内 */
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
} /* 水平範囲外 */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
二点(x1,y1),(x2,y2)を通る直線
|
|
Toshihiro Shimizu |
890ddd |
x - x1 y - y1
|
|
Toshihiro Shimizu |
890ddd |
------- = -------
|
|
Toshihiro Shimizu |
890ddd |
x2 - x1 y2 - y1
|
|
Toshihiro Shimizu |
890ddd |
--> (x - x1) * (y2 - y1) = (y - y1) * (x2 - x1)
|
|
Toshihiro Shimizu |
890ddd |
--> x * (y2 - y1) - x1 * (y2 - y1) = y * (x2 - x1) - y1 * (x2 - x1)
|
|
Toshihiro Shimizu |
890ddd |
--> y * (x2 - x1) - y1 * (x2 - x1) = x * (y2 - y1) - x1 * (y2 - y1)
|
|
Toshihiro Shimizu |
890ddd |
--> y * (x2 - x1) + x1 * (y2 - y1) = x * (y2 - y1) + y1 * (x2 - x1)
|
|
Toshihiro Shimizu |
890ddd |
--> (y1 - y2) * x + (x2 - x1) * y + x1 * (y2 - y1) - y1 * (x2 - x1) = 0
|
|
Toshihiro Shimizu |
890ddd |
--> (y1 - y2) * x + (x2 - x1) * y + x1*y2 - x1*y1 - y1*x2 + y1*x1 = 0
|
|
Toshihiro Shimizu |
890ddd |
--> (y1 - y2) * x + (x2 - x1) * y + x1*y2 - y1*x2 = 0
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
点(x0,y0)と直線との距離(垂線の長さ)(h)
|
|
Toshihiro Shimizu |
890ddd |
a * x + b * y + c = 0 ならば、
|
|
Toshihiro Shimizu |
890ddd |
| a * x0 + b * y0 + c |
|
|
Toshihiro Shimizu |
890ddd |
h = -----------------------
|
|
Toshihiro Shimizu |
890ddd |
sqrt(a * a + b * b)
|
|
Toshihiro Shimizu |
890ddd |
| (y1 - y2) * x0 + (x2 - x1) * y0 + x1*y2 - y1*x2 |
|
|
Toshihiro Shimizu |
890ddd |
h = ---------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
sqrt((y1 - y2) * (y1 - y2) + (x2 - x1) * (x2 - x1))
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
double length_to_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
double radius, double xp, double yp, int polygon_number, double roll_degree)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/* 現在位置での角度 */
|
|
Toshihiro Shimizu |
890ddd |
double radian = atan2(yp, xp); /* 0 ... M_PI , -M_PI ... 0 */
|
|
Toshihiro Shimizu |
890ddd |
if (radian < 0) {
|
|
Toshihiro Shimizu |
890ddd |
radian += M_PI * 2.0;
|
|
Toshihiro Shimizu |
890ddd |
} /* 0 ... M_PI*2 */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 多角形の辺の2点 */
|
|
Toshihiro Shimizu |
890ddd |
double x1 = 0.0, y1 = 0.0, x2 = 0.0, y2 = 0.0;
|
|
Toshihiro Shimizu |
890ddd |
const double add_radian = 2.0 * M_PI / polygon_number;
|
|
Toshihiro Shimizu |
890ddd |
double radian1 = roll_degree * M_PI / 180.0;
|
|
Toshihiro Shimizu |
890ddd |
/* rad1だとMS-VC++_v10でエラー!!! */
|
|
Toshihiro Shimizu |
890ddd |
while (radian1 < 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
radian1 += add_radian;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
double radian2 = radian1 + add_radian;
|
|
Toshihiro Shimizu |
890ddd |
/* rad2だとMS-VC++_v10でエラー!!! */
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 開始角度より現在位置の角度が小さい場合360先に進める */
|
|
Toshihiro Shimizu |
890ddd |
if (radian < radian1) {
|
|
Toshihiro Shimizu |
890ddd |
radian += M_PI * 2.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int ii = 0; ii < polygon_number; ++ii, radian1 = radian2, radian2 += add_radian) {
|
|
Toshihiro Shimizu |
890ddd |
if (radian1 <= radian && radian <= radian2) {
|
|
Toshihiro Shimizu |
890ddd |
x1 = radius * cos(radian1);
|
|
Toshihiro Shimizu |
890ddd |
y1 = radius * sin(radian1);
|
|
Toshihiro Shimizu |
890ddd |
x2 = radius * cos(radian2);
|
|
Toshihiro Shimizu |
890ddd |
y2 = radius * sin(radian2);
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (x1 == 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
/* エラー */
|
|
Toshihiro Shimizu |
890ddd |
return -1.0; //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return fabs((y1 - y2) * xp + (x2 - x1) * yp + x1 * y2 - y1 * x2) /
|
|
Toshihiro Shimizu |
890ddd |
sqrt((y1 - y2) * (y1 - y2) + (x2 - x1) * (x2 - x1));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void alloc_lens_matrix_(
|
|
Toshihiro Shimizu |
890ddd |
const int odd_diameter, std::vector<int> &lens_offsets, std::vector<int> &lens_sizes, std::vector<std::vector<double>> &lens_ratio)</std::vector<double></int></int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
lens_offsets.resize(odd_diameter);
|
|
Toshihiro Shimizu |
890ddd |
lens_sizes.resize(odd_diameter);
|
|
Toshihiro Shimizu |
890ddd |
lens_ratio.resize(odd_diameter);
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0; yy < odd_diameter; ++yy) {
|
|
Toshihiro Shimizu |
890ddd |
lens_ratio.at(yy).resize(odd_diameter);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
void free_lens_matrix_(
|
|
Toshihiro Shimizu |
890ddd |
std::vector<int> &lens_offsets, std::vector<int> &lens_sizes, std::vector<std::vector<double>> &lens_ratio)</std::vector<double></int></int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
lens_ratio.clear();
|
|
Toshihiro Shimizu |
890ddd |
lens_sizes.clear();
|
|
Toshihiro Shimizu |
890ddd |
lens_offsets.clear();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const int igs::maxmin::diameter_from_outer_radius(
|
|
Toshihiro Shimizu |
890ddd |
const double outer_radius)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/* -------- 半径(radius)を含むピクセル直径 --------
|
|
Toshihiro Shimizu |
890ddd |
中心pixelが必要、奇数(1,3,5...)となる
|
|
Toshihiro Shimizu |
890ddd |
---+---|---+---|---+---|---+---|---+---
|
|
Toshihiro Shimizu |
890ddd |
outer_radius--> +---->
|
|
Toshihiro Shimizu |
890ddd |
Pixelの半分幅足す(+0.5) |-------->
|
|
Toshihiro Shimizu |
890ddd |
全体が入るPixel数幅(ceil()) |--------------->
|
|
Toshihiro Shimizu |
890ddd |
整数化時誤差防ぐ(+0.5) |------------------->
|
|
Toshihiro Shimizu |
890ddd |
整数化(static_cast<int>) |-------|-------></int>
|
|
Toshihiro Shimizu |
890ddd |
中心を除く半径Pixel幅(-1) |------->
|
|
Toshihiro Shimizu |
890ddd |
中心除く直径(*2) <-------| |------->
|
|
Toshihiro Shimizu |
890ddd |
直径(+1) <-------|-------|------->
|
|
Toshihiro Shimizu |
890ddd |
-->odd_diameter
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
return (
|
|
Toshihiro Shimizu |
890ddd |
static_cast<int>(ceil(outer_radius + 0.5) + 0.5) - 1) *</int>
|
|
Toshihiro Shimizu |
890ddd |
2 +
|
|
Toshihiro Shimizu |
890ddd |
1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const double igs::maxmin::outer_radius_from_radius(
|
|
Toshihiro Shimizu |
890ddd |
const double radius, const double smooth_outer_range)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (radius < 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
半径ゼロでは処理しない絵となり、
|
|
Toshihiro Shimizu |
890ddd |
わずかな半径に変化したとき、
|
|
Toshihiro Shimizu |
890ddd |
いきなり大きなエッジ足(smooth_outer_range)が
|
|
Toshihiro Shimizu |
890ddd |
飛び出さないように
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
radiusがゼロなら足長さを1.0(影響のない最小値)に、
|
|
Toshihiro Shimizu |
890ddd |
radiusが1ならradius + smooth_outer_rangeになり、
|
|
Toshihiro Shimizu |
890ddd |
影響が反映される
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
smooth_outer_rangeは1以上でないとsmoothにならない。
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
return 1.0 + radius * (radius + smooth_outer_range - 1.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return radius + smooth_outer_range;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const int igs::maxmin::alloc_and_shape_lens_matrix(
|
|
Toshihiro Shimizu |
890ddd |
const double radius // 0<=
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const double outer_radius, const int polygon_number // =2
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const double roll_degree // 0<= ... <=360
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<int> &lens_offsets, std::vector<int> &lens_sizes, std::vector<std::vector<double>> &lens_ratio)</std::vector<double></int></int>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*------ 大きさが無い指定のときMemory解放 ------*/
|
|
Toshihiro Shimizu |
890ddd |
if (radius <= 0.0) {
|
|
Toshihiro Shimizu |
890ddd |
free_lens_matrix_(lens_offsets, lens_sizes, lens_ratio);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*------ 半径から必要なピクセル単位の直径を求める ------*/
|
|
Toshihiro Shimizu |
890ddd |
const int odd_diameter =
|
|
Toshihiro Shimizu |
890ddd |
igs::maxmin::diameter_from_outer_radius(outer_radius);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*------ Memory確保or再利用 ------*/
|
|
Toshihiro Shimizu |
890ddd |
alloc_lens_matrix_(
|
|
Toshihiro Shimizu |
890ddd |
odd_diameter, lens_offsets, lens_sizes, lens_ratio);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*------ lens matrix情報を書き込む ------*/
|
|
Toshihiro Shimizu |
890ddd |
igs::maxmin::reshape_lens_matrix(
|
|
Toshihiro Shimizu |
890ddd |
radius, igs::maxmin::outer_radius_from_radius(radius, outer_radius - radius), odd_diameter, polygon_number, roll_degree, lens_offsets, lens_sizes, lens_ratio);
|
|
Toshihiro Shimizu |
890ddd |
return odd_diameter;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const void igs::maxmin::reshape_lens_matrix(
|
|
Toshihiro Shimizu |
890ddd |
const double radius // 0<=
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const double outer_radius, const int odd_diameter /* 最大直径 */
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const int polygon_number // =2
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
const double roll_degree // 0<= ... <=360
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<int> &lens_offsets /* 最大直径分の配列 */</int>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<int> &lens_sizes /* 最大直径分の配列 */</int>
|
|
Toshihiro Shimizu |
890ddd |
,
|
|
Toshihiro Shimizu |
890ddd |
std::vector<std::vector<double>> &lens_ratio /* 最大直径分の配列 */</std::vector<double>
|
|
Toshihiro Shimizu |
890ddd |
)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/***std::cout
|
|
Toshihiro Shimizu |
890ddd |
<< "ra=" << radius
|
|
Toshihiro Shimizu |
890ddd |
<< " outr=" << outer_radius
|
|
Toshihiro Shimizu |
890ddd |
<< " dia=" << odd_diameter
|
|
Toshihiro Shimizu |
890ddd |
<< " pol=" << polygon_number
|
|
Toshihiro Shimizu |
890ddd |
<< " deg=" << roll_degree
|
|
Toshihiro Shimizu |
890ddd |
<< " lens_offsets=" << lens_offsets.size()
|
|
Toshihiro Shimizu |
890ddd |
<< " lens_sizes=" << lens_sizes.size()
|
|
Toshihiro Shimizu |
890ddd |
<< " lens_ratio=" << lens_ratio.size()
|
|
Toshihiro Shimizu |
890ddd |
<< std::endl;***/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* --- scanlineスタート位置とscanlineサイズ生成 --- */
|
|
Toshihiro Shimizu |
890ddd |
double yp = 0.5 - (odd_diameter / 2.0); /* matrix中心からのy距離 */
|
|
Toshihiro Shimizu |
890ddd |
for (int yy = 0; yy < odd_diameter; ++yy, yp += 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
/* --- 開始位置とサイズを計算 ------------------- */
|
|
Toshihiro Shimizu |
890ddd |
lens_offsets.at(yy) = -1; /* 初期化 */
|
|
Toshihiro Shimizu |
890ddd |
lens_sizes.at(yy) = 0; /* 初期化 */
|
|
Toshihiro Shimizu |
890ddd |
double xp = 0.5 - (odd_diameter / 2.0); /* matrix中心からのx距離 */
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = 0; xx < odd_diameter; ++xx, xp += 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
const double current_radius = sqrt(xp * xp + yp * yp);
|
|
Toshihiro Shimizu |
890ddd |
/* 外枠影響内 */
|
|
Toshihiro Shimizu |
890ddd |
if ((current_radius <= outer_radius) &&
|
|
Toshihiro Shimizu |
890ddd |
inside_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
outer_radius, odd_diameter, xp, yp, polygon_number, roll_degree)) {
|
|
Toshihiro Shimizu |
890ddd |
/* scanlineスタート位置(ポインタ)のセット */
|
|
Toshihiro Shimizu |
890ddd |
if (lens_offsets.at(yy) < 0) {
|
|
Toshihiro Shimizu |
890ddd |
/* 半径内に入った瞬間その位置を記録 */
|
|
Toshihiro Shimizu |
890ddd |
lens_offsets.at(yy) = xx;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} else { /* 影響外 */
|
|
Toshihiro Shimizu |
890ddd |
/* scalineサイズのセット */
|
|
Toshihiro Shimizu |
890ddd |
if ((0 <= lens_offsets.at(yy)) &&
|
|
Toshihiro Shimizu |
890ddd |
(lens_sizes.at(yy) == 0)) {
|
|
Toshihiro Shimizu |
890ddd |
/* 半径内を出た瞬間そこまでのサイズを記録 */
|
|
Toshihiro Shimizu |
890ddd |
lens_sizes.at(yy) = xx - lens_offsets.at(yy);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* scanlineの最後までが半径内のとき */
|
|
Toshihiro Shimizu |
890ddd |
if ((0 <= lens_offsets.at(yy)) && (lens_sizes.at(yy) == 0)) {
|
|
Toshihiro Shimizu |
890ddd |
lens_sizes.at(yy) = odd_diameter - lens_offsets.at(yy);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* --- 外枠から内枠へのリニア変化 --------------- */
|
|
Toshihiro Shimizu |
890ddd |
/* 円の外 */
|
|
Toshihiro Shimizu |
890ddd |
if (lens_sizes.at(yy) <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
continue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* ratio設定 */
|
|
Toshihiro Shimizu |
890ddd |
xp = 0.5 - (odd_diameter / 2.0); /* matrix中心からのx距離 */
|
|
Toshihiro Shimizu |
890ddd |
int xr = 0;
|
|
Toshihiro Shimizu |
890ddd |
for (int xx = 0; xx < odd_diameter; ++xx, xp += 1.0) {
|
|
Toshihiro Shimizu |
890ddd |
const double current_radius = sqrt(xp * xp + yp * yp);
|
|
Toshihiro Shimizu |
890ddd |
/* 外枠内 */
|
|
Toshihiro Shimizu |
890ddd |
if ((current_radius <= outer_radius) &&
|
|
Toshihiro Shimizu |
890ddd |
inside_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
outer_radius, odd_diameter, xp, yp, polygon_number, roll_degree)) {
|
|
Toshihiro Shimizu |
890ddd |
/* 内枠内 */
|
|
Toshihiro Shimizu |
890ddd |
if ((current_radius <= radius) &&
|
|
Toshihiro Shimizu |
890ddd |
inside_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
radius, odd_diameter, xp, yp, polygon_number, roll_degree)) {
|
|
Toshihiro Shimizu |
890ddd |
lens_ratio.at(yy).at(xr++) = 1.0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/* 外枠と内枠の間 */
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
if (polygon_number < 3) {
|
|
Toshihiro Shimizu |
890ddd |
lens_ratio.at(yy).at(xr++) =
|
|
Toshihiro Shimizu |
890ddd |
(outer_radius - current_radius) / (outer_radius - radius);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
const double leninn = length_to_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
radius, xp, yp, polygon_number, roll_degree);
|
|
Toshihiro Shimizu |
890ddd |
const double lenout = length_to_polygon_(
|
|
Toshihiro Shimizu |
890ddd |
outer_radius, xp, yp, polygon_number, roll_degree);
|
|
Toshihiro Shimizu |
890ddd |
lens_ratio.at(yy).at(xr++) =
|
|
Toshihiro Shimizu |
890ddd |
lenout / (leninn + lenout);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|