]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_DataSetActor.cxx
Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / OBJECT / VISU_DataSetActor.cxx
1 //  Copyright (C) 2007-2010  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->SetInput(theDataSet);
105     myMapper->SetInput(myPolyDataExtractor->GetOutput());
106   } else {
107     myExtractor->SetInput(theDataSet);
108     myMapper->SetInput(myExtractor->GetOutput());
109   }
110   //  myMapper->SetInput(theDataSet);
111   SetMapper(myMapper.GetPointer());
112 }
113
114 //----------------------------------------------------------------------------
115 vtkDataSetMapper* VISU_DataSetActor::GetDataSetMapper()
116 {
117   return myMapper.GetPointer();
118 }
119
120 //----------------------------------------------------------------------------
121 void VISU_DataSetActor::RemoveAllClippingPlanes()
122 {
123   myFunction->GetFunction()->RemoveAllItems();
124   myFunction->Modified();
125 }
126
127 //----------------------------------------------------------------------------
128 vtkIdType VISU_DataSetActor::GetNumberOfClippingPlanes()
129 {
130   return myFunction->GetFunction()->GetNumberOfItems();
131 }
132
133 //----------------------------------------------------------------------------
134 bool VISU_DataSetActor::AddClippingPlane(vtkPlane* thePlane)
135 {
136   vtkImplicitFunctionCollection* aFunctions = GetClippingPlanes();
137   aFunctions->InitTraversal();
138   vtkImplicitFunction* aItem;
139   while ((aItem = aFunctions->GetNextItem())) {
140     if (thePlane == aItem)
141       return false;
142   }
143   myFunction->AddFunction(thePlane);
144   return true;
145 }
146
147 //----------------------------------------------------------------------------
148 vtkPlane* VISU_DataSetActor::GetClippingPlane(vtkIdType theID)
149 {
150   vtkPlane* aPlane = NULL;
151   if ((theID >= 0) && (theID < GetNumberOfClippingPlanes())) {
152     vtkImplicitFunctionCollection* aFunction = myFunction->GetFunction();
153     vtkImplicitFunction* aFun = NULL;
154     aFunction->InitTraversal();
155     for (vtkIdType i = 0; i <= theID; i++)
156       aFun = aFunction->GetNextItem();
157     aPlane = dynamic_cast<vtkPlane*>(aFun);
158   }
159   return aPlane;
160 }
161   
162 //----------------------------------------------------------------------------
163 vtkImplicitFunctionCollection* VISU_DataSetActor::GetClippingPlanes()
164 {
165   return myFunction->GetFunction();
166 }