]> SALOME platform Git repositories - modules/visu.git/blob - src/PIPELINE/VISU_CutLinesPL.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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_PipeLineUtils.hxx"
29 #include "VTKViewer_GeometryFilter.h"
30
31 #include <vtkAppendPolyData.h>
32
33 using namespace std;
34
35 vtkStandardNewMacro(VISU_CutLinesPL);
36
37 VISU_CutLinesPL
38 ::VISU_CutLinesPL()
39 {
40   myCondition = 1;
41   myPosition = 0;
42 }
43
44 void
45 VISU_CutLinesPL
46 ::ShallowCopy(VISU_PipeLine *thePipeLine)
47 {
48   if(VISU_CutLinesPL *aPipeLine = dynamic_cast<VISU_CutLinesPL*>(thePipeLine)){
49     SetOrientation(aPipeLine->GetPlaneOrientation(1),
50                    aPipeLine->GetRotateX(1),aPipeLine->GetRotateY(1),1);
51     SetDisplacement(aPipeLine->GetDisplacement(1),1);
52     SetDefault();
53     if (!aPipeLine->IsDefault()) SetPosition(aPipeLine->GetPosition());
54   }
55   VISU_CutPlanesPL::ShallowCopy(thePipeLine);
56 }
57
58 void
59 VISU_CutLinesPL
60 ::Init()
61 {
62   VISU_CutPlanesPL::Init();
63
64   myBasePlane[0] = XY;
65   myBasePlane[1] = YZ;
66   myDisplacement[0] = myDisplacement[1] = 0.5;
67   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
68   myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0;
69
70   myCondition = 1;
71   myPosition = 0;
72 }
73
74
75 void
76 VISU_CutLinesPL
77 ::SetPosition(vtkFloatingPointType thePosition)
78 {
79   myPosition = thePosition;
80   myCondition = 0;
81   Modified();
82 }
83 vtkFloatingPointType 
84 VISU_CutLinesPL
85 ::GetPosition()
86 {
87   vtkFloatingPointType aPosition = myPosition;
88   if(myCondition){
89       vtkFloatingPointType aDir[3], aBounds[6], aBoundPrj[3];
90       GetInput2()->GetBounds(aBounds);
91       GetDir(aDir,myAng[0],myBasePlane[0]);
92       GetBoundProject(aBoundPrj,aBounds,aDir);
93       aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[0];
94   }
95   return aPosition;
96 }
97
98 void
99 VISU_CutLinesPL
100 ::SetDefault()
101 {
102   myCondition = 1;
103   Modified();
104 }
105 int
106 VISU_CutLinesPL
107 ::IsDefault()
108 {
109   return myCondition;
110 }
111
112
113 void
114 VISU_CutLinesPL
115 ::Update()
116 {
117   ClearAppendPolyData(myAppendPolyData);
118   SetPartPosition(1);
119   vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
120   //Build base plane
121   vtkFloatingPointType aDir[2][3], aBaseBounds[6];
122   GetInput2()->GetBounds(aBaseBounds);
123   GetDir(aDir[0],myAng[0],myBasePlane[0]);
124   vtkUnstructuredGrid* anUnstructuredGrid =
125     myFieldTransform->GetUnstructuredGridOutput();
126   CutWithPlanes(anAppendPolyData,anUnstructuredGrid,1,aDir[0],aBaseBounds,
127                 myPosition,myCondition,myDisplacement[0]);
128   //Build lines
129   vtkFloatingPointType aBounds[6];
130   vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
131   aDataSet->Update();
132   if(aDataSet->GetNumberOfCells() == 0)
133     aDataSet = anUnstructuredGrid;
134   aDataSet->GetBounds(aBounds);
135   GetDir(aDir[1],myAng[1],myBasePlane[1]);
136   VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,aDataSet,GetNbParts(),aDir[1],aBounds,
137                                   myPartPosition,myPartCondition,myDisplacement[1]);
138   anAppendPolyData->Register(myAppendPolyData);
139   anAppendPolyData->Delete();
140   //Calculate values for building of table
141   vtkMath::Cross(aDir[0],aDir[1],myDirLn);
142   for (int i=0; i<3 ; i++) {
143     myRealDirLn[i] = myDirLn[i];
144     if(myDirLn[i]<0) myDirLn[i] = (-1)*myDirLn[i];//enk:: correction of bug Bug PAL10401
145   }
146   GetBoundProject(myBoundPrjLn, aBaseBounds, myDirLn);
147   VISU::Mul(myDirLn,myBoundPrjLn[0],myBasePnt);
148   
149   CorrectPnt(myBasePnt,aBaseBounds);
150
151   VISU_ScalarMapPL::Update();
152 }
153
154
155 void
156 VISU_CutLinesPL
157 ::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, 
158                 vtkDataSet* theDataSet,
159                 int theNbPlanes, 
160                 vtkFloatingPointType theDir[3], 
161                 vtkFloatingPointType theBounds[6],
162                 vtkFloatingPointType thePartPosition, 
163                 int thePartCondition,
164                 vtkFloatingPointType theDisplacement)
165 {
166   vector<vtkFloatingPointType> aPartPosition(1,thePartPosition);
167   vector<int> aPartCondition(1,thePartCondition);
168   VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,theDataSet,theNbPlanes,theDir,theBounds,
169                                   aPartPosition,aPartCondition,theDisplacement);
170 }