mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-06-10 11:34:06 +03:00
390 lines
8.9 KiB
Plaintext
Executable File
390 lines
8.9 KiB
Plaintext
Executable File
// Created on: 1995-07-02
|
|
// Created by: Laurent BUCHARD
|
|
// Copyright (c) 1995-1999 Matra Datavision
|
|
// Copyright (c) 1999-2012 OPEN CASCADE SAS
|
|
//
|
|
// The content of this file is subject to the Open CASCADE Technology Public
|
|
// License Version 6.5 (the "License"). You may not use the content of this file
|
|
// except in compliance with the License. Please obtain a copy of the License
|
|
// at http://www.opencascade.org and read it completely before using this file.
|
|
//
|
|
// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
|
|
// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
|
|
//
|
|
// The Original Code and all software distributed under the License is
|
|
// distributed on an "AS IS" basis, without warranty of any kind, and the
|
|
// Initial Developer hereby disclaims all such warranties, including without
|
|
// limitation, any warranties of merchantability, fitness for a particular
|
|
// purpose or non-infringement. Please see the License for the specific terms
|
|
// and conditions governing the rights and limitations under the License.
|
|
|
|
|
|
#include <Extrema_EPCOfExtPC2d.hxx>
|
|
#include <Extrema_POnCurv2d.hxx>
|
|
|
|
#include <GeomAbs_SurfaceType.hxx>
|
|
#include <Standard_OutOfRange.hxx>
|
|
|
|
#include <Handle_Geom_BezierSurface.hxx>
|
|
#include <Handle_Geom_BSplineSurface.hxx>
|
|
#include <Handle_Geom2d_BezierCurve.hxx>
|
|
#include <Handle_Geom2d_BSplineCurve.hxx>
|
|
|
|
#include <Geom_BezierSurface.hxx>
|
|
#include <Geom_BSplineSurface.hxx>
|
|
#include <Geom2d_BezierCurve.hxx>
|
|
#include <Geom2d_BSplineCurve.hxx>
|
|
|
|
static Standard_Real uinf,vinf,usup,vsup;
|
|
|
|
#include TheHSurface_hxx
|
|
#include TheHCurve2d_hxx
|
|
#include TheHVertex_hxx
|
|
|
|
|
|
Standard_Integer Contap_HContToolGen::NbSamplesV
|
|
(const TheHSurface& S,
|
|
const Standard_Real ,
|
|
const Standard_Real )
|
|
{
|
|
Standard_Integer nbs;
|
|
GeomAbs_SurfaceType typS = S->GetType();
|
|
switch(typS) {
|
|
case GeomAbs_Plane:
|
|
{
|
|
nbs = 2;
|
|
}
|
|
break;
|
|
case GeomAbs_BezierSurface:
|
|
{
|
|
nbs = 3 + S->NbVPoles();
|
|
}
|
|
break;
|
|
case GeomAbs_BSplineSurface:
|
|
{
|
|
//-- Handle_Geom_BSplineSurface& HBS=S->BSpline();
|
|
nbs = S->NbVKnots();
|
|
nbs*= S->VDegree();
|
|
if(nbs < 2) nbs=2;
|
|
|
|
}
|
|
break;
|
|
case GeomAbs_Cylinder:
|
|
case GeomAbs_Cone:
|
|
case GeomAbs_Sphere:
|
|
case GeomAbs_Torus:
|
|
case GeomAbs_SurfaceOfRevolution:
|
|
case GeomAbs_SurfaceOfExtrusion:
|
|
{
|
|
nbs = 15;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
{
|
|
nbs = 10;
|
|
}
|
|
break;
|
|
}
|
|
return(nbs);
|
|
}
|
|
|
|
Standard_Integer Contap_HContToolGen::NbSamplesU
|
|
(const TheHSurface& S,
|
|
const Standard_Real ,
|
|
const Standard_Real )
|
|
{
|
|
Standard_Integer nbs;
|
|
GeomAbs_SurfaceType typS = S->GetType();
|
|
switch(typS) {
|
|
case GeomAbs_Plane:
|
|
{
|
|
nbs = 2;
|
|
}
|
|
break;
|
|
case GeomAbs_BezierSurface:
|
|
{
|
|
nbs = 3 + S->NbUPoles();
|
|
}
|
|
break;
|
|
case GeomAbs_BSplineSurface:
|
|
{
|
|
//-- Handle_Geom_BSplineSurface& HBS=S->BSpline();
|
|
nbs = S->NbUKnots();
|
|
nbs*= S->UDegree();
|
|
if(nbs < 2) nbs=2;
|
|
|
|
}
|
|
break;
|
|
case GeomAbs_Torus:
|
|
{
|
|
nbs = 20;
|
|
}
|
|
break;
|
|
case GeomAbs_Cylinder:
|
|
case GeomAbs_Cone:
|
|
case GeomAbs_Sphere:
|
|
case GeomAbs_SurfaceOfRevolution:
|
|
case GeomAbs_SurfaceOfExtrusion:
|
|
{
|
|
nbs = 10;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
{
|
|
nbs = 10;
|
|
}
|
|
break;
|
|
}
|
|
return(nbs);
|
|
}
|
|
|
|
Standard_Integer Contap_HContToolGen::NbSamplePoints
|
|
(const TheHSurface& S)
|
|
{
|
|
uinf = S->FirstUParameter();
|
|
usup = S->LastUParameter();
|
|
vinf = S->FirstVParameter();
|
|
vsup = S->LastVParameter();
|
|
|
|
if (usup < uinf) {
|
|
Standard_Real temp = uinf;
|
|
uinf = usup;
|
|
usup = temp;
|
|
}
|
|
if (vsup < vinf) {
|
|
Standard_Real temp = vinf;
|
|
vinf = vsup;
|
|
vsup = temp;
|
|
}
|
|
if (uinf == RealFirst() && usup == RealLast()) {
|
|
uinf = -1.e5;
|
|
usup = 1.e5;
|
|
}
|
|
else if (uinf == RealFirst()) {
|
|
uinf = usup - 2.e5;
|
|
}
|
|
else if (usup == RealLast()) {
|
|
usup = uinf + 2.e5;
|
|
}
|
|
|
|
if (vinf == RealFirst() && vsup == RealLast()) {
|
|
vinf = -1.e5;
|
|
vsup = 1.e5;
|
|
}
|
|
else if (vinf == RealFirst()) {
|
|
vinf = vsup - 2.e5;
|
|
}
|
|
else if (vsup == RealLast()) {
|
|
vsup = vinf + 2.e5;
|
|
}
|
|
if(S->GetType() == GeomAbs_BSplineSurface) {
|
|
Standard_Integer m = (NbSamplesU(S,uinf,usup)/3) * (NbSamplesV(S,vinf,vsup)/3);
|
|
if(m>5) return(m);
|
|
else return(5);
|
|
}
|
|
else
|
|
return 5;
|
|
}
|
|
|
|
void Contap_HContToolGen::SamplePoint (const TheHSurface& S,
|
|
const Standard_Integer Index,
|
|
Standard_Real& U,
|
|
Standard_Real& V )
|
|
{
|
|
if(S->GetType() == GeomAbs_BSplineSurface) {
|
|
Standard_Integer nbIntU = NbSamplesU(S,uinf,usup)/3;
|
|
Standard_Integer nbIntV = NbSamplesV(S,vinf,vsup)/3;
|
|
if(nbIntU * nbIntV >5) {
|
|
Standard_Integer indU = (Index-1)/nbIntU; //---- 0 --> nbIntV
|
|
Standard_Integer indV = (Index-1) - indU*nbIntU; //---- 0 --> nbIntU
|
|
|
|
U = uinf + ((usup-uinf)/((Standard_Real)(nbIntU+1)))*(Standard_Real)(indU+1);
|
|
V = vinf + ((vsup-vinf)/((Standard_Real)(nbIntV+2)))*(Standard_Real)(indV+1);
|
|
|
|
//-- cout<<"Index :"<<Index<<" uinf:"<<uinf<<" usup:"<<usup<<" vinf:"<<vinf<<" vsup:"<<vsup<<" ";
|
|
//-- cout<<" ("<<indU<<"/"<<nbIntU<<" ->U:"<<U<<" ";
|
|
//-- cout<<" ("<<indV<<"/"<<nbIntV<<" ->V:"<<V<<endl;
|
|
return;
|
|
}
|
|
}
|
|
|
|
switch (Index) {
|
|
case 1:
|
|
U = 0.75*uinf + 0.25*usup; //0.25;
|
|
V = 0.75*vinf + 0.25*vsup; //0.25;
|
|
break;
|
|
case 2:
|
|
U = 0.75*uinf + 0.25*usup; //0.25;
|
|
V = 0.25*vinf + 0.75*vsup; //0.75;
|
|
break;
|
|
case 3:
|
|
U = 0.25*uinf + 0.75*usup; //0.75;
|
|
V = 0.75*vinf + 0.25*vsup; //0.25;
|
|
break;
|
|
case 4:
|
|
U = 0.25*uinf + 0.75*usup; //0.75;
|
|
V = 0.25*vinf + 0.75*vsup; //0.75;
|
|
break;
|
|
default:
|
|
U = 0.5*(uinf+usup); //0.5;
|
|
V = 0.5*(vinf+vsup); //0.5;
|
|
}
|
|
}
|
|
|
|
|
|
Standard_Integer Contap_HContToolGen::NbSamplesOnArc
|
|
(const TheHCurve2d& A) {
|
|
|
|
GeomAbs_CurveType CurveType = A->GetType();
|
|
|
|
Standard_Real nbsOnC = 5;
|
|
switch(CurveType) {
|
|
case GeomAbs_Line:
|
|
nbsOnC = 2;
|
|
break;
|
|
case GeomAbs_Circle:
|
|
case GeomAbs_Ellipse:
|
|
case GeomAbs_Hyperbola:
|
|
case GeomAbs_Parabola:
|
|
nbsOnC = 10;
|
|
break;
|
|
case GeomAbs_BezierCurve:
|
|
nbsOnC = A->NbPoles();
|
|
break;
|
|
case GeomAbs_BSplineCurve: {
|
|
//-- Handle_Geom2d_BSplineCurve& BSC=A->BSpline();
|
|
nbsOnC = 2 + A->NbKnots() * A->Degree();
|
|
break;
|
|
}
|
|
default:
|
|
nbsOnC = 10;
|
|
}
|
|
return (Standard_Integer)(nbsOnC);
|
|
}
|
|
|
|
|
|
void Contap_HContToolGen::Bounds(const TheHCurve2d& A,
|
|
Standard_Real& Ufirst,
|
|
Standard_Real& Ulast)
|
|
{
|
|
Ufirst = A->FirstParameter();
|
|
Ulast = A->LastParameter();
|
|
}
|
|
|
|
|
|
Standard_Boolean Contap_HContToolGen::Project (const TheHCurve2d& C,
|
|
const gp_Pnt2d& P,
|
|
Standard_Real& Paramproj,
|
|
gp_Pnt2d& Ptproj)
|
|
|
|
{
|
|
|
|
Standard_Real epsX = 1.e-8;
|
|
Standard_Integer Nbu = 20;
|
|
Standard_Real Tol = 1.e-5;
|
|
Standard_Real Dist2;
|
|
|
|
Extrema_EPCOfExtPC2d extrema(P,C->Curve2d(),Nbu,epsX,Tol);
|
|
if (!extrema.IsDone()) {
|
|
return Standard_False;
|
|
}
|
|
Standard_Integer Nbext = extrema.NbExt();
|
|
if (Nbext == 0) {
|
|
return Standard_False;
|
|
}
|
|
Standard_Integer indexmin = 1;
|
|
Dist2 = extrema.SquareDistance(1);
|
|
for (Standard_Integer i=2; i<=Nbext; i++) {
|
|
if (extrema.SquareDistance(i) < Dist2) {
|
|
indexmin = i;
|
|
Dist2 = extrema.SquareDistance(i);
|
|
}
|
|
}
|
|
Paramproj = extrema.Point(indexmin).Parameter();
|
|
Ptproj = extrema.Point(indexmin).Value();
|
|
return Standard_True;
|
|
}
|
|
|
|
|
|
Standard_Real Contap_HContToolGen::Tolerance (const TheHVertex& V,
|
|
const TheHCurve2d& C)
|
|
{
|
|
// return BRepAdaptor2d_Curve2dTool::Resolution(C,BRep_Tool::Tolerance(V));
|
|
return V->Resolution(C);
|
|
}
|
|
|
|
Standard_Real Contap_HContToolGen::Parameter (const TheHVertex& V,
|
|
const TheHCurve2d& C)
|
|
{
|
|
// return BRep_Tool::Parameter(V,C.Edge());
|
|
return V->Parameter(C);
|
|
}
|
|
|
|
|
|
|
|
Standard_Boolean Contap_HContToolGen::HasBeenSeen
|
|
(const TheHCurve2d&)
|
|
{
|
|
return Standard_False;
|
|
}
|
|
|
|
Standard_Integer Contap_HContToolGen::NbPoints(const TheHCurve2d&)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void Contap_HContToolGen::Value(const TheHCurve2d&,
|
|
const Standard_Integer,
|
|
gp_Pnt&,
|
|
Standard_Real&,
|
|
Standard_Real&)
|
|
{
|
|
Standard_OutOfRange::Raise();
|
|
}
|
|
|
|
Standard_Boolean Contap_HContToolGen::IsVertex(const TheHCurve2d&,
|
|
const Standard_Integer)
|
|
{
|
|
return Standard_False;
|
|
}
|
|
|
|
void Contap_HContToolGen::Vertex(const TheHCurve2d&,
|
|
const Standard_Integer,
|
|
TheHVertex&)
|
|
{
|
|
Standard_OutOfRange::Raise();
|
|
}
|
|
|
|
Standard_Integer Contap_HContToolGen::NbSegments(const TheHCurve2d&)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
Standard_Boolean Contap_HContToolGen::HasFirstPoint
|
|
(const TheHCurve2d&,
|
|
const Standard_Integer,
|
|
Standard_Integer&)
|
|
{
|
|
Standard_OutOfRange::Raise();
|
|
return Standard_False;
|
|
}
|
|
|
|
Standard_Boolean Contap_HContToolGen::HasLastPoint
|
|
(const TheHCurve2d&,
|
|
const Standard_Integer,
|
|
Standard_Integer&)
|
|
{
|
|
Standard_OutOfRange::Raise();
|
|
return Standard_False;
|
|
}
|
|
|
|
Standard_Boolean Contap_HContToolGen::IsAllSolution
|
|
(const TheHCurve2d&)
|
|
|
|
{
|
|
return Standard_False;
|
|
}
|
|
|