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(vtkFloatingPointType theBounds[6],
166 vtkFloatingPointType theDirection[3],
167 vtkFloatingPointType theMinPnt[3],
168 vtkFloatingPointType& theMaxBoundPrj,
169 vtkFloatingPointType& theMinBoundPrj)
171 vtkFloatingPointType aBounds[6];
172 for(int i = 0; i < 6; i++)
173 aBounds[i] = theBounds[i];
175 //Enlarge bounds in order to avoid conflicts of precision
176 for(int i = 0; i < 6; i += 2){
177 static double EPS = 1.0E-3;
178 vtkFloatingPointType aDelta = (aBounds[i+1] - aBounds[i])*EPS;
179 aBounds[i] -= aDelta;
180 aBounds[i+1] += aDelta;
183 vtkFloatingPointType aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]},
184 {aBounds[1],aBounds[2],aBounds[4]},
185 {aBounds[0],aBounds[3],aBounds[4]},
186 {aBounds[1],aBounds[3],aBounds[4]},
187 {aBounds[0],aBounds[2],aBounds[5]},
188 {aBounds[1],aBounds[2],aBounds[5]},
189 {aBounds[0],aBounds[3],aBounds[5]},
190 {aBounds[1],aBounds[3],aBounds[5]}};
192 int aMaxId = 0, aMinId = aMaxId;
193 theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]);
194 theMinBoundPrj = theMaxBoundPrj;
195 for(int i = 1; i < 8; i++){
196 vtkFloatingPointType aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]);
197 if(theMaxBoundPrj < aTmp){
198 theMaxBoundPrj = aTmp;
201 if(theMinBoundPrj > aTmp){
202 theMinBoundPrj = aTmp;
206 vtkFloatingPointType *aMinPnt = aBoundPoints[aMaxId];
207 theMinPnt[0] = aMinPnt[0];
208 theMinPnt[1] = aMinPnt[1];
209 theMinPnt[2] = aMinPnt[2];
213 //----------------------------------------------------------------------------
215 DistanceToPosition(vtkFloatingPointType theBounds[6],
216 vtkFloatingPointType theDirection[3],
217 vtkFloatingPointType theDist,
218 vtkFloatingPointType thePos[3])
220 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
221 ComputeBoundsParam(theBounds,
226 vtkFloatingPointType aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist;
227 thePos[0] = aMinPnt[0] - theDirection[0] * aLength;
228 thePos[1] = aMinPnt[1] - theDirection[1] * aLength;
229 thePos[2] = aMinPnt[2] - theDirection[2] * aLength;
233 //----------------------------------------------------------------------------
235 PositionToDistance(vtkFloatingPointType theBounds[6],
236 vtkFloatingPointType theDirection[3],
237 vtkFloatingPointType thePos[3],
238 vtkFloatingPointType& theDist)
240 vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
241 ComputeBoundsParam(theBounds,
246 vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
247 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())
261 //----------------------------------------------------------------------------
262 //Compute bounds of the visible part of the dataset
264 ComputeVisibleBounds(vtkDataSet* theDataSet, vtkFloatingPointType theBounds[6]) {
265 int nbCells, i, j, minIdx, maxIdx;
266 vtkFloatingPointType cellBounds[6];
268 if( theDataSet && (nbCells = theDataSet->GetNumberOfCells()) ) {
269 theDataSet->GetCellBounds(0,theBounds);
270 for ( i = 1; i < nbCells; i++ ) {
271 theDataSet->GetCellBounds(i, cellBounds);
272 for ( j = 0; j < 3; j++ ) {
275 if ( cellBounds[minIdx] < theBounds[minIdx] ) {
276 theBounds[minIdx] = cellBounds[minIdx];
278 if ( cellBounds[maxIdx] > theBounds[maxIdx] ) {
279 theBounds[maxIdx] = cellBounds[maxIdx];
284 vtkMath::UninitializeBounds(theBounds);
288 //----------------------------------------------------------------------------
289 //Compute center of the box, box defined as xmin, xmax, ymin, ymax, zmin, zmax
291 ComputeBoxCenter(vtkFloatingPointType theBounds[6], vtkFloatingPointType theCenter[3]) {
292 for (int i=0; i<3; i++) {
293 theCenter[i] = (theBounds[2*i+1] + theBounds[2*i]) / 2.0;
297 //----------------------------------------------------------------------------
298 //Compute length of the box diagonal, box defined as xmin, xmax, ymin, ymax, zmin, zmax
300 ComputeBoxDiagonal(vtkFloatingPointType theBounds[6]) {
301 double diff, len=0.0;
303 for (i=0; i<3; i++) {
304 diff = (double)(theBounds[2*i+1]) - (double)(theBounds[2*i]);