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 // VISU OBJECT : interactive object for VISU entities implementation
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 theTarget->SetInterpolateScalarsBeforeMapping(theSource->GetInterpolateScalarsBeforeMapping());
99 if(theSource->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID)
100 theTarget->ColorByArrayComponent(theSource->GetArrayId(), theSource->GetArrayComponent());
102 theTarget->ColorByArrayComponent(theSource->GetArrayName(), theSource->GetArrayComponent());
104 // To customize vtkAbstractMapper3D::ShallowCopy ...
105 theTarget->SetClippingPlanes(theSource->GetClippingPlanes());
109 //----------------------------------------------------------------------------
111 CopyDataSetMapper(vtkDataSetMapper* theTarget,
112 vtkDataSetMapper* theSource,
115 // To customize vtkDataSetMapper::ShallowCopy ...
116 //theTarget->SetInput(theSource->GetInput());
117 CopyMapper(theTarget, theSource, theIsCopyInput);
121 //----------------------------------------------------------------------------
123 CopyPolyDataMapper(vtkPolyDataMapper* theTarget,
124 vtkPolyDataMapper* theSource,
127 // To customize vtkPolyDataMapper::ShallowCopy ...
128 //theTarget->SetInput(theSource->GetInput());
129 theTarget->SetGhostLevel(theSource->GetGhostLevel());
130 theTarget->SetNumberOfPieces(theSource->GetNumberOfPieces());
131 theTarget->SetNumberOfSubPieces(theSource->GetNumberOfSubPieces());
133 CopyMapper(theTarget, theSource, theIsCopyInput);
137 //----------------------------------------------------------------------------
139 CopyPointSpriteDataMapper(VISU_OpenGLPointSpriteMapper* theTarget,
140 VISU_OpenGLPointSpriteMapper* theSource,
143 // To customize VISU_OpenGLPointSpriteMapper::ShallowCopy ...
144 theTarget->SetPrimitiveType( theSource->GetPrimitiveType() );
146 theTarget->SetPointSpriteMode( theSource->GetPointSpriteMode() );
148 theTarget->SetPointSpriteClamp( theSource->GetPointSpriteClamp() );
149 theTarget->SetPointSpriteSize( theSource->GetPointSpriteSize() );
150 theTarget->SetPointSpriteMinSize( theSource->GetPointSpriteMinSize() );
151 theTarget->SetPointSpriteMaxSize( theSource->GetPointSpriteMaxSize() );
152 theTarget->SetPointSpriteMagnification( theSource->GetPointSpriteMagnification() );
154 theTarget->SetImageData( theSource->GetImageData() );
155 theTarget->SetPointSpriteAlphaThreshold( theSource->GetPointSpriteAlphaThreshold() );
157 CopyPolyDataMapper(theTarget, theSource, theIsCopyInput);
161 //----------------------------------------------------------------------------
163 ComputeBoundsParam(vtkDataSet* theDataSet,
164 vtkFloatingPointType theDirection[3],
165 vtkFloatingPointType theMinPnt[3],
166 vtkFloatingPointType& theMaxBoundPrj,
167 vtkFloatingPointType& theMinBoundPrj)
169 vtkFloatingPointType aBounds[6];
170 theDataSet->GetBounds(aBounds);
172 //Enlarge bounds in order to avoid conflicts of precision
173 for(int i = 0; i < 6; i += 2){
174 static double EPS = 1.0E-3;
175 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
176 aBounds[i] -= aDelta;
177 aBounds[i+1] += aDelta;
180 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
181 {aBounds[1],aBounds[2],aBounds[4]},
182 {aBounds[0],aBounds[3],aBounds[4]},
183 {aBounds[1],aBounds[3],aBounds[4]},
184 {aBounds[0],aBounds[2],aBounds[5]},
185 {aBounds[1],aBounds[2],aBounds[5]},
186 {aBounds[0],aBounds[3],aBounds[5]},
187 {aBounds[1],aBounds[3],aBounds[5]}};
189 int aMaxId = 0, aMinId = aMaxId;
190 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
191 theMinBoundPrj = theMaxBoundPrj;
192 for(int i = 1; i < 8; i++){
193 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
194 if(theMaxBoundPrj < aTmp){
195 theMaxBoundPrj = aTmp;
198 if(theMinBoundPrj > aTmp){
199 theMinBoundPrj = aTmp;
203 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
204 theMinPnt[0] = aMinPnt[0];
205 theMinPnt[1] = aMinPnt[1];
206 theMinPnt[2] = aMinPnt[2];
210 //----------------------------------------------------------------------------
212 DistanceToPosition(vtkDataSet* theDataSet,
213 vtkFloatingPointType theDirection[3],
214 vtkFloatingPointType theDist,
215 vtkFloatingPointType thePos[3])
217 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
218 ComputeBoundsParam(theDataSet,
223 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
224 thePos[0] = aMinPnt[0] - theDirection[0] * aLength;
225 thePos[1] = aMinPnt[1] - theDirection[1] * aLength;
226 thePos[2] = aMinPnt[2] - theDirection[2] * aLength;
230 //----------------------------------------------------------------------------
232 PositionToDistance(vtkDataSet* theDataSet,
233 vtkFloatingPointType theDirection[3],
234 vtkFloatingPointType thePos[3],
235 vtkFloatingPointType& theDist)
237 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
238 ComputeBoundsParam(theDataSet,
243 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
244 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
248 //----------------------------------------------------------------------------