1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // VISU OBJECT : interactive object for VISU entities implementation
23 // File: VISU_ScalarMapPL.cxx
24 // Author: Alexey PETROV
27 #include "VISU_ScalarMapPL.hxx"
28 #include "VISU_DataSetMapperHolder.hxx"
29 #include "VISU_ElnoAssembleFilter.hxx"
30 #include "VISU_FieldTransform.hxx"
32 #include "VISU_AppendFilter.hxx"
33 #include "VISU_MergeFilter.hxx"
34 #include "VISU_ConvertorUtils.hxx"
36 #include <vtkDataSet.h>
37 #include <vtkPointSet.h>
38 #include <vtkUnstructuredGrid.h>
40 #include <vtkDataSetMapper.h>
41 #include <vtkObjectFactory.h>
44 //----------------------------------------------------------------------------
45 vtkStandardNewMacro(VISU_ScalarMapPL);
48 //----------------------------------------------------------------------------
51 VISU_UnstructuredGridPL(this),
52 myElnoAssembleFilter( VISU_ElnoAssembleFilter::New() ),
53 myAppendFilter(VISU_AppendFilter::New()),
54 myMergeFilter(VISU_MergeFilter::New())
56 SetIsShrinkable(true);
57 SetIsFeatureEdgesAllowed(true);
59 SetElnoDisassembleState( false );
61 myElnoAssembleFilter->Delete();
63 myAppendFilter->SetMergingInputs(true);
64 myAppendFilter->Delete();
66 myMergeFilter->SetMergingInputs(true);
67 myMergeFilter->Delete();
71 //----------------------------------------------------------------------------
77 //----------------------------------------------------------------------------
82 unsigned long int aTime = Superclass::GetMTime();
84 aTime = std::max(aTime, myAppendFilter->GetMTime());
85 aTime = std::max(aTime, myMergeFilter->GetMTime());
91 //----------------------------------------------------------------------------
94 ::OnCreateMapperHolder()
96 VISU_UnstructuredGridPL::OnCreateMapperHolder();
100 //----------------------------------------------------------------------------
109 myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
111 vtkDataSet* aDataSet = GetClippedInput();
112 myMergeFilter->SetScalars(aDataSet);
113 myMergeFilter->SetVectors(aDataSet);
115 myMergeFilter->RemoveFields();
116 myMergeFilter->AddField("VISU_FIELD", aDataSet);
117 myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
118 myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
119 myMergeFilter->AddField("ELNO_POINT_COORDS", aDataSet);
121 myElnoAssembleFilter->SetInput( InsertCustomPL() );
123 GetDataSetMapper()->SetInput( myElnoAssembleFilter->GetOutput() );
127 //----------------------------------------------------------------------------
132 Superclass::Update();
134 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput.vtk";
135 // VISU::WriteToFile(GetFieldTransformFilter()->GetUnstructuredGridOutput(), aFileName);
138 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet.vtk";
139 // VISU::WriteToFile(myAppendFilter->GetOutput(), aFileName);
142 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter.vtk";
143 // VISU::WriteToFile(myMergeFilter->GetUnstructuredGridOutput(), aFileName);
148 //----------------------------------------------------------------------------
151 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
154 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
155 VISU_MergedPL::DoShallowCopy(thePipeLine, theIsCopyInput);
159 //----------------------------------------------------------------------------
162 ::SetElnoDisassembleState( bool theIsShrunk )
164 GetDataSetMapperHolder()->SetElnoDisassembleState( theIsShrunk );
165 myElnoAssembleFilter->SetElnoAssembleState( theIsShrunk );
168 //----------------------------------------------------------------------------
171 ::SetSourceGeometry()
173 if(IsExternalGeometryUsed()){
175 myAppendFilter->AddInput(GetClippedInput());
180 //----------------------------------------------------------------------------
183 ::AddGeometry(vtkDataSet* theGeometry, const VISU::TName& theGeomName)
185 // rnv: to fix issue 0020167 (AddMeshOnGroup is not fully taken into account)
186 // clear all inpust of the this->myAppendFilter in case if presentation
187 // constructed on the entire mesh.
188 if(!IsExternalGeometryUsed())
190 AddGeometryName(theGeomName);
191 myAppendFilter->AddInput(theGeometry);
192 return GetNumberOfGeometry();
196 //----------------------------------------------------------------------------
199 ::GetGeometry(int theGeomNumber, VISU::TName& theGeomName)
201 theGeomName = GetGeometryName(theGeomNumber);
202 return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
206 //----------------------------------------------------------------------------
209 ::GetNumberOfGeometry()
211 return myAppendFilter->GetNumberOfInputConnections(0);
215 //----------------------------------------------------------------------------
218 ::IsExternalGeometryUsed()
220 return myAppendFilter->GetInput() != GetClippedInput();
224 //----------------------------------------------------------------------------
229 ClearGeometryNames();
230 myAppendFilter->RemoveAllInputs();
234 //----------------------------------------------------------------------------
237 ::GetSourceRange(vtkFloatingPointType theRange[2])
239 if(!IsExternalGeometryUsed())
240 Superclass::GetSourceRange(theRange);
242 GetMergedInput()->GetScalarRange( theRange );
246 //----------------------------------------------------------------------------
251 return GetMergedInput();
255 //----------------------------------------------------------------------------
260 if(myMergeFilter->GetInput())
261 myMergeFilter->Update();
262 return myMergeFilter->GetOutput();
266 //----------------------------------------------------------------------------