1 // Copyright (C) 2007-2010 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
23 // VISU OBJECT : interactive object for VISU entities implementation
24 // File: VISU_PipeLine.hxx
25 // Author: Alexey PETROV
28 #include "VISU_PipeLineUtils.hxx"
30 #include "VISU_OpenGLPointSpriteMapper.hxx"
33 #include <vtkDataSetMapper.h>
34 #include <vtkPolyDataMapper.h>
38 //----------------------------------------------------------------------------
40 Mul(const vtkFloatingPointType A[3],
41 vtkFloatingPointType b,
42 vtkFloatingPointType C[3])
44 for(int i = 0; i < 3; i++)
49 //----------------------------------------------------------------------------
51 Sub(const vtkFloatingPointType A[3],
52 const vtkFloatingPointType B[3],
53 vtkFloatingPointType C[3])
55 for(int i = 0; i < 3; i++)
60 //----------------------------------------------------------------------------
62 CheckIsSameValue(vtkFloatingPointType theTarget,
63 vtkFloatingPointType theSource)
65 static vtkFloatingPointType TOL = 10.0 / VTK_LARGE_FLOAT;
66 if(fabs(theTarget - theSource) < TOL)
72 //----------------------------------------------------------------------------
74 CheckIsSameRange(vtkFloatingPointType* theTarget,
75 vtkFloatingPointType* theSource)
77 return CheckIsSameValue(theTarget[0], theSource[0]) &&
78 CheckIsSameValue(theTarget[1], theSource[1]);
82 //----------------------------------------------------------------------------
84 CopyMapper(vtkMapper* theTarget,
88 // To customize vtkMapper::ShallowCopy ...
89 theTarget->SetLookupTable(theSource->GetLookupTable());
90 theTarget->SetScalarVisibility(theSource->GetScalarVisibility());
92 vtkFloatingPointType* aScalarRange = theSource->GetScalarRange();
93 if(!CheckIsSameRange(theTarget->GetScalarRange(), aScalarRange))
94 theTarget->SetScalarRange(aScalarRange);
96 theTarget->SetColorMode(theSource->GetColorMode());
97 theTarget->SetScalarMode(theSource->GetScalarMode());
98 theTarget->SetImmediateModeRendering(theSource->GetImmediateModeRendering());
99 theTarget->SetUseLookupTableScalarRange(theSource->GetUseLookupTableScalarRange());
100 theTarget->SetInterpolateScalarsBeforeMapping(theSource->GetInterpolateScalarsBeforeMapping());
101 if(theSource->GetArrayAccessMode() == VTK_GET_ARRAY_BY_ID)
102 theTarget->ColorByArrayComponent(theSource->GetArrayId(), theSource->GetArrayComponent());
104 theTarget->ColorByArrayComponent(theSource->GetArrayName(), theSource->GetArrayComponent());
106 // To customize vtkAbstractMapper3D::ShallowCopy ...
107 theTarget->SetClippingPlanes(theSource->GetClippingPlanes());
111 //----------------------------------------------------------------------------
113 CopyDataSetMapper(vtkDataSetMapper* theTarget,
114 vtkDataSetMapper* theSource,
117 // To customize vtkDataSetMapper::ShallowCopy ...
118 //theTarget->SetInput(theSource->GetInput());
119 CopyMapper(theTarget, theSource, theIsCopyInput);
123 //----------------------------------------------------------------------------
125 CopyPolyDataMapper(vtkPolyDataMapper* theTarget,
126 vtkPolyDataMapper* theSource,
129 // To customize vtkPolyDataMapper::ShallowCopy ...
130 //theTarget->SetInput(theSource->GetInput());
131 theTarget->SetGhostLevel(theSource->GetGhostLevel());
132 theTarget->SetNumberOfPieces(theSource->GetNumberOfPieces());
133 theTarget->SetNumberOfSubPieces(theSource->GetNumberOfSubPieces());
135 CopyMapper(theTarget, theSource, theIsCopyInput);
139 //----------------------------------------------------------------------------
141 CopyPointSpriteDataMapper(VISU_OpenGLPointSpriteMapper* theTarget,
142 VISU_OpenGLPointSpriteMapper* theSource,
145 // To customize VISU_OpenGLPointSpriteMapper::ShallowCopy ...
146 theTarget->SetPrimitiveType( theSource->GetPrimitiveType() );
148 theTarget->SetPointSpriteMode( theSource->GetPointSpriteMode() );
150 theTarget->SetPointSpriteClamp( theSource->GetPointSpriteClamp() );
151 theTarget->SetPointSpriteSize( theSource->GetPointSpriteSize() );
152 theTarget->SetPointSpriteMinSize( theSource->GetPointSpriteMinSize() );
153 theTarget->SetPointSpriteMaxSize( theSource->GetPointSpriteMaxSize() );
154 theTarget->SetPointSpriteMagnification( theSource->GetPointSpriteMagnification() );
156 theTarget->SetImageData( theSource->GetImageData() );
157 theTarget->SetPointSpriteAlphaThreshold( theSource->GetPointSpriteAlphaThreshold() );
159 CopyPolyDataMapper(theTarget, theSource, theIsCopyInput);
163 //----------------------------------------------------------------------------
165 ComputeBoundsParam(vtkDataSet* theDataSet,
166 vtkFloatingPointType theDirection[3],
167 vtkFloatingPointType theMinPnt[3],
168 vtkFloatingPointType& theMaxBoundPrj,
169 vtkFloatingPointType& theMinBoundPrj)
171 vtkFloatingPointType aBounds[6];
172 theDataSet->GetBounds(aBounds);
174 //Enlarge bounds in order to avoid conflicts of precision
175 for(int i = 0; i < 6; i += 2){
176 static double EPS = 1.0E-3;
177 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
178 aBounds[i] -= aDelta;
179 aBounds[i+1] += aDelta;
182 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
183 {aBounds[1],aBounds[2],aBounds[4]},
184 {aBounds[0],aBounds[3],aBounds[4]},
185 {aBounds[1],aBounds[3],aBounds[4]},
186 {aBounds[0],aBounds[2],aBounds[5]},
187 {aBounds[1],aBounds[2],aBounds[5]},
188 {aBounds[0],aBounds[3],aBounds[5]},
189 {aBounds[1],aBounds[3],aBounds[5]}};
191 int aMaxId = 0, aMinId = aMaxId;
192 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
193 theMinBoundPrj = theMaxBoundPrj;
194 for(int i = 1; i < 8; i++){
195 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
196 if(theMaxBoundPrj < aTmp){
197 theMaxBoundPrj = aTmp;
200 if(theMinBoundPrj > aTmp){
201 theMinBoundPrj = aTmp;
205 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
206 theMinPnt[0] = aMinPnt[0];
207 theMinPnt[1] = aMinPnt[1];
208 theMinPnt[2] = aMinPnt[2];
212 //----------------------------------------------------------------------------
214 DistanceToPosition(vtkDataSet* theDataSet,
215 vtkFloatingPointType theDirection[3],
216 vtkFloatingPointType theDist,
217 vtkFloatingPointType thePos[3])
219 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
220 ComputeBoundsParam(theDataSet,
225 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
226 thePos[0] = aMinPnt[0] - theDirection[0] * aLength;
227 thePos[1] = aMinPnt[1] - theDirection[1] * aLength;
228 thePos[2] = aMinPnt[2] - theDirection[2] * aLength;
232 //----------------------------------------------------------------------------
234 PositionToDistance(vtkDataSet* theDataSet,
235 vtkFloatingPointType theDirection[3],
236 vtkFloatingPointType thePos[3],
237 vtkFloatingPointType& theDist)
239 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
240 ComputeBoundsParam(theDataSet,
245 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
246 theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
250 //----------------------------------------------------------------------------
252 IsQuadraticData(vtkDataSet* theDataSet)
254 for(int i = 0, n = theDataSet->GetNumberOfCells(); i < n; i++)
255 if(vtkCell* aCell = theDataSet->GetCell(i))
256 if(!aCell->IsLinear())
262 //----------------------------------------------------------------------------