// 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);
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);
myPicker = vtkCellPicker::New();
myPicker->SetTolerance(0.005); //need some fluff
myPicker->AddPickList(mySphereActor);
- //myPicker->AddPickList(myHandleActor);
myPicker->PickFromListOn();
// Set up the initial properties
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();
// 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
// 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);
}
//====================================================================
// 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
Enabled = 1;
// listen for the following events
- //vtkRenderWindowInteractor *i = this->Interactor;
Interactor->AddObserver(vtkCommand::MouseMoveEvent,
EventCallbackCommand,
Priority);
// 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
}
// 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();
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();
}
// 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]),
// 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);
//
myState = VISU_SphereWidget::Start;
HighlightSphere(0);
- EventCallbackCommand->SetAbortFlag(1);
+ //apo - EventCallbackCommand->SetAbortFlag(1);
EndInteraction();
InvokeEvent(vtkCommand::EndInteractionEvent,NULL);
//
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
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
(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
{
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 (aR1<myRmin){
- aR1=myRmin;
- }
- 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);
-}
-*/