+
+
+vtkImplicitBoolean* SMESH_ActorDef::GetPlaneContainer(){
+ return myImplicitBoolean;
+}
+
+
+static void ComputeBoundsParam(vtkDataSet* theDataSet,
+ float theDirection[3], float theMinPnt[3],
+ float& theMaxBoundPrj, float& theMinBoundPrj)
+{
+ float aBounds[6];
+ theDataSet->GetBounds(aBounds);
+
+ //Enlarge bounds in order to avoid conflicts of precision
+ for(int i = 0; i < 6; i += 2){
+ static double EPS = 1.0E-3;
+ float aDelta = (aBounds[i+1] - aBounds[i])*EPS;
+ aBounds[i] -= aDelta;
+ aBounds[i+1] += aDelta;
+ }
+
+ float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
+ {aBounds[1],aBounds[2],aBounds[4]},
+ {aBounds[0],aBounds[3],aBounds[4]},
+ {aBounds[1],aBounds[3],aBounds[4]},
+ {aBounds[0],aBounds[2],aBounds[5]},
+ {aBounds[1],aBounds[2],aBounds[5]},
+ {aBounds[0],aBounds[3],aBounds[5]},
+ {aBounds[1],aBounds[3],aBounds[5]}};
+
+ int aMaxId = 0, aMinId = aMaxId;
+ theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
+ theMinBoundPrj = theMaxBoundPrj;
+ for(int i = 1; i < 8; i++){
+ float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
+ if(theMaxBoundPrj < aTmp){
+ theMaxBoundPrj = aTmp;
+ aMaxId = i;
+ }
+ if(theMinBoundPrj > aTmp){
+ theMinBoundPrj = aTmp;
+ aMinId = i;
+ }
+ }
+ float *aMinPnt = aBoundPoints[aMaxId];
+ theMinPnt[0] = aMinPnt[0];
+ theMinPnt[1] = aMinPnt[1];
+ theMinPnt[2] = aMinPnt[2];
+}
+
+
+static void DistanceToPosition(vtkDataSet* theDataSet,
+ float theDirection[3], float theDist, float thePos[3])
+{
+ float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
+ ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
+ float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
+ thePos[0] = aMinPnt[0]-theDirection[0]*aLength;
+ thePos[1] = aMinPnt[1]-theDirection[1]*aLength;
+ thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
+}
+
+
+static void PositionToDistance(vtkDataSet* theDataSet,
+ float theDirection[3], float thePos[3], float& theDist)
+{
+ float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
+ ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
+ float aPrj = vtkMath::Dot(theDirection,thePos);
+ theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
+}
+
+
+void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane)
+{
+ thePlane->SetNormal(theDir);
+ float anOrigin[3];
+ ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin);
+ thePlane->SetOrigin(anOrigin);
+}
+
+
+void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane)
+{
+ thePlane->GetNormal(theDir);
+
+ float anOrigin[3];
+ thePlane->GetOrigin(anOrigin);
+ ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist);
+}