144 lines
2.7 KiB
C++
144 lines
2.7 KiB
C++
#include "Stdafx.h"
|
|
#include "SectionAlgo.h"
|
|
|
|
|
|
SectionAlgo::SectionAlgo(void)
|
|
{
|
|
}
|
|
|
|
SectionAlgo::SectionAlgo( TopoDS_Shape shape1, TopoDS_Shape shape2 )
|
|
{
|
|
this->S1 = shape1;
|
|
this->S2 = shape2;
|
|
isDone = false;
|
|
}
|
|
|
|
|
|
SectionAlgo::~SectionAlgo(void)
|
|
{
|
|
}
|
|
|
|
TopoDS_Shape SectionAlgo::SectionFF(TopoDS_Face face1, TopoDS_Face face2)
|
|
{
|
|
TopoDS_Compound TopoShape;
|
|
BRep_Builder b;
|
|
b.MakeCompound(TopoShape);
|
|
try
|
|
{
|
|
BRepAlgoAPI_Section sec(face1,face2,Standard_False); //update by Yu 2012-09-30
|
|
sec.ComputePCurveOn1(Standard_True);
|
|
sec.ComputePCurveOn2(Standard_True);
|
|
sec.Approximation(true);
|
|
sec.Build();
|
|
|
|
if(!sec.IsDone())
|
|
{
|
|
return TopoShape;
|
|
}
|
|
|
|
TopoDS_Shape S = sec.Shape();
|
|
for(TopExp_Explorer ex(S, TopAbs_EDGE);ex.More(); ex.Next())
|
|
{
|
|
TopoDS_Edge edge = TopoDS::Edge(ex.Current());
|
|
if(sec.HasAncestorFaceOn1(edge, face1) && sec.HasAncestorFaceOn2(edge, face2))
|
|
{
|
|
b.Add(TopoShape, edge);
|
|
}
|
|
}
|
|
}
|
|
catch (Standard_Failure e)
|
|
{
|
|
throw e;
|
|
}
|
|
return TopoShape;
|
|
}
|
|
|
|
TopoDS_Shape SectionAlgo::SectionSS(TopoDS_Shape shape1, TopoDS_Shape shape2)
|
|
{
|
|
TopoDS_Compound TopoShape;
|
|
BRep_Builder b;
|
|
b.MakeCompound(TopoShape);
|
|
|
|
|
|
map<int, TopoDS_Edge> mapEdge;
|
|
|
|
for(TopExp_Explorer ex(shape1, TopAbs_FACE); ex.More(); ex.Next())
|
|
{
|
|
TopoDS_Face face1 = TopoDS::Face(ex.Current());
|
|
TopoDS_Shape shape = SectionFS(face1, shape2);
|
|
|
|
for(TopExp_Explorer ex1(shape, TopAbs_EDGE); ex1.More(); ex1.Next())
|
|
{
|
|
mapEdge.insert(make_pair(mapEdge.size(), TopoDS::Edge(ex1.Current())));
|
|
}
|
|
}
|
|
|
|
vector<vector<int>> edgeIndex;
|
|
GetWireSingleEdges(mapEdge,edgeIndex);
|
|
|
|
for(int i = 0; i < edgeIndex.size(); i++)
|
|
{
|
|
vector<int> edges = edgeIndex[i];
|
|
|
|
for(int j = 0; j < edges.size(); j++)
|
|
{
|
|
b.Add(TopoShape, mapEdge[edges[j]]);
|
|
}
|
|
}
|
|
|
|
return TopoShape;
|
|
}
|
|
|
|
TopoDS_Shape SectionAlgo::SectionFS(TopoDS_Face face1, TopoDS_Shape shape2)
|
|
{
|
|
TopoDS_Compound TopoShape;
|
|
BRep_Builder b;
|
|
b.MakeCompound(TopoShape);
|
|
|
|
map<int, TopoDS_Edge> mapEdge;
|
|
|
|
for(TopExp_Explorer ex(shape2, TopAbs_FACE); ex.More(); ex.Next())
|
|
{
|
|
TopoDS_Face face2 = TopoDS::Face(ex.Current());
|
|
TopoDS_Shape shape = SectionFF(face1, face2);
|
|
|
|
for(TopExp_Explorer ex1(shape, TopAbs_EDGE); ex1.More(); ex1.Next())
|
|
{
|
|
mapEdge.insert(make_pair(mapEdge.size(), TopoDS::Edge(ex1.Current())));
|
|
}
|
|
}
|
|
|
|
vector<vector<int>> edgeIndex;
|
|
GetWireSingleEdges(mapEdge,edgeIndex);
|
|
|
|
for(int i = 0; i < edgeIndex.size(); i++)
|
|
{
|
|
vector<int> edges = edgeIndex[i];
|
|
for(int j = 0; j < edges.size(); j++)
|
|
{
|
|
b.Add(TopoShape, mapEdge[edges[j]]);
|
|
}
|
|
}
|
|
return TopoShape;
|
|
}
|
|
|
|
void SectionAlgo::Perform()
|
|
{
|
|
try
|
|
{
|
|
this->result = SectionSS(S1, S2);
|
|
}
|
|
catch (Standard_Failure e)
|
|
{
|
|
return;
|
|
}
|
|
if(!result.IsNull())
|
|
{
|
|
isDone = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|