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