From: apo Date: Wed, 30 Nov 2005 06:22:47 +0000 (+0000) Subject: To remove handle device from the SphereWidget X-Git-Tag: TG-D5-38-2003_D2005-20-12~97 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5fe41f5c43a26f6e3e90b125dc533d235330f42a;p=modules%2Fvisu.git To remove handle device from the SphereWidget --- diff --git a/src/PIPELINE/VISU_SphereWidget.cxx b/src/PIPELINE/VISU_SphereWidget.cxx index 76608c7c..db1b512c 100755 --- a/src/PIPELINE/VISU_SphereWidget.cxx +++ b/src/PIPELINE/VISU_SphereWidget.cxx @@ -27,14 +27,12 @@ vtkStandardNewMacro(VISU_SphereWidget); // function: // purpose: //==================================================================== -VISU_SphereWidget::VISU_SphereWidget(){ - int i, j; - // +VISU_SphereWidget::VISU_SphereWidget() +{ myState = VISU_SphereWidget::Start; this->EventCallbackCommand->SetCallback(VISU_SphereWidget::ProcessEvents); //Build the representation of the widget - // 1. sphere mySphereSource = vtkSphereSource::New(); mySphereSource->SetThetaResolution(16); mySphereSource->SetPhiResolution(15); @@ -44,24 +42,11 @@ VISU_SphereWidget::VISU_SphereWidget(){ mySphereActor = vtkActor::New(); mySphereActor->SetMapper(mySphereMapper); // - // 2. handle - myHandleSource=vtkSphereSource::New(); - myHandleSource->SetThetaResolution(16); - myHandleSource->SetPhiResolution(8); - myHandleMapper=vtkPolyDataMapper::New(); - myHandleMapper->SetInput(myHandleSource->GetOutput()); - myHandleActor=VISU_UnScaledActor::New(); - myHandleActor->SetMapper(myHandleMapper); - myHandleActor->SetSize(24); - myHandleActor->SetCenter(myHandleSource->GetCenter()); - myHandleActor->GetProperty()->SetColor(1.,0.,0.); - // // Define the point coordinates float bounds[6]; - for (i=0; i<3; ++i){ - j=2*i; - bounds[j]=-.5; - bounds[j+1]=-bounds[j]; + for(int i = 0; i < 6; i += 2){ + bounds[i]=-.5; + bounds[i+1]=-bounds[i]; } // Initial creation of the widget, serves to initialize it PlaceWidget(bounds); @@ -70,7 +55,6 @@ VISU_SphereWidget::VISU_SphereWidget(){ myPicker = vtkCellPicker::New(); myPicker->SetTolerance(0.005); //need some fluff myPicker->AddPickList(mySphereActor); - //myPicker->AddPickList(myHandleActor); myPicker->PickFromListOn(); // Set up the initial properties @@ -93,17 +77,13 @@ VISU_SphereWidget::~VISU_SphereWidget() mySphereActor->Delete(); mySphereMapper->Delete(); mySphereSource->Delete(); - // - myHandleActor->Delete(); - myHandleMapper->Delete(); - myHandleSource->Delete(); myPicker->Delete(); - if ( mySphereProperty ) { + if ( mySphereProperty ) { mySphereProperty->Delete(); } - if ( mySelectedSphereProperty ) { + if ( mySelectedSphereProperty ) { mySelectedSphereProperty->Delete(); } mySphere->Delete(); @@ -145,29 +125,12 @@ int VISU_SphereWidget::GetPhiResolution() // function: SetRadius // purpose : //==================================================================== -void VISU_SphereWidget::SetRadius(float aR1) +void VISU_SphereWidget::SetRadius(float theRadius) { - if ( aR1 <= myRmin ) { - aR1=myRmin; - } - // - int i; - float aC[3], aCH[3], aDir[3]; - // - GetCenter(aC); - myHandleSource->GetCenter(aCH); - // - for (i=0; i<3; ++i){ - aDir[i]=aCH[i]-aC[i]; - } - vtkMath::Normalize(aDir); - for (i=0; i<3; ++i){ - aCH[i]=aC[i]+aDir[i]*aR1; + if ( theRadius <= myRmin ) { + theRadius = myRmin; } - // - mySphereSource->SetRadius(aR1); - myHandleSource->SetCenter(aCH); - myHandleActor->SetCenter(aCH); + mySphereSource->SetRadius(theRadius); } //==================================================================== // function: GetRadius @@ -181,39 +144,18 @@ float VISU_SphereWidget::GetRadius() // function: SetCenter // purpose : //==================================================================== -void VISU_SphereWidget::SetCenter(float aC1[3]) +void VISU_SphereWidget::SetCenter(float theCenter[3]) { - int i; - float aC[3], aCH[3], aDir[3], aR; - // - GetCenter(aC); - aR=GetRadius(); - // - for (i=0; i<3; ++i){ - aDir[i]=aC1[i]-aC[i]; - } - vtkMath::Normalize(aDir); - for (i=0; i<3; ++i){ - aCH[i]=aC1[i]+aDir[i]*aR; - } - vtkMath::Normalize(aDir); - // - mySphereSource->SetCenter(aC1); - myHandleSource->SetCenter(aCH); - myHandleActor->SetCenter(aCH); + mySphereSource->SetCenter(theCenter); } //==================================================================== // function: SetCenter // purpose : //==================================================================== -void VISU_SphereWidget::SetCenter(float aX, float aY, float aZ) +void VISU_SphereWidget::SetCenter(float theX, float theY, float theZ) { - float aC1[3]; - // - aC1[0]=aX; - aC1[1]=aY; - aC1[2]=aZ; - SetCenter(aC1); + float aCenter[3] = {theX, theY, theZ}; + SetCenter(aCenter); } //==================================================================== @@ -228,9 +170,9 @@ float* VISU_SphereWidget::GetCenter() // function: GetCenter // purpose : //==================================================================== -void VISU_SphereWidget::GetCenter(float xyz[3]) +void VISU_SphereWidget::GetCenter(float theCenter[3]) { - mySphereSource->GetCenter(xyz); + mySphereSource->GetCenter(theCenter); } //==================================================================== // function: GetSphereProperty @@ -285,7 +227,6 @@ void VISU_SphereWidget::SetEnabled(int enabling) Enabled = 1; // listen for the following events - //vtkRenderWindowInteractor *i = this->Interactor; Interactor->AddObserver(vtkCommand::MouseMoveEvent, EventCallbackCommand, Priority); @@ -305,24 +246,8 @@ void VISU_SphereWidget::SetEnabled(int enabling) // Add the sphere CurrentRenderer->AddActor(mySphereActor); mySphereActor->SetProperty(mySphereProperty); - CurrentRenderer->AddActor(myHandleActor); - // - { - int i; - float aC[3], aR, aDir[3]={1.,0.,0.}; - // - aR= mySphereSource->GetRadius(); - mySphereSource->GetCenter(aC); - // - for (i=0; i<3; ++i){ - aC[i]=aC[i]+aR*aDir[i]; - } - myHandleSource->SetCenter(aC); - myHandleActor->SetCenter(aC); - // - mySphere->SetCenter(mySphereSource->GetCenter()); - mySphere->SetRadius(mySphereSource->GetRadius()); - } + mySphere->SetCenter(mySphereSource->GetCenter()); + mySphere->SetRadius(mySphereSource->GetRadius()); InvokeEvent(vtkCommand::EnableEvent,NULL); //!!!see what will be done } @@ -339,11 +264,10 @@ void VISU_SphereWidget::SetEnabled(int enabling) // don't listen for events any more Interactor->RemoveObserver(EventCallbackCommand); - // turn off the sphere, handle + // turn off the sphere CurrentRenderer->RemoveActor(mySphereActor); - CurrentRenderer->RemoveActor(myHandleActor); InvokeEvent(vtkCommand::DisableEvent,NULL); - CurrentRenderer = NULL;//kruto + CurrentRenderer = NULL; } Interactor->Render(); @@ -389,36 +313,24 @@ void VISU_SphereWidget::OnMiddleButtonDown() int Y = Interactor->GetEventPosition()[1]; // Okay, make sure that the pick is in the current renderer - vtkRenderer *aRenderer=Interactor->FindPokedRenderer(X,Y); + vtkRenderer *aRenderer = Interactor->FindPokedRenderer(X,Y); // - if (aRenderer!=CurrentRenderer) { + if (aRenderer != CurrentRenderer) { myState = VISU_SphereWidget::Outside; return; } // Okay, we can process this. Try to pick handles first; // if no places picked, then try to pick the sphere. - vtkAssemblyPath *path; myPicker->Pick(X, Y, 0., CurrentRenderer); - path = myPicker->GetPath(); - if (!path) { + if(vtkAssemblyPath *aPath = myPicker->GetPath()){ + if(aPath->GetFirstNode()->GetProp() == mySphereActor){ + myState = VISU_SphereWidget::Moving; + HighlightSphere(1); + } + }else{ myState = VISU_SphereWidget::Outside; return; } - else if (path->GetFirstNode()->GetProp()==mySphereActor ) { - myState = VISU_SphereWidget::Moving; - HighlightSphere(1); - // - int aNb; - float aCH[3]; - // - vtkPoints *pPoints=myPicker->GetPickedPositions(); - aNb=pPoints->GetNumberOfPoints(); - if (aNb){ - pPoints->GetPoint(0, aCH); - myHandleSource->SetCenter(aCH); - myHandleActor->SetCenter(aCH); - } - } // EventCallbackCommand->SetAbortFlag(1); StartInteraction(); @@ -451,8 +363,10 @@ void VISU_SphereWidget::OnMouseMove() } // Compute the two points defining the motion vector aCamera->GetFocalPoint(focalPoint); - ComputeWorldToDisplay(focalPoint[0], focalPoint[1], - focalPoint[2], focalPoint); + ComputeWorldToDisplay(focalPoint[0], + focalPoint[1], + focalPoint[2], + focalPoint); z = focalPoint[2]; ComputeDisplayToWorld(double(Interactor->GetLastEventPosition()[0]), double(Interactor->GetLastEventPosition()[1]), @@ -512,29 +426,17 @@ void VISU_SphereWidget::OnLeftButtonDown() // Okay, we can process this. Try to pick handles first; // if no handles picked, then pick the bounding box. - vtkAssemblyPath *path; myPicker->Pick(X, Y, 0., CurrentRenderer); - path = myPicker->GetPath(); - if ( !path ) { + vtkAssemblyPath *aPath = myPicker->GetPath(); + if ( !aPath ) { myState=VISU_SphereWidget::Outside; HighlightSphere(0); return; } HighlightSphere(1); - // - int aNb; - float aCH[3]; - // - vtkPoints *pPoints=myPicker->GetPickedPositions(); - aNb=pPoints->GetNumberOfPoints(); - if (aNb){ - pPoints->GetPoint(0, aCH); - myHandleSource->SetCenter(aCH); - myHandleActor->SetCenter(aCH); - } - // - EventCallbackCommand->SetAbortFlag(1); + + //apo - EventCallbackCommand->SetAbortFlag(1); StartInteraction(); InvokeEvent(vtkCommand::StartInteractionEvent,NULL); // @@ -552,7 +454,7 @@ void VISU_SphereWidget::OnLeftButtonUp() myState = VISU_SphereWidget::Start; HighlightSphere(0); - EventCallbackCommand->SetAbortFlag(1); + //apo - EventCallbackCommand->SetAbortFlag(1); EndInteraction(); InvokeEvent(vtkCommand::EndInteractionEvent,NULL); // @@ -577,13 +479,6 @@ void VISU_SphereWidget::Translate(double *p1, double *p2) mySphereSource->SetCenter(aC1); mySphere->SetCenter(mySphereSource->GetCenter()); mySphere->SetRadius(mySphereSource->GetRadius()); - // - myHandleSource->GetCenter(aC); - aC1[0] = aC[0] + v[0]; - aC1[1] = aC[1] + v[1]; - aC1[2] = aC[2] + v[2]; - myHandleSource->SetCenter(aC1); - myHandleActor->SetCenter(aC1); } //==================================================================== // function:Scale @@ -615,16 +510,6 @@ void VISU_SphereWidget::Scale(double *p1, double *p2, mySphereSource->SetRadius(aR1); mySphere->SetCenter(mySphereSource->GetCenter()); mySphere->SetRadius(mySphereSource->GetRadius()); - // - int i; - float aCH[3]; - // - myHandleSource->GetCenter(aCH); - for (i=0; i<3; ++i){ - aCH[i]=aC[i]+aR1*(aCH[i]-aC[i])/aR; - } - myHandleSource->SetCenter(aCH); - myHandleActor->SetCenter(aCH); } //==================================================================== // function:GetSphere @@ -703,6 +588,9 @@ void VISU_SphereWidget::PlaceWidget(float bds[6]) (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); + static float EPS = 1.0E-1; + myRmin = EPS*InitialLength; + } //==================================================================== // function:GetPolyData @@ -720,43 +608,3 @@ void VISU_SphereWidget::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); } -/* -//==================================================================== -// function:Scale -// purpose: -//==================================================================== -void VISU_SphereWidget::Scale(double *p1, double *p2, - int , int ) -{ - float aC[3], aR, d1, d2, sf, aR1; - // - aR=mySphereSource->GetRadius(); - mySphereSource->GetCenter(aC); - d1=sqrt((p1[0]-aC[0])*(p1[0]-aC[0])+ - (p1[1]-aC[1])*(p1[1]-aC[1])+ - (p1[2]-aC[2])*(p1[2]-aC[2])); - - d2=sqrt((p2[0]-aC[0])*(p2[0]-aC[0])+ - (p2[1]-aC[1])*(p2[1]-aC[1])+ - (p2[2]-aC[2])*(p2[2]-aC[2])); - - sf=1.+(d2-d1)/aR; - aR1=sf*aR; - if (aR1SetRadius(aR1); - mySphere->SetCenter(mySphereSource->GetCenter()); - mySphere->SetRadius(mySphereSource->GetRadius()); - // - int i; - float aCH[3]; - // - myHandleSource->GetCenter(aCH); - for (i=0; i<3; ++i){ - aCH[i]=aC[i]+aR1*(aCH[i]-aC[i])/aR; - } - myHandleSource->SetCenter(aCH); - myHandleActor->SetCenter(aCH); -} -*/ diff --git a/src/PIPELINE/VISU_SphereWidget.hxx b/src/PIPELINE/VISU_SphereWidget.hxx index 80cdcd3c..e83b0c71 100755 --- a/src/PIPELINE/VISU_SphereWidget.hxx +++ b/src/PIPELINE/VISU_SphereWidget.hxx @@ -110,11 +110,6 @@ protected: vtkPolyDataMapper *mySphereMapper; vtkSphereSource *mySphereSource; // - // the handle - vtkSphereSource *myHandleSource; - vtkPolyDataMapper *myHandleMapper; - VISU_UnScaledActor *myHandleActor; - // // the Picker vtkCellPicker *myPicker; // Properties used to control the appearance of selected objects and