Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / PIPELINE / VISU_ScalarMapPL.cxx
index d7b7b4a6f43f1a7d7cbd8344423b7d25774c7725..daaa24e689af776bfd498cc6b9c65aed5d312303 100644 (file)
@@ -1,23 +1,23 @@
 //  VISU OBJECT : interactive object for VISU entities implementation
 //
 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 //
 //
 //
 
 #include "VISU_ScalarMapPL.hxx"
 #include "VISU_PipeLineUtils.hxx"
+#include "SALOME_ExtractGeometry.h"
 
-#ifdef _DEBUG_
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 0;
-#endif
 
+//============================================================================
 vtkStandardNewMacro(VISU_ScalarMapPL);
 
 
-VISU_ScalarMapPL::VISU_ScalarMapPL(){
-  myFieldTransform = VISU_FieldTransform::New();
-  //myFieldTransform->DebugOn();
-
+//----------------------------------------------------------------------------
+VISU_ScalarMapPL
+::VISU_ScalarMapPL()
+{
   myMapperTable = VISU_LookupTable::New();
   myMapperTable->SetScale(VTK_SCALE_LINEAR);
   myMapperTable->SetHueRange(0.667,0.0);
@@ -51,45 +48,90 @@ VISU_ScalarMapPL::VISU_ScalarMapPL(){
   myBarTable->SetHueRange(0.667,0.0);
 
   myExtractor = VISU_Extractor::New();
-  //myExtractor->DebugOn();
+  myExtractor->SetInput(myExtractGeometry->GetOutput());
+
+  myFieldTransform = VISU_FieldTransform::New();
+  myFieldTransform->SetInput(myExtractor->GetOutput());
+
+  myIsShrinkable = true;
 }
 
 
-VISU_ScalarMapPL::~VISU_ScalarMapPL(){
-  myFieldTransform->UnRegisterAllOutputs();
+VISU_ScalarMapPL
+::~VISU_ScalarMapPL()
+{
   myFieldTransform->Delete();
-  myMapperTable->Delete();;
+  myMapperTable->Delete();
   myBarTable->Delete();
-  myExtractor->UnRegisterAllOutputs();
   myExtractor->Delete();
 }
 
 
-void VISU_ScalarMapPL::ShallowCopy(VISU_PipeLine *thePipeLine){
-  VISU_PipeLine::ShallowCopy(thePipeLine);
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::ShallowCopy(VISU_PipeLine *thePipeLine)
+{
   if(VISU_ScalarMapPL *aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine)){
     SetScalarRange(aPipeLine->GetScalarRange());
     SetScalarMode(aPipeLine->GetScalarMode());
     SetNbColors(aPipeLine->GetNbColors());
     SetScaling(aPipeLine->GetScaling());
-    //Update();
+    SetMapScale(aPipeLine->GetMapScale());
   }
+  Superclass::ShallowCopy(thePipeLine);
 }
 
 
-int VISU_ScalarMapPL::GetScalarMode(){
+//----------------------------------------------------------------------------
+int
+VISU_ScalarMapPL
+::GetScalarMode()
+{
   return myExtractor->GetScalarMode();
 }
-void VISU_ScalarMapPL::SetScalarMode(int theScalarMode){
+
+void
+VISU_ScalarMapPL
+::SetScalarMode(int theScalarMode)
+{
+  vtkDataSet *input = GetInput();
+  if (input){
+    if(input->GetPointData()->GetNumberOfArrays()){
+      vtkPointData *inData = input->GetPointData();
+      if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)) {
+       if (theScalarMode==0){
+         return;
+       }
+      }
+    }
+    else {
+      vtkCellData *inData = input->GetCellData();
+      if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)){
+       if (theScalarMode==0){
+         return;
+       }
+      }
+    }
+  }
+  //
   myExtractor->SetScalarMode(theScalarMode);
   Modified();
 }
 
 
-int VISU_ScalarMapPL::GetScaling() { 
+//----------------------------------------------------------------------------
+int
+VISU_ScalarMapPL
+::GetScaling() 
+{
   return myBarTable->GetScale();
 }
-void VISU_ScalarMapPL::SetScaling(int theScaling) {
+
+void
+VISU_ScalarMapPL
+::SetScaling(int theScaling) 
+{
   myBarTable->SetScale(theScaling);
   if(theScaling == VTK_SCALE_LOG10)
     myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
@@ -99,86 +141,150 @@ void VISU_ScalarMapPL::SetScaling(int theScaling) {
 }
 
 
-float* VISU_ScalarMapPL::GetScalarRange() { 
+//----------------------------------------------------------------------------
+float* 
+VISU_ScalarMapPL
+::GetScalarRange() 
+{
   return myFieldTransform->GetScalarRange();
-}  
-void VISU_ScalarMapPL::SetScalarRange(float theRange[2]){
+}
+
+void
+VISU_ScalarMapPL
+::SetScalarRange(float theRange[2])
+{
   myFieldTransform->SetScalarRange(theRange);
   myBarTable->SetRange(theRange);
   Modified();
 }
-void VISU_ScalarMapPL::SetScalarMin(float theValue){
+
+void
+VISU_ScalarMapPL
+::SetScalarMin(float theValue)
+{
   float aScalarRange[2] = {theValue, GetScalarRange()[1]};
   SetScalarRange(aScalarRange);
 }
-void VISU_ScalarMapPL::SetScalarMax(float theValue){
+
+void
+VISU_ScalarMapPL
+::SetScalarMax(float theValue)
+{
   float aScalarRange[2] = {GetScalarRange()[0], theValue};
   SetScalarRange(aScalarRange);
 }
 
 
-void VISU_ScalarMapPL::SetNbColors(int theNbColors) { 
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::SetNbColors(int theNbColors) 
+{
   myMapperTable->SetNumberOfColors(theNbColors);
   myBarTable->SetNumberOfColors(theNbColors);
   Modified();
 }
-int VISU_ScalarMapPL::GetNbColors() { 
+
+int
+VISU_ScalarMapPL
+::GetNbColors() 
+{
   return myMapperTable->GetNumberOfColors();
 }
 
 
-VISU_ScalarMapPL::THook* VISU_ScalarMapPL::DoHook(){
+//----------------------------------------------------------------------------
+VISU_ScalarMapPL::THook* 
+VISU_ScalarMapPL
+::DoHook()
+{
   myMapper->SetColorModeToMapScalars();
   myMapper->ScalarVisibilityOn();
   return myFieldTransform->GetUnstructuredGridOutput();
 }
 
 
-void VISU_ScalarMapPL::Init(){
-  //SetSourceRange();
+void
+VISU_ScalarMapPL
+::Init()
+{
+  SetScalarMode(0);
+  SetSourceRange();
 }
 
-
-void VISU_ScalarMapPL::Build() { 
-  myExtractor->SetInput(myInput);
-  myFieldTransform->SetInput(myExtractor->GetOutput());
+void
+VISU_ScalarMapPL
+::Build() 
+{
   myMapper->SetInput(DoHook());
 }
 
 
-void VISU_ScalarMapPL::Update() {
+void
+VISU_ScalarMapPL
+::Update() 
+{ 
   float *aRange = myFieldTransform->GetScalarRange();
   float aScalarRange[2] = {aRange[0], aRange[1]};
   if(myBarTable->GetScale() == VTK_SCALE_LOG10)
     VISU_LookupTable::ComputeLogRange(aRange,aScalarRange);
   myMapperTable->SetRange(aScalarRange);
-  myMapperTable->SetMapScale(1.0);
 
   myMapperTable->Build();
   myBarTable->Build();
 
-  myMapper->SetLookupTable(myMapperTable);   
+  myMapper->SetLookupTable(myMapperTable);
   myMapper->SetScalarRange(aScalarRange);
 
   VISU_PipeLine::Update();
 }
 
 
-void VISU_ScalarMapPL::SetMapScale(float theMapScale){
+//----------------------------------------------------------------------------
+VISU_LookupTable *
+VISU_ScalarMapPL
+::GetMapperTable()
+{ 
+  return myMapperTable;
+}
+
+VISU_LookupTable*
+VISU_ScalarMapPL
+::GetBarTable()
+{
+  return myBarTable;
+}
+
+
+//----------------------------------------------------------------------------
+void 
+VISU_ScalarMapPL
+::SetMapScale(float theMapScale)
+{
   myMapperTable->SetMapScale(theMapScale);
   myMapperTable->Build();
 }
-float VISU_ScalarMapPL::GetMapScale(){
+
+float
+VISU_ScalarMapPL::GetMapScale()
+{
   return myMapperTable->GetMapScale();
 }
 
 
-void VISU_ScalarMapPL::GetSourceRange(float theRange[2]){
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::GetSourceRange(float theRange[2])
+{
   myExtractor->Update();
   myExtractor->GetOutput()->GetScalarRange(theRange);
 }
 
-void VISU_ScalarMapPL::SetSourceRange(){
+void
+VISU_ScalarMapPL
+::SetSourceRange()
+{
   float aRange[2];
   GetSourceRange(aRange);
   SetScalarRange(aRange);