]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_CutLinesPL.cxx
Salome HOME
3182a43e107a3e89f9c03d492f84ebad5340a4c6
[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   myCondition = 1;
43   myPosition = 0;
44 }
45
46
47 //----------------------------------------------------------------------------
48 void
49 VISU_CutLinesPL
50 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
51                 bool theIsCopyInput)
52 {
53   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
54
55   if(VISU_CutLinesPL *aPipeLine = dynamic_cast<VISU_CutLinesPL*>(thePipeLine)){
56     SetOrientation(aPipeLine->GetPlaneOrientation(1),
57                    aPipeLine->GetRotateX(1),aPipeLine->GetRotateY(1),1);
58     SetDisplacement(aPipeLine->GetDisplacement(1),1);
59     if (aPipeLine->IsDefault())
60       SetDefault();
61     else
62       SetPosition(aPipeLine->GetPosition());
63   }
64 }
65
66
67 //----------------------------------------------------------------------------
68 void
69 VISU_CutLinesPL
70 ::Init()
71 {
72   Superclass::Init();
73
74   myBasePlane[0] = XY;
75   myBasePlane[1] = YZ;
76   myDisplacement[0] = myDisplacement[1] = 0.5;
77   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
78   myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0;
79
80   myCondition = 1;
81   myPosition = 0;
82 }
83
84
85 //----------------------------------------------------------------------------
86 void
87 VISU_CutLinesPL
88 ::SetPosition(vtkFloatingPointType thePosition)
89 {
90   bool anIsSameValue = VISU::CheckIsSameValue(myPosition, thePosition);
91   anIsSameValue &= (myCondition == 0);
92   if(anIsSameValue)
93     return;
94
95   myPosition = thePosition;
96   myCondition = 0;
97   Modified();
98 }
99
100 vtkDataSet* 
101 VISU_CutLinesPL
102 ::InsertCustomPL()
103 {
104   return myAppendPolyData->GetOutput();
105 }
106
107 //----------------------------------------------------------------------------
108 vtkFloatingPointType 
109 VISU_CutLinesPL
110 ::GetPosition()
111 {
112   vtkFloatingPointType aPosition = myPosition;
113   if(myCondition){
114       vtkFloatingPointType aBounds[6];
115       GetMergedInput()->GetBounds(aBounds);
116
117       vtkFloatingPointType aDir[3];
118       GetDir(aDir,
119              myAng[0],
120              myBasePlane[0]);
121
122       vtkFloatingPointType aBoundPrj[3];
123       GetBoundProject(aBoundPrj,
124                       aBounds,
125                       aDir);
126
127       aPosition = aBoundPrj[0] + aBoundPrj[2] * myDisplacement[0];
128   }
129   return aPosition;
130 }
131
132
133 //----------------------------------------------------------------------------
134 void
135 VISU_CutLinesPL
136 ::SetDefault()
137 {
138   if(myCondition == 1)
139     return;
140
141   myCondition = 1;
142   Modified();
143 }
144
145
146 //----------------------------------------------------------------------------
147 int
148 VISU_CutLinesPL
149 ::IsDefault()
150 {
151   return myCondition;
152 }
153
154
155 //----------------------------------------------------------------------------
156 void
157 VISU_CutLinesPL
158 ::Update()
159 {
160   vtkDataSet* aMergedInput = GetMergedInput();
161   if(VISU::IsQuadraticData(aMergedInput)) // Bug 0020123, note 0005343
162     throw std::runtime_error("Impossible to build presentation");
163
164   ClearAppendPolyData(myAppendPolyData);
165
166   SetPartPosition(1);
167
168   vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
169
170   //Build base plane
171   vtkFloatingPointType aBaseBounds[6];
172   GetMergedInput()->GetBounds(aBaseBounds);
173
174   vtkFloatingPointType aDir[2][3];
175   GetDir(aDir[0],
176          myAng[0],
177          myBasePlane[0]);
178
179   CutWithPlanes(anAppendPolyData,
180                 GetMergedInput(),
181                 1,
182                 aDir[0],
183                 aBaseBounds,
184                 myPosition,
185                 myCondition,
186                 myDisplacement[0]);
187   //Build lines
188   vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
189   aDataSet->Update();
190
191   if(aDataSet->GetNumberOfCells() == 0)
192     aDataSet = GetMergedInput();
193
194   vtkFloatingPointType aBounds[6];
195   aDataSet->GetBounds(aBounds);
196
197   GetDir(aDir[1],
198          myAng[1],
199          myBasePlane[1]);
200
201   VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,
202                                   aDataSet,
203                                   GetNbParts(),
204                                   aDir[1],
205                                   aBounds,
206                                   myPartPosition,
207                                   myPartCondition,
208                                   myDisplacement[1]);
209   //{
210   //  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-myAppendPolyData.vtk";
211   //  VISU::WriteToFile(myAppendPolyData->GetOutput(), aFileName);
212   //}
213   anAppendPolyData->Delete();
214
215   //Calculate values for building of table
216   vtkMath::Cross(aDir[0],aDir[1],myDirLn);
217   for (int i = 0; i<3 ; i++) {
218     myRealDirLn[i] = myDirLn[i];
219     if(myDirLn[i] < 0.0) 
220       myDirLn[i] = -1.0*myDirLn[i];//enk:: correction of bug Bug PAL10401
221   }
222
223   GetBoundProject(myBoundPrjLn, 
224                   aBaseBounds, 
225                   myDirLn);
226
227   VISU::Mul(myDirLn,
228             myBoundPrjLn[0],
229             myBasePnt);
230   
231   CorrectPnt(myBasePnt,
232              aBaseBounds);
233
234   VISU_ScalarMapPL::Update();
235 }
236
237
238 //----------------------------------------------------------------------------
239 void
240 VISU_CutLinesPL
241 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
242                 vtkDataSet* theDataSet,
243                 int theNbPlanes, 
244                 vtkFloatingPointType theDir[3], 
245                 vtkFloatingPointType theBounds[6],
246                 vtkFloatingPointType thePartPosition, 
247                 int thePartCondition,
248                 vtkFloatingPointType theDisplacement)
249 {
250   std::vector<vtkFloatingPointType> aPartPosition(1,thePartPosition);
251   std::vector<int> aPartCondition(1,thePartCondition);
252   VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,
253                                   theDataSet,
254                                   theNbPlanes,
255                                   theDir,
256                                   theBounds,
257                                   aPartPosition,
258                                   aPartCondition,
259                                   theDisplacement);
260 }
261
262
263 //----------------------------------------------------------------------------