Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / PIPELINE / VISU_GaussPointsPL.cxx
1 //  VISU OBJECT : interactive object for VISU entities implementation
2 //
3 //  Copyright (C) 2003  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 //
24 // File:    VISU_GaussPoints.cxx
25 // Author:  Alexey PETROV
26 // Module : VISU
27
28
29 #include "VISU_GaussPointsPL.hxx"
30 #include "VISU_PointSpriteMapperHolder.hxx"
31 #include "VISU_OpenGLPointSpriteMapper.hxx"
32 #include "VISU_DeformedShapePL.hxx"
33 #include "VISU_FieldTransform.hxx"
34 #include "VISU_LookupTable.hxx"
35
36 #include "VISU_PipeLineUtils.hxx"
37 #include "VISU_AppendFilter.hxx"
38 #include "VISU_GaussMergeFilter.hxx"
39
40 #include <vtkPointSource.h>
41 #include <vtkElevationFilter.h>
42 #include <vtkImageGaussianSource.h>
43 #include <vtkXMLImageDataReader.h>
44 #include <vtkGeometryFilter.h>
45 #include <vtkImageData.h>
46 #include <vtkWarpVector.h>
47 #include <vtkGlyph3D.h>
48 #include <vtkSphereSource.h>
49 #include <vtkPassThroughFilter.h>
50
51 //----------------------------------------------------------------------------
52 vtkStandardNewMacro(VISU_GaussPointsPL);
53
54 //----------------------------------------------------------------------------
55 VISU_GaussPointsPL
56 ::VISU_GaussPointsPL():
57   myScaleFactor(0.0),
58   myMagnificationIncrement(2),
59   myAppendFilter(VISU_AppendFilter::New()),
60   myMergeFilter(VISU_GaussMergeFilter::New())
61 {
62   SetIsShrinkable(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
198   if(VISU_GaussPointsPL *aPipeLine = dynamic_cast<VISU_GaussPointsPL*>(thePipeLine)){
199     SetPrimitiveType(aPipeLine->GetPrimitiveType());
200     SetBicolor(aPipeLine->GetBicolor());
201     SetClamp(aPipeLine->GetClamp());
202     SetSize(aPipeLine->GetSize());
203     SetMinSize(aPipeLine->GetMinSize());
204     SetMaxSize(aPipeLine->GetMaxSize());
205     SetMagnification(aPipeLine->GetMagnification());
206     SetMagnificationIncrement(aPipeLine->GetMagnificationIncrement());
207     SetAlphaThreshold(aPipeLine->GetAlphaThreshold());
208     SetResolution(aPipeLine->GetResolution());
209
210     SetIsDeformed( aPipeLine->GetIsDeformed() );
211     SetScale( aPipeLine->GetScale() );
212
213     vtkFloatingPointType aRadius = aPipeLine->mySphereSource->GetRadius();
214     if(!VISU::CheckIsSameValue(mySphereSource->GetRadius(), aRadius))
215       mySphereSource->SetRadius( aRadius );
216
217     CopyGlyph( aPipeLine->myGlyph, this->myGlyph );
218   }
219 }
220
221
222 //----------------------------------------------------------------------------
223 VISU_OpenGLPointSpriteMapper* 
224 VISU_GaussPointsPL
225 ::GetPointSpriteMapper()
226 {
227   return GetPointSpriteMapperHolder()->GetPointSpriteMapper();
228 }
229
230
231 //----------------------------------------------------------------------------
232 vtkPolyData* 
233 VISU_GaussPointsPL
234 ::GetPickableDataSet()
235 {
236   return myPassFilter[1]->GetPolyDataOutput();
237 }
238
239
240 //----------------------------------------------------------------------------
241 void
242 VISU_GaussPointsPL
243 ::Init()
244 {
245   Superclass::Init();
246
247   SetExtractInside(false);
248
249   vtkDataSet* aDataSet = GetParentMesh();
250   vtkFloatingPointType aScaleFactor = VISU_DeformedShapePL::GetScaleFactor( aDataSet );
251
252   vtkFloatingPointType* aScalarRange = GetScalarRange();
253   static double EPS = 1.0 / VTK_LARGE_FLOAT;
254   if(fabs(aScalarRange[1]) > EPS)
255     SetScale( aScaleFactor / aScalarRange[1] );
256   else
257     SetScale(0.0);
258 }
259
260
261 //----------------------------------------------------------------------------
262 void
263 VISU_GaussPointsPL
264 ::Build()
265 {
266   Superclass::Build();
267
268   SetSourceGeometry();
269
270   vtkDataSet* aDataSet = GetFieldTransformFilter()->GetOutput();
271   
272   myMergeFilter->SetGeometry(myAppendFilter->GetOutput());
273   
274   myMergeFilter->SetScalars(aDataSet);
275   myMergeFilter->SetVectors(aDataSet);
276   
277   myMergeFilter->RemoveFields();
278   myMergeFilter->AddField("VISU_FIELD", aDataSet);
279   myMergeFilter->AddField("VISU_POINTS_MAPPER", aDataSet);
280   myMergeFilter->AddField("VISU_INPUTS_MAPPER", aDataSet);
281   myMergeFilter->AddField("VISU_CELLS_MAPPER", aDataSet);
282
283   myMergeFilter->SetGaussPtsIDMapper(GetGaussPtsIDMapper());
284   
285   myPassFilter[0]->SetInput(InsertCustomPL());
286
287   myPassFilter[1]->SetInput(myPassFilter[0]->GetOutput());
288
289   // Geometrical Sphere
290   myPassFilter[2]->SetInput(myPassFilter[1]->GetOutput());
291   
292   GetPointSpriteMapper()->SetInput( myPassFilter[2]->GetPolyDataOutput() );
293
294   // Update according the current state
295   SetIsDeformed(GetIsDeformed());
296
297   SetPrimitiveType(GetPrimitiveType());
298 }
299
300
301 //----------------------------------------------------------------------------
302 void
303 VISU_GaussPointsPL
304 ::Update()
305 {
306   if(IsExternalGeometryUsed() || GetNumberOfGeometry() > 1 ){
307     myMergeFilter->Update();
308     myPassFilter[0]->SetInput(myMergeFilter->GetOutput());
309   }
310   else{
311     myPassFilter[0]->SetInput(GetFieldTransformFilter()->GetOutput());
312   }
313
314   SetAverageCellSize( VISU_DeformedShapePL::GetScaleFactor( GetParentMesh() ) );
315
316   this->UpdateGlyph();
317
318   Superclass::Update();
319
320 }
321
322
323 //----------------------------------------------------------------------------
324 unsigned long int
325 VISU_GaussPointsPL
326 ::GetMemorySize()
327 {
328   unsigned long int aSize = Superclass::GetMemorySize();
329   
330   if(GetIsDeformed())
331     if(vtkDataSet* aDataSet = myWarpVector->GetOutput())
332       aSize += aDataSet->GetActualMemorySize() * 1024;
333
334   if(GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere)
335     if(vtkDataSet* aDataSet = myGlyph->GetOutput())
336       aSize += aDataSet->GetActualMemorySize() * 1024;
337
338   return aSize;
339 }
340
341
342 //----------------------------------------------------------------------------
343 void
344 VISU_GaussPointsPL
345 ::UpdateGlyph()
346 {
347   vtkFloatingPointType* aScalarRange = GetScalarRange();
348
349   if( GetPointSpriteMapper()->GetPointSpriteMode() == 0 ) // Results
350   {
351     myGlyph->ClampingOn();
352     myGlyph->SetScaleModeToScaleByScalar();
353     myGlyph->SetColorModeToColorByScalar();
354
355     vtkFloatingPointType aScaleFactor = 0.0;
356     vtkFloatingPointType aMinSize = GetMinSize();
357     vtkFloatingPointType aMaxSize = GetMaxSize();
358     if(!VISU::CheckIsSameValue(aMaxSize, aMinSize))
359       aScaleFactor = ( aScalarRange[1] - aScalarRange[0] ) / ( aMaxSize - aMinSize );
360     
361     vtkFloatingPointType aMinRange = aScalarRange[0] - aMinSize * aScaleFactor;
362     vtkFloatingPointType aMaxRange = aMinRange + aScaleFactor;
363     vtkFloatingPointType aRange[2] = {aMinRange, aMaxRange};
364
365     if(!VISU::CheckIsSameRange(myGlyph->GetRange(), aRange))
366       myGlyph->SetRange( aRange );
367
368     if(!VISU::CheckIsSameValue(myGlyph->GetScaleFactor(), 1.0))
369       myGlyph->SetScaleFactor( 1.0 );
370   }
371   else if( GetPointSpriteMapper()->GetPointSpriteMode() == 1 ) // Geometry
372   {
373     myGlyph->ClampingOff();
374     myGlyph->SetScaleModeToDataScalingOff();
375     myGlyph->SetColorModeToColorByScale();
376
377     vtkFloatingPointType aScaleFactor = GetSize();
378     if(!VISU::CheckIsSameValue(myGlyph->GetScaleFactor(), aScaleFactor))
379       myGlyph->SetScaleFactor( aScaleFactor );
380   }
381   else if( GetPointSpriteMapper()->GetPointSpriteMode() == 2 ) // Outside
382   {
383     myGlyph->ClampingOff();
384     myGlyph->SetScaleModeToDataScalingOff();
385     myGlyph->SetColorModeToColorByScalar();
386
387     vtkFloatingPointType aScaleFactor = GetSize();
388     if(!VISU::CheckIsSameValue(myGlyph->GetScaleFactor(), aScaleFactor))
389       myGlyph->SetScaleFactor( aScaleFactor );
390   }
391
392   vtkFloatingPointType aRadius = GetMagnification() * GetAverageCellSize() / 2.0;
393   if(!VISU::CheckIsSameValue(mySphereSource->GetRadius(), aRadius))
394     mySphereSource->SetRadius( aRadius );
395 }
396
397
398 //----------------------------------------------------------------------------
399 VISU::TGaussPointID 
400 VISU_GaussPointsPL
401 ::GetObjID(vtkIdType theID)
402 {
403   return GetGaussPtsIDMapper()->GetObjID(theID);
404 }
405
406
407 //----------------------------------------------------------------------------
408 void
409 VISU_GaussPointsPL
410 ::SetIsDeformed( bool theIsDeformed )
411 {
412   if(theIsDeformed){
413     myWarpVector->SetInput( myPassFilter[0]->GetPolyDataOutput() );
414     myPassFilter[1]->SetInput(myWarpVector->GetOutput());
415   }else
416     myPassFilter[1]->SetInput(myPassFilter[0]->GetOutput());
417 }
418
419 //----------------------------------------------------------------------------
420 bool
421 VISU_GaussPointsPL
422 ::GetIsDeformed()
423 {
424   return myPassFilter[1]->GetInput() != myPassFilter[0]->GetOutput();
425 }
426
427 //----------------------------------------------------------------------------
428 void
429 VISU_GaussPointsPL
430 ::SetBicolor(bool theBicolor)
431 {
432   if(GetBicolor() == theBicolor)
433     return;
434
435   GetMapperTable()->SetBicolor( theBicolor );
436   GetBarTable()->SetBicolor( theBicolor );
437 }
438
439 //----------------------------------------------------------------------------
440 bool
441 VISU_GaussPointsPL
442 ::GetBicolor()
443 {
444   return GetMapperTable()->GetBicolor();
445 }
446
447 //----------------------------------------------------------------------------
448 void
449 VISU_GaussPointsPL
450 ::SetIsColored(bool theIsColored)
451 {
452   GetPointSpriteMapper()->SetPointSpriteMode( theIsColored ? 0 : 1 ); // Results / Geometry
453 }
454
455 //----------------------------------------------------------------------------
456 bool
457 VISU_GaussPointsPL
458 ::GetIsColored()
459 {
460   return GetPointSpriteMapper()->GetPointSpriteMode() == 0;
461 }
462
463 //----------------------------------------------------------------------------
464 void
465 VISU_GaussPointsPL
466 ::SetPrimitiveType(int thePrimitiveType)
467 {
468   if( thePrimitiveType == VISU_OpenGLPointSpriteMapper::GeomSphere )
469   {
470     myGlyph->SetInput( myPassFilter[1]->GetOutput() );
471     myPassFilter[2]->SetInput(myGlyph->GetOutput());
472   }
473   else
474     myPassFilter[2]->SetInput(myPassFilter[1]->GetOutput());
475
476   GetPointSpriteMapper()->SetPrimitiveType( thePrimitiveType );
477   
478   myPrimitiveType = thePrimitiveType;
479 }
480
481
482 //----------------------------------------------------------------------------
483 int
484 VISU_GaussPointsPL
485 ::GetPrimitiveType()
486 {    
487   return myPrimitiveType;
488 }
489
490
491 //----------------------------------------------------------------------------
492 vtkFloatingPointType
493 VISU_GaussPointsPL
494 ::GetMaximumSupportedSize()
495 {
496   return GetPointSpriteMapper()->GetMaximumSupportedSize();
497 }
498
499
500 //----------------------------------------------------------------------------
501 void
502 VISU_GaussPointsPL
503 ::SetClamp(vtkFloatingPointType theClamp)
504 {
505   GetPointSpriteMapper()->SetPointSpriteClamp( theClamp );
506 }
507
508
509 //----------------------------------------------------------------------------
510 vtkFloatingPointType
511 VISU_GaussPointsPL
512 ::GetClamp()
513 {
514   return GetPointSpriteMapper()->GetPointSpriteClamp();
515 }
516
517 //----------------------------------------------------------------------------
518 void
519 VISU_GaussPointsPL
520 ::SetSize(vtkFloatingPointType theSize)
521 {
522   GetPointSpriteMapper()->SetPointSpriteSize( theSize );
523 }
524
525
526 //----------------------------------------------------------------------------
527 vtkFloatingPointType
528 VISU_GaussPointsPL
529 ::GetSize()
530 {
531   return GetPointSpriteMapper()->GetPointSpriteSize();
532 }
533
534
535 //----------------------------------------------------------------------------
536 void
537 VISU_GaussPointsPL
538 ::SetMinSize(vtkFloatingPointType theMinSize)
539 {
540   GetPointSpriteMapper()->SetPointSpriteMinSize( theMinSize );
541 }
542
543
544 //----------------------------------------------------------------------------
545 vtkFloatingPointType
546 VISU_GaussPointsPL
547 ::GetMinSize()
548 {
549   return GetPointSpriteMapper()->GetPointSpriteMinSize();
550 }
551
552
553 //----------------------------------------------------------------------------
554 void
555 VISU_GaussPointsPL
556 ::SetMaxSize(vtkFloatingPointType theMaxSize)
557 {
558   GetPointSpriteMapper()->SetPointSpriteMaxSize( theMaxSize );
559 }
560
561
562 //----------------------------------------------------------------------------
563 vtkFloatingPointType
564 VISU_GaussPointsPL
565 ::GetMaxSize()
566 {
567   return GetPointSpriteMapper()->GetPointSpriteMaxSize();
568 }
569
570
571 //----------------------------------------------------------------------------
572 void
573 VISU_GaussPointsPL
574 ::SetMagnification(vtkFloatingPointType theMagnification)
575 {
576   GetPointSpriteMapper()->SetPointSpriteMagnification( theMagnification );
577 }
578
579
580 //----------------------------------------------------------------------------
581 vtkFloatingPointType
582 VISU_GaussPointsPL
583 ::GetMagnification()
584 {
585   return GetPointSpriteMapper()->GetPointSpriteMagnification();
586 }
587
588
589 //----------------------------------------------------------------------------
590 void
591 VISU_GaussPointsPL
592 ::SetMagnificationIncrement(vtkFloatingPointType theIncrement)
593 {
594   if(VISU::CheckIsSameValue(myMagnificationIncrement, theIncrement))
595     return;
596
597   myMagnificationIncrement = theIncrement;
598   Modified();
599 }
600
601
602 //----------------------------------------------------------------------------
603 void
604 VISU_GaussPointsPL
605 ::SetAlphaThreshold(vtkFloatingPointType theAlphaThreshold)
606 {
607   GetPointSpriteMapper()->SetPointSpriteAlphaThreshold( theAlphaThreshold );
608 }
609
610
611 //----------------------------------------------------------------------------
612 vtkFloatingPointType
613 VISU_GaussPointsPL
614 ::GetAlphaThreshold()
615 {
616   return GetPointSpriteMapper()->GetPointSpriteAlphaThreshold();
617 }
618
619
620 //----------------------------------------------------------------------------
621 void
622 VISU_GaussPointsPL
623 ::SetResolution(int theResolution)
624 {
625   mySphereSource->SetThetaResolution( theResolution );
626   mySphereSource->SetPhiResolution( theResolution );
627 }
628
629
630 //----------------------------------------------------------------------------
631 int
632 VISU_GaussPointsPL
633 ::GetResolution()
634 {
635   return mySphereSource->GetThetaResolution();
636 }
637
638
639 //----------------------------------------------------------------------------
640 void
641 VISU_GaussPointsPL
642 ::ChangeMagnification( bool up )
643 {
644   vtkFloatingPointType anIncrement = up ? myMagnificationIncrement : 1.0 / myMagnificationIncrement;
645   SetMagnification( GetMagnification() * anIncrement );
646 }
647
648
649 //----------------------------------------------------------------------------
650 vtkFloatingPointType
651 VISU_GaussPointsPL
652 ::GetPointSize(vtkIdType theID, vtkDataArray* theScalarArray)
653 {
654   vtkFloatingPointType aMaxSize = GetAverageCellSize() * GetMaxSize();
655   vtkFloatingPointType aMinSize = GetAverageCellSize() * GetMinSize();
656   vtkFloatingPointType aDelta = aMaxSize - aMinSize;
657   vtkFloatingPointType aVal = theScalarArray->GetTuple1(theID);
658
659   vtkFloatingPointType* aScalarRange = GetScalarRange();
660   vtkFloatingPointType aDeltaScalarRange = aScalarRange[1] - aScalarRange[0];
661
662   return aMinSize + aDelta*(aVal - aScalarRange[0]) / aDeltaScalarRange;
663 }
664
665
666 //----------------------------------------------------------------------------
667 vtkFloatingPointType
668 VISU_GaussPointsPL
669 ::GetMaxPointSize()
670 {
671   return GetAverageCellSize() * GetMaxSize();
672 }
673
674
675 //----------------------------------------------------------------------------
676 vtkFloatingPointType
677 VISU_GaussPointsPL
678 ::GetPointSize(vtkIdType theID)
679 {
680   vtkMapper* aMapper = GetMapper();
681   vtkDataSet* aDataSet = aMapper->GetInput();
682   vtkPointData* aPointData = aDataSet->GetPointData();
683   vtkDataArray* aScalarArray = aPointData->GetScalars();
684   return GetPointSize(theID, aScalarArray);
685 }
686
687
688 //----------------------------------------------------------------------------
689 void
690 VISU_GaussPointsPL
691 ::SetAverageCellSize(vtkFloatingPointType theAverageCellSize)
692 {
693   GetPointSpriteMapper()->SetAverageCellSize( theAverageCellSize );
694 }
695
696
697 //----------------------------------------------------------------------------
698 vtkFloatingPointType
699 VISU_GaussPointsPL
700 ::GetAverageCellSize()
701 {
702   return GetPointSpriteMapper()->GetAverageCellSize();
703 }
704
705
706 //----------------------------------------------------------------------------
707 void
708 VISU_GaussPointsPL
709 ::SetImageData(vtkImageData* theImageData)
710 {
711   GetPointSpriteMapper()->SetImageData( theImageData );
712 }
713
714
715 //----------------------------------------------------------------------------
716 vtkSmartPointer<vtkImageData>
717 VISU_GaussPointsPL
718 ::MakeTexture( const char* theMainTexture, 
719                const char* theAlphaTexture )
720 {
721   if( !theMainTexture || !theAlphaTexture )
722     return 0;
723
724   vtkXMLImageDataReader* aMainReader = vtkXMLImageDataReader::New();
725   vtkXMLImageDataReader* anAlphaReader = vtkXMLImageDataReader::New();
726
727   aMainReader->SetFileName( theMainTexture );
728   anAlphaReader->SetFileName( theAlphaTexture );
729
730   aMainReader->Update();
731   anAlphaReader->Update();
732
733   vtkImageData* aMainImageData = aMainReader->GetOutput();
734   vtkImageData* anAlphaImageData = anAlphaReader->GetOutput();
735
736   int* aMainImageSize = aMainImageData->GetDimensions();
737   int* anAlphaImageSize = anAlphaImageData->GetDimensions();
738   if(aMainImageSize[0] != anAlphaImageSize[0] || aMainImageSize[1] != anAlphaImageSize[1])
739     return NULL;
740
741   vtkSmartPointer<vtkImageData> aCompositeImageData = vtkImageData::New();
742   aCompositeImageData->Delete();
743
744   int aNbCompositeComponents = 4;
745   aCompositeImageData->SetDimensions(aMainImageSize);
746   aCompositeImageData->SetScalarTypeToUnsignedChar();        
747   aCompositeImageData->SetNumberOfScalarComponents(aNbCompositeComponents);
748   aCompositeImageData->AllocateScalars();
749
750   unsigned char* aMainDataPtr = (unsigned char*)aMainImageData->GetScalarPointer();
751   unsigned char* anAlphaDataPtr = (unsigned char*)anAlphaImageData->GetScalarPointer();
752   unsigned char *aCompositeDataPtr = (unsigned char * )aCompositeImageData->GetScalarPointer();
753
754   int aNbMainComponents = aMainImageData->GetNumberOfScalarComponents();
755   int aNbAlphaComponents = anAlphaImageData->GetNumberOfScalarComponents();
756   int aCompositeSize = aMainImageSize[0] * aMainImageSize[1] * aNbCompositeComponents;
757   
758   int aMainId = 0, anAlphaId = 0, aCompositeId = 0;
759   for(; aCompositeId < aCompositeSize;)
760   {
761     aCompositeDataPtr[aCompositeId] = aMainDataPtr[aMainId];
762     aCompositeDataPtr[aCompositeId + 1] = aMainDataPtr[aMainId + 1];
763     aCompositeDataPtr[aCompositeId + 2] = aMainDataPtr[aMainId + 2];
764     aCompositeDataPtr[aCompositeId + 3] = anAlphaDataPtr[anAlphaId];
765
766     aMainId += aNbMainComponents;
767     anAlphaId += aNbAlphaComponents;
768     aCompositeId += aNbCompositeComponents;
769   }
770   aMainReader->Delete();
771   anAlphaReader->Delete();
772   aCompositeImageData->Update();
773
774   return aCompositeImageData;
775 }
776
777
778 void
779 VISU_GaussPointsPL
780 ::SetScale( vtkFloatingPointType theScale )
781 {
782   if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), theScale))
783     return;
784
785   myWarpVector->SetScaleFactor( theScale );
786   myScaleFactor = theScale;
787 }
788
789
790 vtkFloatingPointType 
791 VISU_GaussPointsPL
792 ::GetScale()
793 {
794   return myWarpVector->GetScaleFactor();
795 }
796
797
798 void
799 VISU_GaussPointsPL
800 ::SetMapScale( vtkFloatingPointType theMapScale )
801 {
802   Superclass::SetMapScale( theMapScale );
803
804   vtkFloatingPointType aMapScale = myScaleFactor * theMapScale;
805   if(VISU::CheckIsSameValue(myWarpVector->GetScaleFactor(), aMapScale))
806     return;
807
808   myWarpVector->SetScaleFactor( aMapScale );
809 }
810
811 void
812 VISU_GaussPointsPL
813 ::SetSourceGeometry()
814 {
815   if(IsExternalGeometryUsed()){
816     ClearGeometry();
817     myAppendFilter->AddInput(GetFieldTransformFilter()->GetOutput());
818   }
819 }
820
821 vtkDataSet* 
822 VISU_GaussPointsPL
823 ::InsertCustomPL()
824 {
825   return GetMergedInput();
826 }
827
828 int
829 VISU_GaussPointsPL
830 ::AddGeometry(vtkDataSet* theGeometry)
831 {
832   myAppendFilter->AddInput(theGeometry);
833   return GetNumberOfGeometry();
834 }
835
836 vtkDataSet*
837 VISU_GaussPointsPL
838 ::GetGeometry(int theGeomNumber)
839 {
840   return vtkDataSet::SafeDownCast(myAppendFilter->GetInput(theGeomNumber));
841 }
842
843 int
844 VISU_GaussPointsPL
845 ::GetNumberOfGeometry()
846 {
847   return myAppendFilter->GetNumberOfInputConnections(0);
848 }
849
850 bool
851 VISU_GaussPointsPL
852 ::IsExternalGeometryUsed()
853 {
854   return myAppendFilter->GetInput() != GetFieldTransformFilter()->GetOutput();
855 }
856
857 void
858 VISU_GaussPointsPL
859 ::ClearGeometry()
860 {
861   myAppendFilter->RemoveAllInputs();
862 }
863
864 vtkPointSet* 
865 VISU_GaussPointsPL
866 ::GetMergedInput()
867 {
868   if(myMergeFilter->GetInput())
869     myMergeFilter->Update();
870   return myMergeFilter->GetOutput();
871 }