]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for logarithmic scaling on ScalarMaponDeformedShape
authorapo <apo@opencascade.com>
Thu, 10 May 2007 13:15:18 +0000 (13:15 +0000)
committerapo <apo@opencascade.com>
Thu, 10 May 2007 13:15:18 +0000 (13:15 +0000)
src/PIPELINE/VISU_DeformedShapePL.cxx
src/PIPELINE/VISU_DeformedShapePL.hxx
src/PIPELINE/VISU_PipeLine.hxx
src/PIPELINE/VISU_PrsMergerPL.hxx
src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx
src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx
src/PIPELINE/VISU_ScalarMapPL.cxx
src/PIPELINE/VISU_ScalarMapPL.hxx

index db852b9906e39ec2ae8356ecf643c8cc7416b96e..88a12269b9f4a7a25ce3b4ffda02562bd6b06ca2 100644 (file)
@@ -85,6 +85,24 @@ VISU_DeformedShapePL
 }
 
 
+vtkFloatingPointType
+VISU_DeformedShapePL
+::GetDefaultScale(VISU_PrsMergerPL* thePrsMergerPL)
+{
+  vtkFloatingPointType aScalarRange[2];
+  thePrsMergerPL->GetSourceRange(aScalarRange);
+
+  vtkDataSet* aDataSet = thePrsMergerPL->GetMergedInput();
+  vtkFloatingPointType aScaleFactor = GetScaleFactor( aDataSet );
+
+  static double EPS = 1.0 / VTK_LARGE_FLOAT;
+  if(fabs(aScalarRange[1]) > EPS)
+    return aScaleFactor / aScalarRange[1];
+
+  return 0.0;
+}
+
+
 void
 VISU_DeformedShapePL
 ::SetScale(vtkFloatingPointType theScale) 
@@ -107,17 +125,7 @@ VISU_DeformedShapePL
 {
   Superclass::Init();
 
-  vtkFloatingPointType aScalarRange[2];
-  GetSourceRange(aScalarRange);
-
-  vtkDataSet* aDataSet = GetMergedInput();
-  vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
-
-  static double EPS = 1.0 / VTK_LARGE_FLOAT;
-  if(fabs(aScalarRange[1]) > EPS)
-    SetScale(aScaleFactor / aScalarRange[1]);
-  else
-    SetScale(0.0);
+  SetScale(GetDefaultScale(this));
 }
 
 void
index f6def0edec44e31707087a7d2c9da84b1a092725..9a7ba396b5448517b7e945f254bf0b31d0cf63a3 100644 (file)
@@ -79,6 +79,10 @@ public:
   vtkFloatingPointType
   GetScaleFactor(vtkDataSet* theDataSet);
 
+  static
+  vtkFloatingPointType 
+  GetDefaultScale(VISU_PrsMergerPL* thePrsMergerPL);
+  
 protected:
   virtual
   TInsertCustomPL* 
index 4af292eec4ddab9d061cca41389be6f66d93aac3..92e6296e22611875849269c0a0a706dad3c1cbcf 100644 (file)
@@ -209,14 +209,14 @@ public:
   SALOME_ExtractGeometry*
   GetExtractGeometryFilter();
 
-protected:
-  VISU_PipeLine();
-  VISU_PipeLine(const VISU_PipeLine&);
-
   virtual 
   TInput* 
   GetClippedInput();
 
+protected:
+  VISU_PipeLine();
+  VISU_PipeLine(const VISU_PipeLine&);
+
   virtual
   void
   Build() = 0;
index 443ccf8bc6d59d0c17f791e5c564cd9bc6252838..f6692845cd94a5d2e9913cc57302b33c45e66692 100644 (file)
@@ -158,15 +158,15 @@ public:
    */
   void SetInitialRange();
 
+  virtual
+  vtkPointSet* 
+  GetMergedInput();
+
 protected:
   virtual
   TInsertCustomPL* 
   InsertCustomPL();
 
-  virtual
-  vtkPointSet* 
-  GetMergedInput();
-
   void
   UpdateGeometry();
 
index 1ad109f3669a01273e39da45a99e51fe380f3277..6a0be83a0c1ccecb4d739a6685d2b4675bc7ac0c 100644 (file)
@@ -56,10 +56,12 @@ VISU_ScalarMapOnDeformedShapePL
 {
   myWarpVector = vtkWarpVector::New();
 
-  myMergeScalarsFilter = VISU_MergeFilter::New();
-  myMergeScalarsFilter->SetMergingInputs(true);
+  myScalarsMergeFilter = VISU_MergeFilter::New();
+  myScalarsMergeFilter->SetMergingInputs(true);
 
-  myExtractorScalars = VISU_Extractor::New();
+  myScalarsExtractor = VISU_Extractor::New();
+
+  myScalarsFieldTransform = VISU_FieldTransform::New();
 
   myCellDataToPointData = VISU_CellDataToPointData::New();
 
@@ -73,16 +75,14 @@ VISU_ScalarMapOnDeformedShapePL
 VISU_ScalarMapOnDeformedShapePL
 ::~VISU_ScalarMapOnDeformedShapePL()
 {
-  myWarpVector->UnRegisterAllOutputs();
   myWarpVector->Delete();
 
-  myMergeScalarsFilter->UnRegisterAllOutputs();
-  myMergeScalarsFilter->Delete();
+  myScalarsMergeFilter->Delete();
   
-  myExtractorScalars->UnRegisterAllOutputs();
-  myExtractorScalars->Delete();
+  myScalarsExtractor->Delete();
+
+  myScalarsFieldTransform->Delete();
 
-  myCellDataToPointData->UnRegisterAllOutputs();
   myCellDataToPointData->Delete();
 }
 
@@ -97,15 +97,17 @@ VISU_ScalarMapOnDeformedShapePL
                        myCellDataToPointData,
                        GetMergedInput());
   
-  // Sets geometry for merge filter
-  myMergeScalarsFilter->SetGeometry(myWarpVector->GetUnstructuredGridOutput());
-
   UpdateScalars();
 
-  vtkDataSet* aScalarsDataSet = myExtractorScalars->GetOutput();
-  myMergeScalarsFilter->SetScalars(aScalarsDataSet);
-  myMergeScalarsFilter->AddField("VISU_CELLS_MAPPER", aScalarsDataSet);
-  myMergeScalarsFilter->AddField("VISU_POINTS_MAPPER", aScalarsDataSet);
+  myScalarsFieldTransform->SetInput(myScalarsExtractor->GetOutput());
+
+  // Sets geometry for merge filter
+  myScalarsMergeFilter->SetGeometry(myWarpVector->GetUnstructuredGridOutput());
+
+  vtkDataSet* aScalarsDataSet = myScalarsFieldTransform->GetOutput();
+  myScalarsMergeFilter->SetScalars(aScalarsDataSet);
+  myScalarsMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsDataSet);
+  myScalarsMergeFilter->AddField("VISU_POINTS_MAPPER", aScalarsDataSet);
 }
 
 //=======================================================================
@@ -114,7 +116,7 @@ VISU_ScalarMapOnDeformedShapePL
 ::UpdateScalars()
 {
   vtkPointSet* aScalars = GetScalars();
-  myExtractorScalars->SetInput(aScalars);
+  myScalarsExtractor->SetInput(aScalars);
 
   if(VISU::IsDataOnCells(aScalars))
     myMapper->SetScalarModeToUseCellData();
@@ -131,7 +133,7 @@ VISU_ScalarMapOnDeformedShapePL
   myMapper->SetColorModeToMapScalars();
   myMapper->ScalarVisibilityOn();
 
-  return myMergeScalarsFilter->GetOutput();
+  return myScalarsMergeFilter->GetOutput();
 }
 
 void
@@ -143,7 +145,7 @@ VISU_ScalarMapOnDeformedShapePL
   UpdateScalars();
   //{
   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput2.vtk";
-  //  VISU::WriteToFile(myExtractorScalars->GetUnstructuredGridOutput(), aFileName);
+  //  VISU::WriteToFile(myScalarsExtractor->GetUnstructuredGridOutput(), aFileName);
   //}
   //{
   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet2.vtk";
@@ -151,7 +153,7 @@ VISU_ScalarMapOnDeformedShapePL
   //}
   //{
   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter2.vtk";
-  //  VISU::WriteToFile(myMergeScalarsFilter->GetOutput(), aFileName);
+  //  VISU::WriteToFile(myScalarsMergeFilter->GetOutput(), aFileName);
   //}
 }
 
@@ -164,17 +166,7 @@ VISU_ScalarMapOnDeformedShapePL
 {
   Superclass::Init();
   
-  vtkFloatingPointType aScalarRange[2];
-  GetSourceRange(aScalarRange);
-
-  vtkDataSet* aDataSet = GetMergedInput();
-  vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
-
-  static double EPS = 1.0 / VTK_LARGE_FLOAT;
-  if(fabs(aScalarRange[1]) > EPS)
-    SetScale(aScaleFactor / aScalarRange[1]);
-  else
-    SetScale(0.0);
+  SetScale(VISU_DeformedShapePL::GetDefaultScale(this));
 }
 
 /*!
@@ -221,10 +213,10 @@ void
 VISU_ScalarMapOnDeformedShapePL
 ::SetScale(vtkFloatingPointType theScale) 
 {
-  if(myScaleFactor == theScale) return;
+  if(myScaleFactor == theScale)
+    return;
   myScaleFactor = theScale;
-  myWarpVector->SetScaleFactor(myScaleFactor);
-  Modified();
+  myWarpVector->SetScaleFactor(theScale);
 }
 
 /*!
@@ -246,7 +238,6 @@ VISU_ScalarMapOnDeformedShapePL
 {
   Superclass::SetMapScale(theMapScale); // enk::added
   myWarpVector->SetScaleFactor(myScaleFactor*theMapScale);
-  Modified();
 }
 
 /*!
@@ -256,7 +247,7 @@ int
 VISU_ScalarMapOnDeformedShapePL
 ::GetScalarMode()
 {
-  return myExtractorScalars->GetScalarMode();
+  return myScalarsExtractor->GetScalarMode();
 }
 
 /*!
@@ -266,8 +257,31 @@ void
 VISU_ScalarMapOnDeformedShapePL
 ::SetScalarMode(int theScalarMode)
 {
-  Superclass::SetScalarMode(theScalarMode);
-  myExtractorScalars->SetScalarMode(theScalarMode);
+  VISU_ScalarMapPL::SetScalarMode(theScalarMode, GetScalars(), myScalarsExtractor);
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapOnDeformedShapePL
+::SetScaling(int theScaling) 
+{
+  myBarTable->SetScale(theScaling);
+
+  if(theScaling == VTK_SCALE_LOG10)
+    myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
+  else
+    myScalarsFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapOnDeformedShapePL
+::SetScalarRange(vtkFloatingPointType theRange[2])
+{
+  myScalarsFieldTransform->SetScalarRange(theRange);
+  myBarTable->SetRange(theRange);
 }
 
 /*!
@@ -280,6 +294,6 @@ void
 VISU_ScalarMapOnDeformedShapePL
 ::GetSourceRange(vtkFloatingPointType theRange[2])
 {
-  myExtractorScalars->Update();
-  myExtractorScalars->GetOutput()->GetScalarRange(theRange);
+  myScalarsExtractor->Update();
+  myScalarsExtractor->GetOutput()->GetScalarRange(theRange);
 }
index 686637da89a6a24110e67dcd7eab5e66b38b8718..e1f805f300db16c48f79a3403056305ef968c6b9 100644 (file)
@@ -39,27 +39,57 @@ class VISU_ScalarMapOnDeformedShapePL : public VISU_PrsMergerPL
 {
 protected:
   VISU_ScalarMapOnDeformedShapePL();
+  VISU_ScalarMapOnDeformedShapePL(const VISU_ScalarMapOnDeformedShapePL&);
   
-  virtual ~VISU_ScalarMapOnDeformedShapePL();
+  virtual
+  ~VISU_ScalarMapOnDeformedShapePL();
   
-  VISU_ScalarMapOnDeformedShapePL(const VISU_ScalarMapOnDeformedShapePL&);
 public:
   vtkTypeMacro(VISU_ScalarMapOnDeformedShapePL, VISU_PrsMergerPL);
 
-  static VISU_ScalarMapOnDeformedShapePL* New();
+  static
+  VISU_ScalarMapOnDeformedShapePL* 
+  New();
+
+  virtual
+  void
+  ShallowCopy(VISU_PipeLine *thePipeLine);
+
+  virtual
+  void
+  SetScale(vtkFloatingPointType theScale);
+
+  virtual
+  vtkFloatingPointType
+  GetScale();
+
+  virtual
+  int 
+  GetScalarMode();
 
-  virtual void ShallowCopy(VISU_PipeLine *thePipeLine);
+  virtual 
+  void
+  SetScalarMode(int theScalarMode = 0);
 
-  virtual void SetScale(vtkFloatingPointType theScale);
-  virtual vtkFloatingPointType GetScale();
+  virtual
+  void
+  SetScaling(int theScaling = VTK_SCALE_LINEAR);
+  
+  virtual
+  void
+  SetScalarRange(vtkFloatingPointType theRange[2]);
 
-  virtual int GetScalarMode();
-  virtual void SetScalarMode(int theScalarMode = 0);
+  virtual
+  void
+  GetSourceRange(vtkFloatingPointType theRange[2]);
 
-  virtual void GetSourceRange(vtkFloatingPointType theRange[2]);
+  virtual
+  void
+  SetScalars(vtkDataSet *theScalars);
 
-  virtual void SetScalars(vtkDataSet *theScalars);
-  virtual vtkPointSet* GetScalars();
+  virtual
+  vtkPointSet* 
+  GetScalars();
 
 public:
   //! Redefined method for building of the pipeline.
@@ -80,7 +110,9 @@ public:
   void
   UpdateScalars();
 
-  virtual void SetMapScale(vtkFloatingPointType theMapScale = 1.0);
+  virtual
+  void
+  SetMapScale(vtkFloatingPointType theMapScale = 1.0);
   
 protected:
   //! Redefined method for customization of pipeline building
@@ -90,10 +122,11 @@ protected:
 
   vtkFloatingPointType myScaleFactor;
   vtkWarpVector  *myWarpVector;
-  VISU_MergeFilter *myMergeScalarsFilter;
+  VISU_MergeFilter *myScalarsMergeFilter;
   vtkSmartPointer<vtkUnstructuredGrid> myScalars;
-  VISU_Extractor* myExtractorScalars;
   VISU_CellDataToPointData* myCellDataToPointData;
+  VISU_FieldTransform* myScalarsFieldTransform;
+  VISU_Extractor* myScalarsExtractor;
 };
 
 #endif
index 36a0a62ebdfffc5bd4b2fcf7ff9361859b54e1d5..c9a75b3e12cf43848ac9557e29dc86189a9b0d15 100644 (file)
@@ -91,32 +91,42 @@ VISU_ScalarMapPL
   return myExtractor->GetScalarMode();
 }
 
+
+//----------------------------------------------------------------------------
 void
 VISU_ScalarMapPL
-::SetScalarMode(int theScalarMode)
+::SetScalarMode(int theScalarMode,
+               vtkDataSet *theInput,
+               VISU_Extractor* theExtractor)
 {
-  vtkDataSet *anInput = GetInput();
-  if(anInput){
-    if(VISU::IsDataOnPoints(anInput)){
-      vtkPointData *inData = anInput->GetPointData();
-      if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)) {
-       if (theScalarMode==0){
+  if(theInput){
+    if(VISU::IsDataOnPoints(theInput)){
+      vtkPointData *aPointData = theInput->GetPointData();
+      if(!aPointData->GetAttribute(vtkDataSetAttributes::VECTORS)) {
+       if(theScalarMode == 0){
          return;
        }
       }
-    }
-    else {
-      vtkCellData *inData = anInput->GetCellData();
-      if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)){
-       if (theScalarMode==0){
+    } else {
+      vtkCellData *aCellData = theInput->GetCellData();
+      if(!aCellData->GetAttribute(vtkDataSetAttributes::VECTORS)){
+       if(theScalarMode==0){
          return;
        }
       }
     }
   }
-  //
-  myExtractor->SetScalarMode(theScalarMode);
-  Modified();
+
+  theExtractor->SetScalarMode(theScalarMode);
+}
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::SetScalarMode(int theScalarMode)
+{
+  SetScalarMode(theScalarMode, GetInput(), myExtractor);
 }
 
 
@@ -137,7 +147,6 @@ VISU_ScalarMapPL
     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
   else
     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
-  Modified();
 }
 
 
@@ -146,7 +155,7 @@ vtkFloatingPointType*
 VISU_ScalarMapPL
 ::GetScalarRange() 
 {
-  return myFieldTransform->GetScalarRange();
+  return myBarTable->GetRange();
 }
 
 void
@@ -155,7 +164,6 @@ VISU_ScalarMapPL
 {
   myFieldTransform->SetScalarRange(theRange);
   myBarTable->SetRange(theRange);
-  Modified();
 }
 
 void
@@ -237,8 +245,8 @@ VISU_ScalarMapPL
 { 
   vtkFloatingPointType *aRange = GetScalarRange();
   vtkFloatingPointType aScalarRange[2] = {aRange[0], aRange[1]};
-  if(myBarTable->GetScale() == VTK_SCALE_LOG10)
-    VISU_LookupTable::ComputeLogRange(aRange,aScalarRange);
+  if(GetScaling() == VTK_SCALE_LOG10)
+    VISU_LookupTable::ComputeLogRange(aRange, aScalarRange);
   myMapperTable->SetRange(aScalarRange);
 
   myMapperTable->Build();
index f989ae1f439b21de570aa209ad5c3bb6cca4efed..cbce1354b43bfd877a66f26910f9132f87cfd9da 100644 (file)
@@ -72,6 +72,7 @@ public:
   virtual
   int
   GetScaling();
+
   virtual
   void
   SetScaling(int theScaling = VTK_SCALE_LINEAR);
@@ -139,6 +140,12 @@ public:
   SetSourceRange();
 
   //----------------------------------------------------------------------------
+  static
+  void
+  SetScalarMode(int theScalarMode,
+               vtkDataSet *theInput,
+               VISU_Extractor* theExtractor);
+
 protected:
   typedef vtkPointSet TInsertCustomPL;