1 // SMESH OBJECT : interactive object for SMESH visualization
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Actor.cxx
25 // Author : Nicolas REJNERI
30 #include "SMESH_DeviceActor.h"
32 #include "SALOME_Transform.h"
33 #include "SALOME_TransformFilter.h"
34 #include "SALOME_PassThroughFilter.h"
35 #include "SALOME_ExtractUnstructuredGrid.h"
37 #include "utilities.h"
40 #include <vtkObjectFactory.h>
41 #include <vtkShrinkFilter.h>
42 #include <vtkShrinkPolyData.h>
44 #include <vtkProperty.h>
45 #include <vtkPolyData.h>
46 #include <vtkMergeFilter.h>
47 #include <vtkPolyDataMapper.h>
48 #include <vtkUnstructuredGrid.h>
51 static int MYDEBUG = 0;
52 static int MYDEBUGWITHFILES = 0;
54 static int MYDEBUG = 0;
55 static int MYDEBUGWITHFILES = 0;
61 vtkStandardNewMacro(SMESH_DeviceActor);
64 SMESH_DeviceActor::SMESH_DeviceActor(){
65 if(MYDEBUG) MESSAGE("SMESH_DeviceActor");
67 myIsShrinkable = false;
68 myRepresentation = eSurface;
70 myProperty = vtkProperty::New();
71 myMapper = vtkPolyDataMapper::New();
73 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
74 myPolygonOffsetUnits);
75 //myMapper->SetResolveCoincidentTopologyToShiftZBuffer();
76 //myMapper->SetResolveCoincidentTopologyZShift(0.02);
78 myMapper->UseLookupTableScalarRangeOn();
79 myMapper->SetColorModeToMapScalars();
81 myShrinkFilter = vtkShrinkFilter::New();
83 myExtractUnstructuredGrid = SALOME_ExtractUnstructuredGrid::New();
84 myExtractUnstructuredGrid->SetStoreMapping(true);
86 myMergeFilter = vtkMergeFilter::New();
88 myStoreMapping = false;
89 myGeomFilter = SALOME_GeometryFilter::New();
91 myTransformFilter = SALOME_TransformFilter::New();
93 for(int i = 0; i < 6; i++)
94 myPassFilter.push_back(SALOME_PassThroughFilter::New());
98 SMESH_DeviceActor::~SMESH_DeviceActor(){
99 if(MYDEBUG) MESSAGE("~SMESH_DeviceActor");
100 myProperty->Delete();
102 myMapper->RemoveAllInputs();
105 myShrinkFilter->UnRegisterAllOutputs();
106 myShrinkFilter->Delete();
108 myExtractUnstructuredGrid->UnRegisterAllOutputs();
109 myExtractUnstructuredGrid->Delete();
111 myMergeFilter->UnRegisterAllOutputs();
112 myMergeFilter->Delete();
114 myGeomFilter->UnRegisterAllOutputs();
115 myGeomFilter->Delete();
117 myTransformFilter->UnRegisterAllOutputs();
118 myTransformFilter->Delete();
120 for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++){
121 myPassFilter[i]->UnRegisterAllOutputs();
122 myPassFilter[i]->Delete();
127 void SMESH_DeviceActor::SetStoreMapping(int theStoreMapping){
128 myStoreMapping = theStoreMapping;
133 void SMESH_DeviceActor::SetUnstructuredGrid(vtkUnstructuredGrid* theGrid){
135 //myIsShrinkable = theGrid->GetNumberOfCells() > 10;
136 myIsShrinkable = true;
138 myExtractUnstructuredGrid->SetInput(theGrid);
139 myMergeFilter->SetGeometry(myExtractUnstructuredGrid->GetOutput());
141 theGrid = static_cast<vtkUnstructuredGrid*>(myMergeFilter->GetOutput());
144 myPassFilter.at( anId )->SetInput( theGrid );
145 myPassFilter.at( anId + 1)->SetInput( myPassFilter.at( anId )->GetOutput() );
148 myGeomFilter->SetStoreMapping( myStoreMapping );
149 myGeomFilter->SetInput( myPassFilter.at( anId )->GetOutput() );
152 myPassFilter.at( anId )->SetInput( myGeomFilter->GetOutput() );
153 myPassFilter.at( anId + 1 )->SetInput( myPassFilter.at( anId )->GetOutput() );
156 myTransformFilter->SetInput( myPassFilter.at( anId )->GetPolyDataOutput() );
159 myPassFilter.at( anId )->SetInput( myTransformFilter->GetOutput() );
160 myPassFilter.at( anId + 1 )->SetInput( myPassFilter.at( anId )->GetOutput() );
163 myMapper->SetInput( myPassFilter.at( anId )->GetPolyDataOutput() );
165 vtkLODActor::SetMapper( myMapper );
171 SALOME_ExtractUnstructuredGrid* SMESH_DeviceActor::GetExtractUnstructuredGrid(){
172 return myExtractUnstructuredGrid;
176 vtkUnstructuredGrid* SMESH_DeviceActor::GetUnstructuredGrid(){
177 myExtractUnstructuredGrid->Update();
178 return myExtractUnstructuredGrid->GetOutput();
182 vtkMergeFilter* SMESH_DeviceActor::GetMergeFilter(){
183 return myMergeFilter;
187 vtkPolyData* SMESH_DeviceActor::GetPolyDataInput(){
188 return myPassFilter.back()->GetPolyDataOutput();
192 unsigned long int SMESH_DeviceActor::GetMTime(){
193 unsigned long mTime = this->Superclass::GetMTime();
194 mTime = max(mTime,myExtractUnstructuredGrid->GetMTime());
195 mTime = max(mTime,myMergeFilter->GetMTime());
196 mTime = max(mTime,myGeomFilter->GetMTime());
197 mTime = max(mTime,myTransformFilter->GetMTime());
202 void SMESH_DeviceActor::SetTransform(SALOME_Transform* theTransform){
203 myTransformFilter->SetTransform(theTransform);
207 void SMESH_DeviceActor::SetShrink()
209 if ( !myIsShrinkable ) return;
210 if ( vtkDataSet* aDataSet = myPassFilter.at( 0 )->GetOutput() )
212 myShrinkFilter->SetInput( aDataSet );
213 myPassFilter.at( 1 )->SetInput( myShrinkFilter->GetOutput() );
218 void SMESH_DeviceActor::UnShrink()
220 if ( !myIsShrunk ) return;
221 if ( vtkDataSet* aDataSet = myPassFilter.at( 0 )->GetOutput() )
223 myPassFilter.at( 1 )->SetInput( aDataSet );
224 myPassFilter.at( 1 )->Modified();
231 void SMESH_DeviceActor::SetRepresentation(EReperesent theMode){
234 myGeomFilter->SetInside(true);
235 GetProperty()->SetRepresentation(0);
238 myGeomFilter->SetInside(true);
239 GetProperty()->SetRepresentation(1);
242 GetProperty()->SetRepresentation(theMode);
243 myGeomFilter->SetInside(false);
245 myRepresentation = theMode;
246 myMapper->Modified();
251 void SMESH_DeviceActor::SetVisibility(int theMode){
252 if(!myExtractUnstructuredGrid->GetInput() || GetUnstructuredGrid()->GetNumberOfCells()){
253 vtkLODActor::SetVisibility(theMode);
255 vtkLODActor::SetVisibility(false);
260 int SMESH_DeviceActor::GetVisibility(){
261 if(!GetUnstructuredGrid()->GetNumberOfCells()){
262 vtkLODActor::SetVisibility(false);
264 return vtkLODActor::GetVisibility();
268 int SMESH_DeviceActor::GetObjId(int theVtkID){
269 if (GetRepresentation() == ePoint){
270 return GetNodeObjId(theVtkID);
272 return GetElemObjId(theVtkID);
277 SMESH_DeviceActor::TVectorId SMESH_DeviceActor::GetVtkId(int theObjID){
278 if (GetRepresentation() == ePoint){
279 return GetNodeVtkId(theObjID);
281 return GetElemVtkId(theObjID);
286 int SMESH_DeviceActor::GetNodeObjId(int theVtkID){
287 vtkIdType aRetID = myVisualObj->GetNodeObjId(theVtkID);
288 if(MYDEBUG) MESSAGE("GetNodeObjId - theVtkID = "<<theVtkID<<"; aRetID = "<<aRetID);
292 SMESH_DeviceActor::TVectorId SMESH_DeviceActor::GetNodeVtkId(int theObjID){
293 SMESH_DeviceActor::TVectorId aVecId;
294 vtkIdType anID = myVisualObj->GetNodeVTKId(theObjID);
297 aVecId.push_back(anID);
302 int SMESH_DeviceActor::GetElemObjId(int theVtkID){
303 vtkIdType aGridID = myGeomFilter->GetObjId(theVtkID);
306 vtkIdType anExtractID = myExtractUnstructuredGrid->GetOutId(aGridID);
309 vtkIdType aRetID = myVisualObj->GetElemObjId(anExtractID);
311 MESSAGE("GetElemObjId - theVtkID = "<<theVtkID<<"; anExtractID = "<<anExtractID<<"; aGridID = "<<aGridID<<"; aRetID = "<<aRetID);
315 SMESH_DeviceActor::TVectorId SMESH_DeviceActor::GetElemVtkId(int theObjID){
317 vtkIdType aGridID = myVisualObj->GetElemVTKId(theObjID);
320 aVecId = myGeomFilter->GetVtkId(aGridID);
322 MESSAGE("GetElemVtkId - theObjID = "<<theObjID<<"; aGridID = "<<aGridID<<"; aGridID = "<<aGridID<<"; aVecId[0] = "<<aVecId[0]);
327 float SMESH_DeviceActor::GetShrinkFactor(){
328 return myShrinkFilter->GetShrinkFactor();
331 void SMESH_DeviceActor::SetShrinkFactor(float theValue){
332 theValue = theValue > 0.1? theValue: 0.8;
333 myShrinkFilter->SetShrinkFactor(theValue);
338 void SMESH_DeviceActor::Render(vtkRenderer *ren, vtkMapper* m){
339 int aResolveCoincidentTopology = vtkMapper::GetResolveCoincidentTopology();
340 float aFactor, aUnit;
341 vtkMapper::GetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
343 vtkMapper::SetResolveCoincidentTopologyToPolygonOffset();
344 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(myPolygonOffsetFactor,
345 myPolygonOffsetUnits);
346 vtkLODActor::Render(ren,m);
348 vtkMapper::SetResolveCoincidentTopologyPolygonOffsetParameters(aFactor,aUnit);
349 vtkMapper::SetResolveCoincidentTopology(aResolveCoincidentTopology);
353 void SMESH_DeviceActor::SetPolygonOffsetParameters(float factor, float units){
354 myPolygonOffsetFactor = factor;
355 myPolygonOffsetUnits = units;