Salome HOME
Update copyright information
[modules/visu.git] / src / PIPELINE / VISU_GaussPointsPL.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  VISU OBJECT : interactive object for VISU entities implementation
24 // File:    VISU_GaussPoints.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27 //
28 #include "VISU_GaussPointsPL.hxx"
29 #include "VISU_PointSpriteMapperHolder.hxx"
30 #include "VISU_OpenGLPointSpriteMapper.hxx"
31 #include "VISU_DeformedShapePL.hxx"
32 #include "VISU_FieldTransform.hxx"
33 #include "VISU_LookupTable.hxx"
34
35 #include "VISU_PipeLineUtils.hxx"
36 #include "VISU_AppendFilter.hxx"
37 #include "VISU_GaussMergeFilter.hxx"
38
39 #include <vtkPointSource.h>
40 #include <vtkElevationFilter.h>
41 #include <vtkImageGaussianSource.h>
42 #include <vtkXMLImageDataReader.h>
43 #include <vtkGeometryFilter.h>
44 #include <vtkImageData.h>
45 #include <vtkWarpVector.h>
46 #include <vtkGlyph3D.h>
47 #include <vtkSphereSource.h>
48 #include <vtkPassThroughFilter.h>
49
50 //----------------------------------------------------------------------------
51 vtkStandardNewMacro(VISU_GaussPointsPL);
52
53 //----------------------------------------------------------------------------
54 VISU_GaussPointsPL
55 ::VISU_GaussPointsPL():
56   myScaleFactor(0.0),
57   myMagnificationIncrement(2),
58   myAppendFilter(VISU_AppendFilter::New()),
59   myMergeFilter(VISU_GaussMergeFilter::New())
60 {
61   SetIsShrinkable(false);
62   SetIsFeatureEdgesAllowed(false);
63
64   myWarpVector = vtkWarpVector::New();
65
66   myGlyph = vtkGlyph3D::New();
67   myGlyph->SetScaleModeToScaleByScalar();
68   myGlyph->SetColorModeToColorByScalar();
69   myGlyph->ClampingOn();
70
71   mySphereSource = vtkSphereSource::New();
72   mySphereSource->SetThetaResolution( 8 );
73   mySphereSource->SetPhiResolution( 8 );
74   myGlyph->SetSource( mySphereSource->GetOutput() );
75
76   for(int i = 0; i < 3; i++)
77     myPassFilter.push_back(vtkPassThroughFilter::New());
78
79   myPrimitiveType = VISU_OpenGLPointSpriteMapper::PointSprite;    
80
81   myAppendFilter->SetMergingInputs(true);
82   myAppendFilter->Delete();
83
84   myMergeFilter->SetMergingInputs(true);
85   myMergeFilter->Delete();
86 }
87
88
89 //----------------------------------------------------------------------------
90 VISU_GaussPointsPL
91 ::~VISU_GaussPointsPL()
92 {
93   myWarpVector->Delete();
94
95   myGlyph->Delete();
96
97   mySphereSource->Delete();
98
99   for(int i = 0; i < 3; i++)
100     myPassFilter[i]->Delete();
101 }
102
103
104 //----------------------------------------------------------------------------
105 unsigned long int 
106 VISU_GaussPointsPL
107 ::GetMTime()
108 {
109   unsigned long int aTime = Superclass::GetMTime();
110
111   aTime = std::max(aTime, myWarpVector->GetMTime());
112   aTime = std::max(aTime, myGlyph->GetMTime());
113   aTime = std::max(aTime, mySphereSource->GetMTime());
114   aTime = std::max(aTime, myAppendFilter->GetMTime());
115   aTime = std::max(aTime, myMergeFilter->GetMTime());
116
117   for(int i = 0; i < 3; i++)
118     aTime = std::max(aTime, myPassFilter[i]->GetMTime());
119
120   return aTime;
121 }
122
123
124 //----------------------------------------------------------------------------
125 void  
126 VISU_GaussPointsPL
127 ::OnCreateMapperHolder()
128 {
129   myPointSpriteMapperHolder = VISU_PointSpriteMapperHolder::New();
130   myPointSpriteMapperHolder->Delete();
131
132   SetMapperHolder(myPointSpriteMapperHolder.GetPointer());
133 }
134
135
136 //----------------------------------------------------------------------------
137 void
138 VISU_GaussPointsPL
139 ::SetGaussPtsIDMapper(const VISU::PGaussPtsIDMapper& theIDMapper)
140 {
141   GetPointSpriteMapperHolder()->SetGaussPtsIDMapper(theIDMapper);
142 }
143
144
145 //----------------------------------------------------------------------------
146 const VISU::PGaussPtsIDMapper&  
147 VISU_GaussPointsPL
148 ::GetGaussPtsIDMapper()
149 {
150   return GetPointSpriteMapperHolder()->GetGaussPtsIDMapper();
151 }
152
153
154 //----------------------------------------------------------------------------
155 VISU_PointSpriteMapperHolder*  
156 VISU_GaussPointsPL
157 ::GetPointSpriteMapperHolder()
158 {
159   GetMapperHolder();
160
161   return myPointSpriteMapperHolder.GetPointer();
162 }
163
164 //----------------------------------------------------------------------------
165 vtkDataSet*  
166 VISU_GaussPointsPL
167 ::GetParentMesh()
168 {
169   VISU::TNamedIDMapper* aNamedIDMapper = GetGaussPtsIDMapper()->GetParent();
170   return aNamedIDMapper->GetOutput();
171 }
172
173 //----------------------------------------------------------------------------
174 void
175 CopyGlyph( vtkGlyph3D* theSource, vtkGlyph3D* theDestination )
176 {
177   vtkFloatingPointType* aSourceRange = theSource->GetRange();
178   vtkFloatingPointType* aDestinationRange = theDestination->GetRange();
179   if(!VISU::CheckIsSameRange(aDestinationRange, aSourceRange))
180     theDestination->SetRange( aSourceRange );
181
182   theDestination->SetScaling( theSource->GetScaling() );
183   theDestination->SetClamping( theSource->GetClamping() );
184   theDestination->SetScaleMode( theSource->GetScaleMode() );
185   theDestination->SetColorMode( theSource->GetColorMode() );
186   theDestination->SetScaleFactor( theSource->GetScaleFactor() );
187 }
188
189
190 //----------------------------------------------------------------------------
191 void
192 VISU_GaussPointsPL
193 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
194                 bool theIsCopyInput)
195 {
196   Superclass::DoShallowCopy(thePipeLine, theIsCopyInput);
197   VISU_MergedPL::DoShallowCopy(thePipeLine, theIsCopyInput);
198
199   if(VISU_GaussPointsPL *aPipeLine = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine)){
200     SetPrimitiveType(aPipeLine->GetPrimitiveType());
201     SetBicolor(aPipeLine->GetBicolor());
202     SetClamp(aPipeLine->GetClamp());
203     SetSize(aPipeLine->GetSize());
204     SetMinSize(aPipeLine->GetMinSize());
205     SetMaxSize(aPipeLine->GetMaxSize());
206     SetMagnification(aPipeLine->GetMagnification());
207     SetMagnificationIncrement(aPipeLine->GetMagnificationIncrement());
208     SetAlphaThreshold(aPipeLine->GetAlphaThreshold());
209     SetResolution(aPipeLine->GetResolution());
210
211     SetIsDeformed( aPipeLine->GetIsDeformed() );
212     SetScale( aPipeLine->GetScale() );
213
214     vtkFloatingPointType aRadius = aPipeLine->mySphereSource->GetRadius();
215     if(!VISU::CheckIsSameValue(mySphereSource->GetRadius(), aRadius))
216       mySphereSource->SetRadius( aRadius );
217
218     CopyGlyph( aPipeLine->myGlyph, this->myGlyph );
219   }
220 }
221
222
223 //----------------------------------------------------------------------------
224 VISU_OpenGLPointSpriteMapper* 
225 VISU_GaussPointsPL
226 ::GetPointSpriteMapper()
227 {
228   return GetPointSpriteMapperHolder()->GetPointSpriteMapper();
229 }
230
231
232 //----------------------------------------------------------------------------
233 vtkPolyData* 
234 VISU_GaussPointsPL
235 ::GetPickableDataSet()
236 {
237   return myPassFilter[1]->GetPolyDataOutput();
238 }
239
240
241 //----------------------------------------------------------------------------
242 void
243 VISU_GaussPointsPL
244 ::Init()
245 {
246   Superclass::Init();
247
248   //SetExtractInside(false);
249
250   vtkDataSet* aDataSet = GetParentMesh();
251   vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
252
253   vtkFloatingPointType* aScalarRange = GetScalarRange();
254   static double EPS = 1.0 / VTK_LARGE_FLOAT;
255   if(fabs(aScalarRange[1]) > EPS)
256     SetScale( aScaleFactor / aScalarRange[1] );
257   else
258     SetScale(0.0);
259 }
260
261
262 //----------------------------------------------------------------------------
263 void
264 VISU_GaussPointsPL
265 ::Build()
266 {
267   Superclass::Build();
268
269   SetSourceGeometry();
270
271   vtkDataSet* aDataSet = GetFieldTransformFilter()->GetOutput();
272   
273   myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
274   
275   myMergeFilter->SetScalars(aDataSet);
276   myMergeFilter->SetVectors(aDataSet);
277   
278   myMergeFilter->RemoveFields();
279   myMergeFilter->AddField("VISU_FIELD", aDataSet);
280   myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
281   myMergeFilter->AddField("VISU_INPUTS_MAPPER", aDataSet);
282   myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
283
284   myMergeFilter->SetGaussPtsIDMapper(GetGaussPtsIDMapper());
285   
286   myPassFilter[0]->SetInput(InsertCustomPL());
287
288   myPassFilter[1]->SetInput(myPassFilter[0]->GetOutput());
289
290   // Geometrical Sphere
291   myPassFilter[2]->SetInput(myPassFilter[1]->GetOutput());
292   
293   GetPointSpriteMapper()->SetInput( myPassFilter[2]->GetPolyDataOutput() );
294
295   // Update according the current state
296   SetIsDeformed(GetIsDeformed());
297
298   SetPrimitiveType(GetPrimitiveType());
299 }
300
301
302 //----------------------------------------------------------------------------
303 void
304 VISU_GaussPointsPL
305 ::Update()
306 {
307   if(IsExternalGeometryUsed() || GetNumberOfGeometry() > 1 ){
308     myMergeFilter->Update();
309     myPassFilter[0]->SetInput(myMergeFilter->GetOutput());
310   }
311   else{
312     myPassFilter[0]->SetInput(GetFieldTransformFilter()->GetOutput());
313   }
314
315   SetAverageCellSize( VISU_DeformedShapePL::GetScaleFactor( GetParentMesh() ) );
316
317   this->UpdateGlyph();
318
319   Superclass::Update();
320
321 }
322
323
324 //----------------------------------------------------------------------------
325 unsigned long int
326 VISU_GaussPointsPL
327 ::GetMemorySize()
328 {
329   unsigned long int aSize = Superclass::GetMemorySize();
330   
331   if(GetIsDeformed())
332     if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
333       aSize += aDataSet->GetActualMemorySize() * 1024;
334
335   if(GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
336     if(vtkDataSet* aDataSet = myGlyph->GetOutput())
337       aSize += aDataSet->GetActualMemorySize() * 1024;
338
339   return aSize;
340 }
341
342
343 //----------------------------------------------------------------------------
344 void
345 VISU_GaussPointsPL
346 ::UpdateGlyph()
347 {
348   vtkFloatingPointType* aScalarRange = GetScalarRange();
349
350   if( GetPointSpriteMapper()->GetPointSpriteMode() == 0 ) // Results
351   {
352     myGlyph->ClampingOn();
353     myGlyph->SetScaleModeToScaleByScalar();
354     myGlyph->SetColorModeToColorByScalar();
355
356     vtkFloatingPointType aScaleFactor = 0.0;
357     vtkFloatingPointType aMinSize = GetMinSize();
358     vtkFloatingPointType aMaxSize = GetMaxSize();
359     if(!VISU::CheckIsSameValue(aMaxSize, aMinSize))
360       aScaleFactor = ( aScalarRange[1] - aScalarRange[0] ) / ( aMaxSize - aMinSize );
361     
362     vtkFloatingPointType aMinRange = aScalarRange[0] - aMinSize * aScaleFactor;
363     vtkFloatingPointType aMaxRange = aMinRange + aScaleFactor;
364     vtkFloatingPointType aRange[2] = {aMinRange, aMaxRange};
365
366     if(!VISU::CheckIsSameRange(myGlyph->GetRange(), aRange))
367       myGlyph->SetRange( aRange );
368
369     if(!VISU::CheckIsSameValue(myGlyph->GetScaleFactor(), 1.0))
370       myGlyph->SetScaleFactor( 1.0 );
371   }
372   else if( GetPointSpriteMapper()->GetPointSpriteMode() == 1 ) // Geometry
373   {
374     myGlyph->ClampingOff();
375     myGlyph->SetScaleModeToDataScalingOff();
376     myGlyph->SetColorModeToColorByScale();
377
378     vtkFloatingPointType aScaleFactor = GetSize();
379     if(!VISU::CheckIsSameValue(myGlyph->GetScaleFactor(), aScaleFactor))
380       myGlyph->SetScaleFactor( aScaleFactor );
381   }
382   else if( GetPointSpriteMapper()->GetPointSpriteMode() == 2 ) // Outside
383   {
384     myGlyph->ClampingOff();
385     myGlyph->SetScaleModeToDataScalingOff();
386     myGlyph->SetColorModeToColorByScalar();
387
388     vtkFloatingPointType aScaleFactor = GetSize();
389     if(!VISU::CheckIsSameValue(myGlyph->GetScaleFactor(), aScaleFactor))
390       myGlyph->SetScaleFactor( aScaleFactor );
391   }
392
393   vtkFloatingPointType aRadius = GetMagnification() * GetAverageCellSize() / 2.0;
394   if(!VISU::CheckIsSameValue(mySphereSource->GetRadius(), aRadius))
395     mySphereSource->SetRadius( aRadius );
396 }
397
398
399 //----------------------------------------------------------------------------
400 VISU::TGaussPointID 
401 VISU_GaussPointsPL
402 ::GetObjID(vtkIdType theID)
403 {
404   return GetGaussPtsIDMapper()->GetObjID(theID);
405 }
406
407
408 //----------------------------------------------------------------------------
409 void
410 VISU_GaussPointsPL
411 ::SetIsDeformed( bool theIsDeformed )
412 {
413   if(theIsDeformed){
414     myWarpVector->SetInput( myPassFilter[0]->GetPolyDataOutput() );
415     myPassFilter[1]->SetInput(myWarpVector->GetOutput());
416   }else
417     myPassFilter[1]->SetInput(myPassFilter[0]->GetOutput());
418 }
419
420 //----------------------------------------------------------------------------
421 bool
422 VISU_GaussPointsPL
423 ::GetIsDeformed()
424 {
425   return myPassFilter[1]->GetInput() != myPassFilter[0]->GetOutput();
426 }
427
428 //----------------------------------------------------------------------------
429 void
430 VISU_GaussPointsPL
431 ::SetBicolor(bool theBicolor)
432 {
433   if(GetBicolor() == theBicolor)
434     return;
435
436   GetMapperTable()->SetBicolor( theBicolor );
437   GetBarTable()->SetBicolor( theBicolor );
438 }
439
440 //----------------------------------------------------------------------------
441 bool
442 VISU_GaussPointsPL
443 ::GetBicolor()
444 {
445   return GetMapperTable()->GetBicolor();
446 }
447
448 //----------------------------------------------------------------------------
449 void
450 VISU_GaussPointsPL
451 ::SetIsColored(bool theIsColored)
452 {
453   GetPointSpriteMapper()->SetPointSpriteMode( theIsColored ? 0 : 1 ); // Results / Geometry
454 }
455
456 //----------------------------------------------------------------------------
457 bool
458 VISU_GaussPointsPL
459 ::GetIsColored()
460 {
461   return GetPointSpriteMapper()->GetPointSpriteMode() == 0;
462 }
463
464 //----------------------------------------------------------------------------
465 void
466 VISU_GaussPointsPL
467 ::SetPrimitiveType(int thePrimitiveType)
468 {
469   if( thePrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere )
470   {
471     myGlyph->SetInput( myPassFilter[1]->GetOutput() );
472     myPassFilter[2]->SetInput(myGlyph->GetOutput());
473   }
474   else
475     myPassFilter[2]->SetInput(myPassFilter[1]->GetOutput());
476
477   GetPointSpriteMapper()->SetPrimitiveType( thePrimitiveType );
478   
479   myPrimitiveType = thePrimitiveType;
480 }
481
482
483 //----------------------------------------------------------------------------
484 int
485 VISU_GaussPointsPL
486 ::GetPrimitiveType()
487 {    
488   return myPrimitiveType;
489 }
490
491
492 //----------------------------------------------------------------------------
493 vtkFloatingPointType
494 VISU_GaussPointsPL
495 ::GetMaximumSupportedSize()
496 {
497   return GetPointSpriteMapper()->GetMaximumSupportedSize();
498 }
499
500
501 //----------------------------------------------------------------------------
502 void
503 VISU_GaussPointsPL
504 ::SetClamp(vtkFloatingPointType theClamp)
505 {
506   GetPointSpriteMapper()->SetPointSpriteClamp( theClamp );
507 }
508
509
510 //----------------------------------------------------------------------------
511 vtkFloatingPointType
512 VISU_GaussPointsPL
513 ::GetClamp()
514 {
515   return GetPointSpriteMapper()->GetPointSpriteClamp();
516 }
517
518 //----------------------------------------------------------------------------
519 void
520 VISU_GaussPointsPL
521 ::SetSize(vtkFloatingPointType theSize)
522 {
523   GetPointSpriteMapper()->SetPointSpriteSize( theSize );
524 }
525
526
527 //----------------------------------------------------------------------------
528 vtkFloatingPointType
529 VISU_GaussPointsPL
530 ::GetSize()
531 {
532   return GetPointSpriteMapper()->GetPointSpriteSize();
533 }
534
535
536 //----------------------------------------------------------------------------
537 void
538 VISU_GaussPointsPL
539 ::SetMinSize(vtkFloatingPointType theMinSize)
540 {
541   GetPointSpriteMapper()->SetPointSpriteMinSize( theMinSize );
542 }
543
544
545 //----------------------------------------------------------------------------
546 vtkFloatingPointType
547 VISU_GaussPointsPL
548 ::GetMinSize()
549 {
550   return GetPointSpriteMapper()->GetPointSpriteMinSize();
551 }
552
553
554 //----------------------------------------------------------------------------
555 void
556 VISU_GaussPointsPL
557 ::SetMaxSize(vtkFloatingPointType theMaxSize)
558 {
559   GetPointSpriteMapper()->SetPointSpriteMaxSize( theMaxSize );
560 }
561
562
563 //----------------------------------------------------------------------------
564 vtkFloatingPointType
565 VISU_GaussPointsPL
566 ::GetMaxSize()
567 {
568   return GetPointSpriteMapper()->GetPointSpriteMaxSize();
569 }
570
571
572 //----------------------------------------------------------------------------
573 void
574 VISU_GaussPointsPL
575 ::SetMagnification(vtkFloatingPointType theMagnification)
576 {
577   GetPointSpriteMapper()->SetPointSpriteMagnification( theMagnification );
578 }
579
580
581 //----------------------------------------------------------------------------
582 vtkFloatingPointType
583 VISU_GaussPointsPL
584 ::GetMagnification()
585 {
586   return GetPointSpriteMapper()->GetPointSpriteMagnification();
587 }
588
589
590 //----------------------------------------------------------------------------
591 void
592 VISU_GaussPointsPL
593 ::SetMagnificationIncrement(vtkFloatingPointType theIncrement)
594 {
595   if(VISU::CheckIsSameValue(myMagnificationIncrement, theIncrement))
596     return;
597
598   myMagnificationIncrement = theIncrement;
599   Modified();
600 }
601
602
603 //----------------------------------------------------------------------------
604 void
605 VISU_GaussPointsPL
606 ::SetAlphaThreshold(vtkFloatingPointType theAlphaThreshold)
607 {
608   GetPointSpriteMapper()->SetPointSpriteAlphaThreshold( theAlphaThreshold );
609 }
610
611
612 //----------------------------------------------------------------------------
613 vtkFloatingPointType
614 VISU_GaussPointsPL
615 ::GetAlphaThreshold()
616 {
617   return GetPointSpriteMapper()->GetPointSpriteAlphaThreshold();
618 }
619
620
621 //----------------------------------------------------------------------------
622 void
623 VISU_GaussPointsPL
624 ::SetOpacity(vtkFloatingPointType theOpacity)
625 {
626   GetPointSpriteMapper()->SetPointSpriteOpacity( theOpacity );
627 }
628
629
630 //----------------------------------------------------------------------------
631 vtkFloatingPointType
632 VISU_GaussPointsPL
633 ::GetOpacity()
634 {
635   return GetPointSpriteMapper()->GetPointSpriteOpacity();
636 }
637
638
639 //----------------------------------------------------------------------------
640 void
641 VISU_GaussPointsPL
642 ::SetResolution(int theResolution)
643 {
644   mySphereSource->SetThetaResolution( theResolution );
645   mySphereSource->SetPhiResolution( theResolution );
646 }
647
648
649 //----------------------------------------------------------------------------
650 int
651 VISU_GaussPointsPL
652 ::GetResolution()
653 {
654   return mySphereSource->GetThetaResolution();
655 }
656
657
658 //----------------------------------------------------------------------------
659 void
660 VISU_GaussPointsPL
661 ::ChangeMagnification( bool up )
662 {
663   vtkFloatingPointType anIncrement = up ? myMagnificationIncrement : 1.0 / myMagnificationIncrement;
664   SetMagnification( GetMagnification() * anIncrement );
665 }
666
667
668 //----------------------------------------------------------------------------
669 vtkFloatingPointType
670 VISU_GaussPointsPL
671 ::GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray)
672 {
673   vtkFloatingPointType aMaxSize = GetAverageCellSize() * GetMaxSize();
674   vtkFloatingPointType aMinSize = GetAverageCellSize() * GetMinSize();
675   vtkFloatingPointType aDelta = aMaxSize - aMinSize;
676   vtkFloatingPointType aVal = theScalarArray->GetTuple1(theID);
677
678   vtkFloatingPointType* aScalarRange = GetScalarRange();
679   vtkFloatingPointType aDeltaScalarRange = aScalarRange[1] - aScalarRange[0];
680
681   // to avoid FPE if the minimum is equal to maximum
682   if( aDeltaScalarRange < 1.0 / VTK_LARGE_FLOAT )
683     return aMinSize;
684
685   return aMinSize + aDelta*(aVal - aScalarRange[0]) / aDeltaScalarRange;
686 }
687
688
689 //----------------------------------------------------------------------------
690 vtkFloatingPointType
691 VISU_GaussPointsPL
692 ::GetMaxPointSize()
693 {
694   return GetAverageCellSize() * GetMaxSize();
695 }
696
697
698 //----------------------------------------------------------------------------
699 vtkFloatingPointType
700 VISU_GaussPointsPL
701 ::GetPointSize(vtkIdType theID)
702 {
703   vtkMapper* aMapper = GetMapper();
704   vtkDataSet* aDataSet = aMapper->GetInput();
705   vtkPointData* aPointData = aDataSet->GetPointData();
706   vtkDataArray* aScalarArray = aPointData->GetScalars();
707   return GetPointSize(theID, aScalarArray);
708 }
709
710
711 //----------------------------------------------------------------------------
712 void
713 VISU_GaussPointsPL
714 ::SetAverageCellSize(vtkFloatingPointType theAverageCellSize)
715 {
716   GetPointSpriteMapper()->SetAverageCellSize( theAverageCellSize );
717 }
718
719
720 //----------------------------------------------------------------------------
721 vtkFloatingPointType
722 VISU_GaussPointsPL
723 ::GetAverageCellSize()
724 {
725   return GetPointSpriteMapper()->GetAverageCellSize();
726 }
727
728
729 //----------------------------------------------------------------------------
730 void
731 VISU_GaussPointsPL
732 ::SetImageData(vtkImageData* theImageData)
733 {
734   GetPointSpriteMapper()->SetImageData( theImageData );
735 }
736
737
738 //----------------------------------------------------------------------------
739 vtkSmartPointer<vtkImageData>
740 VISU_GaussPointsPL
741 ::MakeTexture( const char* theMainTexture, 
742                const char* theAlphaTexture )
743 {
744   if( !theMainTexture || !theAlphaTexture )
745     return 0;
746
747   vtkXMLImageDataReader* aMainReader = vtkXMLImageDataReader::New();
748   vtkXMLImageDataReader* anAlphaReader = vtkXMLImageDataReader::New();
749
750   aMainReader->SetFileName( theMainTexture );
751   anAlphaReader->SetFileName( theAlphaTexture );
752
753   aMainReader->Update();
754   anAlphaReader->Update();
755
756   vtkImageData* aMainImageData = aMainReader->GetOutput();
757   vtkImageData* anAlphaImageData = anAlphaReader->GetOutput();
758
759   int* aMainImageSize = aMainImageData->GetDimensions();
760   int* anAlphaImageSize = anAlphaImageData->GetDimensions();
761   if(aMainImageSize[0] != anAlphaImageSize[0] || aMainImageSize[1] != anAlphaImageSize[1])
762     return NULL;
763
764   vtkSmartPointer<vtkImageData> aCompositeImageData = vtkImageData::New();
765   aCompositeImageData->Delete();
766
767   int aNbCompositeComponents = 4;
768   aCompositeImageData->SetDimensions(aMainImageSize);
769   aCompositeImageData->SetScalarTypeToUnsignedChar();        
770   aCompositeImageData->SetNumberOfScalarComponents(aNbCompositeComponents);
771   aCompositeImageData->AllocateScalars();
772
773   unsigned char* aMainDataPtr = (unsigned char*)aMainImageData->GetScalarPointer();
774   unsigned char* anAlphaDataPtr = (unsigned char*)anAlphaImageData->GetScalarPointer();
775   unsigned char *aCompositeDataPtr = (unsigned char * )aCompositeImageData->GetScalarPointer();
776
777   int aNbMainComponents = aMainImageData->GetNumberOfScalarComponents();
778   int aNbAlphaComponents = anAlphaImageData->GetNumberOfScalarComponents();
779   int aCompositeSize = aMainImageSize[0] * aMainImageSize[1] * aNbCompositeComponents;
780   
781   int aMainId = 0, anAlphaId = 0, aCompositeId = 0;
782   for(; aCompositeId < aCompositeSize;)
783   {
784     aCompositeDataPtr[aCompositeId] = aMainDataPtr[aMainId];
785     aCompositeDataPtr[aCompositeId + 1] = aMainDataPtr[aMainId + 1];
786     aCompositeDataPtr[aCompositeId + 2] = aMainDataPtr[aMainId + 2];
787     aCompositeDataPtr[aCompositeId + 3] = anAlphaDataPtr[anAlphaId];
788
789     aMainId += aNbMainComponents;
790     anAlphaId += aNbAlphaComponents;
791     aCompositeId += aNbCompositeComponents;
792   }
793   aMainReader->Delete();
794   anAlphaReader->Delete();
795   aCompositeImageData->Update();
796
797   return aCompositeImageData;
798 }
799
800
801 void
802 VISU_GaussPointsPL
803 ::SetScale( vtkFloatingPointType theScale )
804 {
805   if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), theScale))
806     return;
807
808   myWarpVector->SetScaleFactor( theScale );
809   myScaleFactor = theScale;
810 }
811
812
813 vtkFloatingPointType 
814 VISU_GaussPointsPL
815 ::GetScale()
816 {
817   return myWarpVector->GetScaleFactor();
818 }
819
820
821 void
822 VISU_GaussPointsPL
823 ::SetMapScale( vtkFloatingPointType theMapScale )
824 {
825   Superclass::SetMapScale( theMapScale );
826
827   vtkFloatingPointType aMapScale = myScaleFactor * theMapScale;
828   if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), aMapScale))
829     return;
830
831   myWarpVector->SetScaleFactor( aMapScale );
832 }
833
834 void
835 VISU_GaussPointsPL
836 ::SetSourceGeometry()
837 {
838   if(IsExternalGeometryUsed()){
839     ClearGeometry();
840     myAppendFilter->AddInput(GetFieldTransformFilter()->GetOutput());
841   }
842 }
843
844 vtkDataSet* 
845 VISU_GaussPointsPL
846 ::InsertCustomPL()
847 {
848   return GetMergedInput();
849 }
850
851 int
852 VISU_GaussPointsPL
853 ::AddGeometry(vtkDataSet* theGeometry, const VISU::TName& theGeomName)
854 {
855   // Fix for issue 0020167 (like in VISU_ScalarMapPL)
856   if(!IsExternalGeometryUsed())
857     ClearGeometry();
858   AddGeometryName(theGeomName);
859   myAppendFilter->AddInput(theGeometry);
860   return GetNumberOfGeometry();
861 }
862
863 vtkDataSet*
864 VISU_GaussPointsPL
865 ::GetGeometry(int theGeomNumber, VISU::TName& theGeomName)
866 {
867   theGeomName = GetGeometryName(theGeomNumber);
868   return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
869 }
870
871 int
872 VISU_GaussPointsPL
873 ::GetNumberOfGeometry()
874 {
875   return myAppendFilter->GetNumberOfInputConnections(0);
876 }
877
878 bool
879 VISU_GaussPointsPL
880 ::IsExternalGeometryUsed()
881 {
882   return myAppendFilter->GetInput() != GetFieldTransformFilter()->GetOutput();
883 }
884
885 void
886 VISU_GaussPointsPL
887 ::ClearGeometry()
888 {
889   ClearGeometryNames();
890   myAppendFilter->RemoveAllInputs();
891 }
892
893 void
894 VISU_GaussPointsPL
895 ::GetSourceRange(vtkFloatingPointType theRange[2])
896 {
897   if(!IsExternalGeometryUsed())
898     Superclass::GetSourceRange(theRange);
899   else
900     GetMergedInput()->GetScalarRange( theRange );
901 }
902
903 vtkPointSet* 
904 VISU_GaussPointsPL
905 ::GetMergedInput()
906 {
907   if(myMergeFilter->GetInput())
908     myMergeFilter->Update();
909   return myMergeFilter->GetOutput();
910 }