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
24 // File: VISU_ScalarMapPL.cxx
25 // Author: Alexey PETROV
28 #include "VISU_ScalarMapPL.hxx"
29 #include "VISU_DataSetMapperHolder.hxx"
30 #include "VISU_ElnoAssembleFilter.hxx"
31 #include "VISU_Extractor.hxx"
32 #include "VISU_FieldTransform.hxx"
34 #include "VISU_AppendFilter.hxx"
35 #include "VISU_MergeFilter.hxx"
36 #include "VISU_ConvertorUtils.hxx"
38 #include <vtkDataSet.h>
39 #include <vtkPointSet.h>
40 #include <vtkUnstructuredGrid.h>
42 #include <vtkDataSetMapper.h>
43 #include <vtkObjectFactory.h>
46 //----------------------------------------------------------------------------
47 vtkStandardNewMacro(VISU_ScalarMapPL);
50 //----------------------------------------------------------------------------
53 VISU_UnstructuredGridPL(this),
54 myElnoAssembleFilter( VISU_ElnoAssembleFilter::New() ),
55 myAppendFilter(VISU_AppendFilter::New()),
56 myMergeFilter(VISU_MergeFilter::New())
58 SetIsShrinkable(true);
59 SetIsFeatureEdgesAllowed(true);
61 SetElnoDisassembleState( false );
63 myElnoAssembleFilter->Delete();
65 myAppendFilter->SetMergingInputs(true);
66 myAppendFilter->Delete();
68 myMergeFilter->SetMergingInputs(true);
69 myMergeFilter->Delete();
73 //----------------------------------------------------------------------------
79 //----------------------------------------------------------------------------
84 unsigned long int aTime = Superclass::GetMTime();
86 aTime = std::max(aTime, myAppendFilter->GetMTime());
87 aTime = std::max(aTime, myMergeFilter->GetMTime());
93 //----------------------------------------------------------------------------
96 ::OnCreateMapperHolder()
98 VISU_UnstructuredGridPL::OnCreateMapperHolder();
102 //----------------------------------------------------------------------------
111 myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
113 vtkDataSet* aDataSet = GetClippedInput();
114 myMergeFilter->SetScalars(aDataSet);
115 myMergeFilter->SetVectors(aDataSet);
117 myMergeFilter->RemoveFields();
118 myMergeFilter->AddField("VISU_FIELD", aDataSet);
119 myMergeFilter->AddField("VISU_FIELD_GAUSS_MIN", aDataSet);
120 myMergeFilter->AddField("VISU_FIELD_GAUSS_MAX", aDataSet);
121 myMergeFilter->AddField("VISU_FIELD_GAUSS_MOD", aDataSet);
122 myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
123 myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
124 myMergeFilter->AddField("ELNO_POINT_COORDS", aDataSet);
126 myElnoAssembleFilter->SetInput( InsertCustomPL() );
128 GetDataSetMapper()->SetInput( myElnoAssembleFilter->GetOutput() );
132 //----------------------------------------------------------------------------
137 Superclass::Update();
139 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput.vtk";
140 // VISU::WriteToFile(GetFieldTransformFilter()->GetUnstructuredGridOutput(), aFileName);
143 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet.vtk";
144 // VISU::WriteToFile(myAppendFilter->GetOutput(), aFileName);
147 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter.vtk";
148 // VISU::WriteToFile(myMergeFilter->GetUnstructuredGridOutput(), aFileName);
153 //----------------------------------------------------------------------------
156 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
159 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
160 VISU_MergedPL::DoShallowCopy(thePipeLine, theIsCopyInput);
162 if(VISU_ScalarMapPL* aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine))
163 SetGaussMetric(aPipeLine->GetGaussMetric());
167 //----------------------------------------------------------------------------
170 ::SetElnoDisassembleState( bool theIsShrunk )
172 GetDataSetMapperHolder()->SetElnoDisassembleState( theIsShrunk );
173 myElnoAssembleFilter->SetElnoAssembleState( theIsShrunk );
177 //----------------------------------------------------------------------------
180 ::SetSourceGeometry()
182 if(IsExternalGeometryUsed()){
184 myAppendFilter->AddInput(GetClippedInput());
189 //----------------------------------------------------------------------------
192 ::AddGeometry(vtkDataSet* theGeometry, const VISU::TName& theGeomName)
194 // rnv: to fix issue 0020167 (AddMeshOnGroup is not fully taken into account)
195 // clear all inpust of the this->myAppendFilter in case if presentation
196 // constructed on the entire mesh.
197 if(!IsExternalGeometryUsed())
199 AddGeometryName(theGeomName);
200 myAppendFilter->AddInput(theGeometry);
201 return GetNumberOfGeometry();
205 //----------------------------------------------------------------------------
208 ::GetGeometry(int theGeomNumber, VISU::TName& theGeomName)
210 theGeomName = GetGeometryName(theGeomNumber);
211 return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
215 //----------------------------------------------------------------------------
218 ::GetNumberOfGeometry()
220 return myAppendFilter->GetNumberOfInputConnections(0);
224 //----------------------------------------------------------------------------
227 ::IsExternalGeometryUsed()
229 return myAppendFilter->GetInput() != GetClippedInput();
233 //----------------------------------------------------------------------------
238 ClearGeometryNames();
239 myAppendFilter->RemoveAllInputs();
243 //----------------------------------------------------------------------------
246 ::GetSourceRange(vtkFloatingPointType theRange[2])
248 if(!IsExternalGeometryUsed())
249 Superclass::GetSourceRange(theRange);
251 GetMergedInput()->GetScalarRange( theRange );
255 //----------------------------------------------------------------------------
258 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
260 if(GetGaussMetric() == theGaussMetric)
263 GetExtractorFilter()->SetGaussMetric(theGaussMetric);
267 //----------------------------------------------------------------------------
272 return GetExtractorFilter()->GetGaussMetric();
276 //----------------------------------------------------------------------------
281 return GetMergedInput();
285 //----------------------------------------------------------------------------
290 if(myMergeFilter->GetInput())
291 myMergeFilter->Update();
292 return myMergeFilter->GetOutput();
296 //----------------------------------------------------------------------------