+
+/*!Compute trihedron size.*/
+bool
+ComputeTrihedronSize( vtkRenderer* theRenderer,
+ double& theNewSize,
+ const double theSize,
+ const double theSizeInPercents )
+{
+ // calculating diagonal of visible props of the renderer
+ double bnd[ 6 ];
+ if ( ComputeVisiblePropBounds( theRenderer, bnd ) == 0 )
+ {
+ bnd[ 1 ] = bnd[ 3 ] = bnd[ 5 ] = 100;
+ bnd[ 0 ] = bnd[ 2 ] = bnd[ 4 ] = 0;
+ }
+ double aLength = 0;
+
+ aLength = bnd[ 1 ]-bnd[ 0 ];
+ aLength = std::max( ( bnd[ 3 ] - bnd[ 2 ] ),aLength );
+ aLength = std::max( ( bnd[ 5 ] - bnd[ 4 ] ),aLength );
+
+ static double EPS_SIZE = 5.0E-3;
+ theNewSize = aLength * theSizeInPercents / 100.0;
+
+ // if the new trihedron size have sufficient difference, then apply the value
+ return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
+ fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
+}
+
+bool IsBBEmpty(vtkRenderer* theRenderer)
+{
+ if(!theRenderer)
+ return false;
+
+ double aNewBndBox[6];
+ aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_FLOAT_MAX;
+ aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_FLOAT_MAX;
+
+ // iterate through displayed objects and set size if necessary
+ VTK::ActorCollectionCopy aCopy(theRenderer->GetActors());
+ vtkActorCollection* anActors = aCopy.GetActors();
+ anActors->InitTraversal();
+ bool isAny = false;
+ while(vtkActor* anAct = anActors->GetNextActor())
+ //if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct))
+ if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(anAct))
+ if(anActor->GetVisibility() && !anActor->IsInfinitive())
+ {
+ double *aBounds = anActor->GetBounds();
+ if(aBounds[0] > -VTK_FLOAT_MAX && aBounds[1] < VTK_FLOAT_MAX &&
+ aBounds[2] > -VTK_FLOAT_MAX && aBounds[3] < VTK_FLOAT_MAX &&
+ aBounds[4] > -VTK_FLOAT_MAX && aBounds[5] < VTK_FLOAT_MAX)
+ isAny = true;
+ }
+
+ return !isAny;
+}
+
+/*!
+ Check that the given bounding box is valid, i.e each min bound < each max bound
+*/
+
+bool isBoundValid(double* theBounds) {
+ if(theBounds[0] > theBounds[1] ||
+ theBounds[2] > theBounds[3] ||
+ theBounds[4] > theBounds[5])
+ return false;
+ else
+ return true;
+}
+
+bool ComputeBBCenter(vtkRenderer* theRenderer, double theCenter[3])
+{
+ theCenter[0] = theCenter[1] = theCenter[2] = 0.0;
+
+ if(!theRenderer)
+ return false;
+
+ double aNewBndBox[6];
+ aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_FLOAT_MAX;
+ aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_FLOAT_MAX;
+
+ // iterate through displayed objects and set size if necessary
+ VTK::ActorCollectionCopy aCopy(theRenderer->GetActors());
+ vtkActorCollection* anActors = aCopy.GetActors();
+ anActors->InitTraversal();
+ bool isAny = false;
+ while(vtkActor* anAct = anActors->GetNextActor())
+ {
+ //if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct))
+ if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(anAct))
+ {
+ if(anActor->GetVisibility() && !anActor->IsInfinitive())
+ {
+ double *aBounds = anActor->GetBounds();
+
+ //Ignore invalid bounds
+ if(!isBoundValid(aBounds)) continue;
+
+ if(aBounds[0] > -VTK_FLOAT_MAX && aBounds[1] < VTK_FLOAT_MAX &&
+ aBounds[2] > -VTK_FLOAT_MAX && aBounds[3] < VTK_FLOAT_MAX &&
+ aBounds[4] > -VTK_FLOAT_MAX && aBounds[5] < VTK_FLOAT_MAX)
+ {
+ for(int i = 0; i < 5; i = i + 2){
+ if(aBounds[i] < aNewBndBox[i])
+ aNewBndBox[i] = aBounds[i];
+ if(aBounds[i+1] > aNewBndBox[i+1])
+ aNewBndBox[i+1] = aBounds[i+1];
+ }
+ isAny = true;
+ }
+ }
+ }
+ }
+
+ if ( !isAny )
+ {
+ // null bounding box => the center is (0,0,0)
+ return true;
+ }
+
+ if(aNewBndBox[0] > -VTK_FLOAT_MAX && aNewBndBox[1] < VTK_FLOAT_MAX &&
+ aNewBndBox[2] > -VTK_FLOAT_MAX && aNewBndBox[3] < VTK_FLOAT_MAX &&
+ aNewBndBox[4] > -VTK_FLOAT_MAX && aNewBndBox[5] < VTK_FLOAT_MAX)
+ {
+ static double MIN_DISTANCE = 1.0 / VTK_FLOAT_MAX;
+
+ double aLength = aNewBndBox[1]-aNewBndBox[0];
+ aLength = std::max((aNewBndBox[3]-aNewBndBox[2]),aLength);
+ aLength = std::max((aNewBndBox[5]-aNewBndBox[4]),aLength);
+
+ if(aLength < MIN_DISTANCE)
+ return false;
+
+ double aWidth =
+ sqrt((aNewBndBox[1]-aNewBndBox[0])*(aNewBndBox[1]-aNewBndBox[0]) +
+ (aNewBndBox[3]-aNewBndBox[2])*(aNewBndBox[3]-aNewBndBox[2]) +
+ (aNewBndBox[5]-aNewBndBox[4])*(aNewBndBox[5]-aNewBndBox[4]));
+
+ if(aWidth < MIN_DISTANCE)
+ return false;
+
+ theCenter[0] = (aNewBndBox[0] + aNewBndBox[1])/2.0;
+ theCenter[1] = (aNewBndBox[2] + aNewBndBox[3])/2.0;
+ theCenter[2] = (aNewBndBox[4] + aNewBndBox[5])/2.0;
+ return true;
+ }
+
+ return false;
+
+ /*
+ double aBounds[6];
+ int aCount = ComputeVisiblePropBounds(theRenderer,aBounds);
+ printf("aNewBndBox[0] = %f, aNewBndBox[1] = %f,\naNewBndBox[2] = %f, aNewBndBox[3] = %f,\naNewBndBox[4] = %f, aNewBndBox[5] = %f\n",
+ aBounds[0],aBounds[1],aBounds[2],aBounds[3],aBounds[4],aBounds[5]);
+ printf("aCount = %d\n",aCount);
+
+ if(aCount){
+ static double MIN_DISTANCE = 1.0 / VTK_FLOAT_MAX;
+
+ double aLength = aBounds[1]-aBounds[0];
+ aLength = max((aBounds[3]-aBounds[2]),aLength);
+ aLength = max((aBounds[5]-aBounds[4]),aLength);
+
+ if(aLength < MIN_DISTANCE)
+ return false;
+
+ double aWidth =
+ sqrt((aBounds[1]-aBounds[0])*(aBounds[1]-aBounds[0]) +
+ (aBounds[3]-aBounds[2])*(aBounds[3]-aBounds[2]) +
+ (aBounds[5]-aBounds[4])*(aBounds[5]-aBounds[4]));
+
+ if(aWidth < MIN_DISTANCE)
+ return false;
+
+ theCenter[0] = (aBounds[0] + aBounds[1])/2.0;
+ theCenter[1] = (aBounds[2] + aBounds[3])/2.0;
+ theCenter[2] = (aBounds[4] + aBounds[5])/2.0;
+ return true;
+ }
+ return false;*/
+}