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_Extractor.hxx"
31 #include "VISU_FieldTransform.hxx"
33 #include "VISU_AppendFilter.hxx"
34 #include "VISU_MergeFilter.hxx"
35 #include "VISU_ConvertorUtils.hxx"
37 #include <vtkDataSet.h>
38 #include <vtkPointSet.h>
39 #include <vtkUnstructuredGrid.h>
41 #include <vtkDataSetMapper.h>
42 #include <vtkObjectFactory.h>
45 //----------------------------------------------------------------------------
46 vtkStandardNewMacro(VISU_ScalarMapPL);
49 //----------------------------------------------------------------------------
52 VISU_UnstructuredGridPL(this),
53 myElnoAssembleFilter( VISU_ElnoAssembleFilter::New() ),
54 myAppendFilter(VISU_AppendFilter::New()),
55 myMergeFilter(VISU_MergeFilter::New())
57 SetIsShrinkable(true);
58 SetIsFeatureEdgesAllowed(true);
60 SetElnoDisassembleState( false );
62 myElnoAssembleFilter->Delete();
64 myAppendFilter->SetMergingInputs(true);
65 myAppendFilter->Delete();
67 myMergeFilter->SetMergingInputs(true);
68 myMergeFilter->Delete();
72 //----------------------------------------------------------------------------
78 //----------------------------------------------------------------------------
83 unsigned long int aTime = Superclass::GetMTime();
85 aTime = std::max(aTime, myAppendFilter->GetMTime());
86 aTime = std::max(aTime, myMergeFilter->GetMTime());
92 //----------------------------------------------------------------------------
95 ::OnCreateMapperHolder()
97 VISU_UnstructuredGridPL::OnCreateMapperHolder();
101 //----------------------------------------------------------------------------
110 myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
112 vtkDataSet* aDataSet = GetClippedInput();
113 myMergeFilter->SetScalars(aDataSet);
114 myMergeFilter->SetVectors(aDataSet);
116 myMergeFilter->RemoveFields();
117 myMergeFilter->AddField("VISU_FIELD", aDataSet);
118 myMergeFilter->AddField("VISU_FIELD_GAUSS_MIN", aDataSet);
119 myMergeFilter->AddField("VISU_FIELD_GAUSS_MAX", aDataSet);
120 myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
121 myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
122 myMergeFilter->AddField("ELNO_POINT_COORDS", aDataSet);
124 myElnoAssembleFilter->SetInput( InsertCustomPL() );
126 GetDataSetMapper()->SetInput( myElnoAssembleFilter->GetOutput() );
130 //----------------------------------------------------------------------------
135 Superclass::Update();
137 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aScalarsOutput.vtk";
138 // VISU::WriteToFile(GetFieldTransformFilter()->GetUnstructuredGridOutput(), aFileName);
141 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-aGeomDataSet.vtk";
142 // VISU::WriteToFile(myAppendFilter->GetOutput(), aFileName);
145 // std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myMergeFilter.vtk";
146 // VISU::WriteToFile(myMergeFilter->GetUnstructuredGridOutput(), aFileName);
151 //----------------------------------------------------------------------------
154 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
157 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
158 VISU_MergedPL::DoShallowCopy(thePipeLine, theIsCopyInput);
160 if(VISU_ScalarMapPL* aPipeLine = dynamic_cast<VISU_ScalarMapPL*>(thePipeLine))
161 SetGaussMetric(aPipeLine->GetGaussMetric());
165 //----------------------------------------------------------------------------
168 ::SetElnoDisassembleState( bool theIsShrunk )
170 GetDataSetMapperHolder()->SetElnoDisassembleState( theIsShrunk );
171 myElnoAssembleFilter->SetElnoAssembleState( theIsShrunk );
174 //----------------------------------------------------------------------------
177 ::SetSourceGeometry()
179 if(IsExternalGeometryUsed()){
181 myAppendFilter->AddInput(GetClippedInput());
186 //----------------------------------------------------------------------------
189 ::AddGeometry(vtkDataSet* theGeometry, const VISU::TName& theGeomName)
191 // rnv: to fix issue 0020167 (AddMeshOnGroup is not fully taken into account)
192 // clear all inpust of the this->myAppendFilter in case if presentation
193 // constructed on the entire mesh.
194 if(!IsExternalGeometryUsed())
196 AddGeometryName(theGeomName);
197 myAppendFilter->AddInput(theGeometry);
198 return GetNumberOfGeometry();
202 //----------------------------------------------------------------------------
205 ::GetGeometry(int theGeomNumber, VISU::TName& theGeomName)
207 theGeomName = GetGeometryName(theGeomNumber);
208 return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
212 //----------------------------------------------------------------------------
215 ::GetNumberOfGeometry()
217 return myAppendFilter->GetNumberOfInputConnections(0);
221 //----------------------------------------------------------------------------
224 ::IsExternalGeometryUsed()
226 return myAppendFilter->GetInput() != GetClippedInput();
230 //----------------------------------------------------------------------------
235 ClearGeometryNames();
236 myAppendFilter->RemoveAllInputs();
240 //----------------------------------------------------------------------------
243 ::GetSourceRange(vtkFloatingPointType theRange[2])
245 if(!IsExternalGeometryUsed())
246 Superclass::GetSourceRange(theRange);
248 GetMergedInput()->GetScalarRange( theRange );
252 //----------------------------------------------------------------------------
255 ::SetGaussMetric(VISU::TGaussMetric theGaussMetric)
257 if(GetGaussMetric() == theGaussMetric)
260 GetExtractorFilter()->SetGaussMetric(theGaussMetric);
264 //----------------------------------------------------------------------------
269 return GetExtractorFilter()->GetGaussMetric();
273 //----------------------------------------------------------------------------
278 return GetMergedInput();
282 //----------------------------------------------------------------------------
287 if(myMergeFilter->GetInput())
288 myMergeFilter->Update();
289 return myMergeFilter->GetOutput();
293 //----------------------------------------------------------------------------