myActors[5]->SetOrientation(180., 0. ,0.);
}
+#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>
//==================================================================
-vtkStandardNewMacro(VISU_GPTextActor);
+vtkCxxRevisionMacro(VISU_FramedTextActor, "$Revision$");
+vtkStandardNewMacro(VISU_FramedTextActor);
+
//==================================================================
-// function :
+// function : VISU_FramedTextActor
// purpose :
//==================================================================
-VISU_GPTextActor::VISU_GPTextActor()
+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("some text");
+ 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
+ // 1 -top left corner of the 3D view window
//
for(int i=0; i<4; i++) {
myWorldPoint[i] = 0.;
}
myDistance=10.;
- GetTextProperty()->SetFontSize(12);
- GetTextProperty()->ShadowOn();
+ //
}
//==================================================================
-// function : SetDistance
+// function : ~
// purpose :
//==================================================================
-void VISU_GPTextActor::SetDistance(const float theDistance)
+VISU_FramedTextActor::~VISU_FramedTextActor()
{
- myDistance=theDistance;
+ myTextActor->Delete();
+ myTextMapper->Delete();
+ myTextProperty->Delete();
+ myBarActor->Delete();
+ myBarMapper->Delete();
+ myBar->Delete();
}
//==================================================================
-// function : GetDistance
+// function : SetVisibility
// purpose :
//==================================================================
-float VISU_GPTextActor::GetDistance()const
+void VISU_FramedTextActor::SetVisibility (int theVisibility)
{
- return myDistance;
+ 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 float theTransparency)
+{
+ if (theTransparency>=0. && theTransparency<=1.){
+ myTransparency=theTransparency;
+ myBarActor->GetProperty()->SetOpacity(1.-myTransparency);
+ Modified();
+ }
+}
+//==================================================================
+// function : GetTransparency
+// purpose :
+//==================================================================
+float 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_GPTextActor::SetModePosition(const int theMode)
+void VISU_FramedTextActor::SetModePosition(const int theMode)
{
myModePosition=theMode;
+ Modified();
}
//==================================================================
// function : GetModePosition
// purpose :
//==================================================================
-int VISU_GPTextActor::GetModePosition()const
+int VISU_FramedTextActor::GetModePosition()const
{
return myModePosition;
}
// function : SetWorldPoint
// purpose :
//==================================================================
-void VISU_GPTextActor::SetWorldPoint(const float theWorldPoint[4])
+void VISU_FramedTextActor::SetWorldPoint(const float theWorldPoint[4])
{
- for(int i = 0; i < 4; i++) {
+ for(int i = 0; i<4; ++i) {
myWorldPoint[i] = theWorldPoint[i];
- }
+ }
+ Modified();
}
//==================================================================
// function : GetWorldPoint
// purpose :
//==================================================================
-const float* VISU_GPTextActor::GetWorldPoint()const
+const float* VISU_FramedTextActor::GetWorldPoint()const
{
return myWorldPoint;
}
//==================================================================
+// function : SetDistance
+// purpose :
+//==================================================================
+void VISU_FramedTextActor::SetDistance(const float theDistance)
+{
+ myDistance=theDistance;
+}
+//==================================================================
+// function : GetDistance
+// purpose :
+//==================================================================
+float 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_GPTextActor::RenderOpaqueGeometry(vtkViewport *theViewport)
+int VISU_FramedTextActor::RenderOpaqueGeometry(vtkViewport *viewport)
{
- int iScaledText=GetScaledText();
- int iAlignmentPoint=GetAlignmentPoint();
- float * pPosition2=GetPosition2();
- vtkTextProperty *pTextProperty=GetTextProperty();
+ int renderedSomething=0;
+ int size[2];
+ int aTextSize[2], barWidth, barHeight;
+ float x[3]={0.,0.,0.};
+ //
+ int numPts=4;
+ vtkPoints *pts = vtkPoints::New();
+ pts->SetNumberOfPoints(numPts);
+ vtkCellArray *polys = vtkCellArray::New();
+ polys->Allocate(polys->EstimateSize(1,4));
//
- if (myModePosition==0){
- float aSelectionPoint[3];
- //
- theViewport->SetWorldPoint(myWorldPoint);
- theViewport->WorldToDisplay();
- theViewport->GetDisplayPoint(aSelectionPoint);
+ myBar->Initialize();
+ myBar->SetPoints(pts);
+ myBar->SetPolys(polys);
+ pts->Delete(); polys->Delete();
+ //
+ myTextMapper->GetSize(viewport, aTextSize);
+ //
+ barWidth =aTextSize[0];
+ barHeight=aTextSize[1];
+ //
+ if (myModePosition==0) {
- aSelectionPoint[1] -= myDistance;
- pTextProperty->SetJustificationToCentered();
- pTextProperty->SetVerticalJustificationToTop();
- SetAlignmentPoint(-1);///
- SetPosition(aSelectionPoint);
+ float aSelectionPoint[3], u, v;
+ //
+ viewport->SetWorldPoint(myWorldPoint);
+ viewport->WorldToDisplay();
+ viewport->GetDisplayPoint(aSelectionPoint);
+ u=aSelectionPoint[0];
+ v=aSelectionPoint[1]-myDistance;
+ viewport->ViewportToNormalizedViewport(u, v);
+ //
+ PositionCoordinate->SetValue(u, v);
+ //
+ myTextProperty->SetJustificationToCentered ();
+ myTextProperty->SetVerticalJustificationToTop();
+ //
+ x[0]=-barWidth/2. ; x[1]=0. ; pts->SetPoint(0,x);
+ x[0]=-barWidth/2. ; x[1]=-barHeight ; pts->SetPoint(1,x);
+ x[0]= barWidth/2 ; x[1]=0. ; pts->SetPoint(2,x);
+ x[0]= barWidth/2 ; x[1]=-barHeight ; pts->SetPoint(3,x);
}
- else if (myModePosition==1) {
- pTextProperty->SetJustificationToLeft();
- pTextProperty->SetVerticalJustificationToTop();
- ScaledTextOff ();
- SetPosition2 (1., 1.);
- SetAlignmentPoint(6);
- SetPosition(0., 0.);
- }
- Superclass::RenderOpaqueGeometry(theViewport);
+ else {//if (myModePosition==1) {
+ PositionCoordinate->SetValue(0., 1.);
+ myTextProperty->SetJustificationToLeft();
+ myTextProperty->SetVerticalJustificationToTop();
+ //
+ x[0]=0. ; x[1]=0. ; pts->SetPoint(0,x);
+ x[0]=0. ; x[1]=-barHeight ; pts->SetPoint(1,x);
+ x[0]= barWidth ; x[1]=0. ; pts->SetPoint(2,x);
+ x[0]= barWidth ; x[1]=-barHeight ; pts->SetPoint(3,x);
+ }
+ //
+ myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty);
+ myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
+ myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate);
+ //
+ vtkIdType ptIds[4]={0,1,3,2};
+ polys->InsertNextCell(4,ptIds);
+ //
+ myBuildTime.Modified();
//
- SetAlignmentPoint(iAlignmentPoint);
- SetPosition2(pPosition2);
- SetScaledText(iScaledText);
+ return renderedSomething;
}
vtkSmartPointer<vtkPolyDataMapper> myMappers[6];
vtkSmartPointer<vtkActor> myActors[6];
};
-
-//============================================================================
-#include <vtkTextActor.h>
-
-class VISU_GPTextActor : public vtkTextActor
+//==================================================================
+// class VISU_FramedTextActor
+//
+#include <vtkActor2D.h>
+//
+class vtkViewport;
+class vtkProp;
+class vtkWindow;
+class vtkPolyData;
+class vtkPolyDataMapper2D;
+class vtkActor2D;
+class vtkTimeStamp;
+class vtkTextProperty;
+class vtkTextMapper;
+
+class VISU_FramedTextActor : public vtkActor2D
{
public:
- vtkTypeMacro(VISU_GPTextActor,vtkTextActor);
-
- static VISU_GPTextActor* New();
-
- void SetWorldPoint(const float theWorldPoint[4]);
-
- const float* GetWorldPoint()const;
-
+ // vtks
+ vtkTypeRevisionMacro(VISU_FramedTextActor,vtkActor2D);
+ static VISU_FramedTextActor *New();
+ //
+ virtual int RenderOpaqueGeometry(vtkViewport* viewport);
+ virtual int RenderTranslucentGeometry(vtkViewport*) { return 0; };
+ virtual int RenderOverlay(vtkViewport* viewport);
+ virtual void ReleaseGraphicsResources(vtkWindow *);
+ virtual void SetVisibility (int );
+ virtual int GetVisibility() ;
+ virtual void SetPickable (int ) ;
+ virtual int GetPickable();
+ //
+ // selectors
+ void SetText(const char* theText);
+ char* GetText();
+ //
void SetModePosition(const int theMode);
-
int GetModePosition()const;
-
+ //
+ void SetWorldPoint(const float theWorldPoint[4]);
+ const float* GetWorldPoint()const;
+ //
void SetDistance(const float theDistance);
-
float GetDistance()const;
-
- virtual int RenderOpaqueGeometry(vtkViewport *theViewport);
-
+ //
+ void SetTransparency(const float theTransparency);
+ float GetTransparency()const;
+ //
protected:
- VISU_GPTextActor();
+ VISU_FramedTextActor();
+ ~VISU_FramedTextActor();
protected:
+ vtkPolyData *myBar;
+ vtkPolyDataMapper2D *myBarMapper;
+ vtkActor2D *myBarActor;
+ //
+ vtkTextProperty *myTextProperty;
+ vtkTextMapper *myTextMapper;
+ vtkActor2D *myTextActor;
+ //
+ vtkTimeStamp myBuildTime;
+ //
int myModePosition;
float myWorldPoint[4];
float myDistance;
+ float myTransparency;
+
+private:
+ VISU_FramedTextActor(const VISU_FramedTextActor&); // Not implemented.
+ void operator=(const VISU_FramedTextActor&); // Not implemented.
};
#endif //VISU_GAUSS_PTS_DEVICE_ACTOR_H