COMPASSi/trunk/code/projects/OCC/OCCModeling/OffsetGenerate1.cpp

2447 lines
61 KiB
C++
Raw Normal View History

2025-06-25 15:06:42 +08:00
#include <math.h>
#include "OffsetGenerate1.h"
#include "OCCStructDataMD.h"
//#include "OCCViewer.h"
#include "OCCLib.h"
#include "BRepAlgoAPI_Section.hxx"
#include "BaseAlgo.h"
#include "Bnd_Box.hxx"
#include "BRepBndLib.hxx"
#include "BRepBuilderAPI_MakeFace.hxx"
#include "GC_MakePlane.hxx"
#include "BRepExtrema_DistShapeShape.hxx"
#include "BRepAlgoAPI_Common.hxx"
#include "Quantity_Color.hxx"
#include "Prs3d_PointAspect.hxx"
#include "Aspect_TypeOfMarker.hxx"
extern OCCStructDataMD dataMD;
//extern OCCViewer myOCCViewer;
OffsetGenerate1::OffsetGenerate1(void)
{
SecBottom = 1; //剖面底线
Base = 2; //基线
Water = 3; //水线
MainDeck = 4; //主甲板
UpperDeck = 5;//上甲板
FoldLine = 6; //折角线
ProfileLine = 7; //纵剖线,
}
OffsetGenerate1::~OffsetGenerate1(void)
{}
int OffsetGenerate1::GetOffsetTableData(int upperDeckID, int foldingLinesID[], int isBilge, double BilgeHC, int shiptype, int asymmetricType,
int ids[], int lens[], OffsetTablePoint *pnts)
{
UpperDeckID =upperDeckID ; //上甲板ID
isBilge = isBilge;
BilgeHC = BilgeHC;
ShipType = shiptype;
AsymmetricType=asymmetricType;
try
{
//CalProfile();
//CalAngularL(foldingLinesID);
//CalUpperDeck();
GetHalfShell();
CalMainDeck();
CalSecLine();
CalBaseLine();
CalWaterLine();
map<int,vector<gp_Pnt>>::iterator it;
it=OPoints.begin();
int i = 0;
int j=0;
int cnt=0;
while(it!=OPoints.end()){
ids[i] = it->first;
for (j=0;j<it->second.size();j++)
{
pnts[cnt+j].X= it->second[j].X();
pnts[cnt+j].Y = it->second[j].Y();
pnts[cnt+j].Z = it->second[j].Z();
////
//if(ids[i] > 10000000 && ids[i] < 20000000)//最低点
//{
// TopoDS_Vertex v = BRepBuilderAPI_MakeVertex(it->second[j]);
// AnyCore::ASceneNodePtr aisShape=myOCCViewer.TopoShapeToASceneNode(v);//2016srq
// Quantity_Color color(Quantity_NOC_RED);
// Handle_Prs3d_PointAspect myPointAspect=new Prs3d_PointAspect(Aspect_TOM_O,color,2);
// aisShape->Attributes()->SetPointAspect(myPointAspect);
// myOCCViewer.ShowSceneNode(aisShape,false);//2016srq
//
//}
//if(ids[i] > 20000000 && ids[i] < 30000000)//基线
//{
// TopoDS_Vertex v = BRepBuilderAPI_MakeVertex(it->second[j]);
// AnyCore::ASceneNodePtr aisShape=myOCCViewer.TopoShapeToASceneNode(v);//2016srq
// Quantity_Color color(Quantity_NOC_RED);
// Handle_Prs3d_PointAspect myPointAspect=new Prs3d_PointAspect(Aspect_TOM_X,color,2);
// aisShape->Attributes()->SetPointAspect(myPointAspect);
// myOCCViewer.ShowSceneNode(aisShape,false);//2016srq
//}
//if(ids[i] > 30000000 && ids[i] < 40000000)//水线
//{
// TopoDS_Vertex v = BRepBuilderAPI_MakeVertex(it->second[j]);
// AnyCore::ASceneNodePtr aisShape=myOCCViewer.TopoShapeToASceneNode(v);//2016srq
// Quantity_Color color(Quantity_NOC_RED);
// Handle_Prs3d_PointAspect myPointAspect=new Prs3d_PointAspect(Aspect_TOM_BALL,color,2);
// aisShape->Attributes()->SetPointAspect(myPointAspect);
// myOCCViewer.ShowSceneNode(aisShape,false);//2016srq
//}
//if(ids[i] > 40000000 && ids[i] < 50000000)//甲板甲板
//{
// TopoDS_Vertex v = BRepBuilderAPI_MakeVertex(it->second[j]);
// AnyCore::ASceneNodePtr aisShape=myOCCViewer.TopoShapeToASceneNode(v);//2016srq
// Quantity_Color color(Quantity_NOC_RED);
//Handle_Prs3d_PointAspect myPointAspect=new Prs3d_PointAspect(Aspect_TOM_O_PLUS,color,2);
// aisShape->Attributes()->SetPointAspect(myPointAspect);
// myOCCViewer.ShowSceneNode(aisShape,false);//2016srq
//}
}
cnt = cnt+j;
lens[i] = j;
i++;
it++;
}
return i;
}
catch(Standard_Failure)
{
return 0;
}
}
//////////////////////////////////////////////////////////////////////////
//纵剖面线型值
void OffsetGenerate1::CalProfile()
{
int iIndex ;
map<int,double>::iterator it;
it=dataMD.m_mapButtocklinePos.begin();
int i = 0;
while(it!=dataMD.m_mapButtocklinePos.end()){
//根据给出的纵剖面线,然后每站求交点
vector<Handle(Geom_Curve)> curvesL;
vector<Handle(Geom_Curve)> curvesR;
vector<gp_Pnt> psL;
vector<gp_Pnt> psR;
ExtracteLine(-2,it->second,curvesL,curvesR,psL,psR);
if (curvesL.size() > 0){
double dl,df;
dl = curvesL[0]->FirstParameter();
df = curvesL[0]->LastParameter();
vector<gp_Pnt> ps = CalPoints(curvesL[0],dl,df);
if (((ShipType == 2) && (AsymmetricType == -1)) || (ShipType == 1) || (ShipType == 4))
{
if (it->second < 0)
{
iIndex = ProfileLine*11000+it->first;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps));
}else
{
iIndex = ProfileLine*10000+it->first;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps));
}
}else
{
if (it->second > 0)
{
iIndex = ProfileLine*11000+it->first;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps));
}else
{
iIndex = ProfileLine*10000+it->first;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps));
}
}
///
if (it->second < 0.0001)
CurProfile0 = curvesL[0];
///
}
i++;
++it;
}
//map<string,double> mProfilePos; //纵剖线位置
}
////////////////////////////////////////////////
//折角线半宽和高度 ,根据给出的折角线,然后每站求交点
//注意:折角线的高度不应超过甲板线(上甲板,无上甲板是主甲板),若超出,则填-1
void OffsetGenerate1::CalAngularL(int foldingLinesID[])
{
int iIndex;
for(int i=0;i<MAX_ARRAY_SIZE_L;i++)
{
if(foldingLinesID[i]>1)
{
//根据给出的折角线,然后每站求交点
vector<gp_Pnt> ps = CalPoints(foldingLinesID[i]);
if (((ShipType == 2) && (AsymmetricType == -1)) || (ShipType == 1)|| (ShipType == 4))
{
if (ps[0].Y() > 0)
{
iIndex = FoldLine *1000000+i;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps)); //去掉首尾
}else
{
iIndex = FoldLine *1100000+i;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps)); //去掉首尾
}
}else
{
if (ps[0].Y() < 0)
{
iIndex = FoldLine *1000000+i;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps)); //去掉首尾
}else
{
iIndex = FoldLine *1100000+i;
OPoints.insert(pair<int,vector<gp_Pnt>>(iIndex,ps)); //去掉首尾
}
}
}else
{
break;
}
}
}
////////////////////////////////////////////////
//上甲板半宽和高度 ,需要制定上甲板面,找出此面和船壳的交线,然后每站求交点
void OffsetGenerate1::CalUpperDeck()
{
}
////////////////////////////////////////////////
//主甲板半宽和高度 ,需要制定主甲板面/上甲板面,找出此面和船壳的交线,然后每站求交点
//SurfID 上甲板或者主甲板IDFlagID 上甲板或者主甲板的标识
void OffsetGenerate1::CalMainDeck()
{
TopoDS_Shape mainDeck;
if(dataMD.m_mapMainDeckSurf.size()==1)
mainDeck=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapMainDeckSurf.begin()->first)->second;
else
return;
vector<TopoDS_Edge> edges = GetShellSectionEdges(mainDeck);
Bnd_Box box;
double x1,x2,y1,y2,z1,z2;
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
BRepBndLib::Add(edge, box);
}
box.SetGap(0.0);
box.Get(x1,y1,z1,x2,y2,z2);
//艏端点
vector<gp_Pnt> pSetF;
TopoDS_Face ff = CreateFace(-1, x2);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
//pSetFTmp = CleanPoints(pSetFTmp, -1, x1);
pSetF = AddPoints(pSetF, pSetFTmp);
}
pSetF = GetExtremePoints(pSetF, 1);
OPoints.insert(make_pair(40001000,pSetF));
//艉端点
vector<gp_Pnt> pSetD;
TopoDS_Face fd = CreateFace(-1, x1);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
//pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
pSetD = AddPoints(pSetD, pSetDTmp);
}
pSetD = GetExtremePoints(pSetD, -1);
OPoints.insert(make_pair(40003000,pSetD));
//站
for(int i = 0; i < dataMD.m_mapStation.size(); i++)
{
double x = dataMD.m_mapStation[i];
vector<gp_Pnt> pSet;
TopoDS_Face f = CreateFace(-1, x);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetTmp = GetSectionPoints(edge, f);
pSetTmp = CleanPoints(pSetTmp, -1, x);
pSet = AddPoints(pSet, pSetTmp);
}
OPoints.insert(make_pair(40002000+i,pSet));
}
}
//SurfID 上甲板或者主甲板IDFlagID 上甲板或者主甲板的标识
void OffsetGenerate1::CalDeck()
{
int i = 0;
vector<Handle(Geom_Curve)> curvesL;
vector<Handle(Geom_Curve)> curvesR;
vector<gp_Pnt> psL;
vector<gp_Pnt> psR;
vector<gp_Pnt> ListPnt;
vector<gp_Pnt> ListPnta;
gp_Pnt ptend;
//取得两端点坐标
if (dataMD.m_mapMainDeckSurf.size() > 0)
{
vector<Handle(Geom_Curve)> curvesL;
vector<Handle(Geom_Curve)> curvesR;
vector<gp_Pnt> psL;
vector<gp_Pnt> psR;
// ExtracteLine(dataMD.m_mapMainDeckSurf.begin()->first,-2,0,curvesL,curvesR); //怎么得到主甲板ID YY
//ExtracteLine(SurfID,-2,0,curvesL,curvesR); //怎么得到主甲板ID YY
if (curvesL.size() > 0)
{
double dlp,dfp;
dlp = curvesL[0]->FirstParameter();
dfp = curvesL[0]->LastParameter();
gp_Pnt pt1=curvesL[0]->Value(dlp);
gp_Pnt pt2=curvesL[0]->Value(dfp);
if (pt1.X() > pt2.X())
{
ListPnt.push_back(pt2);
ListPnta.push_back(pt2);
ptend = pt1;
}
else
{
ListPnt.push_back(pt1);
ListPnta.push_back(pt1);
ptend = pt2;
}
}else
{
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
ListPnt.push_back(Or);
ListPnta.push_back(Or);
ptend = Or;
}
}
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
map<int,double>::iterator it;
it=dataMD.m_mapStation.begin();
while(it!=dataMD.m_mapStation.end()){
curvesL.clear();
//ExtracteLine(SurfID,-1,it->second,curvesL,curvesR);
if (curvesL.size() > 0)
{
double dl,df;
dl = curvesL[0]->FirstParameter();
df = curvesL[0]->LastParameter();
gp_Pnt pt1=curvesL[0]->Value(dl);
gp_Pnt pt2=curvesL[0]->Value(df);
if ((ShipType == 2) && (AsymmetricType == 1))
{
if (pt1.Y()>pt2.Y())
{
ListPnt.push_back(pt2);
ListPnta.push_back(pt1);
}
else
{
ListPnt.push_back(pt1);
ListPnta.push_back(pt2);
}
}else{
if (pt1.Y()>pt2.Y())
{
ListPnt.push_back(pt1);
ListPnta.push_back(pt2);
}
else
{
ListPnt.push_back(pt2);
ListPnta.push_back(pt1);
}
}
}else
{
ListPnt.push_back(Or);
ListPnta.push_back(Or);
}
it++;
}
ListPnt.push_back(ptend);
ListPnta.push_back(ptend);
//OPoints.insert(pair<int,vector<gp_Pnt>>(FlagID*10000 ,ListPnt));
//OPoints.insert(pair<int,vector<gp_Pnt>>(FlagID*11000 ,ListPnta));
}
//////////////////////////////////////////////////////////////////////////
//剖面底线半宽,舭部升高的情况,需要算法 最低点
void OffsetGenerate1::CalSecLine()
{
vector<gp_Pnt> pSetF,pSetD;
OPoints.insert(make_pair(10001000,pSetF));
OPoints.insert(make_pair(10003000,pSetD));
//站
for(int i = 0; i < dataMD.m_mapStation.size(); i++)
{
double x = dataMD.m_mapStation[i];
vector<gp_Pnt> pSet;
TopoDS_Face f = CreateFace(-1, x);
vector<TopoDS_Edge> edges = GetShellSectionEdges(f);
Bnd_Box box;
double x1,x2,y1,y2,z1,z2;
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
BRepBndLib::Add(edge, box);
}
box.SetGap(0.0);
box.Get(x1,y1,z1,x2,y2,z2);
TopoDS_Face face = CreateFace(-3, z1);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetTmp = GetSectionPoints(edge, face);
pSetTmp = CleanPoints(pSetTmp, -3, z1);
pSet = AddPoints(pSet, pSetTmp);
}
OPoints.insert(make_pair(10002000+i,pSet));
}
}
///基线求点,基线也就是水线为0时Z=0时的交线在各站号的点和剖面底线一致但不存在舭部升高
void OffsetGenerate1::CalBaseLine()
{
TopoDS_Face face = CreateFace(-3, 0);
vector<TopoDS_Edge> edges = GetShellSectionEdges(face);
Bnd_Box box;
double x1,x2,y1,y2,z1,z2;
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
BRepBndLib::Add(edge, box);
}
box.SetGap(0.0);
box.Get(x1,y1,z1,x2,y2,z2);
//艏端点
vector<gp_Pnt> pSetF;
TopoDS_Face ff = CreateFace(-1, x2);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
//pSetFTmp = CleanPoints(pSetFTmp, -1, x1);
pSetF = AddPoints(pSetF, pSetFTmp);
}
pSetF = GetExtremePoints(pSetF, 1);
OPoints.insert(make_pair(20001000,pSetF));
//艉端点
vector<gp_Pnt> pSetD;
TopoDS_Face fd = CreateFace(-1, x1);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
//pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
pSetD = AddPoints(pSetD, pSetDTmp);
}
pSetD = GetExtremePoints(pSetD, -1);
OPoints.insert(make_pair(20003000,pSetD));
//站
for(int i = 0; i < dataMD.m_mapStation.size(); i++)
{
double x = dataMD.m_mapStation[i];
vector<gp_Pnt> pSet;
TopoDS_Face f = CreateFace(-1, x);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetTmp = GetSectionPoints(edge, f);
pSetTmp = CleanPoints(pSetTmp, -1, x);
pSet = AddPoints(pSet, pSetTmp);
}
OPoints.insert(make_pair(20002000+i,pSet));
}
}
//
// 水线求点
//
void OffsetGenerate1::CalWaterLine()
{
for(int w = 1; w < dataMD.m_mapWaterlinePos.size() ; w++)
{
TopoDS_Face face = CreateFace(-3, dataMD.m_mapWaterlinePos[w]);
vector<TopoDS_Edge> edges = GetShellSectionEdges(face);
Bnd_Box box;
double x1,x2,y1,y2,z1,z2;
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
BRepBndLib::Add(edge, box);
}
box.SetGap(0.0);
box.Get(x1,y1,z1,x2,y2,z2);
//艏端点
vector<gp_Pnt> pSetF;
TopoDS_Face ff = CreateFace(-1, x2);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
//pSetFTmp = CleanPoints(pSetFTmp, -1, x1);
pSetF = AddPoints(pSetF, pSetFTmp);
}
pSetF = GetExtremePoints(pSetF, 1);
OPoints.insert(make_pair(30001000 + w * 10000,pSetF));
//艉端点
vector<gp_Pnt> pSetD;
TopoDS_Face fd = CreateFace(-1, x1);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
//pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
pSetD = AddPoints(pSetD, pSetDTmp);
}
pSetD = GetExtremePoints(pSetD, -1);
OPoints.insert(make_pair(30003000 + w * 10000,pSetD));
//站
for(int i = 0; i < dataMD.m_mapStation.size(); i++)
{
double x = dataMD.m_mapStation[i];
vector<gp_Pnt> pSet;
TopoDS_Face f = CreateFace(-1, x);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetTmp = GetSectionPoints(edge, f);
pSetTmp = CleanPoints(pSetTmp, -1, x);
pSet = AddPoints(pSet, pSetTmp);
}
OPoints.insert(make_pair(30002000 + w * 10000 + i,pSet));
}
}
}
//面与船壳面的交线,返回一条此条交线,对返回的曲线进行拐点分析,如果有,进行曲线的拆分,返回多条曲线,及相应的
//极值点
//FreeBoard =1 取右舷 =-1 取左舷
//Flag = -1 YZ平面 =-2 XZ平面 =-3 XY平面 >0 为上甲板ID或者主甲板ID
//LType 判断线的类型,是否要进行拆分
void OffsetGenerate1::ExtracteLine(int Flag,double Pos,vector<Handle(Geom_Curve)>& CurL,vector<Handle(Geom_Curve)>& CurR,vector<gp_Pnt>& LPnts,vector<gp_Pnt>& RPnts,int LType)
{
TopoDS_Shape face,shell,shellL,shellR,tempshape1,tempshape2;
TopoDS_Edge secedge1,secedge2,secedge;
map<int,TopoDS_Shape>::iterator it;
gp_Pnt Or;
gp_Dir Norm;
switch(Flag)
{
case -1:
Or=gp_Pnt(Pos,0,0);
Norm=gp_Dir(1, 0.,0 );
break;
case -2:
Or=gp_Pnt(0,Pos,0.);
Norm=gp_Dir(0., 1, 0.);
break;
case -3:
Or=gp_Pnt(0,0,Pos);
Norm=gp_Dir(0., 0., 1.);
break;
default:
break;
}
if(Flag<0)
{
// gp_Pln pln(Or,Norm);
// Handle(Geom_Surface)aSurface =GC_MakePlane(pln).Value();
// //BRepBuilderAPI_MakeFace face1 =BRepBuilderAPI_MakeFace(aSurface);// XUEFENG DELETE 202009
// BRepBuilderAPI_MakeFace face1 =BRepBuilderAPI_MakeFace(aSurface, Precision::Confusion()); // XUEFENG ADDED 202009
// face=face1.Shape();
}
else
{
it=dataMD.m_mapAllTopoShapes.find(Flag);
if(it!=dataMD.m_mapAllTopoShapes.end())
{
face=it->second;
}
else
{
return;
}
}
if(dataMD.m_mapShellSurf.size()>0)
{}
else
{
return;
}
tempshape1=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
/*switch(ShipType)
{
case 1:
case 4:
shell=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->second.Src[0])->second;
break;
case 2:
tempshape1=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->second.Src[0])->second;
tempshape2=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->second.Src[1])->second ;
break;
default:
break;
}*/
list<TopoDS_Edge> edgelist;
list<TopoDS_Edge> edgelistL;
list<TopoDS_Edge> edgelistR;
TopoDS_Edge tpedge;
/*if(ShipType==1||ShipType==4)
{
BRepAlgoAPI_Section sec(face,shell,Standard_False);
sec.ComputePCurveOn1(Standard_True);
sec.Approximation(TopOpeBRepTool_APPROX);
sec.Build();
dataMD.GetInsectWirePts(sec.Shape(),edgelist);
if(edgelist.size()<1)
{
shell=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->second.Src[1])->second;
BRepAlgoAPI_Section sec(face,shell,Standard_False);
sec.ComputePCurveOn1(Standard_True);
sec.Approximation(TopOpeBRepTool_APPROX);
sec.Build();
dataMD.GetInsectWirePts(sec.Shape(),edgelist);
}
if(edgelist.size()>0)
{
secedge=dataMD.SetInsectWireToEdge(edgelist);
//2016srq
//Handle_AIS_Shape AISShape=new AIS_Shape(secedge);
//myOCCViewer.myAISContext->Display(AISShape,true);
AnyCore::ASceneNodePtr AISShape=myOCCViewer.TopoShapeToASceneNode(secedge);
myOCCViewer.ShowSceneNode(AISShape,true);
}
double df1,de1;
Handle(Geom_Curve) curveL=BRep_Tool::Curve(secedge,df1,de1);
CurL.push_back(curveL);*/
/*}
else
{*/
BRepAlgoAPI_Section sec1(face,tempshape1,Standard_False);
sec1.ComputePCurveOn1(Standard_True);
sec1.Approximation(TopOpeBRepTool_APPROX);
sec1.Build();
TopoDS_Shape s =sec1.Shape();
dataMD.GetInsectWirePts(s,edgelistL);
secedge1=dataMD.SetInsectWireToEdge(edgelistL);
//if (tempshape2 != null){
/*BRepAlgoAPI_Section sec2(face,tempshape2,Standard_False);
sec2.ComputePCurveOn1(Standard_True);
sec2.Approximation(TopOpeBRepTool_APPROX);
sec2.Build();
dataMD.GetInsectWirePts(sec2.Shape(),edgelistR);
secedge2=dataMD.SetInsectWireToEdge(edgelistR);*/
//}
if(edgelistL.size()>0)
{
secedge1=dataMD.SetInsectWireToEdge(edgelistL);
//2016srq
/*Handle_AIS_Shape AISShape=new AIS_Shape(secedge1);
myOCCViewer.myAISContext->Display(AISShape,true);*/
// DELETE BY XUEFENG 20180731
// FOR CODES COMBINE
/*
AnyCore::ASceneNodePtr AISShape=myOCCViewer.TopoShapeToASceneNode(secedge1);
myOCCViewer.ShowSceneNode(AISShape,true);
*/
// END DELETE
}
/*if(edgelistR.size()>0)
{
secedge2=dataMD.SetInsectWireToEdge(edgelistR);
//Handle_AIS_Shape AISShape=new AIS_Shape(secedge2);
//myOCCViewer.myAISContext->Display(AISShape,true);
AnyCore::ASceneNodePtr AISShape=myOCCViewer.TopoShapeToASceneNode(secedge2);
myOCCViewer.ShowSceneNode(AISShape);
}*/
double df1,de1;//df2,de2; upd by yu for erase warning 14.8.27
Handle(Geom_Curve) curveL=BRep_Tool::Curve(secedge1,df1,de1);
CurL.push_back(curveL);
//Handle(Geom_Curve) curveR=BRep_Tool::Curve(secedge2,df2,de2);
//CurL=SplitGeomCurve(curveL,LPnts);
/*if(curveL->Value(df1).Y()>0||curveL->Value(de1).Y()>0)
{
CurL=SplitGeomCurve(curveL,LPnts);
CurR=SplitGeomCurve(curveR,RPnts);
}
else
{
CurR=SplitGeomCurve(curveL,LPnts);
CurL=SplitGeomCurve(curveR,RPnts);
}*/
//}
}
//针对不是和船壳面求交的情况
void OffsetGenerate1::ExtracteLine(int SurfID,int Flag,double Pos,vector<Handle(Geom_Curve)>& CurL,vector<Handle(Geom_Curve)>& CurR)
{
TopoDS_Shape face,shell,shellL,shellR,tempshape1,tempshape2;
TopoDS_Edge secedge1,secedge2,secedge;
map<int,TopoDS_Shape>::iterator it;
gp_Pnt Or;
gp_Dir Norm;
switch(Flag)
{
case -1:
Or=gp_Pnt(Pos,0,0);
Norm=gp_Dir(1, 0.,0 );
break;
case -2:
Or=gp_Pnt(0,Pos,0.);
Norm=gp_Dir(0., 1, 0.);
break;
case -3:
Or=gp_Pnt(0,0,Pos);
Norm=gp_Dir(0., 0., 1.);
break;
default:
break;
}
if(Flag<0)
{
// gp_Pln pln(Or,Norm);
// Handle(Geom_Surface)aSurface =GC_MakePlane(pln).Value();
// //BRepBuilderAPI_MakeFace face1 =BRepBuilderAPI_MakeFace(aSurface);// XUEFENG DELETE 202009
// BRepBuilderAPI_MakeFace face1 =BRepBuilderAPI_MakeFace(aSurface, Precision::Confusion()); // XUEFENG ADDED 202009
// face=face1.Shape();
}
else
{
it=dataMD.m_mapAllTopoShapes.find(Flag);
if(it!=dataMD.m_mapAllTopoShapes.end())
{
face=it->second;
}
else
{
return;
}
}
it=dataMD.m_mapAllTopoShapes.find(SurfID);
if(it!=dataMD.m_mapAllTopoShapes.end())
{
shell=it->second;
}
else
{
return;
}
list<TopoDS_Edge> edgelist;
list<TopoDS_Edge> edgelistL;
list<TopoDS_Edge> edgelistR;
TopoDS_Edge tpedge;
if(ShipType==1||ShipType==4)
{
BRepAlgoAPI_Section sec(face,shell,Standard_False);
sec.ComputePCurveOn1(Standard_True);
sec.Approximation(TopOpeBRepTool_APPROX);
sec.Build();
TopoDS_Shape s =sec.Shape();
dataMD.GetInsectWirePts(s,edgelist);
if(edgelist.size()<1)
{
shell=dataMD.m_mapAllTopoShapes.find(SurfID)->second;
BRepAlgoAPI_Section sec(face,shell,Standard_False);
sec.ComputePCurveOn1(Standard_True);
sec.Approximation(TopOpeBRepTool_APPROX);
sec.Build();
s =sec.Shape();
dataMD.GetInsectWirePts(s,edgelist);
}
if(edgelist.size()>0)
{
secedge=dataMD.SetInsectWireToEdge(edgelist);
//2016srq
/*Handle_AIS_Shape AISShape=new AIS_Shape(secedge);
myOCCViewer.myAISContext->Display(AISShape,true);
Handle_AIS_Shape AISShape1=new AIS_Shape(shell);
myOCCViewer.myAISContext->Display(AISShape1,true);*/
// DELETE BY XUEFENG 20180731
// FOR CODES COMBINE
/*
AnyCore::ASceneNodePtr AISShape=myOCCViewer.TopoShapeToASceneNode(secedge);
myOCCViewer.ShowSceneNode(AISShape);
AnyCore::ASceneNodePtr AISShape1=myOCCViewer.TopoShapeToASceneNode(shell);
myOCCViewer.ShowSceneNode(AISShape1);
*/
// END DELETE
}
double df1,de1;
Handle(Geom_Curve) curveL=BRep_Tool::Curve(secedge,df1,de1);
CurL.push_back(curveL);
//CurL = curveL;
//CurL=SplitGeomCurve(curveL,LPnts);
//if(curveL->Value(df1).Y()>0||curveL->Value(de1).Y()>0)
//{
// CurL=SplitGeomCurve(curveL,LPnts);
// //CurR=SplitGeomCurve(curveR,RPnts);
//}
//else
//{
// CurR=SplitGeomCurve(curveL,LPnts);
// //CurL=SplitGeomCurve(curveR,RPnts);
//}
}
else
{
BRepAlgoAPI_Section sec1(face,tempshape1,Standard_False);
sec1.ComputePCurveOn1(Standard_True);
sec1.Approximation(TopOpeBRepTool_APPROX);
BRepAlgoAPI_Section sec2(face,tempshape2,Standard_False);
sec2.ComputePCurveOn1(Standard_True);
sec2.Approximation(TopOpeBRepTool_APPROX);
sec1.Build();
TopoDS_Shape s =sec1.Shape();
dataMD.GetInsectWirePts(s,edgelistL);
secedge1=dataMD.SetInsectWireToEdge(edgelistL);
sec2.Build();
s =sec2.Shape();
dataMD.GetInsectWirePts(s,edgelistR);
secedge2=dataMD.SetInsectWireToEdge(edgelistR);
double df1,df2,de1,de2;
Handle(Geom_Curve) curveL=BRep_Tool::Curve(secedge1,df1,de1);
Handle(Geom_Curve) curveR=BRep_Tool::Curve(secedge2,df2,de2);
/*if(curveL->Value(df1).Y()>0||curveL->Value(de1).Y()>0)
{
CurL=SplitGeomCurve(curveL,LPnts);
CurR=SplitGeomCurve(curveR,RPnts);
}
else
{
CurR=SplitGeomCurve(curveL,LPnts);
CurL=SplitGeomCurve(curveR,RPnts);
}*/
}
}
/// <summary>
/// 自动拆分几何曲线(通过峰值、拐点///极值点)
/// </summary>
/// <param name="curve"></param>
/// <returns></returns>
vector<Handle(Geom_Curve)> OffsetGenerate1::SplitGeomCurve(Handle(Geom_Curve) curve, vector<gp_Pnt>& pnts)
{
//Handle(Geom_Curve) aCur = BRep_Tool::Curve(edge,df,dl);
//TopoDS_Edge
map<double,gp_Pnt> mapTempPnts;
map<double,gp_Pnt>::iterator it;
vector<Handle(Geom_Curve)> curves;
gp_Pnt beginP,endP,tempP;
double tempX,tempY,tempZ,tempPara;
gp_Pnt Or;
gp_Dir Norm;
gp_Pln pln;
Geom2dLProp_CurAndInf2d curpro;
Handle(Geom_BSplineCurve) myBSplCurve= Handle(Geom_BSplineCurve)::DownCast( curve);
Handle(Geom_Curve) myCurve=myBSplCurve;
beginP=myBSplCurve->StartPoint();
endP=myBSplCurve->EndPoint();
tempX=abs(beginP.X()-endP.X());
tempY=abs(beginP.Y()-endP.Y());
tempZ=abs(beginP.Z()-endP.Z());
/*if(tempX<10e-6)
{
Or=gp_Pnt(beginP.X(),0,0);
Norm=gp_Dir(1, 0,0 );
}
else if(tempY<10e-6)
{
Or=gp_Pnt(0,beginP.Y(),0);
Norm=gp_Dir(0, 1,0 );
}*/
//else
if(tempZ<10e-6)
{
Or=gp_Pnt(0,0,beginP.Z());
Norm=gp_Dir(0, 0,1 );
}
/*else
{
return curves;
}*/
mapTempPnts.insert(make_pair(myBSplCurve->FirstParameter(),beginP));
mapTempPnts.insert(make_pair(myBSplCurve->LastParameter(),endP));
pln=gp_Pln(Or,Norm);
Handle(Geom2d_Curve) curve2D=GeomAPI::To2d(myCurve,pln);
curpro.Perform(curve2D);
int num=curpro.NbPoints();
for(int i=1;i<=num;i++)
{
if(curpro.Type(i)==LProp_MinCur)
{
tempPara=curpro.Parameter(i);
tempP=myBSplCurve->Value(tempPara);
mapTempPnts.insert(make_pair(tempPara,tempP));
}
if(curpro.Type(i)==LProp_MaxCur)
{
tempPara=curpro.Parameter(i);
tempP=myBSplCurve->Value(tempPara);
mapTempPnts.insert(make_pair(tempPara,tempP));
}
}
if(mapTempPnts.size()>0)
{
for(it=mapTempPnts.begin();it!=mapTempPnts.end();it++)
{
pnts.push_back(it->second);
}
}
if(pnts.size()>0)
{
for(int j=0;j<pnts.size()-2;j++)
{
Handle(Geom_Curve) trimedCurve;
dataMD.TrimEdgeBy2Points(curve,pnts[j],pnts[j+1],trimedCurve);
curves.push_back(trimedCurve);
TopoDS_Edge edge=BRepBuilderAPI_MakeEdge(trimedCurve);
//2016srq
/*Handle_AIS_Shape AISShape=new AIS_Shape(edge);
myOCCViewer.myAISContext->Display(AISShape,true);*/
// DELETE BY XUEFENG 20180731
// FOR CODES COMBINE
/*
AnyCore::ASceneNodePtr AISShape=myOCCViewer.TopoShapeToASceneNode(edge);
myOCCViewer.ShowSceneNode(AISShape);
*/
// END DELETE
}
}
else
{
curves.push_back(curve);
}
////pnts = new vector<gp_Pnt>();//拐点存储
////curves = new vector<Geom_Curve>();
return curves;
}
vector<gp_Pnt> OffsetGenerate1::CalPoints(int ID)
{
vector<gp_Pnt> listPnt;
double df,dl;
map<int,TopoDS_Shape>::iterator it;
it=dataMD.m_mapAllTopoShapes.find(ID);
if(it!=dataMD.m_mapAllTopoShapes.end())
{
TopoDS_Edge edge=TopoDS::Edge(it->second);
Handle_Geom_Curve curve=BRep_Tool::Curve(edge,df,dl);
listPnt=CalPoints(curve,df,dl);
}
//CalPoints(Handle_Geom_Curve curve,int index)
return listPnt;
}
//Flag 当为隧道型船舶
vector<gp_Pnt> OffsetGenerate1::CalPoints(Handle_Geom_Curve curve,gp_Pnt df,gp_Pnt dl)
{
vector<gp_Pnt> listPnt;
int length = 0;
gp_Pnt pt1=df;
gp_Pnt pt2=dl;
listPnt.push_back(pt1);
int i = 0;
map<int,double>::iterator it;
it=dataMD.m_mapStation.begin();
while(it!=dataMD.m_mapStation.end()){
vector<gp_Pnt> Points = ExtractePoint(curve,0,it->second);
int len = Points.size();
if ((ShipType == 1))
{
//取左舷
if (len >1)
{
if (Points[0].Y() > Points[len-1].Y())
listPnt.push_back(Points[0]);
else
listPnt.push_back(Points[len-1]);
}else
{
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
listPnt.push_back(Or);
}
}
if (ShipType == 4)
{
gp_Pnt Or1=gp_Pnt(-99999,0,0);
int vFlag = 0;
for (int i=0;i<len;i++)
if (Points[0].Y() < 0)
vFlag ++;
if (vFlag == len) //判断点如果都小于0的情况
{
for (int i=0;i<3;i++)
listPnt.push_back(Or1);
}else
{
switch (len)
{
case 1:
if (Points[0].Y() > 0)
{
listPnt.push_back(Or1);
listPnt.push_back(Points[0]);
listPnt.push_back(Points[0]);
}
break;
case 2:
if (Points[0].Y() > Points[1].Y())
{
listPnt.push_back(Points[0]);
listPnt.push_back(Or1);
listPnt.push_back(Points[0]);
}
else
{
listPnt.push_back(Points[1]);
listPnt.push_back(Or1);
listPnt.push_back(Points[1]);
}
break;
case 3:
case 4:
case 5:
if (Points[0].Y() > Points[len-1].Y())
{
listPnt.push_back(Points[0]);
listPnt.push_back(Points[1]);
listPnt.push_back(Or1);
}
else
{
listPnt.push_back(Points[len-1]);
listPnt.push_back(Points[len-2]);
listPnt.push_back(Or1);
}
default:
if (Points[0].Y() > Points[len-1].Y())
{
listPnt.push_back(Points[0]);
listPnt.push_back(Points[1]);
listPnt.push_back(Points[2]);
}
else
{
listPnt.push_back(Points[len-1]);
listPnt.push_back(Points[len-2]);
listPnt.push_back(Points[len-3]);
}
}
}
}
if ((ShipType == 2))
{
//取左舷
if (len >1){
if (AsymmetricType == -1)
{
if (len >1)
{
if (Points[0].Y() > Points[len-1].Y()){
listPnt.push_back(Points[0]);
listPnt.push_back(Points[len-1]);}
else{
listPnt.push_back(Points[0]);
listPnt.push_back(Points[len-1]);}
}
}
else
{
if (len >1)
{
if (Points[0].Y() < Points[len-1].Y()){
listPnt.push_back(Points[0]);
listPnt.push_back(Points[len-1]);}
else{
listPnt.push_back(Points[0]);
listPnt.push_back(Points[len-1]);}
}
}
}
else
{
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
listPnt.push_back(Or);
gp_Pnt Or1;
Or1=gp_Pnt(-99999,0,0);
listPnt.push_back(Or1);
}
}
++it;
}
listPnt.push_back(pt2);
return listPnt;
}
/// <summary>
/// 计算水线或者纵剖线的点,给出线根据纵向X值得出每个X值上的点对于首艉端点则在调用此函数时给出
///返回一组点,在调用此函数后,分解需要的点放入型值表表达变量中
/// </summary>
/// <param name="index">最大站点索引(全部为-1</param>
/// <param name="YZ">是半宽y还是高度z</param>
/// <returns></returns>
vector<gp_Pnt> OffsetGenerate1::CalPoints(Handle_Geom_Curve curve,double df,double dl,int Flag)
{
vector<gp_Pnt> listPnt;
int length = 0;
//if (index == -1) length = mStationPos.size();
// else length = index;
gp_Pnt pt1=curve->Value(df);
gp_Pnt pt2=curve->Value(dl);
listPnt.push_back(pt1);
int i = 0;
map<int,double>::iterator it;
it=dataMD.m_mapStation.begin();
while(it!=dataMD.m_mapStation.end()){
vector<gp_Pnt> Points = ExtractePoint(curve,0,it->second);
if (Flag == 1){
int len = Points.size();
if (len >2)
{
if (fabs(Points[0].Y()) > fabs(Points[len-1].Y()))
{
listPnt.push_back(Points[0]);
listPnt.push_back(Points[1]);
listPnt.push_back(Points[2]);
}
else
{
listPnt.push_back(Points[2]);
listPnt.push_back(Points[1]);
listPnt.push_back(Points[0]);
}
}
else if (len = 2)
{
if (fabs(Points[0].Y()) > fabs(Points[1].Y()))
{
listPnt.push_back(Points[0]);
listPnt.push_back(Points[1]);
}
else
{
listPnt.push_back(Points[1]);
listPnt.push_back(Points[0]);
}
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
listPnt.push_back(Or);
}
else if (len == 1)
{
listPnt.push_back(Points[0]);
for (int k=0;k<2;k++)
{
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
listPnt.push_back(Or);
}
}
else
{
for (int k=0;k<3;k++)
{
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
listPnt.push_back(Or);
}
}
}else{
if (Points.size() > 0)
listPnt.push_back(Points[0]);
else
{
gp_Pnt Or;
Or=gp_Pnt(-99999,0,0);
listPnt.push_back(Or);
}
}
++it;
}
listPnt.push_back(pt2);
return listPnt;
}
/// <summary>
/// 几何曲线与平面相交,求交点
/// </summary>
/// <returns></returns>
vector<gp_Pnt> OffsetGenerate1::ExtractePoint(Handle_Geom_Curve curve,int flag,double pos)
{
vector<gp_Pnt> points;
//////////
gp_Pnt Or;
gp_Dir Norm;
switch (flag)
{
case 0:
Or=gp_Pnt(pos,0,0);
Norm=gp_Dir(1, 0.,0 );
break;
case 1:
Or=gp_Pnt(0,pos,0);
Norm=gp_Dir(0, 1,0 );
break;
case 2:
Or=gp_Pnt(0,0,pos);
Norm=gp_Dir(0, 0.,1 );
break;
default:
break;
}
// gp_Pln pln(Or,Norm);
// Handle(Geom_Surface) aSurface =GC_MakePlane(pln).Value();
// GeomAPI_IntCS IntCS(curve,aSurface);
// if (IntCS.IsDone())
// {
// if (IntCS.NbPoints() > 0)
// {
// for (int j = 1; j <= IntCS.NbPoints(); j++)
// {
// points.push_back(IntCS.Point(j));
// }
// }
// }
return points;
}
/// <summary>
/// 获取曲线中直线段与曲线段的连接点
/// </summary>
/// <param name="curve"></param>
/// <returns></returns>
vector<gp_Pnt> OffsetGenerate1::GetInflectionPoints(Handle(Geom_Curve) curve)
{
vector<gp_Pnt> result;
vector<gp_Pnt> resultF;
vector<gp_Pnt> resultB;
std::vector<TopoDS_Edge> edgeSetF;
std::vector<gp_Pnt> pointSetF;
std::vector<TopoDS_Edge> edgeSetB;
std::vector<gp_Pnt> pointSetB;
int level = 1;
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(curve).Edge();
GProp_GProps System;
BRepGProp::LinearProperties(edge,System);
edgeSetF.push_back(edge);
double step = System.Mass() / 10000/*pow(10000.0, level)*/;
step = step < 0.01 ? step : 0.01;
edgeSetF = GetEdgeSet(edgeSetF, step, pointSetF);
resultF = GetIntersections(edgeSetF, pointSetF, level);
for(int i = edgeSetF.size() - 1 ;i > -1; i--)
{
edgeSetB.push_back(edgeSetF[i]);
}
for(int i = pointSetF.size() - 1 ;i > -1; i--)
{
pointSetB.push_back(pointSetF[i]);
}
resultB = GetIntersections(edgeSetB, pointSetB, level);
int count = resultB.size() + resultF.size();
double Y = 10000;
double YMax = -10000;
gp_Pnt tmp;
for(int i = 0; i < count; i++)
{
for(int j = 0; j < resultF.size(); j++)
{
if(resultF[j].Y() < Y && YMax < resultF[j].Y())
{
YMax = resultF[j].Y();
tmp = resultF[j];
}
}
for(int j = 0; j < resultB.size(); j++)
{
if(resultB[j].Y() < Y && YMax < resultB[j].Y())
{
YMax = resultB[j].Y();
tmp = resultB[j];
}
}
result.push_back(tmp);
Y = YMax;
YMax = -10000;
}
return result;
}
vector<gp_Pnt> OffsetGenerate1::GetIntersections(vector<TopoDS_Edge> &edgeSet, vector<gp_Pnt> &pointSet, int lev)
{
vector<gp_Pnt> result;
//pointSet.clear();
if (edgeSet.size() < 2)
{
return result;
}
//连续直线段的长度
double len = 0;
bool isline = false;
gp_Pnt pointStart, pointEnd;
pointStart = pointSet[0];
bool isStartPoint = true;
int edgeIndexStart;
// int edgeBefore; upd by yu for erase warning 14.8.27
for(int i = 0; i < edgeSet.size(); i++)
{
//if (i==(edgeSet.size()-1))
// break;
pointEnd = pointSet[i+1];
double dis = gp_Vec(pointStart,pointEnd).Magnitude();
double d1,d2;
Handle_Geom_Curve curve = BRep_Tool::Curve(edgeSet[i], d1, d2);
TopExp_Explorer ex;
ex.Init(edgeSet[i],TopAbs_VERTEX);
gp_Pnt p1 = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
ex.Next();
gp_Pnt p2 = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
//GeomAdaptor_Curve C(curve);
//GCPnts_AbscissaPoint myAlgo;
//len += myAlgo.Length(C);
GProp_GProps System;
BRepGProp::LinearProperties(edgeSet[i],System);
gp_Pnt G = System.CentreOfMass ();
len += System.Mass();
if(fabs(len - dis) < len * 0.02)
{
isline = true;
//len += dis - System.Mass();
continue;
}
else
{
if(isline)
{
if(!isStartPoint)
{
if(lev - 2 < 0)
{
result.push_back(pointStart);
}
else
{
vector<TopoDS_Edge> tmpEdgeSet;
vector<gp_Pnt> tmpPointSet;
tmpEdgeSet.push_back(edgeSet[edgeIndexStart]);
tmpEdgeSet.push_back(edgeSet[edgeIndexStart + 1]);
double tmpStep = System.Mass() / pow(10.0, lev - 1);
tmpEdgeSet = GetEdgeSet(tmpEdgeSet, tmpStep, tmpPointSet);
vector<gp_Pnt> tmpResult = GetIntersections(tmpEdgeSet, tmpPointSet, lev - 1);
for(int k = 0; k < tmpResult.size(); k++)
{
result.push_back(tmpResult[k]);
}
}
}
if(lev - 2 < 0)
{
result.push_back(pointSet[i]);
}
else
{
vector<TopoDS_Edge> tmpEdgeSet;
vector<gp_Pnt> tmpPointSet;
tmpEdgeSet.push_back(edgeSet[i - 1]);
tmpEdgeSet.push_back(edgeSet[i]);
double tmpStep = System.Mass() / pow(10.0, lev - 1);
tmpEdgeSet = GetEdgeSet(tmpEdgeSet, tmpStep, tmpPointSet);
vector<gp_Pnt> tmpResult = GetIntersections(tmpEdgeSet, tmpPointSet, lev - 1);
for(int k = 0; k < tmpResult.size(); k++)
{
result.push_back(tmpResult[k]);
}
}
pointStart = pointSet[i];
i--;
len = 0;
isline = false;
}
else
{
pointStart = pointEnd;
edgeIndexStart = i;
len = 0;
isStartPoint = false;
}
}
}
if(isline && !isStartPoint)
{
if(lev - 2 < 0)
{
result.push_back(pointStart);
}
else
{
vector<TopoDS_Edge> tmpEdgeSet;
vector<gp_Pnt> tmpPointSet;
tmpEdgeSet.push_back(edgeSet[edgeIndexStart]);
tmpEdgeSet.push_back(edgeSet[edgeIndexStart + 1]);
TopExp_Explorer ex;
ex.Init(edgeSet[edgeIndexStart],TopAbs_VERTEX);
gp_Pnt p1 = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
ex.Next();
gp_Pnt p2 = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
double tmpStep = gp_Vec(p1,p2).Magnitude() / pow(10.0, lev - 1);
tmpEdgeSet = GetEdgeSet(tmpEdgeSet, tmpStep, tmpPointSet);
vector<gp_Pnt> tmpResult = GetIntersections(tmpEdgeSet, tmpPointSet, lev - 1);
for(int k = 0; k < tmpResult.size(); k++)
{
result.push_back(tmpResult[k]);
}
}
}
return result;
}
vector<TopoDS_Edge> OffsetGenerate1::GetEdgeSet(vector<TopoDS_Edge>& edgeSet, double step , vector<gp_Pnt>& pointSet)
{
vector<TopoDS_Edge> newEdgeSet;
pointSet.clear();
for(vector<TopoDS_Edge>::iterator iter = edgeSet.begin(); iter != edgeSet.end(); iter++)
{
TopoDS_Edge edge = *iter;
double df,dl;
Handle(Geom_Curve) aCur = BRep_Tool::Curve(edge,df,dl);
TopExp_Explorer ex(edge, TopAbs_VERTEX);
gp_Pnt startPoint = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
ex.Next();
gp_Pnt endPoint = BRep_Tool::Pnt(TopoDS::Vertex(ex.Current()));
Standard_Real st1 = 0;
Standard_Real st2 = 0;
double len = 0;
//GeomAPI_ProjectPointOnCurve Projector1 (startPoint, aCur); //gp_Pnt Bpnt
//GeomAPI_ProjectPointOnCurve Projector2 (endPoint, aCur); //gp_Pnt Bpnt
//st1 = Projector1.LowerDistanceParameter();
//st2 = Projector2.LowerDistanceParameter();
BaseAlgo algo;
st1 = algo.ProjectPointOnCurvePara(edge, startPoint);
st2 = algo.ProjectPointOnCurvePara(edge, startPoint);
len = fabs(st2 - st1);
double surplus = len;
double head = st1;
while(surplus > step * 1.5)
{
double tail = head + step;
Handle(Geom_TrimmedCurve) myTrimmed = new Geom_TrimmedCurve(aCur, head, tail);
newEdgeSet.push_back(BRepBuilderAPI_MakeEdge(myTrimmed).Edge());
if(pointSet.size() < 1)
{
pointSet.push_back(aCur->Value(head));
}
pointSet.push_back(aCur->Value(tail));
head = tail;
surplus -= step;
}
Handle(Geom_TrimmedCurve) myTrimmed = new Geom_TrimmedCurve(aCur, head, st2);
newEdgeSet.push_back(BRepBuilderAPI_MakeEdge(myTrimmed).Edge());
if(pointSet.size() < 0)
{
pointSet.push_back(aCur->Value(head));
}
pointSet.push_back(aCur->Value(st2));
}
return newEdgeSet;
}
//*根据站和水线位置,计算船壳相应位置的型值点 yc 20141222
int OffsetGenerate1::GetOffsetTableData(int stationNum, double stations[],int waterlineNum,double waterlines[], int pNum[], OffsetTablePoint *pnts, OffsetTablePoint *zmaxPnts,double *zmins,OffsetTablePoint *yPnts)
{
vector<gp_Pnt> pSet;
vector<gp_Pnt> zpmaxSet;
vector<gp_Pnt> ypSet;
OCCLib lib;
BaseAlgo algo;
//获取船壳
TopoDS_Shape shipShell;
if(dataMD.m_mapShellSurf.size()==1)
shipShell=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
if(shipShell.IsNull())
{
return 0;
}
for(int i = 0; i < stationNum; i++)
{
double x = stations[i];
//生成横剖面
TopoDS_Face stationFace = lib.CreateFaceByPoints(gp_Pnt(x, 200, 200),gp_Pnt(x, -200, 200),gp_Pnt(x, -200, -200),gp_Pnt(x, 200, -200));
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(stationFace);
//求交线
TopoDS_Shape stationLine;
BRepAlgoAPI_Section asect(stationFace,shipShell,Standard_False);
asect.ComputePCurveOn1(Standard_True);
asect.Approximation(Standard_True);
asect.Build();
TopoDS_Shape splitResult = asect.Shape();
for(int j = 0; j < waterlineNum; j++)
{
double z = waterlines[j];
//生成水线面
TopoDS_Face waterLineFace = lib.CreateFaceByPoints(gp_Pnt(200, 200, z),gp_Pnt(200, -200, z),gp_Pnt(-200, -200, -z),gp_Pnt(-200, 200, -z));
//与横剖线计算交点
vector<gp_Pnt> pSetTmp;
for(TopExp_Explorer ex(splitResult, TopAbs_EDGE); ex.More(); ex.Next())
{
double first,last;
TopoDS_Edge edge = TopoDS::Edge(ex.Current());
Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, first, last);
curve = new Geom_TrimmedCurve(curve, first, last);
GeomAPI_IntCS intcs_sn(curve, aSurface);
if (!intcs_sn.IsDone())
{
return 0;
}
int nPnt=intcs_sn.NbPoints();
for(int k = 0; k < nPnt; k++)
{
gp_Pnt pnt = intcs_sn.Point(k + 1);
if((abs(pnt.X() - x) < Precision::Confusion() && abs(pnt.Z() - z) < Precision::Confusion()) && !IsFindPoint(pSetTmp, pnt))
{
pSetTmp.push_back(pnt);
}
}
}//for(TopExp_Explorer ex(splitResult, TopAbs_EDGE); ex.More(); ex.Next())
pNum[i * waterlineNum + j] = pSetTmp.size();
for(int k = 0; k < pSetTmp.size(); k++)
{
pSet.push_back(pSetTmp[k]);
}
}// for(int j = 0; j < waterlineNum; j++)
//计算甲板边线
gp_Pnt pZmax(-100,-100,-100), pZmin(100, 100, 100), pY(100,100,100);
Bnd_Box box;
for(TopExp_Explorer ex(splitResult, TopAbs_EDGE); ex.More(); ex.Next())
{
TopoDS_Edge edge = TopoDS::Edge(ex.Current());
gp_Pnt p1,p2;
algo.GetEdgeStartEndPoint(edge, p1,p2);
BRepBndLib::Add(edge, box);
if(p1.Z() > pZmax.Z())
{
pZmax = p1;
}
if(p2.Z() > pZmax.Z())
{
pZmax = p2;
}
if(abs(p1.Y()) < Precision::Confusion())
{
pY = p1;
}
if(abs(p2.Y()) < Precision::Confusion())
{
pY = p2;
}
}
zpmaxSet.push_back(pZmax);
ypSet.push_back(pY);
double x1,x2,y1,y2,z1,z2;
box.SetGap(0.0);
box.Get(x1,y1,z1,x2,y2,z2);
zmins[i] = z1;
}//for(int i = 0; i < stationNum; i++)
for(int i = 0; i < pSet.size(); i++)
{
pnts[i].X = pSet[i].X();
pnts[i].Y = pSet[i].Y();
pnts[i].Z = pSet[i].Z();
}
for(int i = 0; i < zpmaxSet.size(); i++)
{
zmaxPnts[i].X = zpmaxSet[i].X();
zmaxPnts[i].Y = zpmaxSet[i].Y();
zmaxPnts[i].Z = zpmaxSet[i].Z();
}
for(int i = 0; i < ypSet.size(); i++)
{
yPnts[i].X = ypSet[i].X();
yPnts[i].Y = ypSet[i].Y();
yPnts[i].Z = ypSet[i].Z();
}
}
//判断点是否在集合中
bool OffsetGenerate1::IsFindPoint(vector<gp_Pnt> pSet, gp_Pnt p)
{
bool isfind = false;
for(int i = 0; i < pSet.size(); i++)
{
if(p.Distance(pSet[i]) < Precision::Confusion())
{
isfind = true;
break;
}
}
return isfind;
}
//*根据站和水线位置,计算船壳相应位置的型值点 yc 20141222
/// <summary>
/// 生成水线面,横剖面,纵剖面
/// </summary>
/// <param name="flag"> -1 x平面 =-2 y平面 =-3 z平面 </param>
/// <param name="pos"> 位置 </param>
/// <returns></returns>
TopoDS_Face OffsetGenerate1::CreateFace(int flag, double pos)
{
TopoDS_Face face;
gp_Pnt Or;
gp_Dir Norm;
switch(flag)
{
case -1:
Or=gp_Pnt(pos,0,0);
Norm=gp_Dir(1, 0.,0 );
break;
case -2:
Or=gp_Pnt(0,pos,0.);
Norm=gp_Dir(0., 1, 0.);
break;
case -3:
Or=gp_Pnt(0,0,pos);
Norm=gp_Dir(0., 0., 1.);
break;
default:
return face;
}
// gp_Pln pln(Or,Norm);
// Handle(Geom_Surface) aSurface =GC_MakePlane(pln).Value();
// //BRepBuilderAPI_MakeFace face1 =BRepBuilderAPI_MakeFace(aSurface);// XUEFENG DELETE 202009
// BRepBuilderAPI_MakeFace face1 =BRepBuilderAPI_MakeFace(aSurface, Precision::Confusion()); // XUEFENG ADDED 202009
// face=face1.Face();
return face;
}
/// <summary>
/// 求交线
/// </summary>
/// <param name="shape1"> </param>
/// <param name="shape2"> </param>
/// <returns></returns>
vector<TopoDS_Edge> OffsetGenerate1::GetSectionEdges(TopoDS_Shape shape1, TopoDS_Shape shape2)
{
vector<TopoDS_Edge> edges;
BRepAlgoAPI_Section asect(shape1,shape2,Standard_False);
asect.ComputePCurveOn1(Standard_True);
asect.Approximation(Standard_True);
asect.Build();
TopoDS_Shape splitResult = asect.Shape();
for (TopExp_Explorer Ex(splitResult,TopAbs_EDGE); Ex.More(); Ex.Next())
{
TopoDS_Edge anEdge =TopoDS::Edge(Ex.Current());
edges.push_back(anEdge);
//2016srq
////Handle_AIS_Shape aisShape=new AIS_Shape(anEdge);
////
//// myOCCViewer.myAISContext->Display(aisShape,false);
//AnyCore::ASceneNodePtr aisShape=myOCCViewer.TopoShapeToASceneNode(anEdge);
//
// myOCCViewer.ShowSceneNode(aisShape,false);
}
return edges;
}
/// <summary>
/// 求半船壳
/// </summary>
/// <param name="shape1"> </param>
/// <returns></returns>
void OffsetGenerate1::GetHalfShell()
{
if(dataMD.m_mapShellSurf.size()==1)
{
TopoDS_Shape shape2=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
OCCLib lib;
TopoDS_Solid solid = lib.CreateSolid(gp_Pnt(-1000,0,-10), 2000,100,100);
BRepAlgoAPI_Common newcut(solid ,shape2);
if(newcut.IsDone())
{
halfShell = newcut.Shape();
}
}
return ;
}
/// <summary>
/// 与船壳面求交线
/// </summary>
/// <param name="shape1"> </param>
/// <returns></returns>
vector<TopoDS_Edge> OffsetGenerate1::GetShellSectionEdges(TopoDS_Shape shape1)
{
vector<TopoDS_Edge> edges;
edges = GetSectionEdges(shape1, halfShell);
return edges;
}
/// <summary>
/// 线面求交点
/// </summary>
/// <param name="shape1"> </param>
/// <returns></returns>
vector<gp_Pnt> OffsetGenerate1::GetSectionPoints(TopoDS_Edge edge, TopoDS_Face face)
{
vector<gp_Pnt> pnts;
double first,last;
Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, first, last);
curve = new Geom_TrimmedCurve(curve, first, last);
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(face);
GeomAPI_IntCS intcs_sn(curve, aSurface);
if (!intcs_sn.IsDone())
{
return pnts;
}
int nPnt=intcs_sn.NbPoints();
for(int k = 0; k < nPnt; k++)
{
gp_Pnt pnt = intcs_sn.Point(k + 1);
pnts.push_back(pnt);
}
//if(pnts.size() == 0)
//{
// return GetSectionPoints1(edge, face);
//}
return pnts;
}
vector<gp_Pnt> OffsetGenerate1::GetSectionPoints1(TopoDS_Edge edge, TopoDS_Shape face)
{
vector<gp_Pnt> pnts;
BRepExtrema_DistShapeShape inter;
inter.LoadS1(edge);
inter .LoadS2(face);
inter.Perform();
int nPnt= inter.NbSolution();
for(int k = 0; k < nPnt; k++)
{
gp_Pnt pnt1 = inter.PointOnShape1(k+1);
gp_Pnt pnt2 = inter.PointOnShape2(k + 1);
//if(pnt1.Distance(pnt2) > Precision::Confusion())
//{
// continue;
//}
pnts.push_back(pnt1);
}
return pnts;
}
//根据xy或z的值删除点
vector<gp_Pnt> OffsetGenerate1::CleanPoints(vector<gp_Pnt> pSet, int flag, double pos)
{
vector<gp_Pnt> pnts;
for(int i = 0; i < pSet.size(); i++)
{
switch(flag)
{
case -1:
if(abs(pSet[i].X() - pos) <Precision::Confusion())
{
pnts.push_back(pSet[i]);
}
break;
case -2:
if(abs(pSet[i].Y() - pos) <Precision::Confusion())
{
pnts.push_back(pSet[i]);
}
break;
case -3:
if(abs(pSet[i].Z() - pos) <Precision::Confusion())
{
pnts.push_back(pSet[i]);
}
break;
default:
break;
}
}
return pnts;
}
//合并点集合
vector<gp_Pnt> OffsetGenerate1::AddPoints(vector<gp_Pnt> pSet1, vector<gp_Pnt> pSet2)
{
vector<gp_Pnt> pnts;
for(int i = 0; i < pSet1.size(); i++)
{
pnts.push_back(pSet1[i]);
}
for(int i = 0; i < pSet2.size(); i++)
{
bool isfind = false;
for(int j = 0; j < pnts.size(); j++)
{
if(pSet2[i].Distance(pnts[j]) < Precision::Confusion())
{
isfind = true;
break;
}
}
if(!isfind)
{
pnts.push_back(pSet2[i]);
}
}
return pnts;
}
//计算极值点
vector<gp_Pnt> OffsetGenerate1::GetExtremePoints(vector<gp_Pnt> pSet, int flag)
{
vector<gp_Pnt> pnts;
double val ;
switch(flag)
{
case 1:
val = -1e10;
for(int i = 0; i < pSet.size(); i++)
{
gp_Pnt p = pSet[i];
if(abs(p.X() - val) < Precision::Confusion())
{
pnts.push_back(p);
}
else if(p.X() > val)
{
val = p.X();
pnts.clear();
pnts.push_back(p);
}
}
break;
case 2:
val = -1e10;
for(int i = 0; i < pSet.size(); i++)
{
gp_Pnt p = pSet[i];
if(abs(p.Y() - val) < Precision::Confusion())
{
pnts.push_back(p);
}
else if(p.Y() > val)
{
val = p.Y();
pnts.clear();
pnts.push_back(p);
}
}
break;
case 3:
val = -1e10;
for(int i = 0; i < pSet.size(); i++)
{
gp_Pnt p = pSet[i];
if(abs(p.Z() - val) < Precision::Confusion())
{
pnts.push_back(p);
}
else if(p.Z() > val)
{
val = p.Z();
pnts.clear();
pnts.push_back(p);
}
}
break;
case -1:
val = 1e10;
for(int i = 0; i < pSet.size(); i++)
{
gp_Pnt p = pSet[i];
if(abs(p.X() - val) < Precision::Confusion())
{
pnts.push_back(p);
}
else if(p.X() < val)
{
val = p.X();
pnts.clear();
pnts.push_back(p);
}
}
break;
case -2:
val = 1e10;
for(int i = 0; i < pSet.size(); i++)
{
gp_Pnt p = pSet[i];
if(abs(p.Y() - val) < Precision::Confusion())
{
pnts.push_back(p);
}
else if(p.Y() < val)
{
val = p.Y();
pnts.clear();
pnts.push_back(p);
}
}
break;
case -3:
val = 1e10;
for(int i = 0; i < pSet.size(); i++)
{
gp_Pnt p = pSet[i];
if(abs(p.Z() - val) < Precision::Confusion())
{
pnts.push_back(p);
}
else if(p.Z() < val)
{
val = p.Z();
pnts.clear();
pnts.push_back(p);
}
}
break;
default:
break;
}
return pnts;
}
//甲板下移76mm
int OffsetGenerate1::GetMarginLineleData(int lens[], OffsetTablePoint *pnts)
{
TopoDS_Shape TopoShape,sshape1,sshape2, topoSolid;
//GetHalfShell();
if(dataMD.m_mapMainDeckSurf.size()==1)
sshape1=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapMainDeckSurf.begin()->first)->second;
else
return -1; //Volume;
if(dataMD.m_mapShellSurf.size()==1)
sshape2=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
else
return -1; //Volume;
//gp_Trsf theTransformation;
//theTransformation.SetTranslation(gp_Vec(0,0,-0.076));
//sshape1= BRepBuilderAPI_Transform(sshape1, theTransformation, false);
vector<TopoDS_Edge> edges;
//vector<TopoDS_Edge> edges = GetSectionEdges(sshape1, sshape2);
//甲板外边线
for(TopExp_Explorer ex(sshape1, TopAbs_EDGE); ex.More(); ex.Next())
{
TopoDS_Edge edge = TopoDS::Edge(ex.Current());
Bnd_Box boxE;
double xE1,xE2,yE1,yE2,zE1,zE2;
BRepBndLib::Add(edge, boxE);
boxE.SetGap(0.0);
boxE.Get(xE1,yE1,zE1,xE2,yE2,zE2);
if(yE1 < 0 || yE2 < 0)//负半边
{
continue;
}
else if(abs(yE1) <Precision::Confusion() && abs(yE2) < Precision::Confusion())//y=0
{
continue;
}
edges.push_back(edge);
}
Bnd_Box box;
double x1,x2,y1,y2,z1,z2;
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
BRepBndLib::Add(edge, box);
}
box.SetGap(0.0);
box.Get(x1,y1,z1,x2,y2,z2);
//-----------------------------------------------------------------------------------------------------------------------------
//艉端点
vector<gp_Pnt> pSetD;
TopoDS_Face fd = CreateFace(-1, x1);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
//pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
pSetD = AddPoints(pSetD, pSetDTmp);
}
pSetD = GetExtremePoints(pSetD, -1);
double xD = 10000,zD = 0;
for(int i = 0; i < pSetD.size(); i++)
{
if(xD > pSetD[i].X())
{
xD = pSetD[i].X();
zD = pSetD[i].Z();
}
}
fd = CreateFace(-3, zD - 0.076);
pSetD.clear();
vector<TopoDS_Edge> edgesD = GetSectionEdges(sshape2, fd);
for(vector<TopoDS_Edge>::iterator iter = edgesD.begin(); iter != edgesD.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
//pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
pSetD = AddPoints(pSetD, pSetDTmp);
}
pSetD = GetExtremePoints(pSetD, -1);
OPoints.insert(make_pair(OPoints.size(),pSetD));
//------------------------------------------------------------------------------------------------------
//站
int count = 0;
for(int i = 0; i < dataMD.m_mapStation.size(); i++)
{
double x = dataMD.m_mapStation[i];
vector<gp_Pnt> pSet;
//TopoDS_Face f = CreateFace(-1, x);
//vector<TopoDS_Edge> edgesS = GetSectionEdges(sshape2, f);
//if(edgesS.size() > 0)
//{
// Bnd_Box boxS;
// double xS1,xS2,yS1,yS2,zS1,zS2;
// for(vector<TopoDS_Edge>::iterator iter = edgesS.begin(); iter != edgesS.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// BRepBndLib::Add(edge, boxS);
// }
// boxS.SetGap(0.0);
// boxS.Get(xS1,yS1,zS1,xS2,yS2,zS2);
// f = CreateFace(-3, zS2- 0.076);
// for(vector<TopoDS_Edge>::iterator iter = edgesS.begin(); iter != edgesS.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// vector<gp_Pnt> pSetTmp = GetSectionPoints(edge, f);
// pSetTmp = CleanPoints(pSetTmp, -1, x);
// pSet = AddPoints(pSet, pSetTmp);
// count++;
// }
//}
TopoDS_Face f = CreateFace(-1, x);
double z = -1;
for(int k = 0; k < edges.size(); k++)
{
Bnd_Box boxE;
double xE1,xE2,yE1,yE2,zE1,zE2;
BRepBndLib::Add(edges[k], boxE);
boxE.SetGap(0.0);
boxE.Get(xE1,yE1,zE1,xE2,yE2,zE2);
if(xE2 < x || xE1 > x)
{
continue;
}
vector<gp_Pnt> pSetTmp = GetSectionPoints(edges[k], f);
if(pSetTmp.size() == 0)
{
continue;
}
z = pSetTmp[0].Z();
break;
}
if(z < 0)
{
continue;
}
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(gp_Pnt(x,100,z- 0.076), gp_Pnt(x,-100,z- 0.076));
vector<gp_Pnt> pSetTmp = GetSectionPoints1(edge, sshape2);
pSetTmp = CleanPoints(pSetTmp, -1, x);
pSet = AddPoints(pSet, pSetTmp);
OPoints.insert(make_pair(OPoints.size(),pSet));
}
//----------------------------------------------------------------------------------------------
//艏端点
vector<gp_Pnt> pSetF;
TopoDS_Face ff = CreateFace(-1, x2);
for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
//pSetFTmp = CleanPoints(pSetFTmp, -1, x1);
pSetF = AddPoints(pSetF, pSetFTmp);
}
pSetF = GetExtremePoints(pSetF, 1);
double xF = -10000,zF = 0;
for(int i = 0; i < pSetF.size(); i++)
{
if(xF < pSetF[i].X())
{
xF = pSetF[i].X();
zF = pSetF[i].Z();
}
}
ff = CreateFace(-3, zF - 0.076);
pSetF.clear();
vector<TopoDS_Edge> edgesF = GetSectionEdges(sshape2, ff);
for(vector<TopoDS_Edge>::iterator iter = edgesF.begin(); iter != edgesF.end(); iter++)
{
TopoDS_Edge edge = TopoDS::Edge(*iter);
vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
//pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
pSetF = AddPoints(pSetF, pSetFTmp);
}
pSetF = GetExtremePoints(pSetF, 1);
OPoints.insert(make_pair(OPoints.size(),pSetF));
map<int,vector<gp_Pnt>>::iterator it;
it=OPoints.begin();
int i = 0;
int j=0;
int cnt=0;
while(it!=OPoints.end()){
for (j=0;j<it->second.size();j++)
{
if(it->second[j].Y() < 0)
{
continue;
}
pnts[cnt].X= it->second[j].X();
pnts[cnt].Y = it->second[j].Y();
pnts[cnt++].Z = it->second[j].Z();
break;
}
//cnt = cnt+j;
//lens[i] = j;
i++;
it++;
}
lens[0] = OPoints.size();
return 0;
}
//int OffsetGenerate1::GetMarginLineleData(int lens[], OffsetTablePoint *pnts)
//{
// TopoDS_Shape TopoShape,sshape1,sshape2, topoSolid;
// //GetHalfShell();
// if(dataMD.m_mapMainDeckSurf.size()==1)
// sshape1=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapMainDeckSurf.begin()->first)->second;
// else
// return -1; //Volume;
// if(dataMD.m_mapShellSurf.size()==1)
// sshape2=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
// else
// return -1; //Volume;
//
// //gp_Trsf theTransformation;
// //theTransformation.SetTranslation(gp_Vec(0,0,-0.076));
// //sshape1= BRepBuilderAPI_Transform(sshape1, theTransformation, false);
//
// vector<TopoDS_Edge> edges = GetSectionEdges(sshape1, sshape2);
// Bnd_Box box;
// double x1,x2,y1,y2,z1,z2;
// for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// BRepBndLib::Add(edge, box);
// }
// box.SetGap(0.0);
// box.Get(x1,y1,z1,x2,y2,z2);
// //-----------------------------------------------------------------------------------------------------------------------------
// //艉端点
// vector<gp_Pnt> pSetD;
// TopoDS_Face fd = CreateFace(-1, x1);
// for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
// //pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
// pSetD = AddPoints(pSetD, pSetDTmp);
// }
// pSetD = GetExtremePoints(pSetD, -1);
// double xD = 10000,zD = 0;
// for(int i = 0; i < pSetD.size(); i++)
// {
// if(xD > pSetD[i].X())
// {
// xD = pSetD[i].X();
// zD = pSetD[i].Z();
// }
// }
// fd = CreateFace(-3, zD - 0.076);
// pSetD.clear();
// vector<TopoDS_Edge> edgesD = GetSectionEdges(sshape2, fd);
// for(vector<TopoDS_Edge>::iterator iter = edgesD.begin(); iter != edgesD.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// vector<gp_Pnt> pSetDTmp = GetSectionPoints1(edge, fd);
// //pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
// pSetD = AddPoints(pSetD, pSetDTmp);
// }
// pSetD = GetExtremePoints(pSetD, -1);
// OPoints.insert(make_pair(OPoints.size(),pSetD));
// //------------------------------------------------------------------------------------------------------
// //站
// int count = 0;
// for(int i = 0; i < dataMD.m_mapStation.size(); i++)
// {
// double x = dataMD.m_mapStation[i];
// vector<gp_Pnt> pSet;
// TopoDS_Face f = CreateFace(-1, x);
// vector<TopoDS_Edge> edgesS = GetSectionEdges(sshape2, f);
// if(edgesS.size() > 0)
// {
// Bnd_Box boxS;
// double xS1,xS2,yS1,yS2,zS1,zS2;
// for(vector<TopoDS_Edge>::iterator iter = edgesS.begin(); iter != edgesS.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// BRepBndLib::Add(edge, boxS);
// }
// boxS.SetGap(0.0);
// boxS.Get(xS1,yS1,zS1,xS2,yS2,zS2);
// f = CreateFace(-3, zS2- 0.076);
//
// for(vector<TopoDS_Edge>::iterator iter = edgesS.begin(); iter != edgesS.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// vector<gp_Pnt> pSetTmp = GetSectionPoints(edge, f);
// pSetTmp = CleanPoints(pSetTmp, -1, x);
// pSet = AddPoints(pSet, pSetTmp);
// count++;
// }
// }
// OPoints.insert(make_pair(OPoints.size(),pSet));
// }
// //----------------------------------------------------------------------------------------------
// //艏端点
// vector<gp_Pnt> pSetF;
// TopoDS_Face ff = CreateFace(-1, x2);
// for(vector<TopoDS_Edge>::iterator iter = edges.begin(); iter != edges.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
// //pSetFTmp = CleanPoints(pSetFTmp, -1, x1);
// pSetF = AddPoints(pSetF, pSetFTmp);
// }
// pSetF = GetExtremePoints(pSetF, 1);
//
// double xF = -10000,zF = 0;
// for(int i = 0; i < pSetF.size(); i++)
// {
// if(xF < pSetF[i].X())
// {
// xF = pSetF[i].X();
// zF = pSetF[i].Z();
// }
// }
// ff = CreateFace(-3, zF - 0.076);
// pSetF.clear();
// vector<TopoDS_Edge> edgesF = GetSectionEdges(sshape2, ff);
// for(vector<TopoDS_Edge>::iterator iter = edgesF.begin(); iter != edgesF.end(); iter++)
// {
// TopoDS_Edge edge = TopoDS::Edge(*iter);
// vector<gp_Pnt> pSetFTmp = GetSectionPoints1(edge, ff);
// //pSetDTmp = CleanPoints(pSetDTmp, -1, x2);
// pSetF = AddPoints(pSetF, pSetFTmp);
// }
// pSetF = GetExtremePoints(pSetF, 1);
// OPoints.insert(make_pair(OPoints.size(),pSetF));
//
// map<int,vector<gp_Pnt>>::iterator it;
// it=OPoints.begin();
//
// int i = 0;
// int j=0;
// int cnt=0;
// while(it!=OPoints.end()){
// for (j=0;j<it->second.size();j++)
// {
// if(it->second[j].Y() < 0)
// {
// continue;
// }
// pnts[cnt].X= it->second[j].X();
// pnts[cnt].Y = it->second[j].Y();
// pnts[cnt++].Z = it->second[j].Z();
// break;
// }
// //cnt = cnt+j;
// //lens[i] = j;
// i++;
// it++;
// }
// lens[0] = OPoints.size();
// return 0;
//}