12 extern int dmat_solve(
int n,
int rhs_num,
double a[]);
15 : m_angularRotatedRadians(0)
19 : m_angularRotatedRadians(0)
24 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
25 m_normalY = m_normal[1] * m_axisDir;
26 m_n2d[0] = std::cos(m_angle);
27 m_n2d[1] = -std::sin(m_angle);
28 m_hcs.FromNormal(m_axisDir);
29 m_angularRotatedRadians = 0;
34 : m_angularRotatedRadians(0)
36 if (!
Init(p1, p2, p3, n1, n2, n3))
44 if (samples.
size() < 6)
48 size_t c = samples.
size() >> 1;
49 return Init(samples[0], samples[1], samples[2],
50 samples[
c], samples[
c + 1], samples[
c + 2]);
59 template<
class IteratorT >
64 intptr_t size = end - begin;
65 #pragma omp parallel for schedule(static) reduction(+:chi)
66 for (intptr_t i = 0; i < size; ++i)
69 for (
unsigned int j = 0; j < 3; ++j)
71 values[i] += begin[i][j] * params[j];
79 template<
class IteratorT >
84 intptr_t size = end - begin;
85 #pragma omp parallel for schedule(static)
86 for (intptr_t i = 0; i < size; ++i)
88 for (
unsigned int j = 0; j < 3; ++j)
101 size_t c = samples.
size() / 2;
103 #pragma omp parallel for schedule(static)
104 for (intptr_t i = 0; i <
c; ++i)
106 for (
unsigned int j = 0; j < 3; ++j)
108 planes[i][j] = samples[i][j];
110 planes[i][3] = samples[i].dot(samples[i +
c]);
116 double d1 = samples[0].dot(samples[
c + 0]);
117 double d2 = samples[1].dot(samples[
c + 1]);
118 double d3 = samples[2].dot(samples[
c + 2]);
120 a[0 + 0 * 3] = samples[
c + 0][0];
121 a[1 + 0 * 3] = samples[
c + 1][0];
122 a[2 + 0 * 3] = samples[
c + 2][0];
123 a[0 + 1 * 3] = samples[
c + 0][1];
124 a[1 + 1 * 3] = samples[
c + 1][1];
125 a[2 + 1 * 3] = samples[
c + 2][1];
126 a[0 + 2 * 3] = samples[
c + 0][2];
127 a[1 + 2 * 3] = samples[
c + 1][2];
128 a[2 + 2 * 3] = samples[
c + 2][2];
136 m_center[0] =
a[0 + 3 * 3];
137 m_center[1] =
a[1 + 3 * 3];
138 m_center[2] =
a[2 + 3 * 3];
145 #pragma omp parallel for schedule(static)
146 for (intptr_t i = 0; i <
c; ++i)
149 spoints[i].Normalize();
158 #pragma omp parallel for schedule(static) reduction(+:heightSum)
159 for (intptr_t i = 0; i <
c; ++i)
161 heightSum +=
Height(samples[i]);
168 float angleReduction = 0;
169 #pragma omp parallel for schedule(static) reduction(+:angleReduction)
170 for (intptr_t i = 0; i <
c; ++i)
172 float angle = m_axisDir.
dot(samples[i +
c]);
191 angleReduction +=
angle;
194 m_angle = angleReduction;
195 if (m_angle < 1e-6 || m_angle >
float(
M_PI) / 2 - 1e-6)
200 if (m_angle > 1.4835298641951801403851371532153f)
204 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
205 m_normalY = m_normal[1] * m_axisDir;
206 m_n2d[0] = std::cos(m_angle);
207 m_n2d[1] = -std::sin(m_angle);
208 m_hcs.FromNormal(m_axisDir);
209 m_angularRotatedRadians = 0;
215 if (
angle > 1.4835298641951801403851371532153)
222 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
223 m_normalY = m_normal[1] * m_axisDir;
224 m_n2d[0] = std::cos(m_angle);
225 m_n2d[1] = -std::sin(m_angle);
226 m_hcs.FromNormal(m_axisDir);
227 m_angularRotatedRadians = 0;
241 double d1 = p1.
dot(n1);
242 double d2 = p2.
dot(n2);
243 double d3 = p3.
dot(n3);
245 a[0 + 0 * 3] = n1[0];
246 a[1 + 0 * 3] = n2[0];
247 a[2 + 0 * 3] = n3[0];
248 a[0 + 1 * 3] = n1[1];
249 a[1 + 1 * 3] = n2[1];
250 a[2 + 1 * 3] = n3[1];
251 a[0 + 2 * 3] = n1[2];
252 a[1 + 2 * 3] = n2[2];
253 a[2 + 2 * 3] = n3[2];
261 m_center[0] =
a[0 + 3 * 3];
262 m_center[1] =
a[1 + 3 * 3];
263 m_center[2] =
a[2 + 3 * 3];
266 Vec3f s1 = p1 - m_center;
267 Vec3f s2 = p2 - m_center;
268 Vec3f s3 = p3 - m_center;
272 Plane pl(s1 + m_center, s2 + m_center, s3 + m_center);
276 if (m_axisDir.
dot(s1) < 0)
342 if (m_angle < 1e-6 || m_angle >
float(
M_PI) / 2 - 1e-6)
347 if (m_angle > 1.4835298641951801403851371532153f)
351 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
352 m_normalY = m_normal[1] * m_axisDir;
353 m_n2d[0] = std::cos(m_angle);
354 m_n2d[1] = -std::sin(m_angle);
355 m_hcs.FromNormal(m_axisDir);
356 m_angularRotatedRadians = 0;
365 i->read((
char*)&m_center,
sizeof(m_center));
366 i->read((
char*)&m_axisDir,
sizeof(m_axisDir));
367 i->read((
char*)&m_angle,
sizeof(m_angle));
368 i->read((
char*)&rotate,
373 for (
size_t j = 0; j < 3; ++j)
377 for (
size_t j = 0; j < 3; ++j)
379 (*i) >> m_axisDir[j];
384 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
385 m_normalY = m_normal[1] * m_axisDir;
386 m_n2d[0] = std::cos(m_angle);
387 m_n2d[1] = -std::sin(m_angle);
388 m_hcs.FromNormal(m_axisDir);
389 m_angularRotatedRadians = 0;
397 for (
int i = 0; i < 3; i++)
399 m_center[i] = array[i];
400 m_axisDir[i] = array[3 + i];
405 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
406 m_normalY = m_normal[1] * m_axisDir;
407 m_n2d[0] = std::cos(m_angle);
408 m_n2d[1] = -std::sin(m_angle);
409 m_hcs.FromNormal(m_axisDir);
410 m_angularRotatedRadians = 0;
418 fread(&m_center,
sizeof(m_center), 1, i);
419 fread(&m_axisDir,
sizeof(m_axisDir), 1, i);
420 fread(&m_angle,
sizeof(m_angle), 1, i);
421 fread(&rotate,
sizeof(rotate), 1, i);
422 m_normal =
Vec3f(std::cos(-m_angle), std::sin(-m_angle), 0);
423 m_normalY = m_normal[1] * m_axisDir;
424 m_n2d[0] = std::cos(m_angle);
425 m_n2d[1] = -std::sin(m_angle);
426 m_hcs.FromNormal(m_axisDir);
427 m_angularRotatedRadians = 0;
435 float g =
s.dot(m_axisDir);
438 float sqrS =
s.sqrLength();
439 float f = sqrS - (g * g);
448 float da = m_n2d[0] * f;
449 float db = m_n2d[1] * g;
450 if (g < 0 && da - db < 0)
455 float dist = -(da + db);
457 Vec3f plx =
s - g * m_axisDir;
459 Vec3f n = m_normal[0] * plx + m_normalY;
467 float height = m_axisDir.
dot(
s);
468 float planex =
s.dot(m_hcs[0].Data());
469 float planey =
s.dot(m_hcs[1].Data());
470 float l = planex * planex + planey * planey;
476 float angle = std::atan2(planey, planex);
499 float sqrS =
s.sqrLength();
500 float f = sqrS - (height * height);
509 float sdist =
abs(m_n2d[0] * f + ((height < 0) ? -1 : 1) * m_n2d[1] * height);
510 float length =
std::sqrt(sqrS + sdist * sdist);
511 param->first = length;
512 param->second =
angle;
554 q.RotationRad(radians, m_axisDir[0], m_axisDir[1], m_axisDir[2]);
559 m_angularRotatedRadians += radians;
571 for (
unsigned int i = 0; i < 3; ++i)
573 s[i] = x[i] - param[i];
575 float g =
abs(
s[0] * param[3] +
s[1] * param[4] +
s[2] * param[5]);
576 float f =
s.sqrLength() - (g * g);
585 return std::cos(param[6]) * f - std::sin(param[6]) * g;
593 for (
unsigned int i = 0; i < 3; ++i)
595 s[i] = x[i] - param[i];
597 float g =
abs(
s[0] * param[3] +
s[1] * param[4] +
s[2] * param[5]);
598 float f =
s.sqrLength() - (g * g);
608 for (
unsigned int i = 0; i < 3; ++i)
610 ggradient[i] = -param[i + 3];
612 for (
unsigned int i = 0; i < 3; ++i)
614 ggradient[i + 3] =
s[i] - param[i + 3] * g;
619 fgradient[0] =
std::sqrt(1 - param[3] * param[3]);
620 fgradient[1] =
std::sqrt(1 - param[4] * param[4]);
621 fgradient[2] =
std::sqrt(1 - param[5] * param[5]);
625 fgradient[0] = (param[3] * g -
s[0]) / f;
626 fgradient[1] = (param[4] * g -
s[1]) / f;
627 fgradient[2] = (param[5] * g -
s[2]) / f;
629 fgradient[3] = g * fgradient[0];
630 fgradient[4] = g * fgradient[1];
631 fgradient[5] = g * fgradient[2];
632 float sinPhi = -std::sin(param[6]);
633 float cosPhi = std::cos(param[6]);
634 for (
unsigned int i = 0; i < 6; ++i)
636 gradient[i] = cosPhi * fgradient[i] + sinPhi * ggradient[i];
638 gradient[6] = f * sinPhi - g * cosPhi;
645 float l =
std::sqrt(param[3] * param[3] + param[4] * param[4] +
646 param[5] * param[5]);
647 for (
unsigned int i = 3; i < 6; ++i)
652 param[6] -= std::floor(param[6] / (2 *
float(
M_PI))) * (2 *
float(
M_PI));
655 param[6] -= std::floor(param[6] /
float(
M_PI)) *
float(
M_PI);
656 for (
unsigned int i = 3; i < 6; ++i)
661 if (param[6] >
float(
M_PI) / 2)
679 Vec3f center(0, 0, 0);
680 Vec3f axisDir(0, 0, 0);
682 for (
size_t i = 0; i < cones.
size(); ++i)
684 center += weights[i] * cones[i].Center();
685 axisDir += weights[i] * cones[i].AxisDirection();
686 omega += weights[i] * cones[i].Angle();
689 return ic->Init(center, axisDir, omega);
696 o->write((
const char*)&m_center,
sizeof(m_center));
697 o->write((
const char*)&m_axisDir,
sizeof(m_axisDir));
698 o->write((
const char*)&m_angle,
sizeof(m_angle));
699 o->write((
const char*)&m_angularRotatedRadians,
700 sizeof(m_angularRotatedRadians));
704 (*o) << m_center[0] <<
" " << m_center[1] <<
" " << m_center[2] <<
" "
705 << m_axisDir[0] <<
" " << m_axisDir[1] <<
" " << m_axisDir[2] <<
" "
706 << m_angle <<
" " << m_angularRotatedRadians <<
" ";
720 fwrite(&m_center,
sizeof(m_center), 1, o);
721 fwrite(&m_axisDir,
sizeof(m_axisDir), 1, o);
722 fwrite(&m_angle,
sizeof(m_angle), 1, o);
723 fwrite(&m_angularRotatedRadians,
sizeof(m_angularRotatedRadians), 1, o);
733 for (
int i = 0; i < 3; i++)
735 array[i] = m_center[i];
736 array[i + 3] = m_axisDir[i];
739 array[7] = m_angularRotatedRadians;
746 m_center += translate;
754 m_hcs[0] = rot * m_hcs[0];
755 m_hcs[1] = rot * m_hcs[1];
756 m_normalY = m_normal[1] * m_axisDir;