0025418: Debug output to be limited to OCC development environment
[occt.git] / src / IntPatch / IntPatch_CSFunction.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <IntPatch_CSFunction.ixx>
16
17 #include <Adaptor3d_HSurface.hxx>
18 #include <Adaptor3d_HSurfaceTool.hxx>
19 #include <Adaptor2d_HCurve2d.hxx>
20 #include <IntPatch_HCurve2dTool.hxx>
21
22 #include <gp_Pnt.hxx>
23 #include <gp_Vec.hxx>
24 #include <gp_Pnt2d.hxx>
25 #include <gp_Vec2d.hxx>
26
27 #ifndef OCCT_DEBUG
28 #define No_Standard_RangeError
29 #define No_Standard_OutOfRange
30 #endif
31
32
33 #define SURFACE1 (*((Handle(Adaptor3d_HSurface) *)(surface1)))
34 #define SURFACE2 (*((Handle(Adaptor3d_HSurface) *)(surface2)))
35 #define CURVE    (*((Handle(Adaptor2d_HCurve2d) *)(curve)))
36
37 IntPatch_CSFunction::IntPatch_CSFunction(const Handle(Adaptor3d_HSurface)& S1,
38                                                const Handle(Adaptor2d_HCurve2d)& C,
39                                                const Handle(Adaptor3d_HSurface)& S2)
40 {
41   surface1 = (Standard_Address)(&S1);
42   surface2 = (Standard_Address)(&S2);
43   curve    = (Standard_Address)(&C);
44   f = 0.;
45 }
46
47 Standard_Integer IntPatch_CSFunction::NbVariables()const { return 3;}
48
49 Standard_Integer IntPatch_CSFunction::NbEquations()const { return 3;}
50
51 Standard_Boolean IntPatch_CSFunction::Value(const math_Vector& X,
52                                             math_Vector& F){
53
54   gp_Pnt Psurf(Adaptor3d_HSurfaceTool::Value(SURFACE1,X(1),X(2)));
55   gp_Pnt2d p2d(IntPatch_HCurve2dTool::Value(CURVE,X(3)));
56   gp_Pnt Pcurv(Adaptor3d_HSurfaceTool::Value(SURFACE2,p2d.X(),p2d.Y()));
57
58   F(1) = Psurf.X()-Pcurv.X();
59   F(2) = Psurf.Y()-Pcurv.Y();
60   F(3) = Psurf.Z()-Pcurv.Z();
61   f = F(1)*F(1)+ F(2)*F(2)+ F(3)*F(3);
62   p = gp_Pnt((Psurf.XYZ()+Pcurv.XYZ())/2.);
63   return Standard_True;
64 }
65
66 Standard_Boolean IntPatch_CSFunction::Derivatives ( const math_Vector& X,
67                                                     math_Matrix& D) {
68   gp_Pnt Psurf,Pcurv;
69   gp_Vec D1u,D1v,D1w;
70   gp_Pnt2d p2d;
71   gp_Vec2d d2d;
72   gp_Vec d1u,d1v;
73
74   Adaptor3d_HSurfaceTool::D1(SURFACE1,X(1),X(2),Psurf,D1u,D1v);
75   IntPatch_HCurve2dTool::D1(CURVE,X(3),p2d,d2d);
76   Adaptor3d_HSurfaceTool::D1(SURFACE2,p2d.X(),p2d.Y(),Pcurv,d1u,d1v);
77   D1w.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
78
79   D(1,1) = D1u.X();
80   D(1,2) = D1v.X();
81   D(1,3) = -D1w.X();
82   D(2,1) = D1u.Y();
83   D(2,2) = D1v.Y();
84   D(2,3) = -D1w.Y();
85   D(3,1) = D1u.Z();
86   D(3,2) = D1v.Z();
87   D(3,3) = -D1w.Z();
88   return Standard_True;
89
90
91 Standard_Boolean IntPatch_CSFunction::Values( const math_Vector& X,
92                                               math_Vector& F,
93                                               math_Matrix& D) {
94   gp_Pnt Psurf,Pcurv;
95   gp_Vec D1u,D1v,D1w;
96
97   gp_Pnt2d p2d;
98   gp_Vec2d d2d;
99   gp_Vec d1u,d1v;
100
101   Adaptor3d_HSurfaceTool::D1(SURFACE1,X(1),X(2),Psurf,D1u,D1v);
102   IntPatch_HCurve2dTool::D1(CURVE,X(3),p2d,d2d);
103   Adaptor3d_HSurfaceTool::D1(SURFACE2,p2d.X(),p2d.Y(),Pcurv,d1u,d1v);
104   D1w.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
105
106   D(1,1) = D1u.X();
107   D(1,2) = D1v.X();
108   D(1,3) = -D1w.X();
109   D(2,1) = D1u.Y();
110   D(2,2) = D1v.Y();
111   D(2,3) = -D1w.Y();
112   D(3,1) = D1u.Z();
113   D(3,2) = D1v.Z();
114   D(3,3) = -D1w.Z();
115   F(1) = Psurf.X()-Pcurv.X();
116   F(2) = Psurf.Y()-Pcurv.Y();
117   F(3) = Psurf.Z()-Pcurv.Z();
118   f = F(1)*F(1)+ F(2)*F(2)+ F(3)*F(3);
119   p = gp_Pnt((Psurf.XYZ()+Pcurv.XYZ())/2.);
120   return Standard_True;
121 }
122
123 const gp_Pnt& IntPatch_CSFunction::Point() const { return p;}
124
125 Standard_Real IntPatch_CSFunction::Root() const { return f;}
126
127 const Handle(Adaptor3d_HSurface)& IntPatch_CSFunction::AuxillarSurface() const { 
128   return SURFACE1;}
129
130 const Handle(Adaptor2d_HCurve2d)& IntPatch_CSFunction::AuxillarCurve() const { 
131   return CURVE;}
132
133 #undef SURFACE1
134 #undef SURFACE2
135 #undef CURVE