1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: VISU_CutSegmentPL.hxx
21 // Author: Oleg UVAROV
24 #include "VISU_CutSegmentPL.hxx"
25 #include "VISU_PipeLineUtils.hxx"
27 #include <vtkAppendPolyData.h>
29 //----------------------------------------------------------------------------
30 vtkStandardNewMacro(VISU_CutSegmentPL);
33 //----------------------------------------------------------------------------
39 //----------------------------------------------------------------------------
42 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
45 Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
47 if(VISU_CutSegmentPL *aPipeLine = dynamic_cast<VISU_CutSegmentPL*>(thePipeLine)){
48 vtkFloatingPointType x, y, z;
49 aPipeLine->GetPoint1(x, y, z);
51 aPipeLine->GetPoint2(x, y, z);
56 //----------------------------------------------------------------------------
63 vtkFloatingPointType aBounds[6];
64 GetMergedInput()->GetBounds(aBounds);
66 for( int i = 0; i < 3; i++ ) {
67 vtkFloatingPointType min = aBounds[ 2*i ];
68 vtkFloatingPointType max = aBounds[ 2*i+1 ];
69 myPoint1[ i ] = i == 1 ? min : ( min + max ) / 2;
70 myPoint2[ i ] = i == 1 ? max : ( min + max ) / 2;
74 //----------------------------------------------------------------------------
77 ::SetPoint1(vtkFloatingPointType theX,
78 vtkFloatingPointType theY,
79 vtkFloatingPointType theZ )
86 //----------------------------------------------------------------------------
89 ::GetPoint1(vtkFloatingPointType& theX,
90 vtkFloatingPointType& theY,
91 vtkFloatingPointType& theZ )
98 //----------------------------------------------------------------------------
101 ::SetPoint2(vtkFloatingPointType theX,
102 vtkFloatingPointType theY,
103 vtkFloatingPointType theZ )
110 //----------------------------------------------------------------------------
113 ::GetPoint2(vtkFloatingPointType& theX,
114 vtkFloatingPointType& theY,
115 vtkFloatingPointType& theZ )
122 //----------------------------------------------------------------------------
127 return myAppendPolyData->GetOutput();
130 //----------------------------------------------------------------------------
135 vtkDataSet* aMergedInput = GetMergedInput();
136 if(VISU::IsQuadraticData(aMergedInput)) // Bug 0020123, note 0005343
137 throw std::runtime_error("Impossible to build presentation");
139 vtkFloatingPointType aVector12[3], aVector21[3];
140 VISU::Sub( myPoint2, myPoint1, aVector12 );
141 VISU::Sub( myPoint1, myPoint2, aVector21 );
143 double aPrecision = 1.0 / VTK_LARGE_FLOAT;
144 double aNorm = vtkMath::Normalize( aVector12 );
145 if( aNorm < aPrecision )
148 // compute two vectors which are orthogonal to the line between the input points
149 // these vectors could be used as normals of two planes, intersected exactly at this line
150 // origin of these planes should be places at one of the input points
151 vtkFloatingPointType aVector1[3], aVector2[3];
152 vtkMath::Perpendiculars( aVector12, aVector1, aVector2, 0 );
154 ClearAppendPolyData(myAppendPolyData);
158 vtkFloatingPointType aBounds[6];
159 GetMergedInput()->GetBounds(aBounds);
161 // check if the input is planar - in this case one cut plane will be enough
162 // (besides, the second cut corrupts the resulting output, splitting it to points)
163 bool isPlanar = true;
164 vtkFloatingPointType aNormal[3] = { 0.0, 0.0, 0.0 };
165 if( fabs( aBounds[0] - aBounds[1] ) < aPrecision )
167 else if( fabs( aBounds[2] - aBounds[3] ) < aPrecision )
169 else if( fabs( aBounds[4] - aBounds[5] ) < aPrecision )
175 // choose a vector which is not collinear with normal of the plane
176 vtkFloatingPointType aCross[3];
177 vtkMath::Cross( aVector1, aNormal, aCross );
178 bool isFirst = vtkMath::Norm( aCross ) > aPrecision;
179 VISU_CutPlanesPL::CutWithPlane(myAppendPolyData, GetMergedInput(), isFirst ? aVector1 : aVector2, myPoint1);
180 myAppendPolyData->Update();
183 vtkAppendPolyData *anAppendPolyData = vtkAppendPolyData::New();
185 VISU_CutPlanesPL::CutWithPlane(anAppendPolyData, GetMergedInput(), aVector1, myPoint1);
186 vtkDataSet *aDataSet = anAppendPolyData->GetOutput();
189 VISU_CutPlanesPL::CutWithPlane(myAppendPolyData, aDataSet, aVector2, myPoint1);
190 myAppendPolyData->Update();
192 anAppendPolyData->Delete();
195 // calculate values for building of table
196 for (int i = 0; i<3 ; i++) {
197 myRealDirLn[i] = myDirLn[i] = aVector12[i];
199 myDirLn[i] = -1.0*myDirLn[i]; //enk:: correction of bug Bug PAL10401
202 GetBoundProject(myBoundPrjLn,
210 CorrectPnt(myBasePnt,
213 VISU_ScalarMapPL::Update();