From: apo Date: Thu, 10 May 2007 13:15:18 +0000 (+0000) Subject: Fix for logarithmic scaling on ScalarMaponDeformedShape X-Git-Tag: T_EDF_15278~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f923ea7af3d45155b674f6c7756e4d6a410114df;p=modules%2Fvisu.git Fix for logarithmic scaling on ScalarMaponDeformedShape --- diff --git a/src/PIPELINE/VISU_DeformedShapePL.cxx b/src/PIPELINE/VISU_DeformedShapePL.cxx index db852b99..88a12269 100644 --- a/src/PIPELINE/VISU_DeformedShapePL.cxx +++ b/src/PIPELINE/VISU_DeformedShapePL.cxx @@ -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 diff --git a/src/PIPELINE/VISU_DeformedShapePL.hxx b/src/PIPELINE/VISU_DeformedShapePL.hxx index f6def0ed..9a7ba396 100644 --- a/src/PIPELINE/VISU_DeformedShapePL.hxx +++ b/src/PIPELINE/VISU_DeformedShapePL.hxx @@ -79,6 +79,10 @@ public: vtkFloatingPointType GetScaleFactor(vtkDataSet* theDataSet); + static + vtkFloatingPointType + GetDefaultScale(VISU_PrsMergerPL* thePrsMergerPL); + protected: virtual TInsertCustomPL* diff --git a/src/PIPELINE/VISU_PipeLine.hxx b/src/PIPELINE/VISU_PipeLine.hxx index 4af292ee..92e6296e 100644 --- a/src/PIPELINE/VISU_PipeLine.hxx +++ b/src/PIPELINE/VISU_PipeLine.hxx @@ -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; diff --git a/src/PIPELINE/VISU_PrsMergerPL.hxx b/src/PIPELINE/VISU_PrsMergerPL.hxx index 443ccf8b..f6692845 100644 --- a/src/PIPELINE/VISU_PrsMergerPL.hxx +++ b/src/PIPELINE/VISU_PrsMergerPL.hxx @@ -158,15 +158,15 @@ public: */ void SetInitialRange(); + virtual + vtkPointSet* + GetMergedInput(); + protected: virtual TInsertCustomPL* InsertCustomPL(); - virtual - vtkPointSet* - GetMergedInput(); - void UpdateGeometry(); diff --git a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx index 1ad109f3..6a0be83a 100644 --- a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx +++ b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx @@ -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); } diff --git a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx index 686637da..e1f805f3 100644 --- a/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx +++ b/src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx @@ -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 myScalars; - VISU_Extractor* myExtractorScalars; VISU_CellDataToPointData* myCellDataToPointData; + VISU_FieldTransform* myScalarsFieldTransform; + VISU_Extractor* myScalarsExtractor; }; #endif diff --git a/src/PIPELINE/VISU_ScalarMapPL.cxx b/src/PIPELINE/VISU_ScalarMapPL.cxx index 36a0a62e..c9a75b3e 100644 --- a/src/PIPELINE/VISU_ScalarMapPL.cxx +++ b/src/PIPELINE/VISU_ScalarMapPL.cxx @@ -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(); diff --git a/src/PIPELINE/VISU_ScalarMapPL.hxx b/src/PIPELINE/VISU_ScalarMapPL.hxx index f989ae1f..cbce1354 100644 --- a/src/PIPELINE/VISU_ScalarMapPL.hxx +++ b/src/PIPELINE/VISU_ScalarMapPL.hxx @@ -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;