From c16a217aa29070a927adcd3cb7b0534b693cf2e8 Mon Sep 17 00:00:00 2001 From: rnv Date: Mon, 23 Jun 2014 10:44:13 +0400 Subject: [PATCH] Support of the UTF-8 encoding. --- src/SVTK/SALOME_Actor.cxx | 8 ++--- src/SVTK/SALOME_Actor.h | 4 +-- src/VTKViewer/VTKViewer_FramedTextActor.cxx | 34 +++++++++------------ src/VTKViewer/VTKViewer_FramedTextActor.h | 8 ++--- src/VTKViewer/VTKViewer_PolyDataMapper.cxx | 16 +++++----- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 3f4383692..20fafbeae 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -924,7 +924,7 @@ SALOME_Actor */ void SALOME_Actor -::SetNameActorOffset(int theOffset[2]) +::SetNameActorOffset(double theOffset[2]) { myNameActor->SetOffset(theOffset); } @@ -936,7 +936,7 @@ SALOME_Actor */ void SALOME_Actor -::GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const +::GetNameActorSize(vtkRenderer* theRenderer, double theSize[2]) const { myNameActor->GetSize(theRenderer, theSize); } @@ -950,7 +950,7 @@ SALOME_Actor { if( vtkRenderer* aRenderer = GetRenderer() ) { - int anOffset[2] = { 0, 0 }; + double anOffset[2] = { 0, 0 }; VTK::ActorCollectionCopy aCopy(aRenderer->GetActors()); vtkActorCollection* aCollection = aCopy.GetActors(); for( int anIndex = 0, aNbItems = aCollection->GetNumberOfItems(); anIndex < aNbItems; anIndex++ ) @@ -962,7 +962,7 @@ SALOME_Actor anActor->SetNameActorOffset( anOffset ); if( anActor->GetVisibility() ) { - int aSize[2]; + double aSize[2]; anActor->GetNameActorSize( aRenderer, aSize ); anOffset[0] = anOffset[0] + aSize[0]; anOffset[1] = anOffset[1] + aSize[1]; diff --git a/src/SVTK/SALOME_Actor.h b/src/SVTK/SALOME_Actor.h index 573400549..bac5d9ae5 100644 --- a/src/SVTK/SALOME_Actor.h +++ b/src/SVTK/SALOME_Actor.h @@ -202,12 +202,12 @@ class SVTK_EXPORT SALOME_Actor : public VTKViewer_Actor //! To set offset of name actor virtual void - SetNameActorOffset(int theOffset[2]); + SetNameActorOffset(double theOffset[2]); //! To get size of name actor virtual void - GetNameActorSize(vtkRenderer* theRenderer, int theSize[2]) const; + GetNameActorSize(vtkRenderer* theRenderer, double theSize[2]) const; //! To update visibility of name actors virtual diff --git a/src/VTKViewer/VTKViewer_FramedTextActor.cxx b/src/VTKViewer/VTKViewer_FramedTextActor.cxx index 9f9b6dd48..3de2711f1 100644 --- a/src/VTKViewer/VTKViewer_FramedTextActor.cxx +++ b/src/VTKViewer/VTKViewer_FramedTextActor.cxx @@ -64,12 +64,9 @@ VTKViewer_FramedTextActor::VTKViewer_FramedTextActor() myTextProperty->SetItalic(0); myTextProperty->SetShadow(1); myTextProperty->SetFontFamilyToArial(); - - myTextMapper=vtkTextMapper::New(); - myTextMapper->SetInput(""); - myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); - myTextActor=vtkActor2D::New(); - myTextActor->SetMapper(myTextMapper); + + myTextActor=vtkTextActor::New(); + myTextActor->SetTextProperty(myTextProperty); myBarActor->SetVisibility(1); myTextActor->SetVisibility(1); @@ -99,7 +96,6 @@ VTKViewer_FramedTextActor::VTKViewer_FramedTextActor() VTKViewer_FramedTextActor::~VTKViewer_FramedTextActor() { myTextActor->Delete(); - myTextMapper->Delete(); myTextProperty->Delete(); myBarActor->Delete(); myBarMapper->Delete(); @@ -148,9 +144,9 @@ int VTKViewer_FramedTextActor::GetPickable() // function : GetSize // purpose : //================================================================== -void VTKViewer_FramedTextActor::GetSize(vtkRenderer* theRenderer, int theSize[2]) const +void VTKViewer_FramedTextActor::GetSize(vtkRenderer* vport, double theSize[2]) const { - myTextMapper->GetSize(theRenderer, theSize); + myTextActor->GetSize(vport, theSize); theSize[0] = theSize[0] + 2 * GetTextMargin() + OFFSET_SPACING; theSize[1] = theSize[1] + 2 * GetTextMargin() + OFFSET_SPACING; } @@ -164,7 +160,7 @@ void VTKViewer_FramedTextActor::SetForegroundColor(const double r, const double b) { myTextProperty->SetColor(r, g, b); - myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); + myTextActor->GetTextProperty()->ShallowCopy(myTextProperty); Modified(); } @@ -257,7 +253,7 @@ int VTKViewer_FramedTextActor::GetTextMargin() const // function : SetOffset // purpose : //================================================================== -void VTKViewer_FramedTextActor::SetOffset(const int theOffset[2]) +void VTKViewer_FramedTextActor::SetOffset(const double theOffset[2]) { myHorizontalOffset = theOffset[0]; myVerticalOffset = theOffset[1]; @@ -272,7 +268,7 @@ void VTKViewer_FramedTextActor::SetText(const char* theText) { // remove whitespaces from from the start and the end // additionally, consider a case of multi-string text - QString aString(theText); + QString aString(QString::fromUtf8(theText)); QStringList aTrimmedStringList; QStringList aStringList = aString.split("\n"); @@ -280,7 +276,7 @@ void VTKViewer_FramedTextActor::SetText(const char* theText) while(anIter.hasNext()) aTrimmedStringList.append(anIter.next().trimmed()); - myTextMapper->SetInput(aTrimmedStringList.join("\n").toLatin1().constData()); + myTextActor->SetInput(aTrimmedStringList.join("\n").toUtf8().constData()); Modified(); } @@ -290,7 +286,7 @@ void VTKViewer_FramedTextActor::SetText(const char* theText) //================================================================== char* VTKViewer_FramedTextActor::GetText() { - return myTextMapper->GetInput(); + return myTextActor->GetInput(); } //================================================================== @@ -410,8 +406,8 @@ void VTKViewer_FramedTextActor::ReleaseGraphicsResources(vtkWindow *win) int VTKViewer_FramedTextActor::RenderOverlay(vtkViewport *viewport) { int renderedSomething = 0; - myBarActor->RenderOverlay(viewport); renderedSomething +=myTextActor->RenderOverlay(viewport); + renderedSomething +=myBarActor->RenderOverlay(viewport); return renderedSomething; } @@ -431,7 +427,7 @@ VTKViewer_FramedTextActor if(aViewPortWidth == 1 || aViewPortHeight == 1) return anIsRenderedSomething; - if(!myTextMapper->GetInput()) + if(!myTextActor->GetInput()) return anIsRenderedSomething; myBar->Initialize(); @@ -449,8 +445,8 @@ VTKViewer_FramedTextActor myBar->SetPolys(aPolys); aPolys->Delete(); - int aTextSize[2]; - myTextMapper->GetSize(theViewport, aTextSize); + double aTextSize[2]; + myTextActor->GetSize(theViewport, aTextSize); int aBarWidth = aTextSize[0]; int aBarHeight = aTextSize[1]; @@ -511,6 +507,7 @@ VTKViewer_FramedTextActor y / (double)aViewPortHeight); } + aPoints->SetPoint(0, xMin, yMax, 0.0); aPoints->SetPoint(1, xMin, yMin, 0.0); aPoints->SetPoint(2, xMax, yMax, 0.0); @@ -518,7 +515,6 @@ VTKViewer_FramedTextActor myTextProperty->SetVerticalJustificationToCentered(); - myTextMapper->GetTextProperty()->ShallowCopy(myTextProperty); myBarActor ->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); myTextActor->GetPositionCoordinate()->SetReferenceCoordinate(PositionCoordinate); diff --git a/src/VTKViewer/VTKViewer_FramedTextActor.h b/src/VTKViewer/VTKViewer_FramedTextActor.h index 5c4ed01f5..78873a86e 100644 --- a/src/VTKViewer/VTKViewer_FramedTextActor.h +++ b/src/VTKViewer/VTKViewer_FramedTextActor.h @@ -32,6 +32,7 @@ class vtkTextMapper; class vtkTextProperty; class vtkViewport; class vtkWindow; +class vtkTextActor; class VTKVIEWER_EXPORT VTKViewer_FramedTextActor : public vtkActor2D { @@ -53,7 +54,7 @@ public: virtual void SetPickable(int); virtual int GetPickable(); - virtual void GetSize(vtkRenderer* theRenderer, int theSize[2]) const; + virtual void GetSize(vtkRenderer* vport, double theSize[2]) const; void SetText(const char* theText); char* GetText(); @@ -93,7 +94,7 @@ public: void SetTextMargin(const int theMargin); int GetTextMargin() const; - void SetOffset(const int theOffset[2]); + void SetOffset(const double theOffset[2]); protected: VTKViewer_FramedTextActor(); @@ -105,8 +106,7 @@ protected: vtkActor2D* myBarActor; vtkTextProperty* myTextProperty; - vtkTextMapper* myTextMapper; - vtkActor2D* myTextActor; + vtkTextActor* myTextActor; vtkTimeStamp myBuildTime; diff --git a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx index 0f1f19587..91cc92074 100644 --- a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx +++ b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx @@ -522,9 +522,15 @@ void VTKViewer_PolyDataMapper::InitTextures() if( !this->ImageData.GetPointer() ) return; + glEnable( GL_TEXTURE_2D ); + if( this->PointSpriteTexture == 0 ) { + glGenTextures( 1, &this->PointSpriteTexture ); + } + glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture ); + glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); - + if(this->BallEnabled) { glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); @@ -537,11 +543,6 @@ void VTKViewer_PolyDataMapper::InitTextures() unsigned char* dataPtr = (unsigned char*)this->ImageData->GetScalarPointer(); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, aSize[0], aSize[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, dataPtr ); - - //glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - glEnable( GL_TEXTURE_2D ); - glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); - glBindTexture( GL_TEXTURE_2D, this->PointSpriteTexture ); } //----------------------------------------------------------------------------- @@ -561,6 +562,7 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act ) MAPPER_SUPERCLASS::RenderPiece( ren, act ); if( isUsePointSprites ) this->CleanupPointSprites(); + glBindTexture( GL_TEXTURE_2D, 0 ); } else { vtkIdType numPts; vtkPolyData *input= this->GetInput(); @@ -670,8 +672,8 @@ void VTKViewer_PolyDataMapper::RenderPiece( vtkRenderer* ren, vtkActor* act ) this->TimeToDraw = 0.0001; vglUseProgramObjectARB( 0 ); - this->CleanupPointSprites(); + glBindTexture( GL_TEXTURE_2D, 0 ); } } -- 2.39.2