1 // VISU OBJECT : interactive object for VISU entities implementation
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 // File: VISU_PipeLine.cxx
24 // Author: Alexey PETROV
28 #include "VISU_Plot3DPL.hxx"
29 #include "VISU_CutPlanesPL.hxx"
30 #include "VISU_PipeLineUtils.hxx"
32 #include <vtkAppendPolyData.h>
33 #include <vtkCutter.h>
36 #include <vtkCellDataToPointData.h>
37 #include <vtkGeometryFilter.h>
38 #include <vtkContourFilter.h>
39 #include <vtkWarpScalar.h>
40 #include <vtkOutlineFilter.h>
44 vtkStandardNewMacro(VISU_Plot3DPL);
46 VISU_Plot3DPL::VISU_Plot3DPL():
47 myCellDataToPointData(vtkCellDataToPointData::New(),true),
48 myAppendPolyData(vtkAppendPolyData::New(),true),
49 myGeometryFilter(vtkGeometryFilter::New(),true),
50 myContourFilter(vtkContourFilter::New(),true),
51 myWarpScalar(vtkWarpScalar::New(),true),
52 myOrientation(VISU_CutPlanesPL::YZ),
58 myAngle[0] = myAngle[1] = myAngle[2] = 0.;
59 SetNumberOfContours(32);
60 myIsShrinkable = false;
63 VISU_Plot3DPL::~VISU_Plot3DPL()
69 ShallowCopy(VISU_PipeLine *thePipeLine)
71 if(VISU_Plot3DPL *aPipeLine = dynamic_cast<VISU_Plot3DPL*>(thePipeLine)){
72 SetOrientation (aPipeLine->GetPlaneOrientation(),
73 aPipeLine->GetRotateX(), aPipeLine->GetRotateY());
74 SetPlanePosition (aPipeLine->GetPlanePosition(),
75 aPipeLine->IsPositionRelative() );
76 SetScaleFactor( aPipeLine->GetScaleFactor() );
77 SetContourPrs( aPipeLine->GetIsContourPrs() );
78 SetNumberOfContours( aPipeLine->GetNumberOfContours() );
80 VISU_ScalarMapPL::ShallowCopy(thePipeLine);
83 VISU_CutPlanesPL::PlaneOrientation
85 GetOrientation(vtkDataSet* theDataSet)
90 theDataSet->GetBounds(aBounds);
91 float aDelta[3] = {aBounds[1] - aBounds[0], aBounds[3] - aBounds[2], aBounds[5] - aBounds[4]};
93 if(aDelta[0] >= aDelta[1] && aDelta[0] >= aDelta[2])
94 if(aDelta[1] >= aDelta[2])
95 return VISU_CutPlanesPL::XY;
97 return VISU_CutPlanesPL::ZX;
99 if(aDelta[1] >= aDelta[0] && aDelta[1] >= aDelta[2])
100 if(aDelta[0] >= aDelta[2])
101 return VISU_CutPlanesPL::XY;
103 return VISU_CutPlanesPL::YZ;
105 if(aDelta[2] >= aDelta[0] && aDelta[2] >= aDelta[1])
106 if(aDelta[0] >= aDelta[1])
107 return VISU_CutPlanesPL::ZX;
109 return VISU_CutPlanesPL::YZ;
111 return VISU_CutPlanesPL::XY;
116 GetScaleFactor(vtkDataSet* theDataSet)
118 theDataSet->Update();
119 float aLength = theDataSet->GetLength(); // diagonal length
121 float aScalarRange[2];
122 GetSourceRange(aScalarRange);
124 static float EPS = 0.3;
125 float aRange = aScalarRange[1];
127 return aLength / aRange * EPS;
136 VISU_ScalarMapPL::Init();
138 myOrientation = GetOrientation(GetInput2());
139 SetScaleFactor(GetScaleFactor(GetInput2()));
142 VISU_ScalarMapPL::THook*
146 return myAppendPolyData->GetOutput();
153 float aPlaneNormal[3];
155 GetBasePlane( anOrigin, aPlaneNormal );
157 vtkPolyData* aPolyData = 0;
158 vtkCutter *aCutPlane = 0;
159 vtkUnstructuredGrid* anUnstructuredGrid =
160 myFieldTransform->GetUnstructuredGridOutput();
162 if ( !IsPlanarInput() )
164 aCutPlane = vtkCutter::New();
165 aCutPlane->SetInput(anUnstructuredGrid);
167 vtkPlane *aPlane = vtkPlane::New();
168 aPlane->SetOrigin(anOrigin);
169 aPlane->SetNormal(aPlaneNormal);
171 aCutPlane->SetCutFunction(aPlane);
174 aPolyData = aCutPlane->GetOutput();
178 if ( !aPolyData || aPolyData->GetNumberOfCells() == 0 ) {
179 myGeometryFilter->SetInput(anUnstructuredGrid);
180 aPolyData = myGeometryFilter->GetOutput();
183 if ( !myIsContour ) // surface prs
185 if(aPolyData->GetCellData()->GetNumberOfArrays()) {
186 myCellDataToPointData->SetInput(aPolyData);
187 myCellDataToPointData->PassCellDataOn();
188 myWarpScalar->SetInput(myCellDataToPointData->GetPolyDataOutput());
190 myWarpScalar->SetInput(aPolyData);
194 if(aPolyData->GetCellData()->GetNumberOfArrays()) {
195 myCellDataToPointData->SetInput(aPolyData);
196 myCellDataToPointData->PassCellDataOn();
197 myContourFilter->SetInput(myCellDataToPointData->GetOutput());
199 myContourFilter->SetInput(aPolyData);
201 float aScalarRange[2];
202 GetSourceRange(aScalarRange);
204 myContourFilter->GenerateValues(GetNumberOfContours(),aScalarRange);
205 myWarpScalar->SetInput(myContourFilter->GetOutput());
208 VISU_CutPlanesPL::ClearAppendPolyData(myAppendPolyData);
209 myAppendPolyData->AddInput(myWarpScalar->GetPolyDataOutput());
214 myWarpScalar->SetNormal(aPlaneNormal);
216 VISU_ScalarMapPL::Update();
221 SetNumberOfContours(int theNumber)
223 myContourFilter->SetNumberOfContours(theNumber);
228 GetNumberOfContours() const
230 return myContourFilter->GetNumberOfContours();
235 SetScaleFactor(float theScaleFactor)
237 myScaleFactor = theScaleFactor;
238 myWarpScalar->SetScaleFactor(theScaleFactor);
243 GetScaleFactor() const
245 return myScaleFactor;
250 SetPlanePosition(float thePosition,
253 myIsRelative = theIsRelative;
254 myPosition = thePosition;
259 IsPositionRelative() const
264 VISU_CutPlanesPL::PlaneOrientation
266 GetPlaneOrientation() const
268 return myOrientation;
276 switch(myOrientation){
277 case VISU_CutPlanesPL::XY: return myAngle[0];
278 case VISU_CutPlanesPL::YZ: return myAngle[1];
279 case VISU_CutPlanesPL::ZX: return myAngle[2];
287 switch(myOrientation){
288 case VISU_CutPlanesPL::XY: return myAngle[1];
289 case VISU_CutPlanesPL::YZ: return myAngle[2];
290 case VISU_CutPlanesPL::ZX: return myAngle[0];
297 SetOrientation(VISU_CutPlanesPL::PlaneOrientation theOrientation,
301 switch(theOrientation){
302 case VISU_CutPlanesPL::XY: myAngle[0] = theXAngle; break;
303 case VISU_CutPlanesPL::YZ: myAngle[1] = theXAngle; break;
304 case VISU_CutPlanesPL::ZX: myAngle[2] = theXAngle; break;
306 switch(theOrientation){
307 case VISU_CutPlanesPL::XY: myAngle[1] = theYAngle; break;
308 case VISU_CutPlanesPL::YZ: myAngle[2] = theYAngle; break;
309 case VISU_CutPlanesPL::ZX: myAngle[0] = theYAngle; break;
311 myOrientation = theOrientation;
316 GetPlanePosition() const
321 //=======================================================================
322 //function : GetBasePlane
324 //=======================================================================
326 void VISU_Plot3DPL::GetBasePlane(float theOrigin[3],
328 bool theCenterOrigine ) const
330 VISU_CutPlanesPL::GetDir(theNormal,myAngle,myOrientation);
332 float aPosition = myPosition;
333 float aBounds[6], aBoundPrj[3];
336 GetInput()->GetBounds(aBounds);
337 VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,theNormal);
338 aPosition = aBoundPrj[0] + aBoundPrj[2]*myPosition;
340 VISU::Mul(theNormal,aPosition,theOrigin);
342 if ( theCenterOrigine ) {
343 // move theOrigin to the center of aBounds projections to the plane
344 GetInput2()->GetBounds(aBounds);
345 float boundPoints[8][3] = {
346 {aBounds[0],aBounds[2],aBounds[4]},
347 {aBounds[1],aBounds[2],aBounds[4]},
348 {aBounds[0],aBounds[3],aBounds[4]},
349 {aBounds[1],aBounds[3],aBounds[4]},
350 {aBounds[0],aBounds[2],aBounds[5]},
351 {aBounds[1],aBounds[2],aBounds[5]},
352 {aBounds[0],aBounds[3],aBounds[5]},
353 {aBounds[1],aBounds[3],aBounds[5]}};
354 float newOrigin[3] = { 0,0,0 };
355 for(int i = 0; i < 8; i++) {
357 vtkPlane::ProjectPoint( boundPoints[i], theOrigin, theNormal, proj );
358 newOrigin[0] += proj[0];
359 newOrigin[1] += proj[1];
360 newOrigin[2] += proj[2];
362 theOrigin[0] = newOrigin[0] / 8.;
363 theOrigin[1] = newOrigin[1] / 8.;
364 theOrigin[2] = newOrigin[2] / 8.;
368 //=======================================================================
369 //function : GetMinMaxPosition
370 //purpose : return absolute position range
371 //=======================================================================
373 void VISU_Plot3DPL::GetMinMaxPosition( float& minPos, float& maxPos ) const
375 float aBounds[6], aBoundPrj[3], aNormal[3];
376 VISU_CutPlanesPL::GetDir(aNormal,myAngle,myOrientation);
377 GetInput()->GetBounds(aBounds);
378 VISU_CutPlanesPL::GetBoundProject(aBoundPrj,aBounds,aNormal);
379 minPos = aBoundPrj[0];
380 maxPos = aBoundPrj[1];
383 //=======================================================================
384 //function : SetMapScale
386 //=======================================================================
388 void VISU_Plot3DPL::SetMapScale(float theMapScale)
390 VISU_ScalarMapPL::SetMapScale(theMapScale);
394 GetSourceRange(aRange);
395 float aNewRange[] = { aRange[1] - theMapScale*(aRange[1]-aRange[0]), aRange[1] };
396 myContourFilter->GenerateValues(GetNumberOfContours(),aNewRange);
398 myWarpScalar->SetScaleFactor(myScaleFactor*theMapScale);