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

2843 lines
74 KiB
C++
Raw Normal View History

2025-06-25 15:06:42 +08:00
#include "Stdafx.h"
#include "DllImportViewControl.h"
//#include "OCCViewer.h"
//2016srq
//#include "ISession_Text.h"
//#include "Quantity_Color.hxx"
// DELETE BY XUEFENG 20180731
// FOR CODES COMBINE
/*
#include "Style/AFaceStyle.h"
#include "Style/APointStyle.h"
#include "Node/ATextNode.h"
#include "Node/APointNode.h"
#include "Node/AScreenWidget.h"
#include "Render/ARenderWindow.h"
#include "DataType/ACamera.h"
#include "TopoShape/ATopoShapeImpl.h"
#include "Geometry/ARenderableGeometry.h"
#include "View/ARenderer.h"
#include "DataType/ASceneEnvironment.h"
using namespace AnyCore;
//end
*/
// END DELETE
// ADDED BY XUEFENG 20180731
// FOR CODES COMBINE
#include "Prs3d_PointAspect.hxx"
// #include "AIS_Drawer.hxx" // XUEFENG DELETE 202009
#include "CCS_AISShape.h"
#include "Graphic3d_Group.hxx"
#include "Graphic3d_AspectText3d.hxx"
#include "Prs3d_Root.hxx"
// END ADDED
#include "BaseAlgo.h"
//extern OCCViewer myOCCViewer;
extern OCCStructDataMD dataMD;
/*
DLLEXPORT BOOL InitView(int viewsize,HWND hwnd[])
{
if( myOCCViewer.InitViewer(viewsize, hwnd))
{
myOCCViewer.AxoViewF(0);
return TRUE;
}
else
return FALSE;
}
DLLEXPORT void RedrawView(int flag)
{
myOCCViewer.RedrawView(flag);
}
DLLEXPORT void UpdateView(int flag)
{
myOCCViewer.UpdateView(flag);
}
// ADDED BY XUEFENG 20181201
DLLEXPORT void ResetView()
{
myOCCViewer.ResetView();
}
// END ADDED
DLLEXPORT void ZoomWheel(float delta,int flag)
{
myOCCViewer.ZoomWheel(delta,flag);
//myOCCViewer.DepthFitAll(flag);
//20170801 added by czb
bool fflag;
int ID= myOCCViewer.GetCurrentSelectedId(fflag);
int type=ID/MAX_SIZE_OF_OBJECT_GROUP;
if ( myOCCViewer.GetNumofSelected()==1 && type>=1 &&type<2)
{
// DELETE BY XUEFENG 20181020 Why Add?
//ShowPointOnLine(ID);//如果只选中一根线,则要显示线上的点
// END DELETE
}
}
DLLEXPORT void StartRotation(int x,int y,int flag)
{
myOCCViewer.StartRotation(x,y,flag);
//myOCCViewer.DepthFitAll(flag);
//20170801 added by czb
bool fflag;
int ID= myOCCViewer.GetCurrentSelectedId(fflag);
int type=ID/MAX_SIZE_OF_OBJECT_GROUP;
if ( myOCCViewer.GetNumofSelected()==1 && type>=1 &&type<2)
{
// DELETE BY XUEFENG 20181020
//ShowPointOnLine(ID);//如果只选中一根线,则要显示线上的点
// END DELETE
}
}
DLLEXPORT void Rotation(int x, int y,int flag)
{
myOCCViewer.Rotation(x,y,flag);
//myOCCViewer.DepthFitAll(flag);
//20170801 added by czb
bool fflag;
int ID= myOCCViewer.GetCurrentSelectedId(fflag);
int type=ID/MAX_SIZE_OF_OBJECT_GROUP;
if ( myOCCViewer.GetNumofSelected()==1 && type>=1 &&type<2)
{
// DELETE BY XUEFENG 20181020
//ShowPointOnLine(ID);//如果只选中一根线,则要显示线上的点
// END DELETE
}
}
DLLEXPORT void Select()
{
myOCCViewer.Select();
//myOCCViewer.DepthFitAll(2);
}
DLLEXPORT void MoveTo(int x,int y ,int flag)
{
if(dataMD.m_mapAllTopoShapes.size()>0)
{
myOCCViewer.MoveTo(x,y,flag);
// myOCCViewer.DepthFitAll(flag);
}
}
DLLEXPORT void Pan(int x, int y, int flag)
{
myOCCViewer.Pan(x,y,flag);
//myOCCViewer.DepthFitAll(flag);
//20170801 added by czb
bool fflag;
int ID= myOCCViewer.GetCurrentSelectedId(fflag);
int type=ID/MAX_SIZE_OF_OBJECT_GROUP;
if ( myOCCViewer.GetNumofSelected()==1 && type>=1 &&type<2)
{
// DELETE BY XUEFENG 20181020
//ShowPointOnLine(ID);//如果只选中一根线,则要显示线上的点
// END DELETE
}
}
DLLEXPORT void FitAll(int flag,bool isUpdate)
{
myOCCViewer.FitAll(flag,isUpdate);
// myOCCViewer.DepthFitAll(flag);
//20170801 added by czb
bool fflag;
int ID= myOCCViewer.GetCurrentSelectedId(fflag);
int type=ID/MAX_SIZE_OF_OBJECT_GROUP;
if ( myOCCViewer.GetNumofSelected()==1 && type>=1 &&type<2)
{
// DELETE BY XUEFENG 20181020
//ShowPointOnLine(ID);//如果只选中一根线,则要显示线上的点
// END DELETE
}
}
DLLEXPORT void WindowFitAll(int myXmin, int myYmin, int myXmax, int myYmax)
{
myOCCViewer.WindowFitAll(myXmin,myYmin,myXmax,myYmax);
}
DLLEXPORT void SetDisplayMode(int mode)
{
dataMD.m_bshowPoint=(bool)(mode & 1);
dataMD.m_bshowCurve=(bool)(mode & 2);
dataMD.m_bshowSurface=(bool)(mode & 4);
dataMD.m_bshowSolid=(bool)(mode & 8);
dataMD.m_bshowMainDeck=(bool)(mode & 16);
dataMD.m_bshowShell=(bool)(mode & 32);
dataMD.m_bshowDeck=(bool)(mode & 64);
dataMD.m_bshowBound=(bool)(mode & 128);
dataMD.m_bshowSubdiv=(bool)(mode & 256);
dataMD.m_bshowOpenCargoRegion=(bool)(mode & 512);
dataMD.m_bshowSpace=(bool)(mode & 1024);
dataMD.m_bshowAppendage=(bool)(mode & 2048);
dataMD.m_bshowFrameRuler=(bool)(mode & 4096);
dataMD.m_bshowHull=(bool)(mode & 8192);
dataMD.m_bshowMainHull = (bool)(mode&16384);
dataMD.m_bshowSpaceElement = (bool)(mode & 0x8000);
RedrawTypeObjProps();
}
DLLEXPORT void SetAISDisplayMode(int aMode)
{
myOCCViewer.SetAISDisplayMode(aMode);
}
DLLEXPORT void SetViewDirection(int flag, int dir)
{
// dir--0前,1后,2顶,3底,4左,5右,6侧前,7侧后***
switch (dir)
{
case 0:
myOCCViewer.FrontView(flag);
break;
case 1:
myOCCViewer.BackView(flag);
break;
case 2:
myOCCViewer.TopView (flag);
break;
case 3:
myOCCViewer.BottomView(flag);
break;
case 4:
myOCCViewer.LeftView(flag);
break;
case 5:
myOCCViewer.RightView(flag);
break;
case 6:
myOCCViewer.AxoViewF(flag);
break;
case 7:
myOCCViewer.AxoViewB(flag);
break;
default:
break;
}
//myOCCViewer.DepthFitAll(flag);
//20170801 added by czb
bool fflag;
int ID= myOCCViewer.GetCurrentSelectedId(fflag);
int type=ID/MAX_SIZE_OF_OBJECT_GROUP;
if ( myOCCViewer.GetNumofSelected()==1 && type>=1 &&type<2)
{
ShowPointOnLine(ID);//如果只选中一根线,则要显示线上的点
}
}
//打开或关闭定时器 Lvxj
DLLEXPORT void EnableTimer(bool isTimerEnable)
{
myOCCViewer.EnAbleTimer(isTimerEnable);
}
DLLEXPORT BOOL SelectOneMode(int x, int y,int ids[],int flag, double &rx, double &ry, double &rz,bool bctrlselect)
{
}
DLLEXPORT BOOL SelectFrameMode(int prex,int prey,int x,int y,int flag,int IDs[],double &rx, double &ry, double &rz,bool bctrlselect)
{
}
DLLEXPORT BOOL SelectOppositeFrameMode(int prex,int prey,int x,int y,int flag,int IDs[],double &rx, double &ry, double &rz,bool bctrlselect)
{
}
DLLEXPORT bool HiLight( int id [])
{
return true;
}
*/
DLLEXPORT void SetObjVisible(int n,int ids[], int visibles[])
{
}
DLLEXPORT void SetInteractType(int type)
{
//设置图形交互类型(可选择对象类型) type可选择对象类型:0所有图元,1屏幕任意位置,2曲线节点(knot)
dataMD.m_curInteractType=type;
}
DLLEXPORT int GenShapeLine2(double x, ScPoint2D *pt,bool withDeck, int dir, double v)
{
std::map<double ,ScPoint2D> pitmap;
std::map<double ,ScPoint2D>::iterator ptit;
std::map<double ,ScPoint2D> pitmap2;
std::map<double ,ScPoint2D>::iterator ptit2;
TopoDS_Edge tpinsecedge;
double dF,dL;
double dF2,dL2;
gp_Pnt fp,ep,fp2,ep2,tempp;
TopoDS_Shape TopoShape,sshape1,sshape2,sshapeship,sshapetemp;
double step=0.2;
int ptnum=0;
BRepBuilderAPI_MakeWire wiretest ;
TopExp_Explorer ex;
bool insertbehind=false;
if(dataMD.m_mapMainDeckSurf.size()==1)
sshape1=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapMainDeckSurf.begin()->first)->second;
else
return ptnum;
if(dataMD.m_mapShellSurf.size()==1)
sshape2=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
else
return ptnum;
double miny=-100;
double maxy=100;
double minx=x;
double maxx=x;
double minz=-50;
double maxz=100;
gp_Pnt p1;
gp_Pnt p2;
gp_Pnt p3;
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,miny,maxz);
p3=gp_Pnt(minx,maxy,maxz);
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
{
}
else
{
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
sshapetemp = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
}
}
//缝合后求交
BRepOffsetAPI_Sewing aMethod;
aMethod.Add(sshape1);
aMethod.Add(sshape2);
aMethod.Perform();
sshapeship = aMethod.SewedShape();
BRepAlgoAPI_Section sec1(sshapeship,sshapetemp,Standard_False);
sec1.ComputePCurveOn1(Standard_True);
sec1.Approximation(TopOpeBRepTool_APPROX);
BOOL bDone = TRUE;
try
{
sec1.Build();
}
catch(Standard_Failure)
{
bDone = FALSE;
}
if(!bDone || !sec1.IsDone())
{
return ptnum;
}
TopoDS_Shape splitResult = sec1.Shape();
list<TopoDS_Edge> edgeList;
dataMD.GetInsectWirePts( splitResult,edgeList );
//方法一、船壳甲板线弯曲!!!!
//tpinsecedge=dataMD.SetInsectWireToEdge(edgeList);
//Handle(Geom_Curve) aCur= BRep_Tool::Curve(tpinsecedge,dF,dL);
//if(dir==0)//返回所有点
//{
// int k=(int)(dL-dF)/step;
// if (k>0)
// {
// fp=aCur->Value(dF);
// ep=aCur->Value(dL);
// for(int i=0;i<k;i++)
// {
// gp_Pnt pt1=aCur->Value(dF+step*i);
// (pt+ptnum)->Y=pt1.Y();
// (pt+ptnum)->Z=pt1.Z();
// ptnum++;
// }
// }
//}
//else if(dir==1)//返回与y= v的交点
//{
// gp_Pnt Or=gp_Pnt(0,0,0.);
// gp_Dir Norm=gp_Dir(0., 1, 0.);
// gp_Pln pln(Or,Norm);
// Handle(Geom_Surface) aSurface =GC_MakePlane(pln).Value();
// GeomAPI_IntCS intcs_sn(aCur, aSurface);
// if (!intcs_sn.IsDone())
// {
// dataMD.errorinfo="交点生成失败 ";
// return 0;
// }
// int nPnt=intcs_sn.NbPoints();
// if (nPnt<= 0)
// {
// dataMD.errorinfo="不能相交,没有交点 ";
// return 0;
// }
// for(int i=1;i<=nPnt;i++)
// {
// gp_Pnt interpt = intcs_sn.Point(i);
// BRepBuilderAPI_MakeVertex newv(interpt);
// if(!newv.IsDone())
// {
// dataMD.errorinfo="生成交点失败";
// return 0;
// }
// if(abs(interpt.X())<10e-14)
// interpt.SetX(0.0);
// if(abs(interpt.Y())<10e-14)
// interpt.SetY(0.0);
// if(abs(interpt.Z())<10e-14)
// interpt.SetZ(0.0);
// (pt+ptnum)->Y=interpt.Y();
// (pt+ptnum)->Z=interpt.Z();
// ptnum++;
// }
//}
//else if(dir==2)//返回与z= v的交点
//{
// gp_Pnt Or=gp_Pnt(0,0,1);
// gp_Dir Norm=gp_Dir(0.,0, 1);
// gp_Pln pln(Or,Norm);
// Handle(Geom_Surface) aSurface =GC_MakePlane(pln).Value();
// GeomAPI_IntCS intcs_sn(aCur, aSurface);
// if (!intcs_sn.IsDone())
// {
// dataMD.errorinfo="交点生成失败 ";
// return 0;
// }
// int nPnt=intcs_sn.NbPoints();
// if (nPnt<= 0)
// {
// dataMD.errorinfo="不能相交,没有交点 ";
// return 0;
// }
// for(int i=1;i<=nPnt;i++)
// {
// gp_Pnt interpt = intcs_sn.Point(i);
// BRepBuilderAPI_MakeVertex newv(interpt);
// if(!newv.IsDone())
// {
// dataMD.errorinfo="生成交点失败";
// return 0;
// }
// if(abs(interpt.X())<10e-14)
// interpt.SetX(0.0);
// if(abs(interpt.Y())<10e-14)
// interpt.SetY(0.0);
// if(abs(interpt.Z())<10e-14)
// interpt.SetZ(0.0);
// (pt+ptnum)->Y=interpt.Y();
// (pt+ptnum)->Z=interpt.Z();
// ptnum++;
// }
//}
//else
//{
// return 0;
//}
////方法二、测试无问题,
//list<TopoDS_Edge>::iterator iter1,iter2;
//int i=0;
//if(dir==0)
//{
// if(edgeList.size()>2)
// {
// iter1 = edgeList.begin();
// iter2=edgeList.begin();
// iter2++;
// Handle(Geom_Curve) aBeginCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
// Handle(Geom_Curve) aNextCur = BRep_Tool::Curve(TopoDS::Edge(*iter2),dF2,dL2);
// fp=aBeginCur->Value(dF);
// ep=aBeginCur->Value(dL);
// fp2=aNextCur->Value(dF2);
// ep2=aNextCur->Value(dL2);
// if(abs(fp.Distance(fp2))<10e-5)
// {
// tempp=ep;
// }
// else if(abs(fp.Distance(ep2))<10e-5)
// {
// tempp=ep;
// }
// else if(abs(ep.Distance(fp2))<10e-5)
// {
// tempp=fp;
// }
// else if(abs(ep.Distance(ep2))<10e-5)
// {
// tempp=fp;
// }
// for(iter1 = edgeList.begin();iter1 != edgeList.end(); iter1++)
// {
// Handle(Geom_Curve) aCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
// int k=(int)((dL-dF)/step);
// k=k>0?k:1;
// k=k>15?15:k;
// if(k>0)
// {
// fp=aCur->Value(dF);
// ep=aCur->Value(dL);
// if(abs(fp.Distance(tempp))<10e-5)
// {
// for(i=0;i<k;i++)
// {
// gp_Pnt pt1=aCur->Value(dF+step*i);
// if(i==0)
// {
// if(ptnum==0)
// {
// (pt+ptnum)->Y=fp.Y();
// (pt+ptnum)->Z=fp.Z();
// ptnum++;
// }
// }
// else
// {
// (pt+ptnum)->Y=pt1.Y();
// (pt+ptnum)->Z=pt1.Z();
// ptnum++;
// }
// }
// if(i==k)
// {
// (pt+ptnum)->Y=ep.Y();
// (pt+ptnum)->Z=ep.Z();
// ptnum++;
// }
// tempp=ep;
// }
// else
// {
// for(i=0;i<k;i++)
// {
// gp_Pnt pt1=aCur->Value(dL-step*i);
// if(i==0)
// {
// if(ptnum==0)
// {
// (pt+ptnum)->Y=ep.Y();
// (pt+ptnum)->Z=ep.Z();
// ptnum++;
// }
// }
// else
// {
// (pt+ptnum)->Y=pt1.Y();
// (pt+ptnum)->Z=pt1.Z();
// ptnum++;
// }
// }
// if(i==k)
// {
// (pt+ptnum)->Y=fp.Y();
// (pt+ptnum)->Z=fp.Z();
// ptnum++;
// }
// tempp=fp;
// }
// }
// }
// double b1=(pt+ptnum-1)->Y-(pt)->Y;
// double b2=(pt+ptnum-1)->Z-(pt)->Z;
// if((abs(b1)<10e-5)&&(abs(b2)<10e-5))
// ptnum--;
// }
//}
//else if(dir==1)//返回与y= v的交点
//{
// Handle(Geom_Surface) aSurface;
// TopoDS_Shape aface;
// double miny,maxy,minx,maxx,minz,maxz;
// minz=-0.2*dataMD.m_shipDepth<-1?-0.2*dataMD.m_shipDepth:-100;
// maxz=1.2*dataMD.m_shipDepth>1?1.2*dataMD.m_shipDepth:100;
// minx=x;
// maxx=x;
// maxy=v;
// miny=-100;
// p1=gp_Pnt(minx,miny,minz);
// p2=gp_Pnt(minx,maxy,minz);
// p3=gp_Pnt(minx,maxy,maxz);
// gp_Lin aLin(p1,gp_Vec(p1,p2));
// double dist = aLin.Distance(p3);
// if(dist < Precision::Confusion())
// return FALSE;
// TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
// if(!aE.IsNull())
// {
// //计算拉伸方向
// gp_Lin aDLin = aLin.Normal(p3);
// double x,y,z;
// aDLin.Direction().Coord(x,y,z);
// aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
// aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
// }
// if(edgeList.size()>0)
// {
// for(iter1 = edgeList.begin();iter1 != edgeList.end(); iter1++)
// {
// Handle(Geom_Curve) aCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
// GeomAPI_IntCS intcs_sn(aCur, aSurface);
// if (!intcs_sn.IsDone())
// {
// dataMD.errorinfo="交点生成失败 ";
// return 0;
// }
// int nPnt=intcs_sn.NbPoints();
// if (nPnt<= 0)
// {
// continue;
// }
// for(int i=1;i<=nPnt;i++)
// {
// gp_Pnt interpt = intcs_sn.Point(i);
// BRepBuilderAPI_MakeVertex newv(interpt);
// if(abs(interpt.X())<10e-14)
// interpt.SetX(0.0);
// if(abs(interpt.Y())<10e-14)
// interpt.SetY(0.0);
// if(abs(interpt.Z())<10e-14)
// interpt.SetZ(0.0);
// (pt+ptnum)->Y=interpt.Y();
// (pt+ptnum)->Z=interpt.Z();
// ptnum++;
// }
// }
// }
//}
//else if(dir==2)//返回与z= v的交点
//{
// Handle(Geom_Surface) aSurface;
// TopoDS_Shape aface;
// double miny,maxy,minx,maxx,minz,maxz;
// miny=-dataMD.m_shipWidth<-1?-dataMD.m_shipWidth:-100;
// maxy=dataMD.m_shipWidth>1?dataMD.m_shipWidth:100;
// minx=x;
// maxx=x;
// minz=-100;
// maxz=v;
// p1=gp_Pnt(minx,miny,minz);
// p2=gp_Pnt(minx,miny,maxz);
// p3=gp_Pnt(minx,maxy,maxz);
// gp_Lin aLin(p1,gp_Vec(p1,p2));
// double dist = aLin.Distance(p3);
// if(dist < Precision::Confusion())
// return FALSE;
// TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
// if(!aE.IsNull())
// {
// //计算拉伸方向
// gp_Lin aDLin = aLin.Normal(p3);
// double x,y,z;
// aDLin.Direction().Coord(x,y,z);
// aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
// aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
// }
// if(edgeList.size()>0)
// {
// for(iter1 = edgeList.begin();iter1 != edgeList.end(); iter1++)
// {
// Handle(Geom_Curve) aCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
// GeomAPI_IntCS intcs_sn(aCur, aSurface);
// if (!intcs_sn.IsDone())
// {
// dataMD.errorinfo="交点生成失败 ";
// return 0;
// }
// int nPnt=intcs_sn.NbPoints();
// if (nPnt<= 0)
// {
// continue;
// }
// for(int i=1;i<=nPnt;i++)
// {
// gp_Pnt interpt = intcs_sn.Point(i);
// BRepBuilderAPI_MakeVertex newv(interpt);
// if(abs(interpt.X())<10e-14)
// interpt.SetX(0.0);
// if(abs(interpt.Y())<10e-14)
// interpt.SetY(0.0);
// if(abs(interpt.Z())<10e-14)
// interpt.SetZ(0.0);
// (pt+ptnum)->Y=interpt.Y();
// (pt+ptnum)->Z=interpt.Z();
// ptnum++;
// }
// }
// }
//}
//else
//{
// return 0;
//}
//方法三
list<TopoDS_Edge>::iterator iter1,iter2;
int i=0;
if(dir==0)
{
if(edgeList.size()>2)
{
iter1 = edgeList.begin();
iter2=edgeList.begin();
iter2++;
Handle(Geom_Curve) aBeginCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
Handle(Geom_Curve) aNextCur = BRep_Tool::Curve(TopoDS::Edge(*iter2),dF2,dL2);
fp=aBeginCur->Value(dF);
ep=aBeginCur->Value(dL);
fp2=aNextCur->Value(dF2);
ep2=aNextCur->Value(dL2);
if(abs(fp.Distance(fp2))<10e-5)
{
tempp=ep;
}
else if(abs(fp.Distance(ep2))<10e-5)
{
tempp=ep;
}
else if(abs(ep.Distance(fp2))<10e-5)
{
tempp=fp;
}
else if(abs(ep.Distance(ep2))<10e-5)
{
tempp=fp;
}
for(iter1 = edgeList.begin();iter1 != edgeList.end(); iter1++)
{
Handle(Geom_Curve) aCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
int k=(int)((dL-dF)/step);
k=k>0?k:1;
k=k>15?15:k;
if(k>0)
{
fp=aCur->Value(dF);
ep=aCur->Value(dL);
if(abs(fp.Distance(tempp))<10e-5)
{
for(i=0;i<k;i++)
{
gp_Pnt pt1=aCur->Value(dF+step*i);
if(i==0)
{
if(ptnum==0)
{
(pt+ptnum)->Y=fp.Y();
(pt+ptnum)->Z=fp.Z();
ptnum++;
}
}
else
{
(pt+ptnum)->Y=pt1.Y();
(pt+ptnum)->Z=pt1.Z();
ptnum++;
}
}
if(i==k)
{
(pt+ptnum)->Y=ep.Y();
(pt+ptnum)->Z=ep.Z();
ptnum++;
}
tempp=ep;
}
else
{
for(i=0;i<k;i++)
{
gp_Pnt pt1=aCur->Value(dL-step*i);
if(i==0)
{
if(ptnum==0)
{
(pt+ptnum)->Y=ep.Y();
(pt+ptnum)->Z=ep.Z();
ptnum++;
}
}
else
{
(pt+ptnum)->Y=pt1.Y();
(pt+ptnum)->Z=pt1.Z();
ptnum++;
}
}
if(i==k)
{
(pt+ptnum)->Y=fp.Y();
(pt+ptnum)->Z=fp.Z();
ptnum++;
}
tempp=fp;
}
}
}
double b1=(pt+ptnum-1)->Y-(pt)->Y;
double b2=(pt+ptnum-1)->Z-(pt)->Z;
if((abs(b1)<10e-5)&&(abs(b2)<10e-5))
ptnum--;
}
}
else if(dir==1)//返回与y= v的交点
{
tpinsecedge=dataMD.SetInsectWireToEdge(edgeList);
Handle(Geom_Curve) aCur= BRep_Tool::Curve(tpinsecedge,dF,dL);
Handle(Geom_Surface) aSurface;
TopoDS_Shape aface;
double miny,maxy,minx,maxx,minz,maxz;
minz=-0.2*dataMD.m_shipDepth<-1?-0.2*dataMD.m_shipDepth:-100;
maxz=1.2*dataMD.m_shipDepth>1?1.2*dataMD.m_shipDepth:100;
minx=-100;
maxx=100;
maxy=v;
miny=v;
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,miny,maxz);
p3=gp_Pnt(maxx,miny,maxz);
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
return FALSE;
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
}
GeomAPI_IntCS intcs_sn(aCur, aSurface);
if (!intcs_sn.IsDone())
{
dataMD.errorinfo="交点生成失败 ";
return 0;
}
int nPnt=intcs_sn.NbPoints();
for(int i=1;i<=nPnt;i++)
{
gp_Pnt interpt = intcs_sn.Point(i);
BRepBuilderAPI_MakeVertex newv(interpt);
if(abs(interpt.X())<10e-14)
interpt.SetX(0.0);
if(abs(interpt.Y())<10e-14)
interpt.SetY(0.0);
if(abs(interpt.Z())<10e-14)
interpt.SetZ(0.0);
(pt+ptnum)->Y=interpt.Y();
(pt+ptnum)->Z=interpt.Z();
ptnum++;
}
}
else if(dir==2)//返回与z= v的交点
{
tpinsecedge=dataMD.SetInsectWireToEdge(edgeList);
Handle(Geom_Curve) aCur= BRep_Tool::Curve(tpinsecedge,dF,dL);
Handle(Geom_Surface) aSurface;
TopoDS_Shape aface;
double miny,maxy,minx,maxx,minz,maxz;
miny=-dataMD.m_shipWidth<-1?-dataMD.m_shipWidth:-100;
maxy=dataMD.m_shipWidth>1?dataMD.m_shipWidth:100;
minx=-100;
maxx=100;
minz=v;
maxz=v;
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,maxy,minz);
p3=gp_Pnt(maxx,maxy,minz);
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
return FALSE;
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
}
GeomAPI_IntCS intcs_sn(aCur, aSurface);
if (!intcs_sn.IsDone())
{
dataMD.errorinfo="交点生成失败 ";
return 0;
}
int nPnt=intcs_sn.NbPoints();
for(int i=1;i<=nPnt;i++)
{
gp_Pnt interpt = intcs_sn.Point(i);
BRepBuilderAPI_MakeVertex newv(interpt);
if(abs(interpt.X())<10e-14)
interpt.SetX(0.0);
if(abs(interpt.Y())<10e-14)
interpt.SetY(0.0);
if(abs(interpt.Z())<10e-14)
interpt.SetZ(0.0);
(pt+ptnum)->Y=interpt.Y();
(pt+ptnum)->Z=interpt.Z();
ptnum++;
}
}
else
{
return 0;
}
/*Handle_AIS_Shape AISShape=new AIS_Shape(splitResult);
myOCCViewer.myAISContext->SetColor(AISShape,Quantity_Color(1,0,0,Quantity_TOC_RGB), false);
myOCCViewer.myAISContext->SetTransparency(AISShape,1,false);
myOCCViewer.myAISContext->SetMaterial(AISShape, Graphic3d_NOM_SILVER, false);
myOCCViewer.myAISContext->Display(AISShape,false);*/
return ptnum;
}
DLLEXPORT int GenShapeLine(OffsetTablePoint *pt,int dir1, double v1, int dir2, double v2)
{
BaseAlgo algo;
std::map<double ,ScPoint2D> pitmap;
std::map<double ,ScPoint2D>::iterator ptit;
std::map<double ,ScPoint2D> pitmap2;
std::map<double ,ScPoint2D>::iterator ptit2;
TopoDS_Edge tpinsecedge;
double dF,dL;
gp_Pnt fp,ep,fp2,ep2,tempp;
TopoDS_Shape TopoShape,sshape1,sshape2,sshapeship,sshapetemp;
double step=0.2;
int ptnum=0;
BRepBuilderAPI_MakeWire wiretest ;
TopExp_Explorer ex;
bool insertbehind=false;
if(dataMD.m_mapMainDeckSurf.size()==1)
sshape1=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapMainDeckSurf.begin()->first)->second;
else
return ptnum;
if(dataMD.m_mapShellSurf.size()==1)
sshape2=dataMD.m_mapAllTopoShapes.find(dataMD.m_mapShellSurf.begin()->first)->second;
else
return ptnum;
double miny,maxy;
double minx,maxx;
double minz,maxz;
BRepBuilderAPI_MakeFace face;
if(dir1==0)
{
miny=-100;
maxy=100;
minx=v1;
maxx=v1;
minz=-50;
maxz=50;
}
else if(dir1==1)
{
miny=v1;
maxy=v1;
minx=-200;
maxx=500;
minz=-50;
maxz=50;
}
else if(dir1==2)
{
miny=-100;
maxy=100;
minx=-200;
maxx=500;
minz=v1;
maxz=v1;
}
gp_Pnt p1;
gp_Pnt p2;
gp_Pnt p3;
if(dir1==0)
{
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,miny,maxz);
p3=gp_Pnt(minx,maxy,maxz);
}
else if(dir1==1)
{
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,miny,maxz);
p3=gp_Pnt(maxx,miny,maxz);
}
else if(dir1==2)
{
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,maxy,minz);
p3=gp_Pnt(maxx,maxy,minz);
}
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
return ptnum;
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
sshapetemp = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
}
//缝合后求交
BRepOffsetAPI_Sewing aMethod;
aMethod.Add(sshape1);
aMethod.Add(sshape2);
aMethod.Perform();
sshapeship = aMethod.SewedShape();
BRepAlgoAPI_Section sec1(sshapeship,sshapetemp,Standard_False);
sec1.ComputePCurveOn1(Standard_True);
sec1.Approximation(TopOpeBRepTool_APPROX);
BOOL bDone = TRUE;
try
{
sec1.Build();
}
catch(Standard_Failure)
{
bDone = FALSE;
}
if(!bDone || !sec1.IsDone())
{
return ptnum;
}
TopoDS_Shape splitResult = sec1.Shape();
list<TopoDS_Edge> edgeList;
dataMD.GetInsectWirePts( splitResult,edgeList );
map<int, TopoDS_Edge> mapEdge;
for (TopExp_Explorer Ex(splitResult,TopAbs_EDGE); Ex.More(); Ex.Next())
{
mapEdge.insert(make_pair(mapEdge.size(), TopoDS::Edge(Ex.Current())));
}
vector<vector<int>> edgeIndex;
algo.GetWireSingleEdges(mapEdge,edgeIndex);
list<TopoDS_Edge>::iterator iter1,iter2;
int i=0;
if(dir2==-1)
{
//if(edgeList.size()>2)
//{
//iter1 = edgeList.begin();
//iter2=edgeList.begin();
//iter2++;
//Handle(Geom_Curve) aBeginCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
//Handle(Geom_Curve) aNextCur = BRep_Tool::Curve(TopoDS::Edge(*iter2),dF2,dL2);
//fp=aBeginCur->Value(dF);
//ep=aBeginCur->Value(dL);
//fp2=aNextCur->Value(dF2);
//ep2=aNextCur->Value(dL2);
//if(abs(fp.Distance(fp2))<10e-5)
//{
// tempp=ep;
//}
//else if(abs(fp.Distance(ep2))<10e-5)
//{
// tempp=ep;
//}
//else if(abs(ep.Distance(fp2))<10e-5)
//{
// tempp=fp;
//}
//else if(abs(ep.Distance(ep2))<10e-5)
//{
// tempp=fp;
//}
//for(iter1 = edgeList.begin();iter1 != edgeList.end(); iter1++)
//{
// Handle(Geom_Curve) aCur = BRep_Tool::Curve(TopoDS::Edge(*iter1),dF,dL);
// int k=(int)((dL-dF)/step);
// k=k>0?k:1;
// k=k>15?15:k;
// if(k>0)
// {
// fp=aCur->Value(dF);
// ep=aCur->Value(dL);
// if(abs(fp.Distance(tempp))<10e-5)
// {
// for(i=0;i<k;i++)
// {
// gp_Pnt pt1=aCur->Value(dF+step*i);
// if(i==0)
// {
// if(ptnum==0)
// {
// (pt+ptnum)->X=fp.X();
// (pt+ptnum)->Y=fp.Y();
// (pt+ptnum)->Z=fp.Z();
// ptnum++;
// }
// }
// else
// {
// (pt+ptnum)->X=fp.X();
// (pt+ptnum)->Y=pt1.Y();
// (pt+ptnum)->Z=pt1.Z();
// ptnum++;
// }
// }
// if(i==k)
// {
// (pt+ptnum)->X=fp.X();
// (pt+ptnum)->Y=ep.Y();
// (pt+ptnum)->Z=ep.Z();
// ptnum++;
// }
// tempp=ep;
// }
// else
// {
// for(i=0;i<k;i++)
// {
// gp_Pnt pt1=aCur->Value(dL-step*i);
// if(i==0)
// {
// if(ptnum==0)
// {
// (pt+ptnum)->X=fp.X();
// (pt+ptnum)->Y=ep.Y();
// (pt+ptnum)->Z=ep.Z();
// ptnum++;
// }
// }
// else
// {
// (pt+ptnum)->X=fp.X();
// (pt+ptnum)->Y=pt1.Y();
// (pt+ptnum)->Z=pt1.Z();
// ptnum++;
// }
// }
// if(i==k)
// {
// (pt+ptnum)->X=fp.X();
// (pt+ptnum)->Y=fp.Y();
// (pt+ptnum)->Z=fp.Z();
// ptnum++;
// }
// tempp=fp;
// }
// }
//}
//double b3=(pt+ptnum-1)->X-(pt)->X;
//double b1=(pt+ptnum-1)->Y-(pt)->Y;
//double b2=(pt+ptnum-1)->Z-(pt)->Z;
//if((abs(b1)<10e-5)&&(abs(b2)<10e-5)&&(abs(b3)<10e-5))
// ptnum--;
//}
for(int i = 0; i < edgeIndex.size(); i++)
{
vector<int> edgesID = edgeIndex[i];
gp_Pnt startp;
for(int j = 0; j < edgesID.size(); j++)
{
//加首不加尾
int firstID =edgesID[j];
int lastID = edgesID[(j + 1 )% edgesID.size()];
TopoDS_Edge ef = mapEdge[firstID];
TopoDS_Edge el = mapEdge[lastID];
gp_Pnt p01,p02,p11,p12;
double df,dl,df1,dl1;
Handle(Geom_Curve) aCurf= BRep_Tool::Curve(ef,df,dl);
p01 = aCurf->Value(df);
p02 = aCurf->Value(dl);
Handle(Geom_Curve) aCurl= BRep_Tool::Curve(el,df1,dl1);
p11 = aCurl->Value(df1);
p12 = aCurl->Value(dl1);
double step = (dl - df) / 15;
step = step > 0.2 ? step : 0.2;
//algo.GetEdgeStartEndPoint(ef,p01,p02);
//algo.GetEdgeStartEndPoint(el,p11,p12);
double f , l;
if(p02.Distance(p11) < Precision::Confusion() || p02.Distance(p12) < Precision::Confusion())
{
f = df;
l = dl;
if(j == 0)
{
startp = aCurf->Value(f);
}
}
else
{
f= dl;
l = df;
step = -1* step;
if(j == 0)
{
startp = aCurf->Value(f);
}
}
int count = 0;
bool isMore = true;
while(isMore)
{
double u = f + step * count;
gp_Pnt p = aCurf->Value(u);
(pt+ptnum)->X=p.X();
(pt+ptnum)->Y=p.Y();
(pt+ptnum)->Z=p.Z();
count++;
ptnum++;
isMore = (l > f)
? !(l < f + count * step || abs(l - f - count * step ) < Precision::Confusion())
: !(l > f + count * step || abs(l - f -count * step ) < Precision::Confusion()) ;
}
}
(pt+ptnum)->X=startp.X();
(pt+ptnum)->Y=startp.Y();
(pt+ptnum)->Z=startp.Z();
ptnum++;
}
}
else if(dir2==0)//返回与x= v的交点
{
tpinsecedge=dataMD.SetInsectWireToEdge(edgeList);
Handle(Geom_Curve) aCur= BRep_Tool::Curve(tpinsecedge,dF,dL);
Handle(Geom_Surface) aSurface;
TopoDS_Shape aface;
double miny,maxy,minx,maxx,minz,maxz;
minz=-0.2*dataMD.m_shipDepth<-1?-0.2*dataMD.m_shipDepth:-100;
maxz=1.2*dataMD.m_shipDepth>1?1.2*dataMD.m_shipDepth:100;
miny=-100;
maxy=100;
minx=v2;
maxx=v2;
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,miny,maxz);
p3=gp_Pnt(minx,maxy,maxz);
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
return FALSE;
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
}
GeomAPI_IntCS intcs_sn(aCur, aSurface);
if (!intcs_sn.IsDone())
{
dataMD.errorinfo="交点生成失败 ";
return 0;
}
int nPnt=intcs_sn.NbPoints();
for(int i=1;i<=nPnt;i++)
{
gp_Pnt interpt = intcs_sn.Point(i);
BRepBuilderAPI_MakeVertex newv(interpt);
if(abs(interpt.X())<10e-14)
interpt.SetX(0.0);
if(abs(interpt.Y())<10e-14)
interpt.SetY(0.0);
if(abs(interpt.Z())<10e-14)
interpt.SetZ(0.0);
(pt+ptnum)->X=v2;
(pt+ptnum)->Y=interpt.Y();
(pt+ptnum)->Z=interpt.Z();
ptnum++;
}
}
else if(dir2==1)//返回与y= v的交点
{
tpinsecedge=dataMD.SetInsectWireToEdge(edgeList);
Handle(Geom_Curve) aCur= BRep_Tool::Curve(tpinsecedge,dF,dL);
Handle(Geom_Surface) aSurface;
TopoDS_Shape aface;
double miny,maxy,minx,maxx,minz,maxz;
minz=-0.2*dataMD.m_shipDepth<-1?-0.2*dataMD.m_shipDepth:-100;
maxz=1.2*dataMD.m_shipDepth>1?1.2*dataMD.m_shipDepth:100;
minx=-100;
maxx=100;
maxy=v2;
miny=v2;
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,miny,maxz);
p3=gp_Pnt(maxx,miny,maxz);
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
return FALSE;
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
}
GeomAPI_IntCS intcs_sn(aCur, aSurface);
if (!intcs_sn.IsDone())
{
dataMD.errorinfo="交点生成失败 ";
return 0;
}
int nPnt=intcs_sn.NbPoints();
for(int i=1;i<=nPnt;i++)
{
gp_Pnt interpt = intcs_sn.Point(i);
BRepBuilderAPI_MakeVertex newv(interpt);
if(abs(interpt.X())<10e-14)
interpt.SetX(0.0);
if(abs(interpt.Y())<10e-14)
interpt.SetY(0.0);
if(abs(interpt.Z())<10e-14)
interpt.SetZ(0.0);
(pt+ptnum)->Y=v2;
(pt+ptnum)->X=interpt.X();
(pt+ptnum)->Z=interpt.Z();
ptnum++;
}
}
else if(dir2==2)//返回与z= v的交点
{
tpinsecedge=dataMD.SetInsectWireToEdge(edgeList);
Handle(Geom_Curve) aCur= BRep_Tool::Curve(tpinsecedge,dF,dL);
Handle(Geom_Surface) aSurface;
TopoDS_Shape aface;
double miny,maxy,minx,maxx,minz,maxz;
miny=-dataMD.m_shipWidth<-1?-dataMD.m_shipWidth:-100;
maxy=dataMD.m_shipWidth>1?dataMD.m_shipWidth:100;
minx=-100;
maxx=100;
minz=v2;
maxz=v2;
p1=gp_Pnt(minx,miny,minz);
p2=gp_Pnt(minx,maxy,minz);
p3=gp_Pnt(maxx,maxy,minz);
gp_Lin aLin(p1,gp_Vec(p1,p2));
double dist = aLin.Distance(p3);
if(dist < Precision::Confusion())
return FALSE;
TopoDS_Edge aE = BRepBuilderAPI_MakeEdge(p1,p2);
if(!aE.IsNull())
{
//计算拉伸方向
gp_Lin aDLin = aLin.Normal(p3);
double x,y,z;
aDLin.Direction().Coord(x,y,z);
aface = BRepPrimAPI_MakePrism(aE,gp_Vec(dist * x,dist * y,dist * z));
aSurface=BRep_Tool::Surface(TopoDS::Face(aface));
}
GeomAPI_IntCS intcs_sn(aCur, aSurface);
if (!intcs_sn.IsDone())
{
dataMD.errorinfo="交点生成失败 ";
return 0;
}
int nPnt=intcs_sn.NbPoints();
for(int i=1;i<=nPnt;i++)
{
gp_Pnt interpt = intcs_sn.Point(i);
BRepBuilderAPI_MakeVertex newv(interpt);
if(abs(interpt.X())<10e-14)
interpt.SetX(0.0);
if(abs(interpt.Y())<10e-14)
interpt.SetY(0.0);
if(abs(interpt.Z())<10e-14)
interpt.SetZ(0.0);
(pt+ptnum)->X=interpt.X();
(pt+ptnum)->Y=interpt.Y();
(pt+ptnum)->Z=v2;
ptnum++;
}
}
else
{
return 0;
}
return ptnum;
}
// Added by XUEFENG 20180926
// 三角显示
DLLEXPORT bool ShowMeshTriOrNot(bool flag)
{
return true;
}
// End Added
DLLEXPORT void SetOptions(bool autoCross,ModelDisplayOption displayOptions[])
{
}
DLLEXPORT void ShowSectionPos(double x,bool bdrawprofle)
{
dataMD.ShowSectionPos(x,bdrawprofle);
}
DLLEXPORT void ShowTempCurve(bool show, Curve crv, int npnt, Point3D pnt[])
{
dataMD.ShowTempCurve(show,crv,npnt,pnt);
}
void ClearAisTempmodel()
{
}
void ShowFrameRulerModel()
{
}
void ShowProfileModel()
{
}
//曲线上显示节点,ID:曲线ID颜色为“点”对象的颜色
void ShowPointOnLine(int ID, bool isHighLight)
{
}
void PixelToModel(int x, int y,double &rx,double &ry,double &rz,int flag,BOOL bWCS)
{
//2016srq
// V3d_Coordinate XEye,YEye,ZEye,XAt,YAt,ZAt;
// myOCCViewer.view[flag]->Eye(XEye,YEye,ZEye);//视点
// myOCCViewer.view[flag]->At(XAt,YAt,ZAt);//VRC原点
// gp_Pnt EyePoint(XEye,YEye,ZEye);
// gp_Pnt AtPoint(XAt,YAt,ZAt);
//
// gp_Vec EyeVector(EyePoint,AtPoint);
// gp_Dir EyeDir(EyeVector);//视线
//
// gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);//视平面
//
// //屏幕点转换为模型空间(或世界坐标系)的点。
// Standard_Real X,Y,Z;
// myOCCViewer.view[flag]->Convert((int)x,(int)y,X,Y,Z);
// //但点可能不在视平面上,因此要将点投影到视平面,再计算视平面上的点。
// gp_Pnt ConvertedPoint(X,Y,Z);
// gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint);
//
// gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
// ConvertedPointOnPlane.Y(),
// PlaneOfTheView);
//
//#ifdef _VERBOSE_DEBUG
// DTRACE("\n Eye [%.4f,%.4f,%.4f] At [%.4f,%.4f,%.4f],viewpoint [%.4f,%.4f,%.4f],result [%.4f,%.4f,%.4f].",
// XEye,YEye,ZEye,XAt,YAt,ZAt,X,Y,Z,ResultPoint.X(),ResultPoint.Y(),ResultPoint.Z());
//#endif
//
// rx=ResultPoint.X();
// ry=ResultPoint.Y() ;
// rz=ResultPoint.Z();
// DELETE BY XUEFENG 20180731
// FOR CODES COMBINE
/*
auto pt = myOCCViewer.m_Renderer->ScreenPoint2WorldPoint(AnyCore::Vector2(x, y));
rx = pt.x;
ry = pt.y;
rz = pt.z;
*/
// END DELETE
}
void RedrawTypeObjProps()
{
}
// ADDED by GUAN 202009~12
// MERGED by XUEFENG 202101
// Added by XUEFENG
// FOR DEBUG HULL
// 20200820
// 可参考Opencascade论坛上的
// https://www.opencascade.com/content/how-render-bspline-surface-using-glunurbs
#include "Geom_BSplineSurface.hxx"
#include "TColStd_Array1OfReal.hxx"
#include "TColStd_Array1OfInteger.hxx"
#include <TColgp_Array2OfPnt.hxx>
//
#include <TopExp_Explorer.hxx>
#include <Poly_Triangulation.hxx>
//
#include "BRepMesh_IncrementalMesh.hxx"
#include "BRepBuilderAPI_Copy.hxx"
#include "StlAPI_Writer.hxx"
// XUEFENG ADDED 202009
int preNUm(unsigned char byte) {
unsigned char mask = 0x80;
int num = 0;
for (int i = 0; i < 8; i++) {
if ((byte & mask) == mask) {
mask = mask >> 1;
num++;
} else {
break;
}
}
return num;
}
bool isUtf8(unsigned char* data, int len) {
int num = 0;
int i = 0;
while (i < len) {
if ((data[i] & 0x80) == 0x00) {
// 0XXX_XXXX
i++;
continue;
}
else if ((num = preNUm(data[i])) > 2) {
// 110X_XXXX 10XX_XXXX
// 1110_XXXX 10XX_XXXX 10XX_XXXX
// 1111_0XXX 10XX_XXXX 10XX_XXXX 10XX_XXXX
// 1111_10XX 10XX_XXXX 10XX_XXXX 10XX_XXXX 10XX_XXXX
// 1111_110X 10XX_XXXX 10XX_XXXX 10XX_XXXX 10XX_XXXX 10XX_XXXX
// preNUm() 返回首个字节8个bits中首 0bit前面1bit的个数该数量也是该字符所使用的字节数
i++;
for(int j = 0; j < num - 1; j++) {
//判断后面num - 1 个字节是不是都是10开
if ((data[i] & 0xc0) != 0x80) {
return false;
}
i++;
}
} else {
//其他情况说明不是utf-8
return false;
}
}
return true;
}
bool isGBK(unsigned char* data, int len) {
int i = 0;
while (i < len) {
if (data[i] <= 0x7f) {
//编码小于等于127,只有一个字节的编码兼容ASCII
i++;
continue;
} else {
//大于127的使用双字节编码
if (data[i] >= 0x81 &&
data[i] <= 0xfe &&
data[i + 1] >= 0x40 &&
data[i + 1] <= 0xfe &&
data[i + 1] != 0xf7) {
i += 2;
continue;
} else {
return false;
}
}
}
return true;
}
// GBK to UTF-8
std::string GbkToUtf8(const char *src_str)
{
/*
int len = MultiByteToWideChar(CP_ACP, 0, src_str, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, src_str, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* str = new char[len + 1];
memset(str, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
std::string strTemp = str;
if (wstr) delete[] wstr;
if (str) delete[] str;
return strTemp;
*/
return "";
}
// END ADDED
DLLEXPORT bool DebugHullForDoctorGUAN(int id)
{
/*
string filePath = ".";
if(strlen(path) == 0)
{
filePath = tempPath;
}
else
{
string s(path);
filePath = s+"\\";
}
*/
ofstream FileHull;
FileHull.open("Surface.txt",ios::out);
FileHull.close();
///// cqr-20180724
map<int,TopoDS_Shape>::iterator tpit1; //c
tpit1=dataMD.m_mapAllTopoShapes.find(id); //c
if(tpit1!=dataMD.m_mapAllTopoShapes.end()) //c
{
TopoDS_Shape sss = dataMD.m_mapAllTopoShapes.find(id)->second;
//TopoDS_Shape h;
//h = cp.Shape();
// 20200602 by czb, begin
BRepBuilderAPI_Copy cp(sss);
BRepTools::Clean(cp);
//BRepMesh_IncrementalMesh myMesh(cp, 2, Standard_False, 0.5); //cqr-20200716
BRepMesh_IncrementalMesh myMesh(cp, dataMD.GetSTLCoefficient()*250, Standard_False, 0.1); //cqr-20200716
myMesh.Perform();
// 20200602 by czb, end
try
{
StlAPI_Writer stlW;
//stlW.SetCoefficient(GetSTLCoefficient());
//// 20200602 by czb 相对精度修改为绝对精度,使得船体与舱室的网格大小一致
//stlW.RelativeMode() == Standard_False;
//stlW.SetDeflection(0.001);
//stlW.Write(h,(filePath + ".\\" +"hull.stl").c_str());
// XUEFENG ADDED 202102 cqr-20210315从OCCViewer中复制过来并修改
char pFileName[256];
// int pos = GetCurrentDirectory(256, pFileName);
memset(pFileName, 0, sizeof(pFileName)); // 清空数值以防止多个主船体时此次有前面主船体的hull名 cqr-20210315
strcat(pFileName,"Surface.txt");
Standard_CString tmpFileName = (Standard_CString)pFileName;
Standard_Boolean result = false;
int len = strlen(tmpFileName);
bool isutf8 = isUtf8((unsigned char*)tmpFileName, len);
bool isgbk = isGBK((unsigned char*)tmpFileName, len);
if(isutf8==false && isgbk==true) // Chinese path
{
std::string mystr = GbkToUtf8(tmpFileName);
char myUTF8Filepath[1024];
strcpy(myUTF8Filepath, mystr.c_str());
//result = BRepTools::Read(shapeCompound, myUTF8Filepath, aBuilder);
stlW.Write(cp, myUTF8Filepath);
}
else if(isutf8==true && isgbk==true) // English path
{
//result = BRepTools::Read(shapeCompound, aFileName, aBuilder);
stlW.Write(cp, tmpFileName);
}
}
catch(Standard_Failure)
{
}
/* finally //pj change ע<>͵<EFBFBD>finally
{
} */
}
return true;
//myOCCViewer.DebugHullForDoctorGUAN(flag);
map<int,TopoDS_Shape>::iterator it;
int type;
if(dataMD.m_mapAllTopoShapes.size()>0)
{
ofstream ofs;
ofs.open("Surface.txt", ios::out);
ofs << "VARIABLES='X','Y','Z','NX','NY','NZ'" << endl;
//
/*ofs.open("out.stl", ios::out);
string s_normal = " facet normal ";
string s_outer = " outer loop";
string s_vertex = " vertex ";
string s_endloop = " endloop";
string s_endfacet = " endfacet";
string s;
ofs << "solid" << endl;*/
//
int nu=16;
int nv=16;
double* sur=new double[nu*nv];
int Con=1;
for(it=dataMD.m_mapAllTopoShapes.begin();it!=dataMD.m_mapAllTopoShapes.end();++it)
{
int realHullID = it->first;
type=it->first/MAX_SIZE_OF_OBJECT_GROUP;
if(type >=18 && type<19)
{
memset(sur,0,nu*nv*sizeof(int));
/*ofs << "ZONE T='1',I=" << nv << "J=" << nu << ",K=1,F=POINT"<< endl;*/
TopoDS_Shape hullShape = it->second;
//TopoDS_Shell HullShell = (TopoDS_Shell)hullShape;
for (TopExp_Explorer faceExp(hullShape, TopAbs_FACE); faceExp.More(); faceExp.Next()){
TopoDS_Face tmpFace = TopoDS::Face(faceExp.Current());
Handle_Geom_Surface tmpSurface = BRep_Tool::Surface(tmpFace);
////
//TopLoc_Location loc;
////BRepMesh_IncrementalMesh myMesh(tmpFace, 10, Standard_True, 5);
//BRepMesh_IncrementalMesh myMesh(tmpFace, 0.02, Standard_False, 0.5);
//Handle_Poly_Triangulation triFace = BRep_Tool::Triangulation(tmpFace, loc);
////BRepMesh_IncrementalMesh myMesh(triFace, 2, Standard_False, 0.5);
//Standard_Integer nTriangles = triFace->NbTriangles();
//gp_Trsf myTrsf = loc.Transformation();//
//bool myInvert = (tmpFace.Orientation()==TopAbs_REVERSED);//
//if(myTrsf.IsNegative())//
// myInvert =! myInvert;//
//gp_Pnt vertex1;
//gp_Pnt vertex2;
//gp_Pnt vertex3;
//Standard_Integer nVertexIndex1 = 0;
//Standard_Integer nVertexIndex2 = 0;
//Standard_Integer nVertexIndex3 = 0;
//TColgp_Array1OfPnt nodes(1, triFace->NbNodes());
//Poly_Array1OfTriangle triangles(1, triFace->NbTriangles());
//nodes = triFace->Nodes();
//triangles = triFace->Triangles();
//for (Standard_Integer i = 1; i <= nTriangles; i++)
//{
// Poly_Triangle aTriangle = triangles.Value(i);
// aTriangle.Get(nVertexIndex1, nVertexIndex2, nVertexIndex3);
// vertex1 = nodes.Value(nVertexIndex1);
// vertex2 = nodes.Value(myInvert? nVertexIndex3:nVertexIndex2);
// vertex3 = nodes.Value(myInvert? nVertexIndex2:nVertexIndex3);
// gp_XYZ vector12(vertex2.XYZ() - vertex1.XYZ());
// gp_XYZ vector13(vertex3.XYZ() - vertex1.XYZ());
// gp_XYZ normal = vector12.Crossed(vector13);
// Standard_Real rModulus = normal.Modulus();
// if (rModulus > gp::Resolution())
// {
// normal.Normalize();
// }
// else
// {
// normal.SetCoord(0., 0., 0.);
// }
// ofs << s_normal << normal.X() <<" " << normal.Y() << " " << normal.Z() << endl;
// ofs << s_outer << endl;
// ofs << s_vertex << vertex1.X() <<" " << vertex1.Y() << " " << vertex1.Z() << endl;
// ofs << s_vertex << vertex2.X() <<" " << vertex2.Y() << " " << vertex2.Z() << endl;
// ofs << s_vertex << vertex3.X() <<" " << vertex3.Y() << " " << vertex3.Z() << endl;
// ofs << s_endloop << endl;
// ofs << s_endfacet << endl;
//}
//ofs << flush;
////
Handle_Geom_BSplineSurface myBSplineSurface = GeomConvert::SurfaceToBSplineSurface(tmpSurface);
{
//Standard_Integer vdegree = myBSplineSurface->VDegree();
//Standard_Integer myVKnotsNumber = myBSplineSurface->NbVKnots();
//
bool myInvert = (tmpFace.Orientation()==TopAbs_REVERSED);//
//bool myInvert = (myBSplineSurface.Orientation()==TopAbs_REVERSED);//
Standard_Real us = 0.0;
Standard_Real ue = 0.0;
Standard_Real vs = 0.0;
Standard_Real ve = 0.0;
myBSplineSurface->Bounds(us,ue,vs,ve);
Standard_Real uu = 0.0;
Standard_Real vv = 0.0;
gp_Pnt aP00;
gp_Pnt aP01;
gp_Pnt aP10;
gp_Pnt aP11;
Standard_Real Lu0,Lu1,Lv0,Lv1, Lu, Lv, xx,yy, zz;
myBSplineSurface->D0(us, vs, aP00);
myBSplineSurface->D0(us, ve, aP01);
myBSplineSurface->D0(ue, vs, aP10);
myBSplineSurface->D0(ue, ve, aP11);
xx=aP10.X()-aP00.X();
yy=aP10.Y()-aP00.Y();
zz=aP10.Z()-aP00.Z();
Lu0=sqrt(xx*xx+yy*yy+zz*zz);
xx=aP11.X()-aP01.X();
yy=aP11.Y()-aP01.Y();
zz=aP11.Z()-aP01.Z();
Lu1=sqrt(xx*xx+yy*yy+zz*zz);
xx=aP01.X()-aP00.X();
yy=aP01.Y()-aP00.Y();
zz=aP01.Z()-aP00.Z();
Lv0=sqrt(xx*xx+yy*yy+zz*zz);
xx=aP11.X()-aP10.X();
yy=aP11.Y()-aP10.Y();
zz=aP11.Z()-aP10.Z();
Lv1=sqrt(xx*xx+yy*yy+zz*zz);
Lu=Lu0;
if(Lu<Lu1)
{
Lu=Lu1;
}
Lv=Lv0;
if(Lv<Lv1)
{
Lv=Lv1;
}
nu=(int)(25.0*Lu/dataMD.m_shipDepth);
nv=(int)(25.0*Lv/dataMD.m_shipDepth);
if(nu < 6)
{
nu = 6;
}
if(nv < 6)
{
nv = 6;
}
//
gp_Pnt aP;
gp_Vec aDu;
gp_Vec aDv;
gp_Vec normal;
Standard_Real rModulus;
/*ofs << "ZONE T='1',I=" << nv << ",J=" << nu << ",K=1,F=POINT"<< endl;*/
ofs << "ZONE T='"<< Con++ <<"',I=" << nv << ",J=" << nu << ",K=1,F=POINT" << endl;
/*if(Con==9)
{
Standard_Integer Ni=myBSplineSurface->NbUPoles();
Standard_Integer Nj=myBSplineSurface->NbVPoles();
TColgp_Array2OfPnt poles(1,Ni,1,Nj);
myBSplineSurface->Poles(poles);
for(int i=1;i<=Ni;i++)
{
for(int j=1;j<=Nj;j++)
{
aP=poles(i,j);
cout << aP.X() << "\t" << aP.Y() << "\t" << aP.Z() << endl;
}
}
}*/
for(int i=0;i<nu;i++)
{
uu=us+(ue-us)/(nu-1)*(Standard_Real)i;
for(int j=0;j<nv;j++)
{
vv=vs+(ve-vs)/(nv-1)*(Standard_Real)j;
myBSplineSurface->D1(uu, vv, aP, aDu, aDv);
if(myInvert==false)
{
normal = aDu.Crossed(aDv);
}
else
{
normal = -aDu.Crossed(aDv);
}
//normal = aDu.Crossed(aDv);
rModulus = sqrt(normal.X()*normal.X()+normal.Y()*normal.Y()+normal.Z()*normal.Z());
if (rModulus > 1.0e-9) //gp::Resolution()
{
normal.Normalize();
}
else
{
normal.SetCoord(0., 0., 0.);
}
if (fabs(normal.X())<1.0e-6)
{
normal.SetCoord(0.0,normal.Y(),normal.Z());
}
if (fabs(normal.Y())<1.0e-6)
{
normal.SetCoord(normal.X(),0.0,normal.Z());
}
if (fabs(normal.Z())<1.0e-6)
{
normal.SetCoord(normal.X(),normal.Y(),0.0);
}
ofs << aP.X() << "\t" << aP.Y() << "\t" << aP.Z() << "\t" << normal.X() << "\t" << normal.Y() << "\t" << normal.Z() << endl;
}
}
ofs << flush;
}
}
//ofs << "endsolid" << endl;
// 显示目前不能直接显示。
dataMD.m_bshowHull = true;
dataMD.OccDisplayAis(realHullID+1, hullShape, true);
}
}
ofs.close();
}
return true;
}
// End Added
// Added by GUAN
// FOR DEBUG HULL
// 20210103
// 可参考Opencascade论坛上的
// https://www.opencascade.com/content/how-render-bspline-surface-using-glunurbs
#include "Geom_BSplineSurface.hxx"
#include "TColStd_Array1OfReal.hxx"
#include "TColStd_Array1OfInteger.hxx"
#include <TColgp_Array2OfPnt.hxx>
//
#include <TopExp_Explorer.hxx>
#include <Poly_Triangulation.hxx>
//
#include "BRepMesh_IncrementalMesh.hxx"
void Check_uv(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert);
void Check_uv2(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert);
gp_Vec Cal_normal(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert, int k, int n);//
gp_Vec Cal_normal2(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert, int k, int n);//
void Check_normal(int i, int ii, int j, int jj, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve,
vector<Handle_Geom_BSplineSurface> sur1, vector<bool> surInvert, int Mark, vector<bool> modefiedu, vector<bool> modefiedv);
Handle_Geom_BSplineSurface Modefy_sur(int i, int Mark, vector<Handle_Geom_BSplineSurface> sur1, Standard_Real* temp, vector<bool> modefiedu, vector<bool> modefiedv);
Standard_Real Cal_sita(int i, int ii, int j, int jj, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve,
Handle_Geom_BSplineSurface sur1, Handle_Geom_BSplineSurface sur2, vector<bool> surInvert, int n, Standard_Real* normala, int Mark, Standard_Real* sita);
Standard_Real Cal_sita_Modify(int i, int ii, int j, int jj, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve,
Handle_Geom_BSplineSurface sur1, Handle_Geom_BSplineSurface sur2, vector<bool> surInvert, int n, int Mark, Standard_Real* sita);
void Modefy_sur2(int i, int Mark, vector<Handle_Geom_BSplineSurface> sur1, Standard_Real* temp, vector<bool> modefiedu, vector<bool> modefiedv);
DLLEXPORT bool DebugHullForDoctorGUAN2(int id)
{
//myOCCViewer.DebugHullForDoctorGUAN(flag);
map<int,TopoDS_Shape>::iterator it;
int type;
if(dataMD.m_mapAllTopoShapes.size()>0)
{
/*ofstream ofs;
ofs.open("Surface2.txt", ios::out);
ofs << "VARIABLES='X','Y','Z','NX','NY','NZ'" << endl;*/
//
/*ofs.open("out.stl", ios::out);
string s_normal = " facet normal ";
string s_outer = " outer loop";
string s_vertex = " vertex ";
string s_endloop = " endloop";
string s_endfacet = " endfacet";
string s;
ofs << "solid" << endl;*/
//
int nu=16;
int nv=16;
double* sur=new double[nu*nv];
int Con=0;
vector<Standard_Real> us;
vector<Standard_Real> ue;
vector<Standard_Real> vs;
vector<Standard_Real> ve;
vector<gp_Pnt> edge;
vector<Handle_Geom_BSplineSurface> sur1;
vector<bool> surInvert;
vector<bool> modefiedu;
vector<bool> modefiedv;
vector<bool> marked;
for(it=dataMD.m_mapAllTopoShapes.begin();it!=dataMD.m_mapAllTopoShapes.end();++it)
{
int realHullID = it->first;
type=it->first/MAX_SIZE_OF_OBJECT_GROUP;
if(type >=18 && type<19)
{
memset(sur,0,nu*nv*sizeof(int));
TopoDS_Shape hullShape = it->second;
for (TopExp_Explorer faceExp(hullShape, TopAbs_FACE); faceExp.More(); faceExp.Next())
{
TopoDS_Face tmpFace = TopoDS::Face(faceExp.Current());
Handle_Geom_Surface tmpSurface = BRep_Tool::Surface(tmpFace);
////
Handle_Geom_BSplineSurface myBSplineSurface = GeomConvert::SurfaceToBSplineSurface(tmpSurface);
{
//Standard_Integer vdegree = myBSplineSurface->VDegree();
//Standard_Integer myVKnotsNumber = myBSplineSurface->NbVKnots();
//
bool myInvert = (tmpFace.Orientation()==TopAbs_REVERSED);//
//tmpFace.
Standard_Real us0 = 0.0;
Standard_Real ue0 = 0.0;
Standard_Real vs0 = 0.0;
Standard_Real ve0 = 0.0;
myBSplineSurface->Bounds(us0,ue0,vs0,ve0);
gp_Pnt aP00;
gp_Pnt aP01;
gp_Pnt aP10;
gp_Pnt aP11;
myBSplineSurface->D0(us0, vs0, aP00);
myBSplineSurface->D0(us0, ve0, aP01);
myBSplineSurface->D0(ue0, vs0, aP10);
myBSplineSurface->D0(ue0, ve0, aP11);
us.push_back(us0);
ue.push_back(ue0);
vs.push_back(vs0);
ve.push_back(ve0);
//edge:00-10-11-01-00
edge.push_back(aP00);
edge.push_back(aP10);
edge.push_back(aP11);
edge.push_back(aP01);
edge.push_back(aP00);
sur1.push_back(myBSplineSurface);
surInvert.push_back(myInvert);
modefiedu.push_back(false);
modefiedv.push_back(false);
//
marked.push_back(false);
marked.push_back(false);
marked.push_back(false);
marked.push_back(false);
Con++;
//cout<< Con << "\t" << myBSplineSurface->NbUPoles() << "\t" << myBSplineSurface->NbVPoles() << "\t" << myBSplineSurface->NbUKnots() << "\t" << myBSplineSurface->NbVKnots() <<endl;
}
}
//Deleted by GUAN, 20210309
//cout<<endl;
//End Delete
Standard_Real L0, L1, L2, L3;
for(int i=0;i<Con;i++)
{
for(int ii=0;ii<4;ii++)
{
if(marked[4*i+ii]==false)
{
for(int j=i+1;j<Con;j++)
{
for(int jj=0;jj<4;jj++)
{
if(marked[4*j+jj]==false)
{
L0=sqrt(pow(edge[5*i+ii].X()-edge[5*j+jj].X(),2)+pow(edge[5*i+ii].Y()-edge[5*j+jj].Y(),2)+pow(edge[5*i+ii].Z()-edge[5*j+jj].Z(),2));
L1=sqrt(pow(edge[5*i+ii+1].X()-edge[5*j+jj+1].X(),2)+pow(edge[5*i+ii+1].Y()-edge[5*j+jj+1].Y(),2)+pow(edge[5*i+ii+1].Z()-edge[5*j+jj+1].Z(),2));
if(L0<1.0e-6 && L1<1.0e-6)
{
//cout<< i << "\t" << j << "\t" << edge[5*i+ii].X() << "\t" << edge[5*i+ii].Y() << "\t" << edge[5*i+ii].Z() << "\t" << edge[5*i+ii+1].X() << "\t" << edge[5*i+ii+1].Y() << "\t" << edge[5*i+ii+1].Z() <<endl;
//cout<< i << "\t" << j << "\t" << edge[5*j+jj].X() << "\t" << edge[5*j+jj].Y() << "\t" << edge[5*j+jj].Z() << "\t" << edge[5*j+jj+1].X() << "\t" << edge[5*j+jj+1].Y() << "\t" << edge[5*j+jj+1].Z() <<endl;
//Deleted by GUAN, 20210309
//cout<< i << "\t" << j;// << "\t" << us[i] << "\t" << ue[i] << "\t" << vs[i] << "\t" << ve[i]<< "\t" << us[j] << "\t" << ue[j] << "\t" << vs[j] << "\t" << ve[j] <<endl;
//cout<<endl;
//End Delete
Check_normal(i, ii,j, jj,us,ue,vs,ve, sur1, surInvert, 1, modefiedu, modefiedv);//
//Check_uv(i, ii,us,ue,vs,ve, sur1[i], surInvert[i]);//
//cout<<endl;
//Check_uv(j, jj,us,ue,vs,ve, sur1[j], surInvert[j]);//
//cout<<endl;
marked[4*i+ii]=true;
marked[4*j+jj]=true;
jj+=4;
j+=Con;
//ii+=4;
}
else
{
L2=sqrt(pow(edge[5*i+ii].X()-edge[5*j+jj+1].X(),2)+pow(edge[5*i+ii].Y()-edge[5*j+jj+1].Y(),2)+pow(edge[5*i+ii].Z()-edge[5*j+jj+1].Z(),2));
L3=sqrt(pow(edge[5*i+ii+1].X()-edge[5*j+jj].X(),2)+pow(edge[5*i+ii+1].Y()-edge[5*j+jj].Y(),2)+pow(edge[5*i+ii+1].Z()-edge[5*j+jj].Z(),2));
if(L2<1.0e-6 && L3<1.0e-6)
{
//cout<< i << "\t" << j << "\t" << edge[5*i+ii].X() << "\t" << edge[5*i+ii].Y() << "\t" << edge[5*i+ii].Z() << "\t" << edge[5*i+ii+1].X() << "\t" << edge[5*i+ii+1].Y() << "\t" << edge[5*i+ii+1].Z() <<endl;
//cout<< i << "\t" << j << "\t" << edge[5*j+jj].X() << "\t" << edge[5*j+jj].Y() << "\t" << edge[5*j+jj].Z() << "\t" << edge[5*j+jj+1].X() << "\t" << edge[5*j+jj+1].Y() << "\t" << edge[5*j+jj+1].Z() <<endl;
//Deleted by GUAN, 20210309
//cout<< i << "\t" << j;// << "\t" << us[i] << "\t" << ue[i] << "\t" << vs[i] << "\t" << ve[i]<< "\t" << us[j] << "\t" << ue[j] << "\t" << vs[j] << "\t" << ve[j] <<endl;
//cout<<endl;
//End Delete
Check_normal(i, ii,j, jj,us,ue,vs,ve, sur1, surInvert, 2, modefiedu, modefiedv);//
//Check_uv(i, ii,us,ue,vs,ve, sur1[i], surInvert[i]);//
//cout<<endl;
//Check_uv2(j, jj,us,ue,vs,ve, sur1[j], surInvert[j]);//
//cout<<endl;
marked[4*i+ii]=true;
marked[4*j+jj]=true;
jj+=4;
j+=Con;
//ii+=4;
}
}
}
}
}
}
}
}
//ofs << "endsolid" << endl;
////////////////////////////////////////////////////////////
//int Cot=1;
//for(int k=0;k<Con;k++)
//{
// //cout<<k<<endl;
// Handle_Geom_BSplineSurface myBSplineSurface = sur1[k];
// {
// //Standard_Integer vdegree = myBSplineSurface->VDegree();
// //Standard_Integer myVKnotsNumber = myBSplineSurface->NbVKnots();
// //
// bool myInvert = surInvert[k];//
// //bool myInve[k]rt = (myBSplineSurface.Orientation()==TopAbs_REve[k]RSED);//
// Standard_Real uu = 0.0;
// Standard_Real vv = 0.0;
// gp_Pnt aP00;
// gp_Pnt aP01;
// gp_Pnt aP10;
// gp_Pnt aP11;
// Standard_Real Lu0,Lu1,Lv0,Lv1, Lu, Lv, xx,yy, zz;
// myBSplineSurface->D0(us[k], vs[k], aP00);
// myBSplineSurface->D0(us[k], ve[k], aP01);
// myBSplineSurface->D0(ue[k], vs[k], aP10);
// myBSplineSurface->D0(ue[k], ve[k], aP11);
// xx=aP10.X()-aP00.X();
// yy=aP10.Y()-aP00.Y();
// zz=aP10.Z()-aP00.Z();
// Lu0=sqrt(xx*xx+yy*yy+zz*zz);
// xx=aP11.X()-aP01.X();
// yy=aP11.Y()-aP01.Y();
// zz=aP11.Z()-aP01.Z();
// Lu1=sqrt(xx*xx+yy*yy+zz*zz);
// xx=aP01.X()-aP00.X();
// yy=aP01.Y()-aP00.Y();
// zz=aP01.Z()-aP00.Z();
// Lv0=sqrt(xx*xx+yy*yy+zz*zz);
// xx=aP11.X()-aP10.X();
// yy=aP11.Y()-aP10.Y();
// zz=aP11.Z()-aP10.Z();
// Lv1=sqrt(xx*xx+yy*yy+zz*zz);
// Lu=Lu0;
// if(Lu<Lu1)
// {
// Lu=Lu1;
// }
// Lv=Lv0;
// if(Lv<Lv1)
// {
// Lv=Lv1;
// }
// nu=(int)(25.0*Lu/dataMD.m_shipDepth);
// nv=(int)(25.0*Lv/dataMD.m_shipDepth);
// if(nu < 6)
// {
// nu = 6;
// }
// if(nv < 6)
// {
// nv = 6;
// }
// //
// gp_Pnt aP;
// gp_Vec aDu;
// gp_Vec aDv;
// gp_Vec normal;
// Standard_Real rModulus;
// /*ofs << "ZONE T='1',I=" << nv << ",J=" << nu << ",K=1,F=POINT"<< endl;*/
// ofs << "ZONE T='"<< Cot++ <<"',I=" << nv << ",J=" << nu << ",K=1,F=POINT" << endl;
// /*if(Con==9)
// {
// Standard_Integer Ni=myBSplineSurface->NbUPoles();
// Standard_Integer Nj=myBSplineSurface->NbVPoles();
// TColgp_Array2OfPnt poles(1,Ni,1,Nj);
// myBSplineSurface->Poles(poles);
// for(int i=1;i<=Ni;i++)
// {
// for(int j=1;j<=Nj;j++)
// {
// aP=poles(i,j);
// cout << aP.X() << "\t" << aP.Y() << "\t" << aP.Z() << endl;
// }
// }
// }*/
// for(int i=0;i<nu;i++)
// {
// uu=us[k]+(ue[k]-us[k])/(nu-1)*(Standard_Real)i;
// for(int j=0;j<nv;j++)
// {
// vv=vs[k]+(ve[k]-vs[k])/(nv-1)*(Standard_Real)j;
// myBSplineSurface->D1(uu, vv, aP, aDu, aDv);
// if(myInvert==false)
// {
// normal = aDu.Crossed(aDv);
// }
// else
// {
// normal = -aDu.Crossed(aDv);
// }
// //normal = aDu.Crossed(aDv);
// rModulus = sqrt(normal.X()*normal.X()+normal.Y()*normal.Y()+normal.Z()*normal.Z());
// if (rModulus > 1.0e-9) //gp::Resolution()
// {
// normal.Normalize();
// }
// else
// {
// normal.SetCoord(0., 0., 0.);
// }
// if (fabs(normal.X())<1.0e-6)
// {
// normal.SetCoord(0.0,normal.Y(),normal.Z());
// }
// if (fabs(normal.Y())<1.0e-6)
// {
// normal.SetCoord(normal.X(),0.0,normal.Z());
// }
// if (fabs(normal.Z())<1.0e-6)
// {
// normal.SetCoord(normal.X(),normal.Y(),0.0);
// }
// ofs << aP.X() << "\t" << aP.Y() << "\t" << aP.Z() << "\t" << normal.X() << "\t" << normal.Y() << "\t" << normal.Z() << endl;
// }
// }
// ofs << flush;
// }
//}
////////////////////////////////////////////////////////////
// 显示目前不能直接显示。
dataMD.m_bshowHull = true;
dataMD.OccDisplayAis(realHullID+1, hullShape, true);
}
}
//ofs.close();
}
return true;
}
void Check_uv(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert)//
{
Standard_Integer Num;
if(Mark==0)//00-10 vs[i]
{
Num = myBSplineSurface->NbUKnots();
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==1)//10-11 ue[i]
{
Num = myBSplineSurface->NbVKnots();
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
else if(Mark==2)//11-01 ve[i]
{
Num = myBSplineSurface->NbUKnots();
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==3)//01-00 us[i]
{
Num = myBSplineSurface->NbVKnots();
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
/*cout<< "\t" << Num << "\t" << myBSplineSurface->NbUPoles() << "\t" << myBSplineSurface->NbVPoles();*/
//Deleted by GUAN, 20210309
//cout<< "\t" << Num << "\t" << myBSplineSurface->NbUPoles() << "\t" << myBSplineSurface->NbVPoles() << "\t" << myBSplineSurface->NbUKnots() << "\t" << myBSplineSurface->NbVKnots();
//End Delete
}
void Check_uv2(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert)//
{
Standard_Integer Num;
if(Mark==0)//00-10 vs[i]
{
Num = myBSplineSurface->NbUKnots();
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==1)//10-11 ue[i]
{
Num = myBSplineSurface->NbVKnots();
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
else if(Mark==2)//11-01 ve[i]
{
Num = myBSplineSurface->NbUKnots();
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==3)//01-00 us[i]
{
Num = myBSplineSurface->NbVKnots();
}
/*cout<< "\t" << Num << "\t" << myBSplineSurface->NbUPoles() << "\t" << myBSplineSurface->NbVPoles();*/
//Deleted by GUAN, 20210309
//cout<< "\t" << Num << "\t" << myBSplineSurface->NbUPoles() << "\t" << myBSplineSurface->NbVPoles()<< "\t" << myBSplineSurface->NbUKnots() << "\t" << myBSplineSurface->NbVKnots();
//End Delete
}
void Check_normal(int i, int ii, int j, int jj, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve,
vector<Handle_Geom_BSplineSurface> sur1, vector<bool> surInvert, int Mark, vector<bool> modefiedu, vector<bool> modefiedv)
{
int n=4;//8
Standard_Real normala[3];
Standard_Real temp[3];
Standard_Real sita[9];//n+1
Standard_Real average, average1;
average1=Cal_sita(i, ii, j, jj,us,ue,vs,ve, sur1[i], sur1[j], surInvert, n, normala, Mark, sita);
/*if(i==61&j==62)
{
int nn=3;
nn+=4;
}*/
// Deleted by GUAN, 20210309
/*cout<< "修正前:";
for(int k=0;k<=n;k++)
{
cout<<fixed<<setprecision(6)<< "\t" << sita[k];
}
cout<<endl;*/
//End Delete
if(average1>=1.0 && average1<=30.0)//0.01
{
average=average1;
Handle_Geom_BSplineSurface sur;
Standard_Real kk = -0.01;//-0.001
Standard_Real dk = kk;
int Cn=0;
temp[0]=0.0;
temp[1]=0.0;
temp[2]=0.0;
Standard_Real amini=average1;
Standard_Real tpi[3]={0.0,0.0,0.0};
Standard_Real sitami[9];
while(average>1.0 && Cn<30)//0.01 100
{
temp[0]=normala[0]*dk;
temp[1]=normala[1]*dk;
temp[2]=normala[2]*dk;
dk+=kk;
Cn+=1;
if(Cn==15 && average>average1)//50
{
kk = 0.01;
dk = kk;
temp[0]=normala[0]*dk;
temp[1]=normala[1]*dk;
temp[2]=normala[2]*dk;
}
sur=Modefy_sur(i, ii, sur1, temp, modefiedu, modefiedv);
average=Cal_sita_Modify(i, ii, j, jj,us,ue,vs,ve, sur, sur1[j], surInvert, n, Mark, sita);
if(average<amini)
{
amini=average;
tpi[0]=temp[0];
tpi[1]=temp[1];
tpi[2]=temp[2];
for(int k=0;k<=n;k++)
{
sitami[k]=sita[k];
}
}
}
if(amini<average1)//average<2.0
{
Modefy_sur2(i, ii, sur1, tpi, modefiedu, modefiedv);
}
Cn=0;
average=amini;
kk = -0.01;
dk = kk;
Standard_Real tpj[3]={0.0,0.0,0.0};
Standard_Real aminj=amini;
Standard_Real sitamj[9];
while(average>1.0 && Cn<30)//0.01 100
{
temp[0]=normala[0]*dk;
temp[1]=normala[1]*dk;
temp[2]=normala[2]*dk;
dk+=kk;
Cn+=1;
if(Cn==15 && average>amini)//50
{
kk = 0.01;
dk = kk;
temp[0]=normala[0]*dk;
temp[1]=normala[1]*dk;
temp[2]=normala[2]*dk;
}
sur=Modefy_sur(j, jj, sur1, temp, modefiedu, modefiedv);
average=Cal_sita_Modify(i, ii, j, jj,us,ue,vs,ve, sur1[i], sur, surInvert, n, Mark, sita);
if(average<aminj)
{
aminj=average;
tpj[0]=temp[0];
tpj[1]=temp[1];
tpj[2]=temp[2];
for(int k=0;k<=n;k++)
{
sitamj[k]=sita[k];
}
}
}
if(aminj<aminj)//average<2.0
{
Modefy_sur2(j, jj, sur1, tpj, modefiedu, modefiedv);
// Deleted by GUAN, 20210309
/*cout<< "修正后:";
for(int k=0;k<=n;k++)
{
cout<<fixed<<setprecision(6)<< "\t" << sitamj[k];
}*/
//End Delete
}
// Deleted by GUAN, 20210309
/*cout<< "修正后:";
else
{
if(amini<average1)//average<2.0
{
cout<< "修正后:";
for(int k=0;k<=n;k++)
{
cout<<fixed<<setprecision(6)<< "\t" << sitami[k];
}
//End Delete
}
}
cout<<endl;*/
//End Delete
}
}
Standard_Real Cal_sita(int i, int ii, int j, int jj, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve,
Handle_Geom_BSplineSurface sur1, Handle_Geom_BSplineSurface sur2, vector<bool> surInvert, int n, Standard_Real* normala, int Mark, Standard_Real* sita)
{
gp_Vec normal1;
gp_Vec normal2;
Standard_Real rModulus1;
Standard_Real rModulus2;
Standard_Real PI_VALUE=3.1415926535898; //#include "StdAfx.h"PI->PI_VALUE
Standard_Real temp, Csita, sum, average, nx,ny,nz;
normala[0]=0.0;
normala[1]=0.0;
normala[2]=0.0;
int Con=0;
sum=0.0;
for(int k=0;k<=n;k++)
{
normal1=Cal_normal(i, ii,us,ue,vs,ve, sur1, surInvert[i], k, n);//
if(Mark==1)
{
normal2=Cal_normal(j, jj,us,ue,vs,ve, sur2, surInvert[j], k, n);//
}
else
{
normal2=Cal_normal2(j, jj,us,ue,vs,ve, sur2, surInvert[j], k, n);//
}
rModulus1 = sqrt(normal1.X()*normal1.X()+normal1.Y()*normal1.Y()+normal1.Z()*normal1.Z());
rModulus2 = sqrt(normal2.X()*normal2.X()+normal2.Y()*normal2.Y()+normal2.Z()*normal2.Z());
if(rModulus1>0&&rModulus2>0)
{
temp=normal1.X()*normal2.X()+normal1.Y()*normal2.Y()+normal1.Z()*normal2.Z();
Csita=temp/rModulus1/rModulus2;
if(Csita>1.0)
{
Csita=1.0;
}
else if(Csita<-1.0)
{
Csita=-1.0;
}
sita[k]=acos(Csita)*180/PI_VALUE; //pj change
/*cout<< "\t" << sita[i];*/
if(k>0&&k<n)
{
Con++;
sum+=sita[k];
}
normala[0]+=normal1.X();
normala[1]+=normal1.Y();
normala[2]+=normal1.Z();
}
}
if(Con>0)
{
temp=sqrt(normala[0]*normala[0]+normala[1]*normala[1]+normala[2]*normala[2]);
normala[0]/=temp;
normala[1]/=temp;
normala[2]/=temp;
average=sum/Con;
}
else
{
average=0.0;
}
return(average);
}
Standard_Real Cal_sita_Modify(int i, int ii, int j, int jj, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve,
Handle_Geom_BSplineSurface sur1, Handle_Geom_BSplineSurface sur2, vector<bool> surInvert, int n, int Mark, Standard_Real* sita)
{
gp_Vec normal1;
gp_Vec normal2;
Standard_Real rModulus1;
Standard_Real rModulus2;
Standard_Real PI_VALUE=3.1415926535898; // pj change
Standard_Real temp, Csita, sum, average, nx,ny,nz;
int Con=0;
sum=0.0;
for(int k=0;k<=n;k++)
{
normal1=Cal_normal(i, ii,us,ue,vs,ve, sur1, surInvert[i], k, n);//
if(Mark==1)
{
normal2=Cal_normal(j, jj,us,ue,vs,ve, sur2, surInvert[j], k, n);//
}
else
{
normal2=Cal_normal2(j, jj,us,ue,vs,ve, sur2, surInvert[j], k, n);//
}
rModulus1 = sqrt(normal1.X()*normal1.X()+normal1.Y()*normal1.Y()+normal1.Z()*normal1.Z());
rModulus2 = sqrt(normal2.X()*normal2.X()+normal2.Y()*normal2.Y()+normal2.Z()*normal2.Z());
if(rModulus1>0&&rModulus2>0)
{
temp=normal1.X()*normal2.X()+normal1.Y()*normal2.Y()+normal1.Z()*normal2.Z();
Csita=temp/rModulus1/rModulus2;
if(Csita>1.0)
{
Csita=1.0;
}
else if(Csita<-1.0)
{
Csita=-1.0;
}
sita[k]=acos(Csita)*180/PI_VALUE;
/*cout<< "\t" << sita[i];*/
if(k>0&&k<n)
{
Con++;
sum+=sita[k];
}
}
}
if(Con>0)
{
average=sum/Con;
}
else
{
average=0.0;
}
return(average);
}
Handle_Geom_BSplineSurface Modefy_sur(int i, int Mark, vector<Handle_Geom_BSplineSurface> sur1, Standard_Real* temp, vector<bool> modefiedu, vector<bool> modefiedv)
{
int row,col;
gp_Pnt aP;//, aQ
/*Handle_Geom_BSplineSurface sur=sur1[i]->Copy();*/
Handle(Geom_BSplineSurface) sur=Handle(Geom_BSplineSurface)::DownCast(sur1[i]->Copy());
row=sur->NbUPoles();
col=sur->NbVPoles();
if(Mark==0)//00-10 vs[i]
{
for(int k=2;k<row;k++)
{
aP=sur1[i]->Pole(k,2);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur->SetPole(k,2, aP);
//aQ=sur1[i]->Pole(k,2);
}
}
else if(Mark==1)//10-11 ue[i]
{
for(int k=2;k<col;k++)
{
aP=sur1[i]->Pole(row-1,k);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur->SetPole(row-1,k, aP);
//aQ=sur1[i]->Pole(row-1,k);
}
}
else if(Mark==2)//11-01 ve[i]
{
for(int k=2;k<row;k++)
{
aP=sur1[i]->Pole(k,col-1);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur->SetPole(k,col-1, aP);
//aQ=sur1[i]->Pole(k,col-1);
}
}
else// if(Mark==3)//01-00 us[i]
{
for(int k=2;k<col;k++)
{
aP=sur1[i]->Pole(2,k);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur->SetPole(2,k, aP);
//aQ=sur1[i]->Pole(2,k);
}
}
return(sur);
}
void Modefy_sur2(int i, int Mark, vector<Handle_Geom_BSplineSurface> sur1, Standard_Real* temp, vector<bool> modefiedu, vector<bool> modefiedv)
{
int row,col;
gp_Pnt aP;//, aQ
row=sur1[i]->NbUPoles();
col=sur1[i]->NbVPoles();
if(Mark==0)//00-10 vs[i]
{
if(col>3||modefiedu[i]==false)
{
for(int k=2;k<row;k++)
{
aP=sur1[i]->Pole(k,2);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur1[i]->SetPole(k,2, aP);
//aQ=sur1[i]->Pole(k,2);
}
modefiedu[i]=true;
}
}
else if(Mark==1)//10-11 ue[i]
{
if(row>3||modefiedv[i]==false)
{
for(int k=2;k<col;k++)
{
aP=sur1[i]->Pole(row-1,k);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur1[i]->SetPole(row-1,k, aP);
//aQ=sur1[i]->Pole(row-1,k);
}
modefiedv[i]=true;
}
}
else if(Mark==2)//11-01 ve[i]
{
if(col>3||modefiedu[i]==false)
{
for(int k=2;k<row;k++)
{
aP=sur1[i]->Pole(k,col-1);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur1[i]->SetPole(k,col-1, aP);
//aQ=sur1[i]->Pole(k,col-1);
}
modefiedu[i]=true;
}
}
else// if(Mark==3)//01-00 us[i]
{
if(row>3||modefiedv[i]==false)
{
for(int k=2;k<col;k++)
{
aP=sur1[i]->Pole(2,k);
aP.SetCoord(aP.X()+temp[0],aP.Y()+temp[1],aP.Z()+temp[2]);
sur1[i]->SetPole(2,k, aP);
//aQ=sur1[i]->Pole(2,k);
}
modefiedv[i]=true;
}
}
}
gp_Vec Cal_normal(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert, int k, int n)//
{
double uu, vv;
gp_Pnt aP;
gp_Vec aDu;
gp_Vec aDv;
gp_Vec normal;
Standard_Real rModulus;
if(Mark==0)//00-10 vs[i]
{
uu=us[i]+(double)k / n *(ue[i]-us[i]);
vv=vs[i];
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==1)//10-11 ue[i]
{
uu=ue[i];
vv=vs[i]+(double)k / n *(ve[i]-vs[i]);
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
else if(Mark==2)//11-01 ve[i]
{
uu=ue[i]+(double)k / n *(us[i]-ue[i]);
vv=ve[i];
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==3)//01-00 us[i]
{
uu=us[i];
vv=ve[i]+(double)k / n *(vs[i]-ve[i]);
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
myBSplineSurface->D1(uu, vv, aP, aDu, aDv);
if(myInvert==false)
{
normal = aDu.Crossed(aDv);
}
else
{
normal = -aDu.Crossed(aDv);
}
rModulus = sqrt(normal.X()*normal.X()+normal.Y()*normal.Y()+normal.Z()*normal.Z());
if (rModulus > 1.0e-9)
{
normal.Normalize();
}
else
{
normal.SetCoord(0., 0., 0.);
}
if (fabs(normal.X())<1.0e-6)
{
normal.SetCoord(0.0,normal.Y(),normal.Z());
}
if (fabs(normal.Y())<1.0e-6)
{
normal.SetCoord(normal.X(),0.0,normal.Z());
}
if (fabs(normal.Z())<1.0e-6)
{
normal.SetCoord(normal.X(),normal.Y(),0.0);
}
//cout<<fixed<<setprecision(6)<< "\t" << normal.X() << "\t" << normal.Y() << "\t" << normal.Z();
return normal;
/*cout<< "\t" << aP.X() << "\t" << aP.Y() << "\t" << aP.Z();*/
}
gp_Vec Cal_normal2(int i, int Mark, vector<Standard_Real> us, vector<Standard_Real> ue, vector<Standard_Real> vs, vector<Standard_Real> ve, Handle_Geom_BSplineSurface myBSplineSurface, bool myInvert, int k, int n)//
{
double uu, vv;
gp_Pnt aP;
gp_Vec aDu;
gp_Vec aDv;
gp_Vec normal;
Standard_Real rModulus;
if(Mark==0)//00-10 vs[i]
{
uu=us[i]+(double)k / n *(ue[i]-us[i]);
vv=vs[i];
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==1)//10-11 ue[i]
{
uu=ue[i];
vv=vs[i]+(double)k / n *(ve[i]-vs[i]);
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
else if(Mark==2)//11-01 ve[i]
{
uu=ue[i]+(double)k / n *(us[i]-ue[i]);
vv=ve[i];
//cout<< "\t" << us[i] << "\t" << ue[i];
}
else if(Mark==3)//01-00 us[i]
{
uu=us[i];
vv=ve[i]+(double)k / n *(vs[i]-ve[i]);
//cout<< "\t" << vs[i] << "\t" << ve[i];
}
myBSplineSurface->D1(uu, vv, aP, aDu, aDv);
if(myInvert==false)
{
normal = aDu.Crossed(aDv);
}
else
{
normal = -aDu.Crossed(aDv);
}
rModulus = sqrt(normal.X()*normal.X()+normal.Y()*normal.Y()+normal.Z()*normal.Z());
if (rModulus > 1.0e-9)
{
normal.Normalize();
}
else
{
normal.SetCoord(0., 0., 0.);
}
if (fabs(normal.X())<1.0e-6)
{
normal.SetCoord(0.0,normal.Y(),normal.Z());
}
if (fabs(normal.Y())<1.0e-6)
{
normal.SetCoord(normal.X(),0.0,normal.Z());
}
if (fabs(normal.Z())<1.0e-6)
{
normal.SetCoord(normal.X(),normal.Y(),0.0);
}
//cout<<fixed<<setprecision(6)<< "\t" << normal.X() << "\t" << normal.Y() << "\t" << normal.Z();
return normal;
/*cout<< "\t" << aP.X() << "\t" << aP.Y() << "\t" << aP.Z();*/
}
// END GUAN ADDED