]> SALOME platform Git repositories - modules/visu.git/blob - src/OBJECT/VISU_GaussPtsDeviceActor.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / OBJECT / VISU_GaussPtsDeviceActor.cxx
1 //  SMESH OBJECT : interactive object for SMESH visualization
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   :
25 //  Author : 
26 //  Module :
27 //  $Header$
28
29
30 #include "VISU_GaussPtsDeviceActor.h"
31
32 #include "VISU_GaussPointsPL.hxx"
33 #include "VISU_OpenGLPointSpriteMapper.hxx"
34
35 #include "VTKViewer_Transform.h"
36 #include "VTKViewer_TransformFilter.h"
37
38 #include <vtkObjectFactory.h>
39 #include <vtkPolyData.h>
40 #include <vtkRenderer.h>
41 #include <vtkTextProperty.h>
42 #include <vtkProperty.h>
43 #include <vtkTexture.h>
44 #include <vtkPassThroughFilter.h>
45 #include <vtkImageData.h>
46
47 #include <qfileinfo.h>
48
49 #include "utilities.h"
50 #include "VISU_PipeLineUtils.hxx"
51
52 #ifdef _DEBUG_
53 static int MYDEBUG = 0;
54 #else
55 static int MYDEBUG = 0;
56 #endif
57
58
59 //----------------------------------------------------------------
60 namespace VISU
61 {
62   inline
63   std::string
64   Image2VTI(const std::string& theImageFileName)
65   {
66     QFileInfo aFileInfo(theImageFileName.c_str());
67     QString aFormat = aFileInfo.extension(FALSE);
68 #ifdef WIN32
69     QString aTmpDir = getenv( "TEMP" );
70 #else
71     QString aTmpDir = QString( "/tmp/" ) + getenv("USER");
72 #endif
73     QString aVTIName = aTmpDir + "-" + aFileInfo.baseName(TRUE) + ".vti";
74     QString aCommand = QString( "VISU_img2vti " ) + aFormat + " " +  theImageFileName + " " + aVTIName;
75
76     if(system( aCommand.latin1() ) == 0)
77       return aVTIName.latin1();
78
79     return "";
80   }
81
82   inline
83   void
84   RemoveFile(const std::string& theFileName)
85   {
86     if( theFileName != "" ){
87 #ifndef WNT
88       QString aCommand = QString( "rm -fr " ) + theFileName.c_str();
89 #else
90       QString aCommand = QString( "del /F " ) + theFileName.c_str();
91 #endif
92       system( aCommand.latin1() );
93     }
94   }
95   
96   
97   TTextureValue
98   GetTexture(const std::string& theMainTexture, 
99              const std::string& theAlphaTexture)
100   {
101     typedef std::pair<std::string,std::string> TTextureKey;
102     typedef std::map<TTextureKey,TTextureValue> TTextureMap;
103     
104     static TTextureMap aTextureMap;
105     
106     TTextureValue aTextureValue;
107     TTextureKey aTextureKey( theMainTexture.c_str(), theAlphaTexture.c_str() );
108     TTextureMap::const_iterator anIter = aTextureMap.find( aTextureKey );
109     if ( anIter != aTextureMap.end() ) {
110       aTextureValue = anIter->second;
111     } else {
112       QString aMainTextureVTI = Image2VTI(theMainTexture);
113       QString anAlphaTextureVTI = Image2VTI(theAlphaTexture);
114       
115       if( !aMainTextureVTI.isNull() && !anAlphaTextureVTI.isNull() ){
116         aTextureValue =
117           VISU_GaussPointsPL::MakeTexture( aMainTextureVTI.latin1(), 
118                                            anAlphaTextureVTI.latin1());
119
120         if( aTextureValue.GetPointer() )
121           aTextureMap[aTextureKey] = aTextureValue;
122       }
123
124       RemoveFile(aMainTextureVTI);
125       RemoveFile(anAlphaTextureVTI);
126     }
127
128     return aTextureValue;
129   }
130 }
131
132
133 //----------------------------------------------------------------
134 vtkStandardNewMacro(VISU_GaussDeviceActorBase);
135
136
137 VISU_GaussDeviceActorBase
138 ::VISU_GaussDeviceActorBase():
139   myTransformFilter(VTKViewer_TransformFilter::New())
140 {
141   if(MYDEBUG) MESSAGE("VISU_GaussDeviceActorBase - "<<this);
142
143   myTransformFilter->Delete();
144
145   for(int i = 0; i < 3; i++){
146     PPassThroughFilter aFilter(vtkPassThroughFilter::New());
147     myPassFilter.push_back(aFilter);
148     aFilter->Delete();
149   }
150 }
151
152
153 VISU_GaussDeviceActorBase
154 ::~VISU_GaussDeviceActorBase()
155 {
156   if(MYDEBUG) MESSAGE("~VISU_GaussDeviceActorBase - "<<this);
157 }
158
159
160 //----------------------------------------------------------------
161 void
162 VISU_GaussDeviceActorBase
163 ::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
164 {
165   if (this->Mapper == NULL)
166     {
167     vtkErrorMacro("No mapper for actor.");
168     return;
169     }
170   
171   // render the property
172   if (!this->Property)
173     {
174     // force creation of a property
175     this->GetProperty();
176     }
177   this->Property->Render(this, ren);
178   if (this->BackfaceProperty)
179     {
180     this->BackfaceProperty->BackfaceRender(this, ren);
181     this->Device->SetBackfaceProperty(this->BackfaceProperty);
182     }
183   this->Device->SetProperty(this->Property);  
184   
185   // render the texture
186   if (this->Texture)
187     {
188     this->Texture->Render(ren);
189     }
190   
191   // make sure the device has the same matrix
192   vtkMatrix4x4 *matrix = this->Device->GetUserMatrix();
193   this->GetMatrix(matrix);
194   
195   this->Device->Render(ren,Mapper);  
196   this->EstimatedRenderTime = Mapper->GetTimeToDraw();
197 }
198
199
200 //----------------------------------------------------------------
201 void
202 VISU_GaussDeviceActorBase
203 ::SetTransform(VTKViewer_Transform* theTransform)
204 {
205   myTransformFilter->SetTransform(theTransform);
206 }
207
208 //----------------------------------------------------------------
209 void
210 VISU_GaussDeviceActorBase
211 ::SetPointSpriteMapper(VISU_OpenGLPointSpriteMapper* theMapper) 
212 {
213   vtkPolyData* aDataSet = theMapper->GetInput();
214   myMapper = theMapper;
215
216   int anId = 0;
217   myPassFilter[ anId ]->SetInput( aDataSet ); 
218   myPassFilter[ anId + 1 ]->SetInput( myPassFilter[ anId ]->GetOutput() );
219   
220   anId++;
221   myTransformFilter->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
222   
223   anId++;
224   myPassFilter[ anId ]->SetInput( myTransformFilter->GetOutput() );
225   
226   myMapper->SetInput( myPassFilter[ anId ]->GetPolyDataOutput() );
227   
228   Superclass::SetMapper( theMapper );
229 }
230
231 void
232 VISU_GaussDeviceActorBase
233 ::DoMapperShallowCopy( vtkMapper* theMapper,
234                        bool theIsCopyInput )
235 {
236   VISU::CopyMapper( GetMapper(), theMapper, theIsCopyInput );
237 }
238
239 VISU_OpenGLPointSpriteMapper*
240 VISU_GaussDeviceActorBase
241 ::GetPointSpriteMapper()
242 {
243   return myMapper.GetPointer();
244 }
245
246 //----------------------------------------------------------------------------
247 unsigned long int
248 VISU_GaussDeviceActorBase
249 ::GetMemorySize()
250 {
251   vtkDataSet* aDataSet = GetMapper()->GetInput();
252   return aDataSet->GetActualMemorySize() * 1024;
253 }
254
255
256
257 //----------------------------------------------------------------
258 vtkStandardNewMacro(VISU_GaussPtsDeviceActor);
259
260
261 VISU_GaussPtsDeviceActor
262 ::VISU_GaussPtsDeviceActor()
263 {}
264
265
266 VISU_GaussPtsDeviceActor
267 ::~VISU_GaussPtsDeviceActor()
268 {}
269
270
271 //----------------------------------------------------------------------------
272 void
273 VISU_GaussPtsDeviceActor
274 ::AddToRender(vtkRenderer* theRenderer)
275 {
276   theRenderer->AddActor(this);
277 }
278
279 void 
280 VISU_GaussPtsDeviceActor
281 ::RemoveFromRender(vtkRenderer* theRenderer)
282 {
283   theRenderer->RemoveActor(this);
284 }
285
286
287 //----------------------------------------------------------------------------
288 void
289 VISU_GaussPtsDeviceActor
290 ::SetPipeLine(VISU_GaussPointsPL* thePipeLine) 
291 {
292   SetPointSpriteMapper( thePipeLine->GetPointSpriteMapper() );
293
294   myPipeLine = thePipeLine;
295 }
296
297 VISU_GaussPointsPL* 
298 VISU_GaussPtsDeviceActor
299 ::GetPipeLine() 
300
301   return myPipeLine.GetPointer();
302 }
303
304 void
305 VISU_GaussPtsDeviceActor
306 ::ShallowCopyPL(VISU_GaussPointsPL* thePipeLine)
307 {
308   myPipeLine->ShallowCopy(thePipeLine, true);
309 }
310
311
312 //----------------------------------------------------------------------------
313 int
314 VISU_GaussPtsDeviceActor
315 ::GetPickable()
316 {
317   if(Superclass::GetPickable()){
318     if(vtkMapper* aMapper = GetMapper()){
319       if(vtkDataSet* aDataSet= aMapper->GetInput()){
320         aDataSet->Update();
321         return aDataSet->GetNumberOfCells() > 0;
322       }
323     }
324   }
325
326   return false;
327 }
328
329
330 //----------------------------------------------------------------------------
331 unsigned long int
332 VISU_GaussPtsDeviceActor
333 ::GetMemorySize()
334 {
335   unsigned long int aSize = Superclass::GetMemorySize();
336
337   aSize += GetPipeLine()->GetMemorySize();
338
339   return aSize;
340 }
341
342
343
344 //============================================================================
345 #include <vtkActor.h>
346 #include <vtkProperty.h>
347 #include <vtkConeSource.h>
348 #include <vtkAppendPolyData.h>
349 #include <vtkPolyDataMapper.h>
350
351
352 //----------------------------------------------------------------------------
353 vtkStandardNewMacro(VISU_CursorPyramid);
354
355 //----------------------------------------------------------------------------
356 VISU_CursorPyramid
357 ::VISU_CursorPyramid():
358   myHeight(10.0),
359   myRadius(5.0),
360   myMagnification(1.0),
361   myClamp(256.0),
362   myNbCones(6),
363   myAppendFilter(vtkAppendPolyData::New()),
364   myMapper(vtkPolyDataMapper::New())
365 {
366   myAppendFilter->Delete();
367   myMapper->Delete();
368
369   myMapper->SetInput(myAppendFilter->GetOutput());
370
371   for(int i = 0; i < myNbCones; i++){
372     vtkConeSource* aConeSource = vtkConeSource::New();
373     myAppendFilter->AddInput(aConeSource->GetOutput());
374     aConeSource->SetResolution(4);
375     mySources[i] = aConeSource;
376     aConeSource->Delete();
377   }
378 }
379
380
381 //----------------------------------------------------------------------------
382 void
383 VISU_CursorPyramid
384 ::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m))
385 {
386   if (ren == NULL)
387     {
388     vtkErrorMacro("No mapper for actor.");
389     return;
390     }
391
392   this->SetScale(1.0);
393   vtkFloatingPointType aMRadius = myRadius*myMagnification;
394   Init(myHeight,aMRadius*myCursorSize);
395
396   if(myClamp > 0.0f){
397     vtkFloatingPointType aPoint1[3] = {0.0, 0.0, 0.0};
398     ren->SetDisplayPoint(aPoint1);
399     ren->DisplayToWorld();
400     ren->GetWorldPoint(aPoint1);
401
402     vtkFloatingPointType aPoint2[3] = {0.0, myClamp, 0.0};
403     ren->SetDisplayPoint(aPoint2);
404     ren->DisplayToWorld();
405     ren->GetWorldPoint(aPoint2);
406     
407     vtkFloatingPointType aWorldClamp = 
408       (aPoint2[0] - aPoint1[0])*(aPoint2[0] - aPoint1[0]) + 
409       (aPoint2[1] - aPoint1[1])*(aPoint2[1] - aPoint1[1]) + 
410       (aPoint2[2] - aPoint1[2])*(aPoint2[2] - aPoint1[2]); 
411     
412     aWorldClamp = sqrt(aWorldClamp);
413     vtkFloatingPointType aMDiameter = 2.0 * aMRadius;
414     vtkFloatingPointType aCoeff = aWorldClamp / aMDiameter;
415
416     if(aCoeff < 1.0){
417       this->SetScale(aCoeff);
418       //Init(myHeight/aCoeff,aMRadius*aCoeff);
419     }
420   }
421
422   if (this->Mapper == NULL)
423     {
424     vtkErrorMacro("No mapper for actor.");
425     return;
426     }
427   
428   // render the property
429   if (!this->Property)
430     {
431     // force creation of a property
432     this->GetProperty();
433     }
434   this->Property->Render(this, ren);
435   if (this->BackfaceProperty)
436     {
437     this->BackfaceProperty->BackfaceRender(this, ren);
438     this->Device->SetBackfaceProperty(this->BackfaceProperty);
439     }
440   this->Device->SetProperty(this->Property);  
441   
442   // render the texture
443   if (this->Texture)
444     {
445     this->Texture->Render(ren);
446     }
447   
448   // make sure the device has the same matrix
449   vtkMatrix4x4 *matrix = this->Device->GetUserMatrix();
450   this->GetMatrix(matrix);
451   
452   this->Device->Render(ren,Mapper);  
453   this->EstimatedRenderTime = Mapper->GetTimeToDraw();
454 }
455
456
457 //----------------------------------------------------------------------------
458 void
459 VISU_CursorPyramid
460 ::AddToRender(vtkRenderer* theRenderer)
461
462   theRenderer->AddActor(this);
463 }
464
465 void
466 VISU_CursorPyramid
467 ::RemoveFromRender(vtkRenderer* theRenderer)
468
469   theRenderer->RemoveActor(this);
470 }
471
472 //----------------------------------------------------------------------------
473 void 
474 VISU_CursorPyramid
475 ::SetPreferences(vtkFloatingPointType theHeight,
476                  vtkFloatingPointType theCursorSize)
477 {
478   Init(theHeight, theCursorSize, myRadius, myMagnification, myClamp, GetPosition(), GetProperty()->GetColor());
479 }
480
481 //----------------------------------------------------------------------------
482 void
483 VISU_CursorPyramid
484 ::Init(vtkFloatingPointType theHeight,
485        vtkFloatingPointType theCursorSize,
486        vtkFloatingPointType theRadius,
487        vtkFloatingPointType theMagnification,
488        vtkFloatingPointType theClamp,
489        vtkFloatingPointType thePos[3],
490        vtkFloatingPointType theColor[3])
491 {
492   Init(theHeight,theRadius*theMagnification*theCursorSize);
493   SetPosition(thePos[0],thePos[1],thePos[2]);
494   GetProperty()->SetColor(theColor);
495   SetMapper(myMapper.GetPointer());
496
497   myHeight = theHeight;
498   myCursorSize = theCursorSize;
499
500   myRadius = theRadius;
501   myMagnification = theMagnification;
502
503   myClamp = theClamp;
504 }
505
506
507 void
508 VISU_CursorPyramid
509 ::Init(vtkFloatingPointType theHeight,
510        vtkFloatingPointType theRadius)
511 {
512   for(int i = 0; i < myNbCones; ++i){
513     vtkConeSource* aSource = mySources[i].GetPointer();
514     aSource->SetHeight(theHeight);
515     // Set the angle of the cone. As a side effect, the angle plus height sets 
516     // the base radius of the cone.
517     aSource->SetAngle(20.0);
518   }
519   
520   vtkFloatingPointType aDisplacement = -0.5*theHeight - theRadius;
521   
522   // X
523   mySources[0]->SetDirection(1.0, 0.0, 0.0);
524   mySources[0]->SetCenter(aDisplacement, 0.0, 0.0);
525
526   // It is impossible to inverse direction around X axis (VTK bug)
527   mySources[1]->SetDirection(-VTK_LARGE_FLOAT, 1.0, 0.0); // A workaround
528   mySources[1]->SetCenter(-aDisplacement, 0.0, 0.0);
529   
530   // Y
531   mySources[2]->SetDirection(0.0, 1.0, 0.0);
532   mySources[2]->SetCenter(0.0, aDisplacement, 0.0);
533   
534   mySources[3]->SetDirection(0.0, -1.0, 0.0); 
535   mySources[3]->SetCenter(0.0, -aDisplacement, 0.0);
536   
537   // Z
538   mySources[4]->SetDirection(0.0, 0.0, 1.0); 
539   mySources[4]->SetCenter(0.0, 0.0, aDisplacement);
540   
541   mySources[5]->SetDirection(0.0, 0.0, -1.0); 
542   mySources[5]->SetCenter(0.0, 0.0, -aDisplacement);
543 }
544
545
546 //----------------------------------------------------------------------------
547 #include <vtkViewport.h>
548 #include <vtkWindow.h>
549 #include <vtkProp.h>
550 #include <vtkPolyData.h>
551 #include <vtkPolyDataMapper2D.h>
552 #include <vtkActor2D.h>
553 #include <vtkTimeStamp.h>
554 #include <vtkTextProperty.h>
555 #include <vtkTextActor.h>
556 #include <vtkTextMapper.h>
557 #include <vtkPoints.h>
558 #include <vtkCellArray.h>
559 #include <vtkProperty2D.h>
560 //==================================================================
561 vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$");
562 vtkStandardNewMacro(VISU_FramedTextActor);
563
564 //==================================================================
565 // function : VISU_FramedTextActor
566 // purpose  :
567 //==================================================================
568 VISU_FramedTextActor::VISU_FramedTextActor()
569 {
570   PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
571
572   myTransparency=0.;
573   myBar = vtkPolyData::New();
574   myBarMapper = vtkPolyDataMapper2D::New();
575   myBarMapper->SetInput(myBar);
576   myBarActor = vtkActor2D::New();
577   myBarActor->SetMapper(myBarMapper);
578   myBarActor->GetProperty()->SetOpacity(1.-myTransparency);  
579   myBarActor->GetProperty()->SetColor(.5, .5, .5); 
580   //
581   myTextProperty = vtkTextProperty::New();
582   myTextProperty->SetFontSize(12);
583   myTextProperty->SetBold(0);
584   myTextProperty->SetItalic(0);
585   myTextProperty->SetShadow(1);
586   myTextProperty->SetFontFamilyToArial();
587   //
588   myTextMapper=vtkTextMapper::New();
589   myTextMapper->SetInput("some text");
590   myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
591   myTextActor=vtkActor2D::New();
592   myTextActor->SetMapper(myTextMapper);
593   //
594   myBarActor->SetVisibility(1);
595   myTextActor->SetVisibility(1);
596   myBarActor->SetPickable(0);
597   myTextActor->SetPickable(0);
598   //----------------------------------------------------------
599   myModePosition=0;// 0 -centered below the point
600                    // 1 -top left corner of the 3D view window
601   //
602   for(int i=0; i<4; i++) {
603     myWorldPoint[i] = 0.;
604   }
605   myDistance=10.;
606   //
607 }
608 //==================================================================
609 // function : ~
610 // purpose  :
611 //==================================================================
612 VISU_FramedTextActor::~VISU_FramedTextActor()
613 {
614   myTextActor->Delete();
615   myTextMapper->Delete();
616   myTextProperty->Delete();
617   myBarActor->Delete();
618   myBarMapper->Delete();
619   myBar->Delete();
620 }
621 //==================================================================
622 // function : SetVisibility
623 // purpose  :
624 //==================================================================
625 void VISU_FramedTextActor::SetVisibility (int theVisibility)
626 {
627   myBarActor->SetVisibility(theVisibility);
628   myTextActor->SetVisibility(theVisibility);
629 }
630 //==================================================================
631 // function : GetVisibility
632 // purpose  :
633 //==================================================================
634 int VISU_FramedTextActor::GetVisibility() 
635 {
636   return myBarActor->GetVisibility();
637 }
638 //==================================================================
639 // function : SetPickable
640 // purpose  :
641 //==================================================================
642 void VISU_FramedTextActor::SetPickable (int thePickability) 
643 {
644   myBarActor->SetPickable(thePickability);
645   myTextActor->SetPickable(thePickability);
646 }
647 //==================================================================
648 // function : GetPickable
649 // purpose  :
650 //==================================================================
651 int VISU_FramedTextActor::GetPickable()
652 {
653   return myBarActor->GetPickable();
654 }
655 //==================================================================
656 // function : SetTransparency
657 // purpose  :
658 //==================================================================
659 void VISU_FramedTextActor::SetTransparency(const vtkFloatingPointType theTransparency)
660 {
661   if (theTransparency>=0.  && theTransparency<=1.){
662     myTransparency=theTransparency;
663     myBarActor->GetProperty()->SetOpacity(1.-myTransparency);  
664     Modified();
665   }
666 }
667 //==================================================================
668 // function : GetTransparency
669 // purpose  :
670 //==================================================================
671 vtkFloatingPointType VISU_FramedTextActor::GetTransparency()const
672 {
673   return myTransparency;
674 }
675 //==================================================================
676 // function : SetText
677 // purpose  :
678 //==================================================================
679 void VISU_FramedTextActor::SetText(const char* theText)
680 {
681   myTextMapper->SetInput(theText); 
682   Modified();
683 }
684 //==================================================================
685 // function : GetText
686 // purpose  :
687 //==================================================================
688 char* VISU_FramedTextActor::GetText()
689 {
690   return myTextMapper->GetInput();
691 }
692 //==================================================================
693 // function : SetModePosition
694 // purpose  :
695 //==================================================================
696 void VISU_FramedTextActor::SetModePosition(const int theMode)
697 {
698   myModePosition=theMode;
699   Modified();
700 }
701 //==================================================================
702 // function : GetModePosition
703 // purpose  :
704 //==================================================================
705 int VISU_FramedTextActor::GetModePosition()const
706 {
707   return myModePosition;
708 }
709 //==================================================================
710 // function : SetWorldPoint
711 // purpose  :
712 //==================================================================
713 void VISU_FramedTextActor::SetWorldPoint(const vtkFloatingPointType theWorldPoint[4])
714 {
715   for(int i = 0; i<4; ++i) {
716     myWorldPoint[i] = theWorldPoint[i];
717   } 
718   Modified();
719 }
720 //==================================================================
721 // function : GetWorldPoint
722 // purpose  :
723 //==================================================================
724 const vtkFloatingPointType* VISU_FramedTextActor::GetWorldPoint()const 
725 {
726   return myWorldPoint;
727 }
728 //==================================================================
729 // function : SetDistance
730 // purpose  :
731 //==================================================================
732 void VISU_FramedTextActor::SetDistance(const vtkFloatingPointType theDistance)
733 {
734   myDistance=theDistance;
735 }
736 //==================================================================
737 // function : GetDistance
738 // purpose  :
739 //==================================================================
740 vtkFloatingPointType VISU_FramedTextActor::GetDistance()const
741 {
742   return myDistance;
743 }
744 //==================================================================
745 // function : ReleaseGraphicsResources
746 // purpose  :
747 //==================================================================
748 void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win)
749 {
750   myTextActor->ReleaseGraphicsResources(win);
751   myBarActor->ReleaseGraphicsResources(win);
752 }
753 //==================================================================
754 // function : RenderOverlay
755 // purpose  :
756 //==================================================================
757 int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport)
758 {
759   int renderedSomething = 0;
760   myBarActor->RenderOverlay(viewport);
761   renderedSomething +=myTextActor->RenderOverlay(viewport);
762   return renderedSomething;
763 }
764 //==================================================================
765 // function : RenderOpaqueGeometry
766 // purpose  :
767 //==================================================================
768 int 
769 VISU_FramedTextActor
770 ::RenderOpaqueGeometry(vtkViewport *theViewport)
771 {
772   int anIsRenderedSomething = 0;
773   int* aViewportSize = theViewport->GetSize();
774   if(aViewportSize[0] == 1 || aViewportSize[1] == 1)
775     return anIsRenderedSomething;
776
777   myBar->Initialize();
778
779   int aNbPoints = 4;
780   vtkPoints *aPoints = vtkPoints::New();
781   aPoints->SetNumberOfPoints(aNbPoints);
782   myBar->SetPoints(aPoints);
783   aPoints->Delete();
784
785   vtkCellArray *aPolys = vtkCellArray::New();
786   aPolys->Allocate(aPolys->EstimateSize(1,4));
787   vtkIdType aPointsIds[4] = {0, 1, 3, 2};
788   aPolys->InsertNextCell(4,aPointsIds);
789   myBar->SetPolys(aPolys);
790   aPolys->Delete(); 
791
792   int aTextSize[2]; 
793   myTextMapper->GetSize(theViewport, aTextSize);
794   int aBarWidth = aTextSize[0];
795   int aBarHeight = aTextSize[1];
796
797   if (myModePosition==0) {
798     theViewport->SetWorldPoint(myWorldPoint);
799     theViewport->WorldToDisplay();
800
801     vtkFloatingPointType aSelectionPoint[3];
802     theViewport->GetDisplayPoint(aSelectionPoint);
803     vtkFloatingPointType u = aSelectionPoint[0];
804     vtkFloatingPointType v = aSelectionPoint[1] - myDistance;
805     theViewport->ViewportToNormalizedViewport(u, v);
806     PositionCoordinate->SetValue(u, v);
807     //
808     myTextProperty->SetJustificationToCentered();
809     myTextProperty->SetVerticalJustificationToTop();
810     //
811     aBarWidth /= 2;
812     aPoints->SetPoint(0, -aBarWidth,         0.0, 0.0);
813     aPoints->SetPoint(1, -aBarWidth, -aBarHeight, 0.0);
814     aPoints->SetPoint(2,  aBarWidth,         0.0, 0.0);
815     aPoints->SetPoint(3,  aBarWidth, -aBarHeight, 0.0);
816   }
817   else {//if (myModePosition==1) {
818     PositionCoordinate->SetValue(0.0, 1.0);
819     myTextProperty->SetJustificationToLeft();
820     myTextProperty->SetVerticalJustificationToTop();  
821     //
822     aPoints->SetPoint(0,        0.0,         0.0, 0.0);
823     aPoints->SetPoint(1,        0.0, -aBarHeight, 0.0);
824     aPoints->SetPoint(2,  aBarWidth,         0.0, 0.0);
825     aPoints->SetPoint(3,  aBarWidth, -aBarHeight, 0.0);
826   }
827   //
828   myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
829   myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
830   myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
831   //
832   myBuildTime.Modified();
833   //
834   return anIsRenderedSomething;
835 }