From 820aaef032c49ce6894cf0f0dc39f69ddba73b11 Mon Sep 17 00:00:00 2001 From: mkr Date: Tue, 21 Nov 2006 14:06:47 +0000 Subject: [PATCH] Fix for IPAL10048 : Changing rotation point in GUI visualization. --- src/VTKViewer/VTKViewer_Utilities.cxx | 137 ++++++++++++++++++ src/VTKViewer/VTKViewer_Utilities.h | 7 + src/VTKViewer/resources/VTKViewer_images.po | 3 + .../resources/view_rotation_point.png | Bin 0 -> 988 bytes 4 files changed, 147 insertions(+) create mode 100755 src/VTKViewer/resources/view_rotation_point.png diff --git a/src/VTKViewer/VTKViewer_Utilities.cxx b/src/VTKViewer/VTKViewer_Utilities.cxx index 5f061a64b..b436045ed 100755 --- a/src/VTKViewer/VTKViewer_Utilities.cxx +++ b/src/VTKViewer/VTKViewer_Utilities.cxx @@ -20,6 +20,8 @@ #include "VTKViewer_Utilities.h" #include "VTKViewer_Actor.h" +//#include "SALOME_Actor.h" + #include // VTK Includes @@ -214,3 +216,138 @@ ComputeTrihedronSize( vtkRenderer* theRenderer, return fabs( theNewSize - theSize) > theSize * EPS_SIZE || fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE; } + +bool IsBBEmpty(vtkRenderer* theRenderer) +{ + if(!theRenderer) + return false; + + vtkFloatingPointType aNewBndBox[6]; + aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT; + aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; + + // iterate through displayed objects and set size if necessary + vtkActorCollection* anActors = theRenderer->GetActors(); + anActors->InitTraversal(); + bool isAny = false; + while(vtkActor* anAct = anActors->GetNextActor()) + //if(SALOME_Actor* anActor = dynamic_cast(anAct)) + if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(anAct)) + if(anActor->GetVisibility() && !anActor->IsInfinitive()) + { + vtkFloatingPointType *aBounds = anActor->GetBounds(); + if(aBounds[0] > -VTK_LARGE_FLOAT && aBounds[1] < VTK_LARGE_FLOAT && + aBounds[2] > -VTK_LARGE_FLOAT && aBounds[3] < VTK_LARGE_FLOAT && + aBounds[4] > -VTK_LARGE_FLOAT && aBounds[5] < VTK_LARGE_FLOAT) + isAny = true; + } + + return !isAny; +} + +bool ComputeBBCenter(vtkRenderer* theRenderer, vtkFloatingPointType theCenter[3]) +{ + theCenter[0] = theCenter[1] = theCenter[2] = 0.0; + + if(!theRenderer) + return false; + + vtkFloatingPointType aNewBndBox[6]; + aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT; + aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; + + // iterate through displayed objects and set size if necessary + vtkActorCollection* anActors = theRenderer->GetActors(); + anActors->InitTraversal(); + bool isAny = false; + while(vtkActor* anAct = anActors->GetNextActor()) + { + //if(SALOME_Actor* anActor = dynamic_cast(anAct)) + if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(anAct)) + { + if(anActor->GetVisibility() && !anActor->IsInfinitive()) + { + vtkFloatingPointType *aBounds = anActor->GetBounds(); + if(aBounds[0] > -VTK_LARGE_FLOAT && aBounds[1] < VTK_LARGE_FLOAT && + aBounds[2] > -VTK_LARGE_FLOAT && aBounds[3] < VTK_LARGE_FLOAT && + aBounds[4] > -VTK_LARGE_FLOAT && aBounds[5] < VTK_LARGE_FLOAT) + { + 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_LARGE_FLOAT && aNewBndBox[1] < VTK_LARGE_FLOAT && + aNewBndBox[2] > -VTK_LARGE_FLOAT && aNewBndBox[3] < VTK_LARGE_FLOAT && + aNewBndBox[4] > -VTK_LARGE_FLOAT && aNewBndBox[5] < VTK_LARGE_FLOAT) + { + static vtkFloatingPointType MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT; + + vtkFloatingPointType aLength = aNewBndBox[1]-aNewBndBox[0]; + aLength = max((aNewBndBox[3]-aNewBndBox[2]),aLength); + aLength = max((aNewBndBox[5]-aNewBndBox[4]),aLength); + + if(aLength < MIN_DISTANCE) + return false; + + vtkFloatingPointType 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; + + /* + vtkFloatingPointType 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 vtkFloatingPointType MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT; + + vtkFloatingPointType 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; + + vtkFloatingPointType 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;*/ +} diff --git a/src/VTKViewer/VTKViewer_Utilities.h b/src/VTKViewer/VTKViewer_Utilities.h index 7ef9cc550..f9bd70e0f 100755 --- a/src/VTKViewer/VTKViewer_Utilities.h +++ b/src/VTKViewer/VTKViewer_Utilities.h @@ -47,4 +47,11 @@ ComputeTrihedronSize(vtkRenderer* theRenderer, const vtkFloatingPointType theSize, const vtkFloatingPointType theSizeInPercents); +VTKVIEWER_EXPORT +extern +bool IsBBEmpty(vtkRenderer* theRenderer); +VTKVIEWER_EXPORT +extern +bool ComputeBBCenter(vtkRenderer* theRenderer, + vtkFloatingPointType theCenter[3]); #endif diff --git a/src/VTKViewer/resources/VTKViewer_images.po b/src/VTKViewer/resources/VTKViewer_images.po index 0f618ddc5..895766a66 100755 --- a/src/VTKViewer/resources/VTKViewer_images.po +++ b/src/VTKViewer/resources/VTKViewer_images.po @@ -62,6 +62,9 @@ msgstr "view_reset.png" msgid "ICON_VTKVIEWER_VIEW_RIGHT" msgstr "view_right.png" +msgid "ICON_VTKVIEWER_VIEW_ROTATION_POINT" +msgstr "view_rotation_point.png" + msgid "ICON_VTKVIEWER_VIEW_ROTATE" msgstr "view_rotate.png" diff --git a/src/VTKViewer/resources/view_rotation_point.png b/src/VTKViewer/resources/view_rotation_point.png new file mode 100755 index 0000000000000000000000000000000000000000..59f59311bc5105d7ba1246598d169259af3bf8c7 GIT binary patch literal 988 zcmbVKZAep57=F(--Q6wI&SXetxo|ZRBqeFhA35F3k<+2(Y*-m&SgGiowxAzl4az@d z31U$pG(tk82#lm)B#D%TP=@%YT^g2w5qS4uAKc!1r=wr}=x{#X^Soc@dEe7-uQ`;) zZesx;&01xy!!uJ{j2!n#$I3xGR9#g^djK}6#YN!O?JNK}*sB{Xs1yY7dc8wKLxLc9 z&J6&hBM3m&(r4&uH6euZS@E4m;yOJVP+spCWH1hnEU3bXmN;GI2JmkFrgRFzFS^Q$ zUeSxq+IB~tSMnNhZFh>s3gXH%(dgI;+eRaSicwiYu%xciNEi{kf-GMO50qb^{4>k` z+~pDjrr;dUX+(o6#1X8#yGxRTpYF|JUW^=BE24Y|$f<<8+6go|!x=1n8iI~iB|Jsrn}fiwdk zol(xF@9Ou2#jC%}!_e6K;S@c{=tg`3gd#{Ip*H@-fD-aZjqCiKVf9T=z8ov%k_MzKZmW|1GBItRTxL^w>liGxU5ZNybM(LQ0bevSBqo z8V8rQNV30z4aK5y4^RMP0bo#1%q5D0?Lfimx6v4uLV*SnUol~FEHZ;;yrj76YU=T$ z3h;AcOFaVJR