From 7f410f7ee6f6c9ff9e80cc6118c4e0ac6ac0001a Mon Sep 17 00:00:00 2001 From: ouv Date: Wed, 22 Jan 2014 14:09:58 +0000 Subject: [PATCH] 1) Introducing Plot3d_Actor 2) Implemented possibility to create SVTK_ViewWindow without active SUIT session/application. --- src/SVTK/Plot3d_Actor.cxx | 317 +++++++++++++++++++++++++++++++++++ src/SVTK/Plot3d_Actor.h | 88 ++++++++++ src/SVTK/SVTK_ViewWindow.cxx | 23 ++- 3 files changed, 421 insertions(+), 7 deletions(-) create mode 100644 src/SVTK/Plot3d_Actor.cxx create mode 100644 src/SVTK/Plot3d_Actor.h diff --git a/src/SVTK/Plot3d_Actor.cxx b/src/SVTK/Plot3d_Actor.cxx new file mode 100644 index 000000000..f09f1e840 --- /dev/null +++ b/src/SVTK/Plot3d_Actor.cxx @@ -0,0 +1,317 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "Plot3d_Actor.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +vtkStandardNewMacro(Plot3d_Actor); + +//============================================================================= +// Function : Plot3d_Actor +// Purpose : Constructor +//============================================================================= +Plot3d_Actor::Plot3d_Actor() +{ + myIsDistance = false; + + myStartPoint = 0; + myEndPoint = 0; + + // Scalar bar + myToDisplayScalarBar = false; + + myScalarBarActor = vtkScalarBarActor::New(); + myScalarBarActor->SetVisibility( false ); + + // Title props + QColor aTextColor = Qt::white; + + vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New(); + aScalarBarTitleProp->SetColor( aTextColor.redF(), aTextColor.greenF(), aTextColor.blueF() ); + aScalarBarTitleProp->SetFontFamilyToArial(); + int aSize = 24; + aScalarBarTitleProp->SetFontSize( aSize ); + myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp ); + aScalarBarTitleProp->Delete(); + + // Label props + vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New(); + aScalarBarLabelProp->SetColor( aTextColor.redF(), aTextColor.greenF(), aTextColor.blueF() ); + aScalarBarLabelProp->SetFontFamilyToArial(); + myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp ); + aScalarBarLabelProp->Delete(); + + // Position + double aXPos = 0.01, aYPos = 0.1; + myScalarBarActor->SetPosition( aXPos, aYPos ); + + // Width + double aWidth = 0.10, aHeight = 0.80; + myScalarBarActor->SetWidth( aWidth ); + myScalarBarActor->SetHeight( aHeight ); + + // Number of labels and Maximum number of colors + myScalarBarActor->SetNumberOfLabels( 5 ); + myScalarBarActor->SetMaximumNumberOfColors( 99 ); + + // ScalarBar widget + myScalarBarWg = vtkScalarBarWidget::New(); + myScalarBarWg->SetScalarBarActor( myScalarBarActor.GetPointer() ); + + // Property + this->GetProperty()->ShadingOff(); + this->GetProperty()->LightingOff(); +} + +//============================================================================= +// Function : ~Plot3d_Actor +// Purpose : Destructor +//============================================================================= +Plot3d_Actor::~Plot3d_Actor() +{ +} + +//============================================================================= +// Function : SetVisibility +// Purpose : +//============================================================================= +void Plot3d_Actor::SetVisibility( int theVisibility ) +{ + Superclass::SetVisibility( theVisibility ); + + myScalarBarActor->SetVisibility( GetVisibility() && myToDisplayScalarBar ); + + if ( !theVisibility || !myScalarBarActor->GetLookupTable() || !myToDisplayScalarBar ) + myScalarBarWg->EnabledOff(); + else + myScalarBarWg->EnabledOn(); +} + +//============================================================================= +// Function : SetMapper +// Purpose : +//============================================================================= +void Plot3d_Actor::SetMapper( vtkMapper* theMapper ) +{ + Superclass::SetMapper(theMapper); +} + +//============================================================================= +// Function : AddToRender +// Purpose : +//============================================================================= +void Plot3d_Actor::AddToRender( vtkRenderer* theRenderer ) +{ + Superclass::AddToRender( theRenderer ); + + if ( vtkRenderWindow *win = theRenderer->GetRenderWindow() ) + { + if ( vtkRenderWindowInteractor *interactor = win->GetInteractor() ) + { + myScalarBarWg->SetInteractor( interactor ); + if ( myToDisplayScalarBar ) + myScalarBarWg->EnabledOn(); + } + } + + theRenderer->AddActor( myScalarBarActor.GetPointer() ); +} + +//============================================================================= +// Function : RemoveFromRender +// Purpose : +//============================================================================= +void Plot3d_Actor::RemoveFromRender( vtkRenderer* theRenderer ) +{ + myScalarBarWg->EnabledOff(); + theRenderer->RemoveActor( myScalarBarActor.GetPointer() ); + + Superclass::RemoveFromRender( theRenderer ); +} + +//============================================================================= +// Function : GetScalarBarActor +// Purpose : +//============================================================================= +vtkSmartPointer Plot3d_Actor::GetScalarBarActor() const +{ + return myScalarBarActor; +} + +//============================================================================= +// Function : DisplayScalarBar +// Purpose : +//============================================================================= +void Plot3d_Actor::DisplayScalarBar( const bool theToDisplay ) +{ + myToDisplayScalarBar = theToDisplay; + myScalarBarActor->SetVisibility( GetVisibility() && theToDisplay ); + myScalarBarWg->SetEnabled( GetVisibility() && theToDisplay ? 1 : 0 ); +} + +//============================================================================= +// Function : Build +// Purpose : +//============================================================================= +void Plot3d_Actor::Build( const int theNX, + const int theNY, + const QList& thePntList, + const QList& theValueList, + const double theMinValue, + const double theMaxValue ) +{ + vtkPolyData* aPointSet = vtkPolyData::New(); + aPointSet->Allocate( ( theNX - 1 ) * ( theNY - 1 ) ); + + vtkPoints* aPoints = vtkPoints::New(); + QListIterator aPntIter( thePntList ); + while( aPntIter.hasNext() ) + { + const QPointF& aPnt = aPntIter.next(); + aPoints->InsertNextPoint( aPnt.x(), aPnt.y(), 0 ); + } + aPointSet->SetPoints( aPoints ); + + vtkIdType pts[ 4 ]; + for( int i = 0; i < theNX - 1; i++ ) + { + for( int j = 0; j < theNY - 1; j++ ) + { + pts[0] = j + theNY * i; + pts[1] = j + theNY * i + 1; + pts[2] = j + theNY * ( i + 1 ) + 1; + pts[3] = j + theNY * ( i + 1 ); + aPointSet->InsertNextCell( VTK_QUAD, 4, pts ); + } + } + + vtkFloatArray* aFloatArray = vtkFloatArray::New(); + QListIterator aValueIter( theValueList ); + while( aValueIter.hasNext() ) + { + const double aValue = aValueIter.next(); + aFloatArray->InsertNextTuple1( aValue ); + } + + vtkPointData* aPointData = aPointSet->GetPointData(); + aPointData->SetScalars( aFloatArray ); + + vtkWarpScalar* aWarpScalar = vtkWarpScalar::New(); + aWarpScalar->SetInput( aPointSet ); + aWarpScalar->SetScaleFactor( 1 ); + + vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); + aMapper->SetInput( aWarpScalar->GetPolyDataOutput() ); + aMapper->SetScalarRange( theMinValue, theMaxValue ); + + SetMapper( aMapper ); + + vtkLookupTable* aLookupTable = vtkLookupTable::New(); + aLookupTable->SetHueRange( 0.66667, 0.0 ); + + aMapper->SetLookupTable( aLookupTable ); + myScalarBarActor->SetLookupTable( aLookupTable ); + + aPoints->Delete(); + aFloatArray->Delete(); + aPointSet->Delete(); +} + +//============================================================================= +// Function : SetUnits +// Purpose : +//============================================================================= +void Plot3d_Actor::SetUnits( const QString& theUnits ) +{ + myUnits = theUnits; +} + +//============================================================================= +// Function : GetUnits +// Purpose : +//============================================================================= +QString Plot3d_Actor::GetUnits() const +{ + return myUnits; +} + +//============================================================================= +// Function : SetIsDistance +// Purpose : +//============================================================================= +void Plot3d_Actor::SetIsDistance( const bool theIsDistance ) +{ + myIsDistance = theIsDistance; +} + +//============================================================================= +// Function : GetIsDistance +// Purpose : +//============================================================================= +bool Plot3d_Actor::GetIsDistance() const +{ + return myIsDistance; +} + +//============================================================================= +// Function : SetBoundaryPoints +// Purpose : +//============================================================================= +void Plot3d_Actor::SetBoundaryPoints( const int theStartPoint, + const int theEndPoint ) +{ + myStartPoint = theStartPoint; + myEndPoint = theEndPoint; +} + +//============================================================================= +// Function : GetBoundaryPoints +// Purpose : +//============================================================================= +void Plot3d_Actor::GetBoundaryPoints( int& theStartPoint, + int& theEndPoint ) +{ + theStartPoint = myStartPoint; + theEndPoint = myEndPoint; +} + +//============================================================================= +// Function : SetTextColor +// Purpose : +//============================================================================= +void Plot3d_Actor::SetTextColor( const QColor& theColor ) +{ + vtkTextProperty* aScalarBarTitleProp = myScalarBarActor->GetTitleTextProperty(); + aScalarBarTitleProp->SetColor( theColor.redF(), theColor.greenF(), theColor.blueF() ); + + vtkTextProperty* aScalarBarLabelProp = myScalarBarActor->GetLabelTextProperty(); + aScalarBarLabelProp->SetColor( theColor.redF(), theColor.greenF(), theColor.blueF() ); +} diff --git a/src/SVTK/Plot3d_Actor.h b/src/SVTK/Plot3d_Actor.h new file mode 100644 index 000000000..dfc98ea8a --- /dev/null +++ b/src/SVTK/Plot3d_Actor.h @@ -0,0 +1,88 @@ +// Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef PLOT3D_VIEWMODEL_H +#define PLOT3D_VIEWMODEL_H + +#include "SVTK.h" + +#include "SALOME_Actor.h" + +#include +#include +#include +#include + +class vtkScalarBarActor; +class vtkScalarBarWidget; + +/* + Class : Plot3d_Actor + Descrtiption : Class for presentation of the Plot3d graph +*/ + +class SVTK_EXPORT Plot3d_Actor : public SALOME_Actor +{ +public: + static Plot3d_Actor* New(); + vtkTypeMacro( Plot3d_Actor, SALOME_Actor ); + + Plot3d_Actor(); + virtual ~Plot3d_Actor(); + + virtual void AddToRender( vtkRenderer* theRender ); + virtual void RemoveFromRender(vtkRenderer* theRendere); + + virtual void SetVisibility( int ); + + virtual void SetMapper( vtkMapper* theMapper ); + + vtkSmartPointer GetScalarBarActor() const; + void DisplayScalarBar( const bool ); + + void Build( const int theNX, + const int theNY, + const QList& thePntList, + const QList& theValueList, + const double theMinValue, + const double theMaxValue ); + + void SetUnits( const QString& ); + QString GetUnits() const; + + void SetIsDistance( const bool ); + bool GetIsDistance() const; + + void SetBoundaryPoints( const int, const int ); + void GetBoundaryPoints( int&, int& ); + + void SetTextColor( const QColor& theColor ); + +protected: + vtkSmartPointer myScalarBarActor; + vtkSmartPointer myScalarBarWg; + bool myToDisplayScalarBar; + + QString myUnits; + bool myIsDistance; + + int myStartPoint; + int myEndPoint; +}; + +#endif diff --git a/src/SVTK/SVTK_ViewWindow.cxx b/src/SVTK/SVTK_ViewWindow.cxx index 30ecde209..b029798e7 100755 --- a/src/SVTK/SVTK_ViewWindow.cxx +++ b/src/SVTK/SVTK_ViewWindow.cxx @@ -116,6 +116,7 @@ SVTK_ViewWindow::SVTK_ViewWindow(SUIT_Desktop* theDesktop): myDumpImage(QImage()), myStandardInteractorStyle(SVTK_InteractorStyle::New()), myKeyFreeInteractorStyle(SVTK_KeyFreeInteractorStyle::New()), + myViewsAction( NULL ), myMode2D( false ) { setWindowFlags( windowFlags() & ~Qt::Window ); @@ -155,8 +156,11 @@ void SVTK_ViewWindow::Initialize(SVTK_ViewModelBase* theModel) myToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_LABEL"), -1, this ); myRecordingToolBar = toolMgr()->createToolBar( tr("LBL_TOOLBAR_RECORD_LABEL"), -1, this ); - createActions( SUIT_Session::session()->activeApplication()->resourceMgr() ); - createToolBar(); + if( SUIT_Session* aSession = SUIT_Session::session() ) + { + createActions( aSession->activeApplication()->resourceMgr() ); + createToolBar(); + } SetEventDispatcher(myInteractor->GetDevice()); myInteractor->setBackgroundRole( QPalette::NoRole );//NoBackground @@ -727,11 +731,16 @@ void SVTK_ViewWindow::onMode2D( bool theOn ) { myMode2D = theOn; - getAction( ViewTrihedronId )->setVisible( !theOn ); - getAction( ChangeRotationPointId )->setVisible( !theOn ); - getAction( RotationId )->setVisible( !theOn ); - myViewsAction->setVisible( !theOn ); - getAction( ResetId )->setVisible( !theOn ); + if( getAction( ViewTrihedronId ) ) + getAction( ViewTrihedronId )->setVisible( !theOn ); + if( getAction( ViewTrihedronId ) ) + getAction( ViewTrihedronId )->setVisible( !theOn ); + if( getAction( ChangeRotationPointId ) ) + getAction( ChangeRotationPointId )->setVisible( !theOn ); + if( myViewsAction ) + myViewsAction->setVisible( !theOn ); + if( getAction( ViewTrihedronId ) ) + getAction( ViewTrihedronId )->setVisible( !theOn ); SVTK_ComboAction* a = ::qobject_cast( toolMgr()->action( ProjectionModeId ) ); if( a ) -- 2.39.2