+
+ //----------------------------------------------------------------------------
+ // internal function
+ void ComputeBoundsParam( double theBounds[6],
+ double theDirection[3],
+ double theMinPnt[3],
+ double& theMaxBoundPrj,
+ double& theMinBoundPrj )
+ {
+ //Enlarge bounds in order to avoid conflicts of precision
+ for(int i = 0; i < 6; i += 2){
+ static double EPS = 1.0E-3;
+ double aDelta = (theBounds[i+1] - theBounds[i])*EPS;
+ theBounds[i] -= aDelta;
+ theBounds[i+1] += aDelta;
+ }
+
+ double aBoundPoints[8][3] = { {theBounds[0],theBounds[2],theBounds[4]},
+ {theBounds[1],theBounds[2],theBounds[4]},
+ {theBounds[0],theBounds[3],theBounds[4]},
+ {theBounds[1],theBounds[3],theBounds[4]},
+ {theBounds[0],theBounds[2],theBounds[5]},
+ {theBounds[1],theBounds[2],theBounds[5]},
+ {theBounds[0],theBounds[3],theBounds[5]},
+ {theBounds[1],theBounds[3],theBounds[5]}};
+
+ int aMaxId = 0;
+ theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
+ theMinBoundPrj = theMaxBoundPrj;
+ for(int i = 1; i < 8; i++){
+ double aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
+ if(theMaxBoundPrj < aTmp){
+ theMaxBoundPrj = aTmp;
+ aMaxId = i;
+ }
+ if(theMinBoundPrj > aTmp){
+ theMinBoundPrj = aTmp;
+ }
+ }
+ double *aMinPnt = aBoundPoints[aMaxId];
+ theMinPnt[0] = aMinPnt[0];
+ theMinPnt[1] = aMinPnt[1];
+ theMinPnt[2] = aMinPnt[2];
+ }
+
+ // internal function
+ void DistanceToPosition( double theBounds[6],
+ double theDirection[3],
+ double theDist,
+ double thePos[3] )
+ {
+ double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
+ ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
+ double 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;
+ }
+
+ // internal function (currently unused, left just in case)
+ void PositionToDistance( double theBounds[6],
+ double theDirection[3],
+ double thePos[3],
+ double& theDist )
+ {
+ double aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
+ ComputeBoundsParam(theBounds,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
+ double aPrj = vtkMath::Dot(theDirection,thePos);
+ theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
+ }
+
+ bool ComputeClippingPlaneParameters( std::list<vtkActor*> theActorList,
+ double theNormal[3],
+ double theDist,
+ double theBounds[6],
+ double theOrigin[3] )
+ {
+ bool anIsOk = false;
+ theBounds[0] = theBounds[2] = theBounds[4] = VTK_DOUBLE_MAX;
+ theBounds[1] = theBounds[3] = theBounds[5] = -VTK_DOUBLE_MAX;
+ std::list<vtkActor*>::iterator anIter = theActorList.begin();
+ for( ; anIter != theActorList.end(); anIter++ ) {
+ if( vtkActor* aVTKActor = *anIter ) {
+ if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) {
+ double aBounds[6];
+ anActor->GetUnstructuredGrid()->GetBounds( aBounds );
+ theBounds[0] = std::min( theBounds[0], aBounds[0] );
+ theBounds[1] = std::max( theBounds[1], aBounds[1] );
+ theBounds[2] = std::min( theBounds[2], aBounds[2] );
+ theBounds[3] = std::max( theBounds[3], aBounds[3] );
+ theBounds[4] = std::min( theBounds[4], aBounds[4] );
+ theBounds[5] = std::max( theBounds[5], aBounds[5] );
+ anIsOk = true;
+ }
+ }
+ }
+
+ if( !anIsOk )
+ return false;
+
+ DistanceToPosition( theBounds, theNormal, theDist, theOrigin );
+ return true;
+ }
+
+#ifndef DISABLE_PLOT2DVIEWER
+ //================================================================================
+ /*!
+ * \brief Find all SMESH_Actor's in the View Window.
+ * If actor constains Plot2d_Histogram object remove it from each Plot2d Viewer.
+ */
+ //================================================================================
+
+ void ClearPlot2Viewers( SUIT_ViewWindow* theWindow ) {
+ if(SVTK_ViewWindow* aViewWindow = GetVtkViewWindow(theWindow)){
+ vtkRenderer *aRenderer = aViewWindow->getRenderer();
+ VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
+ vtkActorCollection *aCollection = aCopy.GetActors();
+ aCollection->InitTraversal();
+ while(vtkActor *anAct = aCollection->GetNextActor()){
+ if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
+ if(anActor->hasIO() && anActor->GetPlot2Histogram() ){
+ ProcessIn2DViewers(anActor,RemoveFrom2dViewer);
+ }
+ }
+ }
+ }
+ }
+
+#endif
+
+} // end of namespace SMESH