0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / GProp / GProp_CelGProps.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
16 #include <ElCLib.hxx>
17 #include <gp.hxx>
18 #include <gp_Circ.hxx>
19 #include <gp_Lin.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp_Vec.hxx>
22 #include <GProp.hxx>
23 #include <GProp_CelGProps.hxx>
24 #include <math_Jacobi.hxx>
25 #include <math_Matrix.hxx>
26 #include <math_Vector.hxx>
27 #include <Standard_NotImplemented.hxx>
28
29 GProp_CelGProps::GProp_CelGProps(){}
30
31 void GProp_CelGProps::SetLocation(const gp_Pnt& CLocation)
32 {
33   loc = CLocation;
34 }
35
36
37 void GProp_CelGProps::Perform(const gp_Circ& C,                               
38                               const Standard_Real U1,
39                               const Standard_Real U2)
40 {
41   Standard_Real X0,Y0,Z0,Xa1,Ya1,Za1,Xa2,Ya2,Za2,Xa3,Ya3,Za3;
42   C.Location().Coord(X0,Y0,Z0);
43   C.XAxis().Direction().Coord(Xa1,Ya1,Za1);
44   C.YAxis().Direction().Coord(Xa2,Ya2,Za2);
45   C.Axis().Direction().Coord(Xa3,Ya3,Za3);
46   Standard_Real Ray = C.Radius();
47
48   dim = Ray*Abs(U2-U1);
49   Standard_Real xloc =Ray*(Sin(U2)-Sin(U1))/(U2-U1);
50   Standard_Real yloc =Ray*(Cos(U1)-Cos(U2))/(U2-U1);
51
52   g.SetCoord(xloc*Xa1+yloc*Xa2+X0,xloc*Ya1+yloc*Ya2+Y0,Z0);
53
54   math_Matrix Dm(1,3,1,3);
55   Dm(1,1)= Ray*Ray*Ray*(U2/2-U1/2-Sin(2*U2)/4+Sin(2*U1)/4);
56   Dm(2,2)= Ray*Ray*Ray*(U2/2-U1/2+Sin(2*U2)/4-Sin(2*U1)/4);
57   Dm(3,3)= Ray*Ray*dim; 
58   Dm(2,1)= Dm(1,2) = - Ray*Ray*Ray*(Cos(2*U1)/4-Cos(2*U2)/4);
59   Dm(3,1) = Dm(1,3) = 0.;
60   Dm(3,2) = Dm(2,3) = 0.;
61   math_Matrix Passage (1,3,1,3);
62   Passage(1,1) = Xa1; Passage(1,2) = Xa2 ;Passage(1,3) = Xa3;
63   Passage(2,1) = Ya1; Passage(2,2) = Ya2 ;Passage(2,3) = Ya3;
64   Passage(3,1) = Za1; Passage(3,2) = Za2 ;Passage(3,3) = Za3;
65
66   math_Jacobi J(Dm);
67   math_Vector V1(1,3),V2(1,3),V3(1,3);
68   J.Vector(1,V1);
69   V1.Multiply(Passage,V1);
70   V1.Multiply(J.Value(1));
71   J.Vector(2,V2);
72   V2.Multiply(Passage,V2);
73   V2.Multiply(J.Value(2));
74   J.Vector(3,V3);
75   V3.Multiply(Passage,V3);
76   V3.Multiply(J.Value(3));
77
78   inertia = gp_Mat (gp_XYZ(V1(1),V2(1),V3(1)),
79                     gp_XYZ(V1(2),V2(2),V3(2)),
80                     gp_XYZ(V1(3),V2(3),V3(3)));
81
82   gp_Mat Hop;
83   GProp::HOperator(g,loc,dim,Hop);
84   inertia = inertia+Hop;
85 }
86
87
88 void GProp_CelGProps::Perform(const gp_Lin& C,                        
89                               const Standard_Real U1,
90                               const Standard_Real U2)
91 {
92   gp_Ax1 Pos = C.Position();
93   gp_Pnt P1 = ElCLib::LineValue(U1,Pos);
94   dim =Abs(U2-U1);
95   gp_Pnt P2 = ElCLib::LineValue(U2,Pos);
96   g.SetCoord((P1.X()+P2.X())/2.,(P1.Y()+P2.Y())/2.,(P1.Z()+P2.Z())/2.);
97   Standard_Real Vx,Vy,Vz,X0,Y0,Z0;
98   Pos.Direction().Coord(Vx,Vy,Vz);
99   Pos.Location().Coord(X0,Y0,Z0);
100   Standard_Real alfa1 = (Vz*Vz+Vy*Vy)/3.;
101   Standard_Real alfa2 = Vy*Y0+Vz*Z0;
102   Standard_Real alfa3 = Y0*Y0+Z0*Z0;
103   Standard_Real Ixx =  (U2*(U2*(U2*alfa1+alfa2)+alfa3)) -
104               (U1*(U1*(U1*alfa1+alfa2)+alfa3));
105   alfa1 = (Vz*Vz+Vx*Vx)/3.;
106   alfa2 = Vx*X0+Vz*Z0;
107   alfa3 = X0*X0+Z0*Z0;
108   Standard_Real Iyy =  (U2*(U2*(U2*alfa1+alfa2)+alfa3)) -
109               (U1*(U1*(U1*alfa1+alfa2)+alfa3));
110   alfa1 = (Vy*Vy+Vx*Vx)/3.;
111   alfa2 = Vy*Y0+Vz*Z0;
112   alfa3 = Y0*Y0+Z0*Z0;
113   Standard_Real Izz =  (U2*(U2*(U2*alfa1+alfa2)+alfa3)) -
114                        (U1*(U1*(U1*alfa1+alfa2)+alfa3));
115   alfa1 = (Vy*Vx)/3.;
116   alfa2 = (Vy*X0+Vx*Y0)/2.;
117   alfa3 = Y0*X0;
118   Standard_Real Ixy =  (U2*(U2*(U2*alfa1+alfa2)+alfa3)) -
119                        (U1*(U1*(U1*alfa1+alfa2)+alfa3));
120   alfa1 = (Vz*Vx)/3.;
121   alfa2 = (Vz*X0+Vx*Z0)/2;
122   alfa3 = Z0*X0;
123   Standard_Real Ixz =  (U2*(U2*(U2*alfa1+alfa2)+alfa3)) -
124                        (U1*(U1*(U1*alfa1+alfa2)+alfa3));
125   alfa1 = (Vy*Vz)/3.;
126   alfa2 = (Vy*Z0+Vz*Y0)/2.;
127   alfa3 = Y0*Z0;
128   Standard_Real Iyz =  (U2*(U2*(U2*alfa1+alfa2)+alfa3)) -
129                        (U1*(U1*(U1*alfa1+alfa2)+alfa3));
130
131   inertia = gp_Mat (gp_XYZ (Ixx, -Ixy,-Ixz),
132                     gp_XYZ (-Ixy, Iyy,-Iyz),
133                     gp_XYZ (-Ixz,-Iyz, Izz));
134 }
135
136
137 GProp_CelGProps::GProp_CelGProps (const gp_Circ& C, const gp_Pnt& CLocation) 
138 {
139   SetLocation(CLocation);
140   Perform(C,0.,2.*M_PI);
141 }
142
143 GProp_CelGProps::GProp_CelGProps (const gp_Circ& C, 
144                                   const Standard_Real U1, 
145                                   const Standard_Real U2,
146                                   const gp_Pnt& CLocation)
147 {
148   SetLocation(CLocation);
149   Perform(C,U1,U2);
150 }
151
152 GProp_CelGProps::GProp_CelGProps (const gp_Lin& C, 
153                                   const Standard_Real U1, 
154                                   const Standard_Real U2,
155                                   const gp_Pnt& CLocation)
156 {
157   SetLocation(CLocation);
158   Perform(C,U1,U2);
159 }
160