]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_DataSetActor.cxx
Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/visu.git] / src / OBJECT / VISU_DataSetActor.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 //  File   : 
25 //  Author : 
26 //  Module : VISU
27 //
28 #include "VISU_DataSetActor.h"
29 #include "VISU_UnstructuredGridPL.hxx"
30 #include "VISU_PipeLineUtils.hxx"
31
32 #include <VTKViewer_DataSetMapper.h>
33
34 #include <vtkObjectFactory.h>
35 #include <vtkImplicitBoolean.h>
36 #include <SALOME_ExtractGeometry.h>
37 #include <SALOME_ExtractPolyDataGeometry.h>
38 #include <vtkImplicitFunctionCollection.h>
39 #include <vtkPlane.h>
40
41 #include <boost/bind.hpp>
42
43 using namespace std;
44
45 #ifdef _DEBUG_
46 static int MYDEBUG = 0;
47 #else
48 static int MYDEBUG = 0;
49 #endif
50
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_DataSetActor);
53
54 //----------------------------------------------------------------------------
55 VISU_DataSetActor
56 ::VISU_DataSetActor():
57   myMapper(VTKViewer_DataSetMapper::New()),
58   myExtractor(SALOME_ExtractGeometry::New()),
59   myPolyDataExtractor(SALOME_ExtractPolyDataGeometry::New()),
60   myFunction(vtkImplicitBoolean::New())
61 {
62   if(MYDEBUG) MESSAGE("VISU_DataSetActor::VISU_DataSetActor - this = "<<this);
63
64   myExtractor->SetImplicitFunction(myFunction);
65   myPolyDataExtractor->SetImplicitFunction(myFunction);
66   //myExtractor->ExtractBoundaryCellsOn();
67   //myPolyDataExtractor->ExtractBoundaryCellsOn();
68
69   myFunction->SetOperationTypeToIntersection();
70
71   myMapper->Delete();
72   myExtractor->Delete();
73   myPolyDataExtractor->Delete();
74   myFunction->Delete();
75 }
76
77 //----------------------------------------------------------------------------
78 VISU_DataSetActor
79 ::~VISU_DataSetActor()
80 {
81   if(MYDEBUG) MESSAGE("~VISU_DataSetActor() - this = "<<this);
82 }
83
84 //----------------------------------------------------------------------------
85 void
86 VISU_DataSetActor
87 ::ShallowCopyPL(VISU_PipeLine* thePipeLine)
88 {
89   Superclass::ShallowCopyPL(thePipeLine);
90
91   if(VISU_UnstructuredGridPL* aPipeLine = dynamic_cast<VISU_UnstructuredGridPL*>(thePipeLine)){
92     vtkDataSetMapper* aTarget = GetDataSetMapper();
93     vtkDataSetMapper* aSource = aPipeLine->GetDataSetMapper();    
94     VISU::CopyDataSetMapper(aTarget, aSource, true);
95   }
96 }
97
98 //----------------------------------------------------------------------------
99 void
100 VISU_DataSetActor
101 ::SetMapperInput(vtkDataSet* theDataSet) 
102 {
103   if (theDataSet->IsA("vtkPolyData")) {
104     myPolyDataExtractor->SetInputData(theDataSet);
105     myMapper->SetInputConnection(myPolyDataExtractor->GetOutputPort());
106   } else {
107     myExtractor->SetInputData(theDataSet);
108     myMapper->SetInputConnection(myExtractor->GetOutputPort());
109   }
110   //  myMapper->SetInputData(theDataSet);
111   myMapper->Update();
112   SetMapper(myMapper.GetPointer());
113 }
114
115 //----------------------------------------------------------------------------
116 vtkDataSetMapper* VISU_DataSetActor::GetDataSetMapper()
117 {
118   return myMapper.GetPointer();
119 }
120
121 //----------------------------------------------------------------------------
122 void VISU_DataSetActor::RemoveAllClippingPlanes()
123 {
124   myFunction->GetFunction()->RemoveAllItems();
125   myFunction->Modified();
126 }
127
128 //----------------------------------------------------------------------------
129 vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes()
130 {
131   return myFunction->GetFunction()->GetNumberOfItems();
132 }
133
134 //----------------------------------------------------------------------------
135 bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane)
136 {
137   vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
138   aFunctions->InitTraversal();
139   vtkImplicitFunction* aItem;
140   while ((aItem = aFunctions->GetNextItem())) {
141     if (thePlane == aItem)
142       return false;
143   }
144   myFunction->AddFunction(thePlane);
145   return true;
146 }
147
148 //----------------------------------------------------------------------------
149 vtkPlane* VISU_DataSetActor::GetClippingPlane(vtkIdType theID)
150 {
151   vtkPlane* aPlane = NULL;
152   if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
153     vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
154     vtkImplicitFunction* aFun = NULL;
155     aFunction->InitTraversal();
156     for (vtkIdType i = 0; i <= theID; i++)
157       aFun = aFunction->GetNextItem();
158     aPlane = dynamic_cast<vtkPlane*>(aFun);
159   }
160   return aPlane;
161 }
162   
163 //----------------------------------------------------------------------------
164 vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes()
165 {
166   return myFunction->GetFunction();
167 }