Salome HOME
Merge from V5_1_main 10/06/2010
[modules/visu.git] / src / PIPELINE / VISU_ScalarMapPL.cxx
index 5025d98ec9b6a10f25da8fce87e58358f6e6b5a7..17638d39c6599dd5c1cab72d3e649519597043cd 100644 (file)
-//  VISU OBJECT : interactive object for VISU entities implementation
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  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 
+//  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// File:    VISU_PipeLine.cxx
-// Author:  Alexey PETROV
-// Module : VISU
-
 
+//  VISU OBJECT : interactive object for VISU entities implementation
+//  File:    VISU_ScalarMapPL.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+//
 #include "VISU_ScalarMapPL.hxx"
-#include "VISU_PipeLineUtils.hxx"
+#include "VISU_DataSetMapperHolder.hxx"
+#include "VISU_ElnoAssembleFilter.hxx"
+#include "VISU_Extractor.hxx"
+#include "VISU_FieldTransform.hxx"
+
+#include "VISU_AppendFilter.hxx"
+#include "VISU_MergeFilter.hxx"
+#include "VISU_ConvertorUtils.hxx"
+
+#include <vtkDataSet.h>
+#include <vtkPointSet.h>
+#include <vtkUnstructuredGrid.h>
 
-#ifdef _DEBUG_
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 0;
-#endif
+#include <vtkDataSetMapper.h>
+#include <vtkObjectFactory.h>
 
+
+//----------------------------------------------------------------------------
 vtkStandardNewMacro(VISU_ScalarMapPL);
 
 
-VISU_ScalarMapPL::VISU_ScalarMapPL(){
-  myFieldTransform = VISU_FieldTransform::New();
+//----------------------------------------------------------------------------
+VISU_ScalarMapPL
+::VISU_ScalarMapPL():
+  VISU_UnstructuredGridPL(this),
+  myElnoAssembleFilter( VISU_ElnoAssembleFilter::New() ),
+  myAppendFilter(VISU_AppendFilter::New()),
+  myMergeFilter(VISU_MergeFilter::New())
+{
+  SetIsShrinkable(true);
+  SetIsFeatureEdgesAllowed(true);
+
+  SetElnoDisassembleState( false );
 
-  myMapperTable = VISU_LookupTable::New();
-  myMapperTable->SetScale(VTK_SCALE_LINEAR);
-  myMapperTable->SetHueRange(0.667,0.0);
+  myElnoAssembleFilter->Delete();
 
-  myBarTable = VISU_LookupTable::New();
-  myBarTable->SetScale(VTK_SCALE_LINEAR);
-  myBarTable->SetHueRange(0.667,0.0);
+  myAppendFilter->SetMergingInputs(true);
+  myAppendFilter->Delete();
 
-  myExtractor = VISU_Extractor::New();
+  myMergeFilter->SetMergingInputs(true);
+  myMergeFilter->Delete();
 }
 
 
-VISU_ScalarMapPL::~VISU_ScalarMapPL(){
-  myFieldTransform->Delete();
-  myMapperTable->Delete();;
-  myBarTable->Delete();
-  myExtractor->Delete();
-}
+//----------------------------------------------------------------------------
+VISU_ScalarMapPL
+::~VISU_ScalarMapPL()
+{}
 
 
-void VISU_ScalarMapPL::ShallowCopy(VISU_PipeLine *thePipeLine){
-  VISU_PipeLine::ShallowCopy(thePipeLine);
-  if(VISU_ScalarMapPL *aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine)){
-    SetScalarRange(aPipeLine->GetScalarRange());
-    SetScalarMode(aPipeLine->GetScalarMode());
-    SetNbColors(aPipeLine->GetNbColors());
-    SetScaling(aPipeLine->GetScaling());
-    //Update();
-  }
-}
+//----------------------------------------------------------------------------
+unsigned long int
+VISU_ScalarMapPL
+::GetMTime()
+{
+  unsigned long int aTime = Superclass::GetMTime();
 
+  aTime = std::max(aTime, myAppendFilter->GetMTime());
+  aTime = std::max(aTime, myMergeFilter->GetMTime());
 
-int VISU_ScalarMapPL::GetScalarMode(){
-  return myExtractor->GetScalarMode();
-}
-void VISU_ScalarMapPL::SetScalarMode(int theScalarMode){
-  myExtractor->SetScalarMode(theScalarMode);
-  Modified();
+  return aTime;
 }
 
 
-int VISU_ScalarMapPL::GetScaling() { 
-  return myBarTable->GetScale();
-}
-void VISU_ScalarMapPL::SetScaling(int theScaling) {
-  myBarTable->SetScale(theScaling);
-  if(theScaling == VTK_SCALE_LOG10)
-    myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Log10));
-  else
-    myFieldTransform->SetScalarTransform(&(VISU_FieldTransform::Ident));
-  Modified();
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::OnCreateMapperHolder()
+{
+  VISU_UnstructuredGridPL::OnCreateMapperHolder();
 }
 
 
-float* VISU_ScalarMapPL::GetScalarRange() { 
-  return myFieldTransform->GetScalarRange();
-}  
-void VISU_ScalarMapPL::SetScalarRange(float theRange[2]){
-  myFieldTransform->SetScalarRange(theRange);
-  myBarTable->SetRange(theRange);
-  Modified();
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::Build()
+{
+  Superclass::Build();
+
+  SetSourceGeometry();
+
+  myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
+
+  vtkDataSet* aDataSet = GetClippedInput();
+  myMergeFilter->SetScalars(aDataSet);
+  myMergeFilter->SetVectors(aDataSet);
+
+  myMergeFilter->RemoveFields();
+  myMergeFilter->AddField("VISU_FIELD", aDataSet);
+  myMergeFilter->AddField("VISU_FIELD_GAUSS_MIN", aDataSet);
+  myMergeFilter->AddField("VISU_FIELD_GAUSS_MAX", aDataSet);
+  myMergeFilter->AddField("VISU_FIELD_GAUSS_MOD", aDataSet);
+  myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
+  myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
+  myMergeFilter->AddField("ELNO_POINT_COORDS", aDataSet);
+
+  myElnoAssembleFilter->SetInput( InsertCustomPL() );
+
+  GetDataSetMapper()->SetInput( myElnoAssembleFilter->GetOutput() );
 }
-void VISU_ScalarMapPL::SetScalarMin(float theValue){
-  float aScalarRange[2] = {theValue, GetScalarRange()[1]};
-  SetScalarRange(aScalarRange);
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::Update()
+{
+  Superclass::Update();
+  //{
+  //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput.vtk";
+  //  VISU::WriteToFile(GetFieldTransformFilter()->GetUnstructuredGridOutput(), aFileName);
+  //}
+  //{
+  //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet.vtk";
+  //  VISU::WriteToFile(myAppendFilter->GetOutput(), aFileName);
+  //}
+  //{
+  //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter.vtk";
+  //  VISU::WriteToFile(myMergeFilter->GetUnstructuredGridOutput(), aFileName);
+  //}
 }
-void VISU_ScalarMapPL::SetScalarMax(float theValue){
-  float aScalarRange[2] = {GetScalarRange()[0], theValue};
-  SetScalarRange(aScalarRange);
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::DoShallowCopy(VISU_PipeLine *thePipeLine,
+                bool theIsCopyInput)
+{
+  Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
+  VISU_MergedPL::DoShallowCopy(thePipeLine, theIsCopyInput);
+
+  if(VISU_ScalarMapPL* aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine))
+    SetGaussMetric(aPipeLine->GetGaussMetric());
 }
 
 
-void VISU_ScalarMapPL::SetNbColors(int theNbColors) { 
-  myMapperTable->SetNumberOfColors(theNbColors);
-  myBarTable->SetNumberOfColors(theNbColors);
-  Modified();
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::SetElnoDisassembleState( bool theIsShrunk )
+{
+  GetDataSetMapperHolder()->SetElnoDisassembleState( theIsShrunk );
+  myElnoAssembleFilter->SetElnoAssembleState( theIsShrunk );
 }
-int VISU_ScalarMapPL::GetNbColors() { 
-  return myMapperTable->GetNumberOfColors();
+
+
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::SetSourceGeometry()
+{
+  if(IsExternalGeometryUsed()){
+    ClearGeometry();
+    myAppendFilter->AddInput(GetClippedInput());
+  }
 }
 
 
-VISU_ScalarMapPL::THook* VISU_ScalarMapPL::DoHook(){
-  myMapper->SetColorModeToMapScalars();
-  myMapper->ScalarVisibilityOn();
-  return myFieldTransform->GetUnstructuredGridOutput();
+//----------------------------------------------------------------------------
+int
+VISU_ScalarMapPL
+::AddGeometry(vtkDataSet* theGeometry, const VISU::TName& theGeomName)
+{
+  // rnv: to fix issue 0020167 (AddMeshOnGroup is not fully taken into account)
+  // clear all inpust of the this->myAppendFilter in case if presentation
+  // constructed on the entire mesh.
+  if(!IsExternalGeometryUsed())
+    ClearGeometry();
+  AddGeometryName(theGeomName);
+  myAppendFilter->AddInput(theGeometry);
+  return GetNumberOfGeometry();
 }
 
 
-void VISU_ScalarMapPL::Init(){
-  //SetSourceRange();
+//----------------------------------------------------------------------------
+vtkDataSet*
+VISU_ScalarMapPL
+::GetGeometry(int theGeomNumber, VISU::TName& theGeomName)
+{
+  theGeomName = GetGeometryName(theGeomNumber);
+  return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
 }
 
 
-void VISU_ScalarMapPL::Build() { 
-  myExtractor->SetInput(myInput);
-  myFieldTransform->SetInput(myExtractor->GetOutput());
-  myMapper->SetInput(DoHook());
+//----------------------------------------------------------------------------
+int
+VISU_ScalarMapPL
+::GetNumberOfGeometry()
+{
+  return myAppendFilter->GetNumberOfInputConnections(0);
 }
 
 
-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);
+//----------------------------------------------------------------------------
+bool
+VISU_ScalarMapPL
+::IsExternalGeometryUsed()
+{
+  return myAppendFilter->GetInput() != GetClippedInput();
+}
 
-  myMapperTable->Build();
-  myBarTable->Build();
 
-  myMapper->SetLookupTable(myMapperTable);   
-  myMapper->SetScalarRange(aScalarRange);
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::ClearGeometry()
+{
+  ClearGeometryNames();
+  myAppendFilter->RemoveAllInputs();
+}
 
-  myFieldTransform->Update();
 
-  VISU_PipeLine::Update();
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::GetSourceRange(vtkFloatingPointType theRange[2])
+{
+  if(!IsExternalGeometryUsed())
+    Superclass::GetSourceRange(theRange);
+  else
+    GetMergedInput()->GetScalarRange( theRange );
 }
 
 
-void VISU_ScalarMapPL::SetMapScale(float theMapScale){
-  myMapperTable->SetMapScale(theMapScale);
-  myMapperTable->Build();
+//----------------------------------------------------------------------------
+void
+VISU_ScalarMapPL
+::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
+{
+  if(GetGaussMetric() == theGaussMetric)
+    return;
+
+  GetExtractorFilter()->SetGaussMetric(theGaussMetric);
 }
-float VISU_ScalarMapPL::GetMapScale(){
-  return myMapperTable->GetMapScale();
+
+
+//----------------------------------------------------------------------------
+VISU::TGaussMetric
+VISU_ScalarMapPL
+::GetGaussMetric()
+{
+  return GetExtractorFilter()->GetGaussMetric();
 }
 
 
-void VISU_ScalarMapPL::GetSourceRange(float theRange[2]){
-  myExtractor->Update();
-  myExtractor->GetOutput()->GetScalarRange(theRange);
+//----------------------------------------------------------------------------
+vtkDataSet*
+VISU_ScalarMapPL
+::InsertCustomPL()
+{
+  return GetMergedInput();
 }
 
-void VISU_ScalarMapPL::SetSourceRange(){
-  float aRange[2];
-  GetSourceRange(aRange);
-  SetScalarRange(aRange);
+
+//----------------------------------------------------------------------------
+vtkPointSet*
+VISU_ScalarMapPL
+::GetMergedInput()
+{
+  if(myMergeFilter->GetInput())
+    myMergeFilter->Update();
+  return myMergeFilter->GetOutput();
 }
+
+
+//----------------------------------------------------------------------------