Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Created on: 1995-05-29
// Created by: Jacques GOUSSARD
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRepIntCurveSurface_Inter.hxx>
#include <Geom_Circle.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <gp_Ax1.hxx>
#include <gp_Circ.hxx>
#include <gp_Lin.hxx>
#include <LocOpe_CurveShapeIntersector.hxx>
#include <LocOpe_PntFace.hxx>
#include <Precision.hxx>
#include <StdFail_NotDone.hxx>
#include <TopoDS_Shape.hxx>
static void Perform(BRepIntCurveSurface_Inter&, NCollection_Sequence<LocOpe_PntFace>&);
//=================================================================================================
void LocOpe_CurveShapeIntersector::Init(const gp_Ax1& Axis, const TopoDS_Shape& S)
{
myDone = false;
myPoints.Clear();
if (S.IsNull())
{
return;
}
double Tol = Precision::Confusion();
BRepIntCurveSurface_Inter theInt;
theInt.Init(S, gp_Lin(Axis), Tol);
Perform(theInt, myPoints);
myDone = true;
}
//=================================================================================================
void LocOpe_CurveShapeIntersector::Init(const gp_Circ& C, const TopoDS_Shape& S)
{
myDone = false;
myPoints.Clear();
if (S.IsNull())
{
return;
}
double Tol = Precision::Confusion();
occ::handle<Geom_Circle> GC = new Geom_Circle(C);
GeomAdaptor_Curve AC(GC, 0., 2. * M_PI);
BRepIntCurveSurface_Inter theInt;
theInt.Init(S, AC, Tol);
Perform(theInt, myPoints);
myDone = true;
}
//=================================================================================================
bool LocOpe_CurveShapeIntersector::LocalizeAfter(const double From,
TopAbs_Orientation& Or,
int& IndFrom,
int& IndTo) const
{
if (!myDone)
{
throw StdFail_NotDone();
}
double Eps = Precision::Confusion();
double param, FMEPS = From - Eps;
int i, ifirst, nbpoints = myPoints.Length();
for (ifirst = 1; ifirst <= nbpoints; ifirst++)
{
if (myPoints(ifirst).Parameter() >= FMEPS)
{
break;
}
}
bool RetVal = false;
if (ifirst <= nbpoints)
{
i = ifirst;
IndFrom = ifirst;
bool found = false;
while (!found)
{
Or = myPoints(i).Orientation();
param = myPoints(i).Parameter();
i = i + 1;
while (i <= nbpoints)
{
if (myPoints(i).Parameter() - param <= Eps)
{
if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation())
{
Or = TopAbs_EXTERNAL;
}
i++;
}
else
{
break;
}
}
if (Or == TopAbs_EXTERNAL)
{
found = (i > nbpoints);
IndFrom = i;
}
else
{ // on a une intersection franche
IndTo = i - 1;
found = true;
RetVal = true;
}
}
}
return RetVal;
}
//=================================================================================================
bool LocOpe_CurveShapeIntersector::LocalizeBefore(const double From,
TopAbs_Orientation& Or,
int& IndFrom,
int& IndTo) const
{
if (!myDone)
{
throw StdFail_NotDone();
}
double Eps = Precision::Confusion();
double param, FPEPS = From + Eps;
int i, ifirst, nbpoints = myPoints.Length();
for (ifirst = nbpoints; ifirst >= 1; ifirst--)
{
if (myPoints(ifirst).Parameter() <= FPEPS)
{
break;
}
}
bool RetVal = false;
if (ifirst >= 1)
{
i = ifirst;
IndTo = ifirst;
bool found = false;
while (!found)
{
Or = myPoints(i).Orientation();
param = myPoints(i).Parameter();
i = i - 1;
while (i >= 1)
{
if (param - myPoints(i).Parameter() <= Eps)
{
if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation())
{
Or = TopAbs_EXTERNAL;
}
i--;
}
else
{
break;
}
}
if (Or == TopAbs_EXTERNAL)
{
found = (i < 1);
IndTo = i;
}
else
{ // on a une intersection franche
IndFrom = i + 1;
found = true;
RetVal = true;
}
}
}
return RetVal;
}
//=================================================================================================
bool LocOpe_CurveShapeIntersector::LocalizeAfter(const int FromInd,
TopAbs_Orientation& Or,
int& IndFrom,
int& IndTo) const
{
if (!myDone)
{
throw StdFail_NotDone();
}
int nbpoints = myPoints.Length();
if (FromInd >= nbpoints)
{
return false;
}
double Eps = Precision::Confusion();
double param, FMEPS;
int i, ifirst;
if (FromInd >= 1)
{
FMEPS = myPoints(FromInd).Parameter() - Eps;
for (ifirst = FromInd + 1; ifirst <= nbpoints; ifirst++)
{
if (myPoints(ifirst).Parameter() >= FMEPS)
{
break;
}
}
}
else
{
ifirst = 1;
}
bool RetVal = false;
if (ifirst <= nbpoints)
{
i = ifirst;
IndFrom = ifirst;
bool found = false;
while (!found)
{
Or = myPoints(i).Orientation();
param = myPoints(i).Parameter();
i = i + 1;
while (i <= nbpoints)
{
if (myPoints(i).Parameter() - param <= Eps)
{
if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation())
{
Or = TopAbs_EXTERNAL;
}
i++;
}
else
{
break;
}
}
if (Or == TopAbs_EXTERNAL)
{
found = (i > nbpoints);
IndFrom = i;
}
else
{ // on a une intersection franche
IndTo = i - 1;
found = true;
RetVal = true;
}
}
}
return RetVal;
}
//=================================================================================================
bool LocOpe_CurveShapeIntersector::LocalizeBefore(const int FromInd,
TopAbs_Orientation& Or,
int& IndFrom,
int& IndTo) const
{
if (!myDone)
{
throw StdFail_NotDone();
}
int nbpoints = myPoints.Length();
if (FromInd <= 1)
{
return false;
}
double Eps = Precision::Confusion();
double param, FPEPS;
int i, ifirst;
if (FromInd <= nbpoints)
{
FPEPS = myPoints(FromInd).Parameter() + Eps;
for (ifirst = FromInd - 1; ifirst >= 1; ifirst--)
{
if (myPoints(ifirst).Parameter() <= FPEPS)
{
break;
}
}
}
else
{
ifirst = nbpoints;
}
bool RetVal = false;
if (ifirst >= 1)
{
i = ifirst;
IndTo = ifirst;
bool found = false;
while (!found)
{
Or = myPoints(i).Orientation();
param = myPoints(i).Parameter();
i = i - 1;
while (i >= 1)
{
if (param - myPoints(i).Parameter() <= Eps)
{
if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation())
{
Or = TopAbs_EXTERNAL;
}
i--;
}
else
{
break;
}
}
if (Or == TopAbs_EXTERNAL)
{
found = (i < 1);
IndTo = i;
}
else
{ // on a une intersection franche
IndFrom = i + 1;
found = true;
RetVal = true;
}
}
}
return RetVal;
}
//=================================================================================================
static void Perform(BRepIntCurveSurface_Inter& theInt,
NCollection_Sequence<LocOpe_PntFace>& thePoints)
{
double param, paramu, paramv;
int i, nbpoints = 0;
TopAbs_Orientation theor = TopAbs_FORWARD, orface;
while (theInt.More())
{
const gp_Pnt& thept = theInt.Pnt();
const TopoDS_Face& theface = theInt.Face();
orface = theface.Orientation();
param = theInt.W();
paramu = theInt.U();
paramv = theInt.V();
switch (theInt.Transition())
{
case IntCurveSurface_In:
if (orface == TopAbs_FORWARD)
{
theor = TopAbs_FORWARD;
}
else if (orface == TopAbs_REVERSED)
{
theor = TopAbs_REVERSED;
}
else
{
theor = TopAbs_EXTERNAL;
}
break;
case IntCurveSurface_Out:
if (orface == TopAbs_FORWARD)
{
theor = TopAbs_REVERSED;
}
else if (orface == TopAbs_REVERSED)
{
theor = TopAbs_FORWARD;
}
else
{
theor = TopAbs_EXTERNAL;
}
break;
case IntCurveSurface_Tangent:
theor = TopAbs_EXTERNAL;
break;
}
LocOpe_PntFace newpt(thept, theface, theor, param, paramu, paramv);
for (i = 1; i <= nbpoints; i++)
{
if (thePoints(i).Parameter() - param > 0.)
{
break;
}
}
if (i <= nbpoints)
{
thePoints.InsertBefore(i, newpt);
}
else
{
thePoints.Append(newpt);
}
nbpoints++;
theInt.Next();
}
}