1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "OCCViewer_ClipPlane.h"
26 #include <Precision.hxx>
31 Cross product of two 3-vectors. Result vector in result[3].
33 void Cross(const double first[3], const double second[3], double result[3])
35 result[0] = first[1]*second[2] - first[2]*second[1];
36 result[1] = first[2]*second[0] - first[0]*second[2];
37 result[2] = first[0]*second[1] - first[1]*second[0];
41 OCCViewer_ClipPlane::OCCViewer_ClipPlane()
48 OrientationType = AbsoluteCustom;
49 AbsoluteOrientation.Dx = 0.0;
50 AbsoluteOrientation.Dy = 0.0;
51 AbsoluteOrientation.Dz = 1.0;
52 AbsoluteOrientation.IsInvert = false;
56 Operator of another OCCViewer_ClipPlane assignment.
57 @param theOther the OCCViewer_ClipPlane to assign.
58 @return the assigned OCCViewer_ClipPlane.
60 OCCViewer_ClipPlane& OCCViewer_ClipPlane::operator = ( const OCCViewer_ClipPlane& theOther )
68 OrientationType = theOther.OrientationType;
73 AbsoluteOrientation.IsInvert = theOther.AbsoluteOrientation.IsInvert;
74 AbsoluteOrientation.Dx = theOther.AbsoluteOrientation.Dx;
75 AbsoluteOrientation.Dy = theOther.AbsoluteOrientation.Dy;
76 AbsoluteOrientation.Dz = theOther.AbsoluteOrientation.Dz;
80 RelativeOrientation.Rotation1 = theOther.RelativeOrientation.Rotation1;
81 RelativeOrientation.Rotation2 = theOther.RelativeOrientation.Rotation2;
89 Converts defined orientation to direction.
90 @param theDx [out] the direction x component.
91 @param theDy [out] the direction y component.
92 @param theDz [out] the direction y component.
94 void OCCViewer_ClipPlane::OrientationToXYZ( double &theDx, double &theDy, double &theDz ) const
96 // Absolute definition of the clipping plane
97 if ( Mode == Absolute )
99 switch ( OrientationType )
104 theDz = AbsoluteOrientation.IsInvert ? 1.0 : -1.0;
108 theDx = AbsoluteOrientation.IsInvert ? 1.0 : -1.0;
115 theDy = AbsoluteOrientation.IsInvert ? 1.0 : -1.0;
119 case AbsoluteCustom :
120 int anInvertCoeff = AbsoluteOrientation.IsInvert ? 1 : -1;
121 theDx = anInvertCoeff * AbsoluteOrientation.Dx;
122 theDy = anInvertCoeff * AbsoluteOrientation.Dy;
123 theDz = anInvertCoeff * AbsoluteOrientation.Dz;
130 // Relative definition of the clipping plane
131 RelativeToDXYZ( OrientationType,
132 RelativeOrientation.Rotation1,
133 RelativeOrientation.Rotation2,
134 theDx, theDy, theDz );
138 Converts normal direction to relative definition.
139 @param theDx [in] the direction x component.
140 @param theDy [in] the direction y component.
141 @param theDz [in] the direction y component.
142 @param theRelativeType [in] the relative orientation type.
143 @param theRotation1 [out] the angle of rotation around first axis.
144 @param theRotation2 [out] the angle of rotation around second axis.
146 void OCCViewer_ClipPlane::DXYZToRelative( const double theDx,
149 const int theOrientationType,
150 double& theRotation1,
151 double& theRotation2 )
153 gp_Dir aPlaneN( theDx, theDy, theDz );
155 const gp_Dir& aDX = gp::DX();
156 const gp_Dir& aDY = gp::DY();
157 const gp_Dir& aDZ = gp::DZ();
160 switch ( theOrientationType )
164 if ( aDY.IsParallel( aPlaneN, Precision::Angular() ) )
171 if ( aDX.IsParallel( aPlaneN, Precision::Angular() ) )
178 gp_Dir aDir1 = aPlaneN ^ aDX;
179 gp_Dir aDir2 = aDY ^ aPlaneN;
180 gp_Ax3 aRightHand( gp::Origin(), aPlaneN, aDY ^ aPlaneN );
182 if ( aDir1 * aRightHand.YDirection() < 0.0 )
186 if ( aDir2 * aRightHand.XDirection() < 0.0 )
191 anAng1 = aDY.AngleWithRef( aDir1, aDX );
192 anAng2 = aDX.AngleWithRef( aDir2, -aDY );
198 if ( aDZ.IsParallel( aPlaneN, Precision::Angular() ) )
205 if ( aDY.IsParallel( aPlaneN, Precision::Angular() ) )
212 gp_Dir aDir1 = aPlaneN ^ aDY;
213 gp_Dir aDir2 = aDZ ^ aPlaneN;
214 gp_Ax3 aRightHand( gp::Origin(), aPlaneN, aDZ ^ aPlaneN );
216 if ( aDir1 * aRightHand.YDirection() < 0.0 )
220 if ( aDir2 * aRightHand.XDirection() < 0.0 )
225 anAng1 = aDZ.AngleWithRef( aDir1, aDY );
226 anAng2 = aDY.AngleWithRef( aDir2, -aDZ );
232 if ( aDX.IsParallel( aPlaneN, Precision::Angular() ) )
239 if ( aDZ.IsParallel( aPlaneN, Precision::Angular() ) )
246 gp_Dir aDir1 = aPlaneN ^ aDZ;
247 gp_Dir aDir2 = aDX ^ aPlaneN;
248 gp_Ax3 aRightHand( gp::Origin(), aPlaneN, aDX ^ aPlaneN );
250 if ( aDir1 * aRightHand.YDirection() < 0.0 )
254 if ( aDir2 * aRightHand.XDirection() < 0.0 )
259 anAng1 = aDX.AngleWithRef( aDir1, aDZ );
260 anAng2 = aDZ.AngleWithRef( aDir2, -aDX );
265 theRotation1 = anAng1 * ( 180.0 / M_PI );
266 theRotation2 = anAng2 * ( 180.0 / M_PI );
270 Converts normal direction to relative definition.
271 @param theDx [in] the direction x component.
272 @param theDy [in] the direction y component.
273 @param theDz [in] the direction y component.
274 @param theRelativeType [in] the relative orientation type.
275 @param theRotation1 [out] the angle of rotation around first axis.
276 @param theRotation2 [out] the angle of rotation around second axis.
278 void OCCViewer_ClipPlane::RelativeToDXYZ( const int theOrientationType,
279 const double theRotation1,
280 const double theRotation2,
286 double aDir[2][3] = { { 0.0, 0.0, 0.0 }, { 0.0, 0.0, 0.0 } };
288 static double aCoeff = M_PI / 180.0;
290 double anU[2] = { cos( aCoeff * theRotation1 ), cos( aCoeff * theRotation2 ) };
291 double aV[2] = { sqrt( 1.0 - anU[0] * anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) };
293 aV[0] = theRotation1 > 0.0 ? aV[0] : -aV[0];
294 aV[1] = theRotation2 > 0.0 ? aV[1] : -aV[1];
296 switch ( theOrientationType )
320 Cross( aDir[1], aDir[0], aNormal );
324 aDen = sqrt( aNormal[0] * aNormal[0] + aNormal[1] * aNormal[1] + aNormal[2] * aNormal[2] );
327 for (int i = 0; i < 3; i++)