mySources[5]->SetCenter(0.0, 0.0, -aDisplacement);
}
-
-//----------------------------------------------------------------------------
-#include <vtkViewport.h>
-#include <vtkWindow.h>
-#include <vtkProp.h>
-#include <vtkPolyData.h>
-#include <vtkPolyDataMapper2D.h>
-#include <vtkActor2D.h>
-#include <vtkTimeStamp.h>
-#include <vtkTextProperty.h>
-#include <vtkTextActor.h>
-#include <vtkTextMapper.h>
-#include <vtkPoints.h>
-#include <vtkCellArray.h>
-#include <vtkProperty2D.h>
-//==================================================================
-vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$");
-vtkStandardNewMacro(VISU_FramedTextActor);
-
-//==================================================================
-// function : VISU_FramedTextActor
-// purpose :
-//==================================================================
-VISU_FramedTextActor::VISU_FramedTextActor()
-{
- PositionCoordinate->SetCoordinateSystemToNormalizedViewport();
-
- myTransparency=0.;
- myBar = vtkPolyData::New();
- myBarMapper = vtkPolyDataMapper2D::New();
- myBarMapper->SetInput(myBar);
- myBarActor = vtkActor2D::New();
- myBarActor->SetMapper(myBarMapper);
- myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
- myBarActor->GetProperty()->SetColor(.5, .5, .5);
- //
- myTextProperty = vtkTextProperty::New();
- myTextProperty->SetFontSize(12);
- myTextProperty->SetBold(0);
- myTextProperty->SetItalic(0);
- myTextProperty->SetShadow(1);
- myTextProperty->SetFontFamilyToArial();
- //
- myTextMapper=vtkTextMapper::New();
- myTextMapper->SetInput("");
- myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
- myTextActor=vtkActor2D::New();
- myTextActor->SetMapper(myTextMapper);
- //
- myBarActor->SetVisibility(1);
- myTextActor->SetVisibility(1);
- myBarActor->SetPickable(0);
- myTextActor->SetPickable(0);
- //----------------------------------------------------------
- myModePosition=0;// 0 -centered below the point
- // 1 -top left corner of the 3D view window
- //
- for(int i=0; i<4; i++) {
- myWorldPoint[i] = 0.;
- }
- myDistance=10.;
- //
-}
-//==================================================================
-// function : ~
-// purpose :
-//==================================================================
-VISU_FramedTextActor::~VISU_FramedTextActor()
-{
- myTextActor->Delete();
- myTextMapper->Delete();
- myTextProperty->Delete();
- myBarActor->Delete();
- myBarMapper->Delete();
- myBar->Delete();
-}
-//==================================================================
-// function : SetVisibility
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetVisibility (int theVisibility)
-{
- myBarActor->SetVisibility(theVisibility);
- myTextActor->SetVisibility(theVisibility);
-}
-//==================================================================
-// function : GetVisibility
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::GetVisibility()
-{
- return myBarActor->GetVisibility();
-}
-//==================================================================
-// function : SetPickable
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetPickable (int thePickability)
-{
- myBarActor->SetPickable(thePickability);
- myTextActor->SetPickable(thePickability);
-}
-//==================================================================
-// function : GetPickable
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::GetPickable()
-{
- return myBarActor->GetPickable();
-}
-//==================================================================
-// function : SetTransparency
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetTransparency(const vtkFloatingPointType theTransparency)
-{
- if (theTransparency>=0. && theTransparency<=1.){
- myTransparency=theTransparency;
- myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
- Modified();
- }
-}
-//==================================================================
-// function : GetTransparency
-// purpose :
-//==================================================================
-vtkFloatingPointType VISU_FramedTextActor::GetTransparency()const
-{
- return myTransparency;
-}
-//==================================================================
-// function : SetText
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetText(const char* theText)
-{
- myTextMapper->SetInput(theText);
- Modified();
-}
-//==================================================================
-// function : GetText
-// purpose :
-//==================================================================
-char* VISU_FramedTextActor::GetText()
-{
- return myTextMapper->GetInput();
-}
-//==================================================================
-// function : SetModePosition
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetModePosition(const int theMode)
-{
- myModePosition=theMode;
- Modified();
-}
-//==================================================================
-// function : GetModePosition
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::GetModePosition()const
-{
- return myModePosition;
-}
-//==================================================================
-// function : SetWorldPoint
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetWorldPoint(const vtkFloatingPointType theWorldPoint[4])
-{
- for(int i = 0; i<4; ++i) {
- myWorldPoint[i] = theWorldPoint[i];
- }
- Modified();
-}
-//==================================================================
-// function : GetWorldPoint
-// purpose :
-//==================================================================
-const vtkFloatingPointType* VISU_FramedTextActor::GetWorldPoint()const
-{
- return myWorldPoint;
-}
-//==================================================================
-// function : SetDistance
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::SetDistance(const vtkFloatingPointType theDistance)
-{
- myDistance=theDistance;
-}
-//==================================================================
-// function : GetDistance
-// purpose :
-//==================================================================
-vtkFloatingPointType VISU_FramedTextActor::GetDistance()const
-{
- return myDistance;
-}
-//==================================================================
-// function : ReleaseGraphicsResources
-// purpose :
-//==================================================================
-void VISU_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win)
-{
- myTextActor->ReleaseGraphicsResources(win);
- myBarActor->ReleaseGraphicsResources(win);
-}
-//==================================================================
-// function : RenderOverlay
-// purpose :
-//==================================================================
-int VISU_FramedTextActor::RenderOverlay(vtkViewport *viewport)
-{
- int renderedSomething = 0;
- myBarActor->RenderOverlay(viewport);
- renderedSomething +=myTextActor->RenderOverlay(viewport);
- return renderedSomething;
-}
-//==================================================================
-// function : RenderOpaqueGeometry
-// purpose :
-//==================================================================
-int
-VISU_FramedTextActor
-::RenderOpaqueGeometry(vtkViewport *theViewport)
-{
- int anIsRenderedSomething = 0;
- int* aViewportSize = theViewport->GetSize();
- if(aViewportSize[0] == 1 || aViewportSize[1] == 1)
- return anIsRenderedSomething;
-
- myBar->Initialize();
-
- int aNbPoints = 4;
- vtkPoints *aPoints = vtkPoints::New();
- aPoints->SetNumberOfPoints(aNbPoints);
- myBar->SetPoints(aPoints);
- aPoints->Delete();
-
- vtkCellArray *aPolys = vtkCellArray::New();
- aPolys->Allocate(aPolys->EstimateSize(1,4));
- vtkIdType aPointsIds[4] = {0, 1, 3, 2};
- aPolys->InsertNextCell(4,aPointsIds);
- myBar->SetPolys(aPolys);
- aPolys->Delete();
-
- int aTextSize[2];
- myTextMapper->GetSize(theViewport, aTextSize);
- int aBarWidth = aTextSize[0];
- int aBarHeight = aTextSize[1];
-
- if (myModePosition==0) {
- theViewport->SetWorldPoint(myWorldPoint);
- theViewport->WorldToDisplay();
-
- vtkFloatingPointType aSelectionPoint[3];
- theViewport->GetDisplayPoint(aSelectionPoint);
- vtkFloatingPointType u = aSelectionPoint[0];
- vtkFloatingPointType v = aSelectionPoint[1] - myDistance;
- theViewport->ViewportToNormalizedViewport(u, v);
- PositionCoordinate->SetValue(u, v);
- //
- myTextProperty->SetJustificationToCentered();
- myTextProperty->SetVerticalJustificationToTop();
- //
- aBarWidth /= 2;
- aPoints->SetPoint(0, -aBarWidth, 0.0, 0.0);
- aPoints->SetPoint(1, -aBarWidth, -aBarHeight, 0.0);
- aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
- aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
- }
- else {//if (myModePosition==1) {
- PositionCoordinate->SetValue(0.0, 1.0);
- myTextProperty->SetJustificationToLeft();
- myTextProperty->SetVerticalJustificationToTop();
- //
- aPoints->SetPoint(0, 0.0, 0.0, 0.0);
- aPoints->SetPoint(1, 0.0, -aBarHeight, 0.0);
- aPoints->SetPoint(2, aBarWidth, 0.0, 0.0);
- aPoints->SetPoint(3, aBarWidth, -aBarHeight, 0.0);
- }
- //
- myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
- myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
- myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
- //
- myBuildTime.Modified();
- //
- return anIsRenderedSomething;
-}