]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
fix for Bug GVIEW10170
authorpkv <pkv@opencascade.com>
Mon, 17 Oct 2005 11:00:43 +0000 (11:00 +0000)
committerpkv <pkv@opencascade.com>
Mon, 17 Oct 2005 11:00:43 +0000 (11:00 +0000)
src/OBJECT/VISU_GaussPtsAct.cxx
src/PIPELINE/VISU_ImplicitFunctionWidget.cxx
src/PIPELINE/VISU_ImplicitFunctionWidget.h

index 5b3370dcd75fcbfd65e144ea758e32b55f4076be..0155c28fb3990802dca2a76ed281b1189ba0a93f 100644 (file)
@@ -459,7 +459,7 @@ VISU_GaussPtsAct
 //----------------------------------------------------------------------------
 bool VISU_GaussPtsAct::IsInfinitive()
 {
-  if(vtkMapper* aMapper = GetMapper()){
+  if(vtkMapper* aMapper = myDeviceActor->GetMapper()){
     if(vtkDataSet* aDataSet= aMapper->GetInput()){
       aDataSet->Update();
       myIsInfinite = aDataSet->GetNumberOfCells() < 2;
index 258fcafa39719cb187edca3bf58c8488ca3a66fe..fd1e9e30867aae8f6f017d339077d14f242a5925 100644 (file)
 #include <vtkTubeFilter.h>
 #include <vtkImplicitBoolean.h>
 #include <vtkImplicitFunctionCollection.h>
+////
+#include <vtkFollower.h>
+#include <vtkObjectFactory.h>
+#include <vtkDataSet.h>
+#include <vtkRenderWindow.h>
+////
+//==================================================================
+// class   : VISU_UnScaledActor
+// purpose :
+//==================================================================
+class VISU_UnScaledActor: public vtkFollower
+{
+  
+public:
+  
+  vtkTypeMacro(VISU_UnScaledActor,vtkFollower);
+  static VISU_UnScaledActor *New();
+  
+  
+  void SetCenter(float *);
+  virtual void SetSize(int theSize);
+  virtual void Render(vtkRenderer *theRenderer);
+  virtual float *GetBounds();
+
+protected:
+  VISU_UnScaledActor();
+  ~VISU_UnScaledActor(){}
 
+  float myCenter[3];
+  int mySize;
+};
+
+////
+
+vtkStandardNewMacro(VISU_UnScaledActor);
+
+//====================================================================
+// function: VISU_UnScaledActor
+// purpose:
+//====================================================================
+VISU_UnScaledActor::VISU_UnScaledActor() 
+{
+  for (int i=0; i<3; ++i){
+    myCenter[i]=0.;
+  }
+  mySize=24;
+}
+//====================================================================
+// function: SetCenter
+// purpose:
+//====================================================================
+void VISU_UnScaledActor::SetCenter(float *pC)
+{
+  for (int i=0; i<3; ++i){
+    myCenter[i]=pC[i];
+  }
+}
+//====================================================================
+// function:GetBounds
+// purpose:
+//====================================================================
+float* VISU_UnScaledActor::GetBounds()
+{
+  Superclass::GetBounds();
+  //
+  for (int i=0; i<3; ++i){
+    Bounds[2*i]=myCenter[i];
+    Bounds[2*i+1]=myCenter[i];
+  }
+  return Bounds;
+}
+//====================================================================
+// function:Render
+// purpose:
+//====================================================================
+void VISU_UnScaledActor::Render(vtkRenderer *theRenderer)
+{
+  if(theRenderer){
+    float P[2][3] = {{-1.0, -1.0, 0.0},{+1.0, +1.0, 0.0}};
+    theRenderer->ViewToWorld(P[0][0],P[0][1],P[0][2]);
+    theRenderer->ViewToWorld(P[1][0],P[1][1],P[1][2]);
+    float aWorldDiag = sqrt((P[1][0]-P[0][0])*(P[1][0]-P[0][0])+
+                            (P[1][1]-P[0][1])*(P[1][1]-P[0][1])+
+                            (P[1][2]-P[0][2])*(P[1][2]-P[0][2]));
+    int* aSize = theRenderer->GetRenderWindow()->GetSize();
+    float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1]));
+    vtkDataSet* aDataSet = GetMapper()->GetInput();
+    float aLength = aDataSet->GetLength();
+    float aPrecision = 1.e-3;
+    float anOldScale = GetScale()[0];
+    float aScale = 
+      mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1]));
+
+    SetOrigin(myCenter);  
+    //
+    if(fabs(aScale - anOldScale)/aScale > aPrecision){
+      SetScale(aScale);
+    }
+  }
+  vtkFollower::Render(theRenderer);
+  
+}
+//====================================================================
+// function:SetSize
+// purpose:
+//====================================================================
+void VISU_UnScaledActor::SetSize(int theSize)
+{
+  mySize = theSize;
+}
+////
 static float DistanceToPlane(const float x[3], 
                             const float n[3], 
                             const float p0[3]);
@@ -69,39 +179,39 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget()
 : 
   vtkPolyDataSourceWidget()
 {
-  this->State = VISU_ImplicitFunctionWidget::Start;
-  this->EventCallbackCommand->SetCallback(VISU_ImplicitFunctionWidget::ProcessEvents);
+  State = VISU_ImplicitFunctionWidget::Start;
+  EventCallbackCommand->SetCallback(VISU_ImplicitFunctionWidget::ProcessEvents);
   
-  this->NormalToXAxis = 0;
-  this->NormalToYAxis = 0;
-  this->NormalToZAxis = 0;
+  NormalToXAxis = 0;
+  NormalToYAxis = 0;
+  NormalToZAxis = 0;
 
-  this->HandleMoveEvent = true;
-  this->HandleLeftButtonEvent = true;
-  this->HandleMiddleButtonEvent = false;
-  this->HandleRightButtonEvent = false;
+  HandleMoveEvent = true;
+  HandleLeftButtonEvent = true;
+  HandleMiddleButtonEvent = false;
+  HandleRightButtonEvent = false;
 
   // Build the representation of the widget
   // 
-  this->Plane = vtkPlane::New();
-  this->Plane->SetNormal(0,0,1);
-  this->Plane->SetOrigin(0,0,0);
+  Plane = vtkPlane::New();
+  Plane->SetNormal(0,0,1);
+  Plane->SetOrigin(0,0,0);
   //
-  this->myDistance = 10.;
-  this->myPlane2 = vtkPlane::New();
-  this->myPlane2->SetNormal(0.,0.,-1.);
-  this->myPlane2->SetOrigin(0,0,this->myDistance);
+  myDistance = 10.;
+  myPlane2 = vtkPlane::New();
+  myPlane2->SetNormal(0.,0.,-1.);
+  myPlane2->SetOrigin(0,0,myDistance);
   //
-  this->myImplicitFunction = vtkImplicitBoolean::New();
-  this->myImplicitFunction->SetOperationType(VTK_UNION);  
+  myImplicitFunction = vtkImplicitBoolean::New();
+  myImplicitFunction->SetOperationType(VTK_UNION);  
   //
-  this->Box = vtkImageData::New();
-  this->Box->SetDimensions(2,2,2);
-  this->Outline = vtkOutlineFilter::New();
-  this->Outline->SetInput(this->Box);
-  this->OutlineMapper = vtkPolyDataMapper::New();
-  this->OutlineMapper->SetInput(this->Outline->GetOutput());
-  this->OutlineActor = vtkActor::New();
+  Box = vtkImageData::New();
+  Box->SetDimensions(2,2,2);
+  Outline = vtkOutlineFilter::New();
+  Outline->SetInput(Box);
+  OutlineMapper = vtkPolyDataMapper::New();
+  OutlineMapper->SetInput(Outline->GetOutput());
+  OutlineActor = vtkActor::New();
   this->OutlineActor->SetMapper(this->OutlineMapper);
   this->OutlineActor->PickableOff();
   this->OutlineTranslation = 0;
@@ -124,15 +234,14 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget()
   this->myCutActor2->SetMapper(this->myCutMapper2);
 
   this->Edges = vtkFeatureEdges::New();
+  Edges->SetColoring(0); 
   this->Edges->SetInput(this->Cutter->GetOutput());
-  this->EdgesTuber = vtkTubeFilter::New();
-  this->EdgesTuber->SetInput(this->Edges->GetOutput());
-  this->EdgesTuber->SetNumberOfSides(12);
   this->EdgesMapper = vtkPolyDataMapper::New();
-  this->EdgesMapper->SetInput(this->EdgesTuber->GetOutput());
+  this->EdgesMapper->SetInput(this->Edges->GetOutput());
   this->EdgesActor = vtkActor::New();
   this->EdgesActor->SetMapper(this->EdgesMapper);
-  this->Tubing = 1; //control whether tubing is on
+  EdgesActor->GetProperty()->SetLineWidth(4.); 
+  EdgesActor->GetProperty()->SetColor(0., .5, .7); 
 
   // Create the + plane normal
   this->LineSource = vtkLineSource::New();
@@ -144,11 +253,13 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget()
 
   this->ConeSource = vtkConeSource::New();
   this->ConeSource->SetResolution(12);
-  this->ConeSource->SetAngle(25.0);
+  this->ConeSource->SetAngle(20.);
   this->ConeMapper = vtkPolyDataMapper::New();
   this->ConeMapper->SetInput(this->ConeSource->GetOutput());
-  this->ConeActor = vtkActor::New();
+  this->ConeActor = VISU_UnScaledActor::New();
   this->ConeActor->SetMapper(this->ConeMapper);
+  ConeActor->SetSize(36);
+  ConeActor->SetCenter(ConeSource->GetCenter());
 
   // Create the - plane normal
   this->LineSource2 = vtkLineSource::New();
@@ -160,11 +271,13 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget()
 
   this->ConeSource2 = vtkConeSource::New();
   this->ConeSource2->SetResolution(12);
-  this->ConeSource2->SetAngle(25.0);
+  this->ConeSource2->SetAngle(20.);
   this->ConeMapper2 = vtkPolyDataMapper::New();
   this->ConeMapper2->SetInput(this->ConeSource2->GetOutput());
-  this->ConeActor2 = vtkActor::New();
+  this->ConeActor2 = VISU_UnScaledActor::New();
   this->ConeActor2->SetMapper(this->ConeMapper2);
+  ConeActor2->SetSize(36);
+  ConeActor2->SetCenter(ConeSource2->GetCenter());
 
   // Create the origin handle
   this->Sphere = vtkSphereSource::New();
@@ -172,8 +285,10 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget()
   this->Sphere->SetPhiResolution(8);
   this->SphereMapper = vtkPolyDataMapper::New();
   this->SphereMapper->SetInput(this->Sphere->GetOutput());
-  this->SphereActor = vtkActor::New();
+  this->SphereActor = VISU_UnScaledActor::New();
   this->SphereActor->SetMapper(this->SphereMapper);
+  SphereActor->SetSize(36);
+  SphereActor->SetCenter(Sphere->GetCenter());
 
   this->Transform = vtkTransform::New();
 
@@ -204,6 +319,7 @@ VISU_ImplicitFunctionWidget::VISU_ImplicitFunctionWidget()
   
   // Set up the initial properties
   this->CreateDefaultProperties();
+  
 }
 //==================================================================
 // function: ~
@@ -230,7 +346,6 @@ VISU_ImplicitFunctionWidget::~VISU_ImplicitFunctionWidget()
   myCutActor2->Delete();
   
   this->Edges->Delete();
-  this->EdgesTuber->Delete();
   this->EdgesMapper->Delete();
   this->EdgesActor->Delete();
   
@@ -332,7 +447,10 @@ void VISU_ImplicitFunctionWidget::SetEnabled(int enabling)
         return;
       }
     }
-
+    //
+    vtkCamera *pCamera=CurrentRenderer->GetActiveCamera();
+    pCamera->SetParallelProjection(1);
+    //
     this->myImplicitFunction->AddFunction(this->Plane);
     this->myImplicitFunction->AddFunction(this->myPlane2);
 
@@ -1374,6 +1492,7 @@ void VISU_ImplicitFunctionWidget::UpdateRepresentation()
   this->LineSource->SetPoint2(p2);
   this->ConeSource->SetCenter(p2);
   this->ConeSource->SetDirection(normal);
+  ConeActor->SetCenter(p2);
 
   p2[0] = origin[0] - 0.30 * d * normal[0];
   p2[1] = origin[1] - 0.30 * d * normal[1];
@@ -1383,17 +1502,13 @@ void VISU_ImplicitFunctionWidget::UpdateRepresentation()
   this->LineSource2->SetPoint2(p2);
   this->ConeSource2->SetCenter(p2);
   this->ConeSource2->SetDirection(normal);
+  ConeActor2->SetCenter(p2);
 
   // Set up the position handle
   this->Sphere->SetCenter(origin);
+  SphereActor->SetCenter(origin);
 
-  // Control the look of the edges
-  if ( this->Tubing )    {
-    this->EdgesMapper->SetInput(this->EdgesTuber->GetOutput());
-  }
-  else     {
-    this->EdgesMapper->SetInput(this->Edges->GetOutput());
-  }
+  this->EdgesMapper->SetInput(this->Edges->GetOutput());
 }
 //==================================================================
 // function:SizeHandles
@@ -1401,16 +1516,8 @@ void VISU_ImplicitFunctionWidget::UpdateRepresentation()
 //==================================================================
 void VISU_ImplicitFunctionWidget::SizeHandles()
 {
-  float radius = this->vtk3DWidget::SizeHandles(1.35);
-
-  this->ConeSource->SetHeight(2.0*radius);
-  this->ConeSource->SetRadius(radius);
-  this->ConeSource2->SetHeight(2.0*radius);
-  this->ConeSource2->SetRadius(radius);
-  
-  this->Sphere->SetRadius(radius);
-
-  this->EdgesTuber->SetRadius(0.25*radius);
+  //  float radius = 
+  this->vtk3DWidget::SizeHandles(1.35);
 }
 //==================================================================
 // function:PrintSelf
@@ -1490,7 +1597,6 @@ void VISU_ImplicitFunctionWidget::PrintSelf(ostream& os, vtkIndent indent)
   os << indent << "Normal To Z Axis: " 
      << (this->NormalToZAxis ? "On" : "Off") << "\n";
 
-  os << indent << "Tubing: " << (this->Tubing ? "On" : "Off") << "\n";
   os << indent << "Outline Translation: " 
      << (this->OutlineTranslation ? "On" : "Off") << "\n";
   os << indent << "Draw Plane: " << (this->DrawPlane ? "On" : "Off") << "\n";
index 304664b29a2b8b45892f99b87dec7f7c71ba8495..cdb4eb9981a4998db2c5b0fcef3929de1886fe18 100644 (file)
@@ -37,7 +37,6 @@ class vtkCellPicker;
 class vtkConeSource;
 class vtkLineSource;
 class vtkSphereSource;
-class vtkTubeFilter;
 class vtkPlane;
 class vtkCutter;
 class vtkProperty;
@@ -48,7 +47,8 @@ class vtkPolyData;
 class vtkTransform;
 class vtkImplicitBoolean;
 class vtkImplicitFunction;
+class VISU_UnScaledActor;
+
 class  VISU_ImplicitFunctionWidget : public vtkPolyDataSourceWidget
 {
 public:
@@ -104,9 +104,9 @@ public:
   // Description:
   // Turn on/off tubing of the wire outline of the plane. The tube thickens
   // the line by wrapping with a vtkTubeFilter.
-  vtkSetMacro(Tubing,int);
-  vtkGetMacro(Tubing,int);
-  vtkBooleanMacro(Tubing,int);
+  //vtkSetMacro(Tubing,int);
+  //vtkGetMacro(Tubing,int);
+  //vtkBooleanMacro(Tubing,int);
 
   // Description:
   // Enable/disable the drawing of the plane. In some cases the plane
@@ -239,15 +239,15 @@ protected:
   
   // Optional tubes are represented by extracting boundary edges and tubing
   vtkFeatureEdges   *Edges;
-  vtkTubeFilter     *EdgesTuber;
+  //vtkTubeFilter     *EdgesTuber;
   vtkPolyDataMapper *EdgesMapper;
   vtkActor          *EdgesActor;
-  int               Tubing; //control whether tubing is on
+  //int               Tubing; //control whether tubing is on
 
   // The + normal cone
-  vtkConeSource     *ConeSource;
-  vtkPolyDataMapper *ConeMapper;
-  vtkActor          *ConeActor;
+  vtkConeSource      *ConeSource;
+  vtkPolyDataMapper  *ConeMapper;
+  VISU_UnScaledActor *ConeActor;
   void HighlightNormal(int highlight);
 
   // The + normal line
@@ -256,9 +256,9 @@ protected:
   vtkActor          *LineActor;
 
   // The - normal cone
-  vtkConeSource     *ConeSource2;
-  vtkPolyDataMapper *ConeMapper2;
-  vtkActor          *ConeActor2;
+  vtkConeSource      *ConeSource2;
+  vtkPolyDataMapper  *ConeMapper2;
+  VISU_UnScaledActor *ConeActor2;
 
   // The - normal line
   vtkLineSource     *LineSource2;
@@ -266,9 +266,9 @@ protected:
   vtkActor          *LineActor2;
 
   // The origin positioning handle
-  vtkSphereSource   *Sphere;
-  vtkPolyDataMapper *SphereMapper;
-  vtkActor          *SphereActor;
+  vtkSphereSource    *Sphere;
+  vtkPolyDataMapper  *SphereMapper;
+  VISU_UnScaledActor *SphereActor;
 
   // Do the picking
   vtkCellPicker *Picker;