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.cxx
24 // Author: Alexey PETROV
28 #include "VISU_StreamLinesPL.hxx"
29 #include "VISU_PipeLineUtils.hxx"
30 #include "VISU_UsedPointsFilter.hxx"
31 #include "VTKViewer_GeometryFilter.h"
36 #include <vtkPointSet.h>
37 #include <vtkStreamLine.h>
40 static int MYDEBUG = 0;
42 static int MYDEBUG = 0;
45 static vtkFloatingPointType EPS = 1.0e-7;
46 static vtkFloatingPointType aMinNbOfSteps = 1.0E+2;
47 //static vtkFloatingPointType aMaxNbOfSteps = 1.0E+3;
48 static vtkFloatingPointType aCoeffOfIntStep = 1.0E+1;
51 vtkStandardNewMacro(VISU_StreamLinesPL);
53 VISU_StreamLinesPL::VISU_StreamLinesPL(){
54 myStream = vtkStreamLine::New();
55 myCenters = vtkCellCenters::New();
56 myGeomFilter = VTKViewer_GeometryFilter::New();
57 myPointsFilter = VISU_UsedPointsFilter::New();
62 VISU_StreamLinesPL::~VISU_StreamLinesPL(){
63 myPointsFilter->UnRegisterAllOutputs();
64 myPointsFilter->Delete();
66 myCenters->UnRegisterAllOutputs();
69 myGeomFilter->UnRegisterAllOutputs();
70 myGeomFilter->Delete();
72 myStream->UnRegisterAllOutputs();
76 void VISU_StreamLinesPL::ShallowCopy(VISU_PipeLine *thePipeLine){
77 if(VISU_StreamLinesPL *aPipeLine = dynamic_cast<VISU_StreamLinesPL*>(thePipeLine)){
78 SetParams(aPipeLine->GetIntegrationStep(),
79 aPipeLine->GetPropagationTime(),
80 aPipeLine->GetStepLength(),
81 aPipeLine->GetSource(),
82 aPipeLine->GetUsedPoints(),
83 aPipeLine->GetDirection());
85 VISU_DeformedShapePL::ShallowCopy(thePipeLine);
91 ::GetNecasseryMemorySize(vtkIdType theNbOfPoints,
92 vtkFloatingPointType theStepLength,
93 vtkFloatingPointType thePropogationTime,
94 vtkFloatingPointType thePercents)
96 static vtkFloatingPointType aStreamPointSize = sizeof(vtkFloatingPointType)*15 + sizeof(vtkIdType)*2;
97 static vtkFloatingPointType aStreamArraySize = aStreamPointSize*1024; // == 69632
99 vtkFloatingPointType aNbCells = thePercents*theNbOfPoints*2.0;
100 vtkFloatingPointType aNbPointsPerCell = thePropogationTime/theStepLength;
101 vtkFloatingPointType aCellsSize = aNbCells*(1+aNbPointsPerCell);
102 vtkFloatingPointType aPointsSize = aCellsSize*3.0*sizeof(vtkFloatingPointType);
104 vtkFloatingPointType aConnectivitySize = aCellsSize*sizeof(vtkIdType);
105 vtkFloatingPointType aTypesSize = aNbCells*sizeof(char);
106 vtkFloatingPointType aLocationsSize = aNbCells*sizeof(int);
107 //vtkFloatingPointType aNbCellsPerPoint = aCellsSize / aNbCells - 1;
108 vtkFloatingPointType aMeshSize = aPointsSize + aConnectivitySize + aTypesSize + aLocationsSize;
110 vtkFloatingPointType anAssignedDataSize = aCellsSize*4.0*sizeof(vtkFloatingPointType);
111 vtkFloatingPointType anOutputDataSetSize = aMeshSize + anAssignedDataSize;
113 vtkFloatingPointType aResult = aStreamArraySize*aNbCells + anOutputDataSetSize;
119 ::FindPossibleParams(vtkPointSet* theDataSet,
120 vtkFloatingPointType& theStepLength,
121 vtkFloatingPointType& thePropogationTime,
122 vtkFloatingPointType& thePercents)
124 static vtkFloatingPointType aPercentsDecrease = 3.0, aStepLengthIncrease = 9.0;
125 vtkIdType aNbOfPoints = theDataSet->GetNumberOfPoints();
126 vtkFloatingPointType aSize = GetNecasseryMemorySize(aNbOfPoints,theStepLength,thePropogationTime,thePercents);
127 int isPoss = CheckAvailableMemory(aSize);
129 vtkFloatingPointType aMaxStepLength = max(GetMaxStepLength(theDataSet),thePropogationTime);
130 vtkFloatingPointType aMinStepLength = GetMinStepLength(theDataSet);
131 vtkFloatingPointType aDeltaStepLength = (aMaxStepLength - aMinStepLength)/aStepLengthIncrease;
132 for(int i = 2, aStepChanged = 1, aPerecentsChanged = 1; aStepChanged || aPerecentsChanged; i++){
133 vtkFloatingPointType aStepLength = theStepLength + aDeltaStepLength;
134 if(aStepLength < aMaxStepLength) theStepLength = aStepLength;
135 else if(aStepChanged){
136 aStepLength = aMaxStepLength;
139 vtkFloatingPointType aPercents = thePercents /= aPercentsDecrease;
140 if(aPercents*aNbOfPoints > 1) thePercents = aPercents;
141 else if(aPerecentsChanged) {
142 thePercents = 1.1 / aNbOfPoints;
143 aPerecentsChanged = 0;
145 aSize = GetNecasseryMemorySize(aNbOfPoints,theStepLength,thePropogationTime,thePercents);
146 if(CheckAvailableMemory(aSize)){
152 if(MYDEBUG) MESSAGE("FindPossibleParams - aSize = "<<aSize<<"; isPoss = "<<isPoss);
159 ::SetParams(vtkFloatingPointType theIntStep,
160 vtkFloatingPointType thePropogationTime,
161 vtkFloatingPointType theStepLength,
162 vtkPointSet* theSource,
163 vtkFloatingPointType thePercents,
167 vtkPointSet* aDataSet = theSource? theSource: myFieldTransform->GetUnstructuredGridOutput();
169 vtkIdType aNbOfPoints = aDataSet->GetNumberOfPoints();
170 vtkPointSet* aPointSet = myExtractor->GetOutput();
171 if(thePercents*aNbOfPoints < 1) thePercents = 2.0/aNbOfPoints;
172 theIntStep = CorrectIntegrationStep(theIntStep,aPointSet,thePercents);
173 thePropogationTime = CorrectPropagationTime(thePropogationTime,aPointSet);
174 theStepLength = CorrectStepLength(theStepLength,aPointSet);
175 int isAccepted = FindPossibleParams(aPointSet,theStepLength,thePropogationTime,thePercents);
176 if((!isOnlyTry && isAccepted) || (isOnlyTry && isAccepted == 1)){
177 mySource = theSource;
178 myPercents = thePercents;
179 if(GetInput2()->GetCellData()->GetNumberOfArrays()){
180 myCenters->SetInput(aDataSet);
181 myCenters->VertexCellsOn();
182 aDataSet = myCenters->GetOutput();
184 myPointsFilter->SetInput(aDataSet);
185 myPointsFilter->SetPercentsOfUsedPoints(thePercents);
186 aDataSet = myPointsFilter->GetOutput();
187 myStream->SetSource(aDataSet);
188 myStream->SetIntegrationStepLength(theIntStep);
189 myStream->SetMaximumPropagationTime(thePropogationTime);
190 myStream->SetStepLength(theStepLength);
191 myStream->SetSavePointInterval(theIntStep*aMinNbOfSteps);
192 myStream->SetIntegrationDirection(theDirection);
193 myStream->Modified();
216 ::GetStreamerSource()
218 return myStream->GetSource();
225 return GetVelocityCoeff(myExtractor->GetOutput());
230 ::GetVelocityCoeff(vtkPointSet* theDataSet)
232 vtkFloatingPointType* aScalarRange = theDataSet->GetScalarRange();
233 return (fabs(aScalarRange[1]) + fabs(aScalarRange[0]))/2.0;
239 ::IsPossible(vtkPointSet* theDataSet,
240 vtkFloatingPointType thePercents)
242 vtkFloatingPointType aStepLength = GetBaseStepLength(theDataSet);
243 vtkFloatingPointType aBasePropTime = GetBasePropagationTime(theDataSet);
244 VISU_UsedPointsFilter *aPointsFilter = VISU_UsedPointsFilter::New();
245 aPointsFilter->SetInput(theDataSet);
246 vtkPointSet* aDataSet = aPointsFilter->GetOutput();
248 int aRes = FindPossibleParams(aDataSet,aStepLength,aBasePropTime,thePercents);
249 aPointsFilter->UnRegisterAllOutputs();
250 aPointsFilter->Delete();
257 ::GetIntegrationStep()
259 return myStream->GetIntegrationStepLength();
266 return myStream->GetStepLength();
271 ::GetPropagationTime()
273 return myStream->GetMaximumPropagationTime();
280 return myStream->GetIntegrationDirection();
286 ::GetMinIntegrationStep(vtkPointSet* theDataSet,
287 vtkFloatingPointType thePercents)
289 if(!theDataSet) return -1.0;
290 vtkFloatingPointType aVolume = 1.0;
292 theDataSet->Update();
293 vtkFloatingPointType* aBounds = theDataSet->GetBounds();
294 for(int i = 0, j = 0; i < 3; ++i, j = 2*i){
295 vtkFloatingPointType tmp = aBounds[j+1] - aBounds[j];
301 if (degree < 1) return 0.0; // absolutely empty object
302 vtkFloatingPointType anStepLength = GetMaxIntegrationStep(theDataSet)/aCoeffOfIntStep;
303 vtkFloatingPointType aBasePropTime = GetBasePropagationTime(theDataSet)/GetVelocityCoeff(theDataSet);
305 vtkIdType aNbOfPoints = theDataSet->GetNumberOfPoints();
306 vtkFloatingPointType aSize = GetNecasseryMemorySize(aNbOfPoints,anStepLength,aBasePropTime,thePercents);
307 vtkFloatingPointType aRealSize = GetAvailableMemory(aSize);
308 vtkFloatingPointType anAverageVolume = aVolume / aRealSize;
309 vtkFloatingPointType aStep = pow(double(anAverageVolume), double(1.0/double(degree)));
315 ::GetMinIntegrationStep()
317 return GetMinIntegrationStep(myExtractor->GetOutput(),GetUsedPoints());
323 ::GetMaxIntegrationStep(vtkPointSet* theDataSet)
325 if(!theDataSet) return -1.0;
326 theDataSet->Update();
327 vtkFloatingPointType aLength = theDataSet->GetLength();
328 vtkFloatingPointType* aBounds = theDataSet->GetBounds();
329 vtkFloatingPointType aMaxSizeY = (aBounds[3]-aBounds[2])/aLength;
330 vtkFloatingPointType aMaxSizeZ = (aBounds[5]-aBounds[4])/aLength;
331 vtkFloatingPointType aMinMax = (aBounds[1] - aBounds[0])/aLength;
332 if (aMinMax < EPS || (aMaxSizeY < aMinMax && aMaxSizeY > EPS)) aMinMax = aMaxSizeY;
333 if (aMinMax < EPS || (aMaxSizeZ < aMinMax && aMaxSizeZ > EPS)) aMinMax = aMaxSizeZ;
334 return aMinMax*aLength/2.0;
339 ::GetMaxIntegrationStep()
341 return GetMaxIntegrationStep(myExtractor->GetOutput());
346 ::GetBaseIntegrationStep(vtkPointSet* theDataSet,
347 vtkFloatingPointType thePercents)
349 theDataSet->Update();
350 vtkFloatingPointType aMinIntegrationStep = GetMinIntegrationStep(theDataSet,thePercents);
351 vtkFloatingPointType aMaxIntegrationStep = GetMaxIntegrationStep(theDataSet);
352 vtkFloatingPointType anIntegrationStep = aMaxIntegrationStep / aCoeffOfIntStep;
353 vtkFloatingPointType aMinMax = theDataSet->GetLength()/theDataSet->GetNumberOfPoints();
354 if(aMinMax > anIntegrationStep)
355 anIntegrationStep = (anIntegrationStep*aCoeffOfIntStep*0.9+aMinMax)/aCoeffOfIntStep;
356 if(aMinIntegrationStep > anIntegrationStep)
357 anIntegrationStep = aMinIntegrationStep;
358 return anIntegrationStep;
363 ::CorrectIntegrationStep(vtkFloatingPointType theStep,
364 vtkPointSet* theDataSet,
365 vtkFloatingPointType thePercents)
367 theDataSet->Update();
368 vtkFloatingPointType aMinIntegrationStep = GetMinIntegrationStep(theDataSet,thePercents);
369 vtkFloatingPointType aMaxIntegrationStep = GetMaxIntegrationStep(theDataSet);
370 if(aMinIntegrationStep > theStep)
371 theStep = aMinIntegrationStep;
372 if(aMaxIntegrationStep < theStep)
373 theStep = aMaxIntegrationStep;
380 ::GetMinPropagationTime(vtkPointSet* theDataSet)
382 if(!theDataSet) return -1.0;
383 return GetMinStepLength(theDataSet);
388 ::GetMinPropagationTime()
390 return GetMinPropagationTime(myExtractor->GetOutput());
395 ::GetMaxPropagationTime(vtkPointSet* theDataSet)
397 if(!theDataSet) return -1.0;
398 return GetBasePropagationTime(theDataSet)*aMinNbOfSteps;
401 vtkFloatingPointType VISU_StreamLinesPL::GetMaxPropagationTime(){
402 return GetMaxPropagationTime(myExtractor->GetOutput());
407 ::CorrectPropagationTime(vtkFloatingPointType thePropagationTime,
408 vtkPointSet* theDataSet)
410 vtkFloatingPointType aMinPropagationTime = GetMinPropagationTime(theDataSet);
411 vtkFloatingPointType aMaxPropagationTime = GetMaxPropagationTime(theDataSet);
412 if(aMinPropagationTime > thePropagationTime)
413 thePropagationTime = aMinPropagationTime;
414 if(aMaxPropagationTime < thePropagationTime)
415 thePropagationTime = aMaxPropagationTime;
416 return thePropagationTime;
421 ::GetBasePropagationTime(vtkPointSet* theDataSet)
423 if(!theDataSet) return -1.0;
424 theDataSet->Update();
425 vtkFloatingPointType aPropagationTime = theDataSet->GetLength()/GetVelocityCoeff(theDataSet);
426 return aPropagationTime;
431 ::GetBasePropagationTime()
433 return GetBasePropagationTime(myExtractor->GetOutput());
439 ::GetMinStepLength(vtkPointSet* theDataSet)
441 static vtkFloatingPointType aNbOfStepsOfIntStep = 1.0E+1;
442 vtkFloatingPointType anIntStep = GetMinIntegrationStep(theDataSet);
443 vtkFloatingPointType aStepLength = anIntStep*aNbOfStepsOfIntStep/GetVelocityCoeff(theDataSet);
451 return GetMinStepLength(myExtractor->GetOutput());
456 ::GetMaxStepLength(vtkPointSet* theDataSet)
458 vtkFloatingPointType aStepLength = GetBasePropagationTime(theDataSet);
466 return GetMaxStepLength(myExtractor->GetOutput());
471 ::CorrectStepLength(vtkFloatingPointType theStep,
472 vtkPointSet* theDataSet)
474 vtkFloatingPointType aMinStep = GetMinStepLength(theDataSet);
475 if(theStep < aMinStep) theStep = aMinStep;
476 vtkFloatingPointType aMaxStep = GetMaxStepLength(theDataSet);
477 if(theStep > aMaxStep) theStep = aMaxStep;
483 ::GetBaseStepLength(vtkPointSet* theDataSet)
485 static vtkFloatingPointType anAvgNbOfSteps = 1.0E+2;
486 vtkFloatingPointType aPropagationTime = GetBasePropagationTime(theDataSet);
487 vtkFloatingPointType aStepLength = aPropagationTime/anAvgNbOfSteps;
488 aStepLength = CorrectStepLength(aStepLength,theDataSet);
497 VISU_ScalarMapPL::Init();
498 vtkPointSet* aDataSet = myExtractor->GetOutput();
499 vtkFloatingPointType anIntStep = GetBaseIntegrationStep(aDataSet);
500 vtkFloatingPointType aPropagationTime = GetBasePropagationTime(aDataSet);
501 vtkFloatingPointType aStepLength = GetBaseStepLength(aDataSet);
502 SetParams(anIntStep,aPropagationTime,aStepLength);
505 VISU_ScalarMapPL::THook*
509 GetInput2()->Update();
510 VISU::CellDataToPoint(myStream,myCellDataToPointData,GetInput2(),myFieldTransform);
511 vtkFloatingPointType *aBounds = GetInput2()->GetBounds();
512 myGeomFilter->SetExtent(aBounds);
513 myGeomFilter->ExtentClippingOn();
514 myGeomFilter->SetInput(myStream->GetOutput());
515 return myGeomFilter->GetOutput();
522 VISU_ScalarMapPL::Update();
527 ::SetMapScale(vtkFloatingPointType theMapScale)
529 VISU_ScalarMapPL::SetMapScale(theMapScale);