Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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::VISU_CutLinesPL(){
38   myCondition = 1;
39   myPosition = 0;
40 }
41
42 void VISU_CutLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){
43   if(VISU_CutLinesPL *aPipeLine = dynamic_cast<VISU_CutLinesPL*>(thePipeLine)){
44     SetOrientation(aPipeLine->GetPlaneOrientation(1),
45                    aPipeLine->GetRotateX(1),aPipeLine->GetRotateY(1),1);
46     SetDisplacement(aPipeLine->GetDisplacement(1),1);
47     SetDefault();
48     if (!aPipeLine->IsDefault()) SetPosition(aPipeLine->GetPosition());
49   }
50   VISU_CutPlanesPL::ShallowCopy(thePipeLine);
51 }
52
53 void VISU_CutLinesPL::Init(){
54   VISU_CutPlanesPL::Init();
55
56   myBasePlane[0] = XY;
57   myBasePlane[1] = YZ;
58   myDisplacement[0] = myDisplacement[1] = 0.5;
59   myAng[0][0] = myAng[0][1] = myAng[0][2] = 0.0;
60   myAng[1][0] = myAng[1][1] = myAng[1][2] = 0.0;
61
62   myCondition = 1;
63   myPosition = 0;
64 }
65
66
67 void VISU_CutLinesPL::SetPosition(float thePosition){
68   myPosition = thePosition;
69   myCondition = 0;
70   Modified();
71 }
72 float VISU_CutLinesPL::GetPosition(){
73   float aPosition = myPosition;
74   if(myCondition){
75       float aDir[3], aBounds[6], aBoundPrj[3];
76       GetInput2()->GetBounds(aBounds);
77       GetDir(aDir,myAng[0],myBasePlane[0]);
78       GetBoundProject(aBoundPrj,aBounds,aDir);
79       aPosition = aBoundPrj[0] + aBoundPrj[2]*myDisplacement[0];
80   }
81   return aPosition;
82 }
83
84 void VISU_CutLinesPL::SetDefault(){
85   myCondition = 1;
86   Modified();
87 }
88 int VISU_CutLinesPL::IsDefault(){
89   return myCondition;
90 }
91
92
93 void VISU_CutLinesPL::Update(){
94   ClearAppendPolyData(myAppendPolyData);
95   SetPartPosition(1);
96   vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
97   //Build base plane
98   float aDir[2][3], aBaseBounds[6];
99   GetInput2()->GetBounds(aBaseBounds);
100   GetDir(aDir[0],myAng[0],myBasePlane[0]);
101   vtkUnstructuredGrid* anUnstructuredGrid =
102     myFieldTransform->GetUnstructuredGridOutput();
103   CutWithPlanes(anAppendPolyData,anUnstructuredGrid,1,aDir[0],aBaseBounds,
104                 myPosition,myCondition,myDisplacement[0]);
105   //Build lines
106   float aBounds[6];
107   vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
108   aDataSet->Update();
109   if(aDataSet->GetNumberOfCells() == 0)
110     aDataSet = anUnstructuredGrid;
111   aDataSet->GetBounds(aBounds);
112   GetDir(aDir[1],myAng[1],myBasePlane[1]);
113   VISU_CutPlanesPL::CutWithPlanes(myAppendPolyData,aDataSet,GetNbParts(),aDir[1],aBounds,
114                                   myPartPosition,myPartCondition,myDisplacement[1]);
115   anAppendPolyData->Register(myAppendPolyData);
116   anAppendPolyData->Delete();
117   //Calculate values for building of table
118   vtkMath::Cross(aDir[0],aDir[1],myDirLn);
119   for (int i=0; i<3 ; i++) if(myDirLn[i]<0) myDirLn[i] = (-1)*myDirLn[i];//enk:: correction of bug Bug PAL10401
120   GetBoundProject(myBoundPrjLn, aBaseBounds, myDirLn);
121   VISU::Mul(myDirLn,myBoundPrjLn[0],myBasePnt);
122   CorrectPnt(myBasePnt,aBaseBounds);
123
124   VISU_ScalarMapPL::Update();
125 }
126
127
128 void VISU_CutLinesPL::CutWithPlanes(vtkAppendPolyData* theAppendPolyData, vtkDataSet* theDataSet,
129                                     int theNbPlanes, float theDir[3], float theBounds[6],
130                                     float thePartPosition, int thePartCondition,
131                                     float theDisplacement)
132 {
133   vector<float> aPartPosition(1,thePartPosition);
134   vector<int> aPartCondition(1,thePartCondition);
135   VISU_CutPlanesPL::CutWithPlanes(theAppendPolyData,theDataSet,theNbPlanes,theDir,theBounds,
136                                   aPartPosition,aPartCondition,theDisplacement);
137 }