]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_CutLinesPL.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / PIPELINE / VISU_CutLinesPL.cxx
1 //
2 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
3 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 //
5 //  This library is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU Lesser General Public
7 //  License as published by the Free Software Foundation; either
8 //  version 2.1 of the License.
9 //
10 //  This library is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 //  Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with this library; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 //
22 // File:    VISU_PipeLine.cxx
23 // Author:  Alexey PETROV
24 // Module : VISU
25
26
27 #include "VISU_CutLinesPL.hxx"
28 #include "VISU_FieldTransform.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VTKViewer_GeometryFilter.h"
31
32 #include <vtkAppendPolyData.h>
33
34
35 //----------------------------------------------------------------------------
36 vtkStandardNewMacro(VISU_CutLinesPL);
37
38
39 //----------------------------------------------------------------------------
40 VISU_CutLinesPL
41 ::VISU_CutLinesPL()
42 {
43   SetIsShrinkable(false);
44
45   myCondition = 1;
46   myPosition = 0;
47 }
48
49
50 //----------------------------------------------------------------------------
51 void
52 VISU_CutLinesPL
53 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
54                 bool theIsCopyInput)
55 {
56   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
57
58   if(VISU_CutLinesPL *aPipeLine = dynamic_cast<VISU_CutLinesPL*>(thePipeLine)){
59     SetOrientation(aPipeLine->GetPlaneOrientation(1),
60                    aPipeLine->GetRotateX(1),aPipeLine->GetRotateY(1),1);
61     SetDisplacement(aPipeLine->GetDisplacement(1),1);
62     if (aPipeLine->IsDefault())
63       SetDefault();
64     else
65       SetPosition(aPipeLine->GetPosition());
66   }
67 }
68
69
70 //----------------------------------------------------------------------------
71 void
72 VISU_CutLinesPL
73 ::Init()
74 {
75   Superclass::Init();
76
77   myBasePlane[0] = XY;
78   myBasePlane[1] = YZ;
79   myDisplacement[0] = myDisplacement[1] = 0.5;
80   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
81   myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0;
82
83   myCondition = 1;
84   myPosition = 0;
85 }
86
87
88 //----------------------------------------------------------------------------
89 void
90 VISU_CutLinesPL
91 ::SetPosition(vtkFloatingPointType thePosition)
92 {
93   bool anIsSameValue = VISU::CheckIsSameValue(myPosition, thePosition);
94   anIsSameValue &= (myCondition == 0);
95   if(anIsSameValue)
96     return;
97
98   myPosition = thePosition;
99   myCondition = 0;
100   Modified();
101 }
102
103
104 //----------------------------------------------------------------------------
105 vtkFloatingPointType 
106 VISU_CutLinesPL
107 ::GetPosition()
108 {
109   vtkFloatingPointType aPosition = myPosition;
110   if(myCondition){
111       vtkFloatingPointType aBounds[6];
112       GetMergedInput()->GetBounds(aBounds);
113
114       vtkFloatingPointType aDir[3];
115       GetDir(aDir,
116              myAng[0],
117              myBasePlane[0]);
118
119       vtkFloatingPointType aBoundPrj[3];
120       GetBoundProject(aBoundPrj,
121                       aBounds,
122                       aDir);
123
124       aPosition = aBoundPrj[0] + aBoundPrj[2] * myDisplacement[0];
125   }
126   return aPosition;
127 }
128
129
130 //----------------------------------------------------------------------------
131 void
132 VISU_CutLinesPL
133 ::SetDefault()
134 {
135   if(myCondition == 1)
136     return;
137
138   myCondition = 1;
139   Modified();
140 }
141
142
143 //----------------------------------------------------------------------------
144 int
145 VISU_CutLinesPL
146 ::IsDefault()
147 {
148   return myCondition;
149 }
150
151
152 //----------------------------------------------------------------------------
153 void
154 VISU_CutLinesPL
155 ::Update()
156 {
157   ClearAppendPolyData(myAppendPolyData);
158
159   SetPartPosition(1);
160
161   vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
162
163   //Build base plane
164   vtkFloatingPointType aBaseBounds[6];
165   GetMergedInput()->GetBounds(aBaseBounds);
166
167   vtkFloatingPointType aDir[2][3];
168   GetDir(aDir[0],
169          myAng[0],
170          myBasePlane[0]);
171
172   CutWithPlanes(anAppendPolyData,
173                 GetMergedInput(),
174                 1,
175                 aDir[0],
176                 aBaseBounds,
177                 myPosition,
178                 myCondition,
179                 myDisplacement[0]);
180   //Build lines
181   vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
182   aDataSet->Update();
183
184   if(aDataSet->GetNumberOfCells() == 0)
185     aDataSet = GetMergedInput();
186
187   vtkFloatingPointType aBounds[6];
188   aDataSet->GetBounds(aBounds);
189
190   GetDir(aDir[1],
191          myAng[1],
192          myBasePlane[1]);
193
194   VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,
195                                   aDataSet,
196                                   GetNbParts(),
197                                   aDir[1],
198                                   aBounds,
199                                   myPartPosition,
200                                   myPartCondition,
201                                   myDisplacement[1]);
202   //{
203   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myAppendPolyData.vtk";
204   //  VISU::WriteToFile(myAppendPolyData->GetOutput(), aFileName);
205   //}
206   anAppendPolyData->Delete();
207
208   //Calculate values for building of table
209   vtkMath::Cross(aDir[0],aDir[1],myDirLn);
210   for (int i = 0; i<3 ; i++) {
211     myRealDirLn[i] = myDirLn[i];
212     if(myDirLn[i] < 0.0) 
213       myDirLn[i] = -1.0*myDirLn[i];//enk:: correction of bug Bug PAL10401
214   }
215
216   GetBoundProject(myBoundPrjLn, 
217                   aBaseBounds, 
218                   myDirLn);
219
220   VISU::Mul(myDirLn,
221             myBoundPrjLn[0],
222             myBasePnt);
223   
224   CorrectPnt(myBasePnt,
225              aBaseBounds);
226
227   VISU_ScalarMapPL::Update();
228 }
229
230
231 //----------------------------------------------------------------------------
232 void
233 VISU_CutLinesPL
234 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
235                 vtkDataSet* theDataSet,
236                 int theNbPlanes, 
237                 vtkFloatingPointType theDir[3], 
238                 vtkFloatingPointType theBounds[6],
239                 vtkFloatingPointType thePartPosition, 
240                 int thePartCondition,
241                 vtkFloatingPointType theDisplacement)
242 {
243   std::vector<vtkFloatingPointType> aPartPosition(1,thePartPosition);
244   std::vector<int> aPartCondition(1,thePartCondition);
245   VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,
246                                   theDataSet,
247                                   theNbPlanes,
248                                   theDir,
249                                   theBounds,
250                                   aPartPosition,
251                                   aPartCondition,
252                                   theDisplacement);
253 }
254
255
256 //----------------------------------------------------------------------------