]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_CutLinesPL.cxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/visu.git] / src / PIPELINE / VISU_CutLinesPL.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 // File:    VISU_PipeLine.cxx
23 // Author:  Alexey PETROV
24 // Module : VISU
25 //
26 #include "VISU_CutLinesPL.hxx"
27 #include "VISU_FieldTransform.hxx"
28 #include "VISU_PipeLineUtils.hxx"
29 #include "VTKViewer_GeometryFilter.h"
30
31 #include <vtkAppendPolyData.h>
32
33
34 //----------------------------------------------------------------------------
35 vtkStandardNewMacro(VISU_CutLinesPL);
36
37
38 //----------------------------------------------------------------------------
39 VISU_CutLinesPL
40 ::VISU_CutLinesPL()
41 {
42   SetIsShrinkable(false);
43   SetIsFeatureEdgesAllowed(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 vtkDataSet* 
104 VISU_CutLinesPL
105 ::InsertCustomPL()
106 {
107   return myAppendPolyData->GetOutput();
108 }
109
110 //----------------------------------------------------------------------------
111 vtkFloatingPointType 
112 VISU_CutLinesPL
113 ::GetPosition()
114 {
115   vtkFloatingPointType aPosition = myPosition;
116   if(myCondition){
117       vtkFloatingPointType aBounds[6];
118       GetMergedInput()->GetBounds(aBounds);
119
120       vtkFloatingPointType aDir[3];
121       GetDir(aDir,
122              myAng[0],
123              myBasePlane[0]);
124
125       vtkFloatingPointType aBoundPrj[3];
126       GetBoundProject(aBoundPrj,
127                       aBounds,
128                       aDir);
129
130       aPosition = aBoundPrj[0] + aBoundPrj[2] * myDisplacement[0];
131   }
132   return aPosition;
133 }
134
135
136 //----------------------------------------------------------------------------
137 void
138 VISU_CutLinesPL
139 ::SetDefault()
140 {
141   if(myCondition == 1)
142     return;
143
144   myCondition = 1;
145   Modified();
146 }
147
148
149 //----------------------------------------------------------------------------
150 int
151 VISU_CutLinesPL
152 ::IsDefault()
153 {
154   return myCondition;
155 }
156
157
158 //----------------------------------------------------------------------------
159 void
160 VISU_CutLinesPL
161 ::Update()
162 {
163   ClearAppendPolyData(myAppendPolyData);
164
165   SetPartPosition(1);
166
167   vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
168
169   //Build base plane
170   vtkFloatingPointType aBaseBounds[6];
171   GetMergedInput()->GetBounds(aBaseBounds);
172
173   vtkFloatingPointType aDir[2][3];
174   GetDir(aDir[0],
175          myAng[0],
176          myBasePlane[0]);
177
178   CutWithPlanes(anAppendPolyData,
179                 GetMergedInput(),
180                 1,
181                 aDir[0],
182                 aBaseBounds,
183                 myPosition,
184                 myCondition,
185                 myDisplacement[0]);
186   //Build lines
187   vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
188   aDataSet->Update();
189
190   if(aDataSet->GetNumberOfCells() == 0)
191     aDataSet = GetMergedInput();
192
193   vtkFloatingPointType aBounds[6];
194   aDataSet->GetBounds(aBounds);
195
196   GetDir(aDir[1],
197          myAng[1],
198          myBasePlane[1]);
199
200   VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,
201                                   aDataSet,
202                                   GetNbParts(),
203                                   aDir[1],
204                                   aBounds,
205                                   myPartPosition,
206                                   myPartCondition,
207                                   myDisplacement[1]);
208   //{
209   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myAppendPolyData.vtk";
210   //  VISU::WriteToFile(myAppendPolyData->GetOutput(), aFileName);
211   //}
212   anAppendPolyData->Delete();
213
214   //Calculate values for building of table
215   vtkMath::Cross(aDir[0],aDir[1],myDirLn);
216   for (int i = 0; i<3 ; i++) {
217     myRealDirLn[i] = myDirLn[i];
218     if(myDirLn[i] < 0.0) 
219       myDirLn[i] = -1.0*myDirLn[i];//enk:: correction of bug Bug PAL10401
220   }
221
222   GetBoundProject(myBoundPrjLn, 
223                   aBaseBounds, 
224                   myDirLn);
225
226   VISU::Mul(myDirLn,
227             myBoundPrjLn[0],
228             myBasePnt);
229   
230   CorrectPnt(myBasePnt,
231              aBaseBounds);
232
233   VISU_ScalarMapPL::Update();
234 }
235
236
237 //----------------------------------------------------------------------------
238 void
239 VISU_CutLinesPL
240 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
241                 vtkDataSet* theDataSet,
242                 int theNbPlanes, 
243                 vtkFloatingPointType theDir[3], 
244                 vtkFloatingPointType theBounds[6],
245                 vtkFloatingPointType thePartPosition, 
246                 int thePartCondition,
247                 vtkFloatingPointType theDisplacement)
248 {
249   std::vector<vtkFloatingPointType> aPartPosition(1,thePartPosition);
250   std::vector<int> aPartCondition(1,thePartCondition);
251   VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,
252                                   theDataSet,
253                                   theNbPlanes,
254                                   theDir,
255                                   theBounds,
256                                   aPartPosition,
257                                   aPartCondition,
258                                   theDisplacement);
259 }
260
261
262 //----------------------------------------------------------------------------