📄 lines3h.h
字号:
//Copyright(c)2004 Alexander Kadyrov
// different form line2h.h by using Peano indexing at the end:
// see comments "the 1st only difference from line2h.h"
// "the 2nd only difference from line2h.h"
const int dg=12,BN=1<<dg;const int BN2=1<<(dg-1);
int *allEnds(int xSize,int ySize,int Nfi4,double dp,double dt,
int*MaxInd_p,int*Lrulelines,int*Llines,int*Enfi1,int*Ltrack)
// This corresponds trace transform such that
// p takes (*MaxInd_p)*2+1 values and fi takes 4*Nfi4 values.
// *Llines is size of the "lines" array if it is computed later
// in "alllines"
// Format int*Ends
// nfi=0, number_of_trace_lines_for_this_nfi,xB_inc,yB_inc,
// it_beg,it_end,xB,yB - for the first line
// it_beg,it_end,xB,yB - for the second line
// ...
// nfi=1(-its address=pnfi1),number_of_trace_lines_for_this_nfi,xB_inc,yB_inc,
// it_beg,it_end,xB,yB - for the first line
// it_beg,it_end,xB,yB - for the second line
// ...
// ...
// nfi=Nfi4,number_of_trace_lines_for_this_nfi,xB_inc,yB_inc,
// it_beg,it_end,xB,yB - for the first line
// it_beg,it_end,xB,yB - for the second line
// ...
// nfi=Nfi4+1,number_of_trace_lines_for_this_nfi,xB_inc,yB_inc,
// it_beg,it_end,xB,yB - for the first line
// it_beg,it_end,xB,yB - for the second line
// ...
//////line coordinates are retrieved as shown in "alllines"
//************************************************************
{
//A pixel is a square of 1x1; Centers of pixels start form O=(0,0) in the plane
int Xsz1=xSize-1,Ysz1=ySize-1;//-OXY coordinates of far most pixel corner
double cX=Xsz1/2.0,cY=Ysz1/2.0; //image geometrical center in OXY, 2.-point is essential
double xszH=0.5+cX,yszH=0.5+cY;//image semi-width
double tHUGE=sqrt(xszH*xszH+yszH*yszH)-0.001;//maximal possible abs(t) and abs(p)
*MaxInd_p=int (floor(tHUGE/dp));
//*****************************************
int Nfi=2*Nfi4; double dfi=pi/Nfi;
// const int dg=12,BN=1<<dg;const int BN2=1<<(dg-1); - see external
//- a pixel area is subdivided to BNxBN to avoid working with "double"
// BN2 serves for round, that is going back from "fine" coordinates.
// First condition:
// if four bytes for integer (i.e. integer in [-2^31,2^31-1]) then
// BN*tHUGE should be less than 2^31
// if two bytes for integer then it should be less than 2^15
// Second condition:
// maximal inherited error of using fine grid due to rounding
// and collecing is eps = 1/BN/2 + (1/BN/2)*((2*tHUGE/dt)
// this eps should be less than 0.5 (reasonable)
// THEN: 2^dg shuld be at least the biggest expected size of image
// and 2*dg<31.
int xSizeBN=xSize*BN,ySizeBN=ySize*BN;
*Ltrack=int(1+2*floor(tHUGE/dt));
double eps = (1+2*tHUGE/dt)/(BN*2.), xszHe=xszH-eps,yszHe=yszH-eps;
// clip the image eps river each side to avoid possible
// getting out of the image due to fine subnet
// fi loop:
int nfi;
double fi,cfi,sfi,ort1,ort2,pmax;int Np,np;
// p loop:
double p,xbase,ybase,t_vert_1,t_vert_2,t_hori_1,t_hori_2,t1,t2;
int xB, xB_inc,yB, yB_inc;
int it_beg,it_end,Count1,rem1,rem2;
double border=sqrt(dp*dp+dt*dt);
int maxparallellines=1+2*(*MaxInd_p);
int maxgridpoins=int (ceil((xSize+2*border)*(ySize+2*border)/(dp*dt)));
*Lrulelines = Nfi*(2+2*maxparallellines); /// DEBUG ??????
*Llines = Nfi*(maxgridpoins); /// DEBUG ??????
int *ends=new int[4*(*MaxInd_p)];int e=0;
int LEnds = 1+(Nfi4+1)*(4+4*maxparallellines);
int *Ends=new int[LEnds];int E=0;
nfi=0; Ends[E++]=nfi;
cfi=1,sfi=0,ort1=-sfi,ort2=cfi;
pmax=xszHe;
Np= int (floor(pmax/dp));
Ends[E++]=2*Np+1;
xB_inc=0; yB_inc=round((dt*ort2)*BN);//-going to fine coordinates
Ends[E++]=xB_inc;Ends[E++]=yB_inc;
ybase=0;
t1=-yszHe;t2=yszHe;//- from t1 to t2 real track line goes.
it_beg=int (ceil(t1/dt)),it_end=int (floor(t2/dt));
yB=round((cY+ybase)*BN)+yB_inc*it_beg+BN2;
rem1=xB_inc*it_beg+BN2;
for (np=-Np;np<=Np;np++)
{ p=np*dp; xbase=p,
xB=round((cX+xbase)*BN)+rem1;
Ends[E++]=it_beg;
Ends[E++]=it_end;
Ends[E++]=xB;
Ends[E++]=yB;
}
*Enfi1=E; int*EndsTemp=Ends;Ends=Ends+E;
for (nfi=1;nfi<Nfi4;nfi++)
{(*Ends++)=nfi;
fi=dfi*nfi,cfi=cos(fi),sfi=sin(fi),ort1=-sfi,ort2=cfi;
// Given fi and Size find pmax by projecting one (it is sufficient) corners of the image
// to the vector (cfi,sfi); then p in [-pmax,pmax]
pmax=cfi*xszHe+sfi*yszHe;
Np= int (floor(pmax/dp));
(*Ends++)=2*Np+1;
xB_inc=round((dt*ort1)*BN); yB_inc=round((dt*ort2)*BN);//-going to fine coordinates
(*Ends++)=xB_inc;(*Ends++)=yB_inc;
e=0;
for (np=-Np;np<0;np++)
{p=np*dp;xbase=p*cfi,ybase=p*sfi; //the nearest point in the track line to the center of the image
// the track line equations: x=xbase+t*ort1;y=ybase+t*ort2;
// track line intercects vertical lines x= (+-)xszHeps :
t_vert_2=(-xszHe-xbase)/ort1;t_vert_1=(xszHe-xbase)/ort1;
// track line intercects horizontal lines y= (+-)yszH :
t_hori_1=(-yszHe-ybase)/ort2;t_hori_2=(yszHe-ybase)/ort2;
t1=maxD(t_vert_1,t_hori_1),t2=minD(t_vert_2,t_hori_2);
//- from t1 to t2 real track line goes.
it_beg=int (ceil(t1/dt)),it_end=int (floor(t2/dt));//it may happen it_beg>it_end
Count1=it_end-it_beg;
// Going to fine coordinates:
xB=round((cX+xbase)*BN)+xB_inc*it_beg+BN2;
yB=round((cY+ybase)*BN)+yB_inc*it_beg+BN2;
(*Ends++)=it_beg;
(*Ends++)=it_end;
(*Ends++)=xB;
(*Ends++)=yB;
ends[e++]=xB+xB_inc*Count1;
ends[e++]=yB+yB_inc*Count1;
ends[e++]=it_beg; ends[e++]=it_end;
}
np=0;
{xbase=0,ybase=0; //the nearest point in the track line to the center of the image
// the track line equations: x=xbase+t*ort1;y=ybase+t*ort2;
// track line intercects vertical lines x= (+-)xszHeps :
t_vert_2=(-xszHe-xbase)/ort1;t_vert_1=(xszHe-xbase)/ort1;
// track line intercects horizontal lines y= (+-)yszH :
t_hori_1=(-yszHe-ybase)/ort2;t_hori_2=(yszHe-ybase)/ort2;
t1=maxD(t_vert_1,t_hori_1),t2=minD(t_vert_2,t_hori_2);
//- from t1 to t2 real track line goes.
it_beg=int (ceil(t1/dt)),it_end=int (floor(t2/dt));//it may happen it_beg>it_end
//Count1=it_end-it_beg;
// Going to fine coordinates:
xB=round((cX+xbase)*BN)+xB_inc*it_beg+BN2;
yB=round((cY+ybase)*BN)+yB_inc*it_beg+BN2;
(*Ends++)=it_beg;
(*Ends++)=it_end;
(*Ends++)=xB;
(*Ends++)=yB;
}
for (np=1;np<=Np;np++)
{
(*Ends++)=it_beg=-ends[--e];
(*Ends++)=it_end=-ends[--e]; //Count1=it_end-it_beg;
yB= ySizeBN-ends[--e];
xB= xSizeBN-ends[--e];//"+BN" =+2*BN2, it is due to rounding
(*Ends++)=xB;
(*Ends++)=yB;
}
}///for (nfi=1;nfi<Nfi4;nfi++)
nfi=Nfi4;
(*Ends++)=nfi;
fi=dfi*nfi,cfi=0,sfi=1,ort1=-sfi,ort2=cfi;
pmax=yszHe;
Np= int (floor(pmax/dp));
(*Ends++)=2*Np+1;
xB_inc=round((dt*ort1)*BN); yB_inc=0;//-going to fine coordinates
(*Ends++)=xB_inc;(*Ends++)=yB_inc;
xbase=0;
t1=-xszHe;t2=xszHe;//- from t1 to t2 real track line goes.
it_beg=int (ceil(t1/dt)),it_end=int (floor(t2/dt));
xB=round((cX+xbase)*BN)+xB_inc*it_beg+BN2; // -going to fine coordinates
rem2=yB_inc*it_beg+BN2;
for (np=-Np;np<=Np;np++)
{p=np*dp; ybase=p;
t_hori_1=(-yszHe-ybase)/ort2;t_hori_2=(yszHe-ybase)/ort2;
t1=-xszHe,t2=xszHe;//- from t1 to t2 real track line goes.
it_beg=int (ceil(t1/dt)),it_end=int (floor(t2/dt));//it may happen it_beg>it_end
yB=round((cY+ybase)*BN)+rem2; // -going to fine coordinates
(*Ends++)=it_beg;
(*Ends++)=it_end;
(*Ends++)=xB;
(*Ends++)=yB;
}
Ends=EndsTemp;
return Ends;
}//END.int *allEnds(
///************** MAKE SET OF ALL TRACING LINES
//Format (int or unsigned short int)*rulelines:
// nfi=0,number_of_trace_lines_for_this_nfi,
// first_line_start_index_t,first_line_finish_index_t,
//Format int*lines: coordinate1,coordinate2,..
//Format (int or unsigned short int)*rulelines:
// second_line_start_index_t,second_line_finish_index_t,
//Format int*lines: coordinate1,coordinate2,..
// ...
// nfi=1,...
// nfi=Npi4*2-1,...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -