You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
5.8 KiB
C++

#include "StdAfx.h"
#include "ObjFill.h"
#include "GlobalFunction.h"
#include "GlobalDrawMgr.h"
#include "LogMgr.h"
#define MAX_FILL_LINE_LEN 500 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ
CObjFill::CObjFill(vector<CSequentialPoint> &Vec)
:m_SequentialPointVec(Vec)
{
}
CObjFill::~CObjFill(void)
{
}
//<2F><><EFBFBD><EFBFBD>obj <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFill::CreatFill(vector<vector<Dbxy>> &LinesVec,DbRect rect)
{
if(m_FillPar.bFill ==false)
return;
Dbxy Pt1,Pt2,Offset;
int ScanTimes = 0;
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(Pt1,Pt2<74>ǵ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>),<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>ߵĴ<DFB5><C4B4><EFBFBD>
GetScanLine(rect,Pt1,Pt2,Offset,ScanTimes);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>չ˵<D5B9>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
Pt1.x -= Offset.x/2;
Pt2.x -= Offset.x/2;
Pt1.y -= Offset.y/2;
Pt2.y -= Offset.y/2;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>һ<EFBFBD><D2BB>
for(int i=0;i<ScanTimes;i++)
{
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
vector<Dbxy> IntersectionVec;
if(GetIntersection(LinesVec,Pt1,Pt2,IntersectionVec,rect))
{
//<2F>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SortIntersection(IntersectionVec);
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SaveScanResult(IntersectionVec);
}
//ɨ<><C9A8><EFBFBD><EFBFBD>ƫ<EFBFBD><C6AB>
Pt1.x += Offset.x;
Pt1.y += Offset.y;
Pt2.x += Offset.x;
Pt2.y += Offset.y;
}
}
#if 1//<2F><><EFBFBD><EFBFBD>
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(ScanTimes <20><>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>ƫ<EFBFBD>ƵĴ<C6B5><C4B4><EFBFBD>)
void CObjFill::GetScanLine(DbRect rect,Dbxy &Pt1,Dbxy &Pt2,Dbxy &Offset,int &ScanTimes)
{
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><E3B9BB><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
double R = MAX_FILL_LINE_LEN;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>Χ
Dbxy CenterPt(rect.L,rect.T);
Pt1.y = Pt2.y = rect.T;
Pt1.x = rect.L-R;
Pt2.x = rect.R+R;
double FillGap = m_FillPar.m_FillGap;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Dbxy Pt(Pt1.x,Pt1.y-FillGap);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>ÿ<EFBFBD>ε<EFBFBD>ƫ<EFBFBD><C6AB>
//<2F><>תɨ<D7AA><C9A8><EFBFBD><EFBFBD>
double Angle = _360ToAngle(m_FillPar.m_FillAngle);
Pt1 = RotatoPt(Pt1,Angle,CenterPt);
Pt2 = RotatoPt(Pt2,Angle,CenterPt);
Pt = RotatoPt(Pt,Angle,CenterPt);
double len = CalDistance(Dbxy(rect.L,rect.T),Dbxy(rect.R,rect.B));
ScanTimes = len/FillGap;
//ÿ<><C3BF>ɨ<EFBFBD><C9A8><EFBFBD>ߵ<EFBFBD>ƫ<EFBFBD><C6AB>
Offset.x = Pt.x - Pt1.x;
Offset.y = Pt.y - Pt1.y;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶κ<DFB6>pt1,pt2 <20>߶εĽ<CEB5><C4BD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>浽IntersectionVec)
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>rect <20><>Χ<EFBFBD><CEA7>
bool CObjFill::GetIntersection(vector<vector<Dbxy>> &LinesVec,Dbxy pt1,Dbxy pt2,vector<Dbxy> &IntersectionVec,DbRect rect)
{
IntersectionVec.clear();
if(pt1.x>3.66 && pt1.x<4.44)
{
int a = 0;
}
vector<vector<Dbxy>>::iterator iter = LinesVec.begin();
vector<vector<Dbxy>>::iterator iter_end = LinesVec.end();
for(;iter!=iter_end;iter++)
{
int size = (*iter).size();
for(int i=0;i<size-1;i++)
{
Dbxy u1((*iter)[i].x,(*iter)[i].y);//<2F><>ǰ<EFBFBD>߶ε<DFB6><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Dbxy u2((*iter)[i+1].x,(*iter)[i+1].y);
if((u1.x>7.974 && u1.x<7.976)&&(u2.x>4.04 && u2.x<4.06))
{
int a=0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ˵<C7B6><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(dot_online_in(u1,pt1,pt2) && dot_online_in(u2,pt1,pt2))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3B6BC>pt1,pt2 <20><>
{
//<2F><>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>΢<EFBFBD>س<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>,<2C><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
double offset = 0.0001;
pt1.x -= offset;
pt2.x -= offset;
pt1.y -= offset;
pt2.y -= offset;
//<2F>ݹ麯<DDB9><E9BAAF><><D7A2>)
return GetIntersection(LinesVec,pt1,pt2,IntersectionVec,rect);
}
else if(dot_online_in(u1,pt1,pt2))//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pt1,pt2 <20><>
{
continue;
}
else if(dot_online_in(u2,pt1,pt2))//<2F>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>pt1,pt2 <20><>
{
//<2F><>һ<EFBFBD><D2BB><EFBFBD>߶εĵڶ<C4B5><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E3BDBB>
if((i+2)<size)
{
Dbxy u3((*iter)[i+2].x,(*iter)[i+2].y);
if(!dot_online_in(u3,pt1,pt2) && IsTwoLineIntersect(u1,u3,pt1,pt2))
{
if(IsPointInRect(u2,rect))
{
IntersectionVec.push_back(u2);
}
}
}
else if(i==(size-2))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(2018-10-15)
{
if(IsPointInRect(u2,rect))
{
IntersectionVec.push_back(u2);
}
}
}
else if(IsTwoLineIntersect(u1,u2,pt1,pt2))//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>u1,u2 <20>м<EFBFBD>
{
Dbxy pt = CalIntersection(u1,u2,pt1,pt2);//<2F><><EFBFBD><EFBFBD><E3BDBB>
if(IsPointInRect(pt,rect))
{
IntersectionVec.push_back(pt);
}
}
}
}
return !IntersectionVec.empty();
}
//<2F>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFill::SortIntersection(vector<Dbxy> &IntersectionVec)
{
if(m_FillPar.m_FillAngle<=45)
{
sort(IntersectionVec.begin(),IntersectionVec.end(),CompareDbxyByX);
}
else
{
sort(IntersectionVec.begin(),IntersectionVec.end(),CompareDbxyByY);
}
}
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void CObjFill::SaveScanResult(vector<Dbxy> &IntersectionVec)
{
int size = IntersectionVec.size();
int idx = 1;
for(int i=1;i<size;i++)
{
if(idx%2 !=0)//<2F>ѽ<EFBFBD><D1BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߶Σ<DFB6><CEA3><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>Ŵ<EFBFBD><C5B4><EFBFBD><EFBFBD>߶<EFBFBD>
{
CSequentialPoint SequentialPoint;
m_SequentialPointVec.push_back(SequentialPoint);
int size1 = m_SequentialPointVec.size();
m_SequentialPointVec[size1-1].AddDataPoint(IntersectionVec[i-1]);
m_SequentialPointVec[size1-1].AddDataPoint(IntersectionVec[i]);
}
idx++;
}
}
#endif