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