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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: VISU_PipeLine.hxx
24 // Author: Alexey PETROV
27 #include "VISU_PipeLineUtils.hxx"
29 #include "VISU_OpenGLPointSpriteMapper.hxx"
31 #include <vtkDataSetMapper.h>
32 #include <vtkPolyDataMapper.h>
36 //----------------------------------------------------------------------------
38 Mul(const vtkFloatingPointType A[3],
39 vtkFloatingPointType b,
40 vtkFloatingPointType C[3])
42 for(int i = 0; i < 3; i++)
47 //----------------------------------------------------------------------------
49 Sub(const vtkFloatingPointType A[3],
50 const vtkFloatingPointType B[3],
51 vtkFloatingPointType C[3])
53 for(int i = 0; i < 3; i++)
58 //----------------------------------------------------------------------------
60 CheckIsSameValue(vtkFloatingPointType theTarget,
61 vtkFloatingPointType theSource)
63 static vtkFloatingPointType TOL = 10.0 / VTK_LARGE_FLOAT;
64 if(fabs(theTarget - theSource) < TOL)
70 //----------------------------------------------------------------------------
72 CheckIsSameRange(vtkFloatingPointType* theTarget,
73 vtkFloatingPointType* theSource)
75 return CheckIsSameValue(theTarget[0], theSource[0]) &&
76 CheckIsSameValue(theTarget[1], theSource[1]);
80 //----------------------------------------------------------------------------
82 CopyMapper(vtkMapper* theTarget,
86 // To customize vtkMapper::ShallowCopy ...
87 theTarget->SetLookupTable(theSource->GetLookupTable());
88 theTarget->SetScalarVisibility(theSource->GetScalarVisibility());
90 vtkFloatingPointType* aScalarRange = theSource->GetScalarRange();
91 if(!CheckIsSameRange(theTarget->GetScalarRange(), aScalarRange))
92 theTarget->SetScalarRange(aScalarRange);
94 theTarget->SetColorMode(theSource->GetColorMode());
95 theTarget->SetScalarMode(theSource->GetScalarMode());
96 theTarget->SetImmediateModeRendering(theSource->GetImmediateModeRendering());
97 theTarget->SetUseLookupTableScalarRange(theSource->GetUseLookupTableScalarRange());
98 if(theSource->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID)
99 theTarget->ColorByArrayComponent(theSource->GetArrayId(), theSource->GetArrayComponent());
101 theTarget->ColorByArrayComponent(theSource->GetArrayName(), theSource->GetArrayComponent());
103 // To customize vtkAbstractMapper3D::ShallowCopy ...
104 theTarget->SetClippingPlanes(theSource->GetClippingPlanes());
108 //----------------------------------------------------------------------------
110 CopyDataSetMapper(vtkDataSetMapper* theTarget,
111 vtkDataSetMapper* theSource,
114 // To customize vtkDataSetMapper::ShallowCopy ...
115 //theTarget->SetInput(theSource->GetInput());
116 CopyMapper(theTarget, theSource, theIsCopyInput);
120 //----------------------------------------------------------------------------
122 CopyPolyDataMapper(vtkPolyDataMapper* theTarget,
123 vtkPolyDataMapper* theSource,
126 // To customize vtkPolyDataMapper::ShallowCopy ...
127 //theTarget->SetInput(theSource->GetInput());
128 theTarget->SetGhostLevel(theSource->GetGhostLevel());
129 theTarget->SetNumberOfPieces(theSource->GetNumberOfPieces());
130 theTarget->SetNumberOfSubPieces(theSource->GetNumberOfSubPieces());
132 CopyMapper(theTarget, theSource, theIsCopyInput);
136 //----------------------------------------------------------------------------
138 CopyPointSpriteDataMapper(VISU_OpenGLPointSpriteMapper* theTarget,
139 VISU_OpenGLPointSpriteMapper* theSource,
142 // To customize VISU_OpenGLPointSpriteMapper::ShallowCopy ...
143 theTarget->SetPrimitiveType( theSource->GetPrimitiveType() );
145 theTarget->SetPointSpriteMode( theSource->GetPointSpriteMode() );
147 theTarget->SetPointSpriteClamp( theSource->GetPointSpriteClamp() );
148 theTarget->SetPointSpriteSize( theSource->GetPointSpriteSize() );
149 theTarget->SetPointSpriteMinSize( theSource->GetPointSpriteMinSize() );
150 theTarget->SetPointSpriteMaxSize( theSource->GetPointSpriteMaxSize() );
151 theTarget->SetPointSpriteMagnification( theSource->GetPointSpriteMagnification() );
153 theTarget->SetImageData( theSource->GetImageData() );
154 theTarget->SetPointSpriteAlphaThreshold( theSource->GetPointSpriteAlphaThreshold() );
156 CopyPolyDataMapper(theTarget, theSource, theIsCopyInput);
160 //----------------------------------------------------------------------------
162 ComputeBoundsParam(vtkDataSet* theDataSet,
163 vtkFloatingPointType theDirection[3],
164 vtkFloatingPointType theMinPnt[3],
165 vtkFloatingPointType& theMaxBoundPrj,
166 vtkFloatingPointType& theMinBoundPrj)
168 vtkFloatingPointType aBounds[6];
169 theDataSet->GetBounds(aBounds);
171 //Enlarge bounds in order to avoid conflicts of precision
172 for(int i = 0; i < 6; i += 2){
173 static double EPS = 1.0E-3;
174 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
175 aBounds[i] -= aDelta;
176 aBounds[i+1] += aDelta;
179 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
180 {aBounds[1],aBounds[2],aBounds[4]},
181 {aBounds[0],aBounds[3],aBounds[4]},
182 {aBounds[1],aBounds[3],aBounds[4]},
183 {aBounds[0],aBounds[2],aBounds[5]},
184 {aBounds[1],aBounds[2],aBounds[5]},
185 {aBounds[0],aBounds[3],aBounds[5]},
186 {aBounds[1],aBounds[3],aBounds[5]}};
188 int aMaxId = 0, aMinId = aMaxId;
189 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
190 theMinBoundPrj = theMaxBoundPrj;
191 for(int i = 1; i < 8; i++){
192 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
193 if(theMaxBoundPrj < aTmp){
194 theMaxBoundPrj = aTmp;
197 if(theMinBoundPrj > aTmp){
198 theMinBoundPrj = aTmp;
202 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
203 theMinPnt[0] = aMinPnt[0];
204 theMinPnt[1] = aMinPnt[1];
205 theMinPnt[2] = aMinPnt[2];
209 //----------------------------------------------------------------------------
211 DistanceToPosition(vtkDataSet* theDataSet,
212 vtkFloatingPointType theDirection[3],
213 vtkFloatingPointType theDist,
214 vtkFloatingPointType thePos[3])
216 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
217 ComputeBoundsParam(theDataSet,
222 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
223 thePos[0] = aMinPnt[0] - theDirection[0] * aLength;
224 thePos[1] = aMinPnt[1] - theDirection[1] * aLength;
225 thePos[2] = aMinPnt[2] - theDirection[2] * aLength;
229 //----------------------------------------------------------------------------
231 PositionToDistance(vtkDataSet* theDataSet,
232 vtkFloatingPointType theDirection[3],
233 vtkFloatingPointType thePos[3],
234 vtkFloatingPointType& theDist)
236 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
237 ComputeBoundsParam(theDataSet,
242 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
243 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
247 //----------------------------------------------------------------------------