1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: VISU_CutSegmentPL.hxx
23 // Author: Oleg UVAROV
26 #include "VISU_CutSegmentPL.hxx"
27 #include "VISU_PipeLineUtils.hxx"
29 #include <vtkAppendPolyData.h>
31 //----------------------------------------------------------------------------
32 vtkStandardNewMacro(VISU_CutSegmentPL);
35 //----------------------------------------------------------------------------
41 //----------------------------------------------------------------------------
44 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
47 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
49 if(VISU_CutSegmentPL *aPipeLine = dynamic_cast<VISU_CutSegmentPL*>(thePipeLine)){
50 vtkFloatingPointType x, y, z;
51 aPipeLine->GetPoint1(x, y, z);
53 aPipeLine->GetPoint2(x, y, z);
58 //----------------------------------------------------------------------------
65 vtkFloatingPointType aBounds[6];
66 GetMergedInput()->GetBounds(aBounds);
68 for( int i = 0; i < 3; i++ ) {
69 vtkFloatingPointType min = aBounds[ 2*i ];
70 vtkFloatingPointType max = aBounds[ 2*i+1 ];
71 myPoint1[ i ] = i == 1 ? min : ( min + max ) / 2;
72 myPoint2[ i ] = i == 1 ? max : ( min + max ) / 2;
76 //----------------------------------------------------------------------------
79 ::SetPoint1(vtkFloatingPointType theX,
80 vtkFloatingPointType theY,
81 vtkFloatingPointType theZ )
88 //----------------------------------------------------------------------------
91 ::GetPoint1(vtkFloatingPointType& theX,
92 vtkFloatingPointType& theY,
93 vtkFloatingPointType& theZ )
100 //----------------------------------------------------------------------------
103 ::SetPoint2(vtkFloatingPointType theX,
104 vtkFloatingPointType theY,
105 vtkFloatingPointType theZ )
112 //----------------------------------------------------------------------------
115 ::GetPoint2(vtkFloatingPointType& theX,
116 vtkFloatingPointType& theY,
117 vtkFloatingPointType& theZ )
124 //----------------------------------------------------------------------------
129 return myAppendPolyData->GetOutput();
132 //----------------------------------------------------------------------------
137 vtkDataSet* aMergedInput = GetMergedInput();
138 if(VISU::IsQuadraticData(aMergedInput)) // Bug 0020123, note 0005343
139 throw std::runtime_error("Impossible to build presentation");
141 vtkFloatingPointType aVector12[3], aVector21[3];
142 VISU::Sub( myPoint2, myPoint1, aVector12 );
143 VISU::Sub( myPoint1, myPoint2, aVector21 );
145 double aPrecision = 1.0 / VTK_LARGE_FLOAT;
146 double aNorm = vtkMath::Normalize( aVector12 );
147 if( aNorm < aPrecision )
150 // compute two vectors which are orthogonal to the line between the input points
151 // these vectors could be used as normals of two planes, intersected exactly at this line
152 // origin of these planes should be places at one of the input points
153 vtkFloatingPointType aVector1[3], aVector2[3];
154 vtkMath::Perpendiculars( aVector12, aVector1, aVector2, 0 );
156 ClearAppendPolyData(myAppendPolyData);
160 vtkFloatingPointType aBounds[6];
161 GetMergedInput()->GetBounds(aBounds);
163 // check if the input is planar - in this case one cut plane will be enough
164 // (besides, the second cut corrupts the resulting output, splitting it to points)
165 bool isPlanar = true;
166 vtkFloatingPointType aNormal[3] = { 0.0, 0.0, 0.0 };
167 if( fabs( aBounds[0] - aBounds[1] ) < aPrecision )
169 else if( fabs( aBounds[2] - aBounds[3] ) < aPrecision )
171 else if( fabs( aBounds[4] - aBounds[5] ) < aPrecision )
177 // choose a vector which is not collinear with normal of the plane
178 vtkFloatingPointType aCross[3];
179 vtkMath::Cross( aVector1, aNormal, aCross );
180 bool isFirst = vtkMath::Norm( aCross ) > aPrecision;
181 VISU_CutPlanesPL::CutWithPlane(myAppendPolyData, GetMergedInput(), isFirst ? aVector1 : aVector2, myPoint1);
182 myAppendPolyData->Update();
185 vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
187 VISU_CutPlanesPL::CutWithPlane(anAppendPolyData, GetMergedInput(), aVector1, myPoint1);
188 vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
191 VISU_CutPlanesPL::CutWithPlane(myAppendPolyData, aDataSet, aVector2, myPoint1);
192 myAppendPolyData->Update();
194 anAppendPolyData->Delete();
197 // calculate values for building of table
198 for (int i = 0; i<3 ; i++) {
199 myRealDirLn[i] = myDirLn[i] = aVector12[i];
201 myDirLn[i] = -1.0*myDirLn[i]; //enk:: correction of bug Bug PAL10401
204 GetBoundProject(myBoundPrjLn,
212 CorrectPnt(myBasePnt,
215 VISU_ScalarMapPL::Update();