/usr/include/vigra/project2ellipse.hxx is in libvigraimpex-dev 1.9.0+dfsg-10+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | /************************************************************************/
/* */
/* Copyright 2012 by Frank Lenzen & */
/* Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_PROJECT2ELLIPSE_HXX
#define VIGRA_PROJECT2ELLIPSE_HXX
#include <iostream>
namespace vigra{
namespace detail{
//---------------------------------------------------------------------------
void projectEllipse2D_FirstQuad (double &vx, double &vy, double a, double b, const double eps, const int iter_max){
double t=0,tmin,tmax,d1,d2,f,x1,y1,l;
int i;
tmax=std::max(2*a*vx,2*b*vy);
tmin=-b*b;
d1=a*vx/(tmax+a*a);
d2=b*vy/(tmax+b*b);
f=d1*d1+d2*d2-1;
for (i=0;i<iter_max;i++){
t=.5*(tmin+tmax);
d1=a*vx/(t+a*a);
d2=b*vy/(t+b*b);
f=d1*d1+d2*d2-1;
x1=a*vx/(t+a*a);
y1=b*vy/(t+b*b);
l=x1*x1+y1*y1-1;
if (fabs(l)<eps)
break;
if(f>0)
tmin=t;
else if(f<0)
tmax=t;
else
break;
}
d1=vx;
d2=vy;
vx=a*a*vx/(t+a*a);
vy=b*b*vy/(t+b*b);
d1 = vx - d1;
d2 = vy - d2;
return;
}
void projectEllipse2D(double &vx, double &vy, const double _a,const double _b,const double eps,const int max_iter){
//double err;
double a=_a,b=_b;
//check if inside ellipse
if (((vx/a)*(vx/a)+(vy/b)*(vy/b))<=1){
return;
}
// special case of a circle
if (fabs(a-b) < eps){
double l = sqrt(vx*vx+vy*vy);
if (l>(a+b)/2.){
vx=(a+b)/(2*l)*vx;
vy=(a+b)/(2*l)*vy;
}
return;
}
// reflect vx -> -vx, if necessary
bool x_reflect;
if (vx > eps){
x_reflect = false;
}
else if (vx < -eps){
x_reflect = true;
vx = -vx;
}
else{
x_reflect = false;
vx = 0.0;
}
// reflect vy -> vy = -V if necessary
bool y_reflect;
if (vy > eps){
y_reflect = false;
}
else if (vy < -eps){
y_reflect = true;
vy = -vy;
}
else{
y_reflect = false;
vy = 0.0;
}
// swap axes if necessary
bool swapped;
if (a >= b){
swapped = false;
}
else{
swapped = true;
std::swap(a,b);
std::swap(vx,vy);
}
if (vx != 0.0){
if (vy != 0.0){
projectEllipse2D_FirstQuad(vx,vy,a,b,eps,max_iter);
}
else{
if (vx < a - b*b/a){
double vx_temp = vx;
vx = a*a*vx/(a*a-b*b);
vy = vy*sqrt(fabs(1.0-vx_temp/a*vx_temp/a));
}
else{
vx = a;
vy = 0.0;
}
}
}
else{
vx = 0.0;
vy = b;
}
if (swapped){
std::swap(vx,vy);
}
if (y_reflect){
vy = -vy;
}
if (x_reflect){
vx = -vx;
}
return;
}
} //closing namespace detail
} //closing namespace vigra
#endif // VIGRA_PROJECT2ELLIPSE_HXX
|