From 0eac807ec151becae655c3c3791c2ef5ed118ca7 Mon Sep 17 00:00:00 2001 From: eap Date: Mon, 20 Jan 2014 10:34:46 +0000 Subject: [PATCH] 22316: EDF 2719 SMESH: Split hexas into prisms + void SetArrowShapeAndNb( int nbArrows, + double headLength, + double headRadius, + double start=0.); + void SetArrows( const gp_Ax1* axes, + double length); + vtkUnstructuredGrid* GetGrid() const; --- src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx | 106 ++++++++++++++++++++++ src/SMESHGUI/SMESHGUI_MeshEditPreview.h | 17 +++- 2 files changed, 122 insertions(+), 1 deletion(-) diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx index 439abbb57..f80c0dc52 100644 --- a/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx +++ b/src/SMESHGUI/SMESHGUI_MeshEditPreview.cxx @@ -53,6 +53,8 @@ #include #include CORBA_SERVER_HEADER(SMESH_MeshEditor) +#include + //================================================================================ /*! * \brief Constructor @@ -224,6 +226,98 @@ void SMESHGUI_MeshEditPreview::SetData (const SMESH::MeshPreviewStruct* previewD SetVisibility(true); } +//================================================================================ +/*! + * \brief Set shape of an arrow of a unit length and nb of arrows + */ +//================================================================================ + +void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int nbArrows, + double headLength, + double headRadius, + double start) +{ + const int theNbPoints = 10; // in one arrow + myUnitArrowPnts.reserve( theNbPoints ); + myUnitArrowPnts.clear(); + + // unit arrow || OZ + + for ( int i = 0; i < theNbPoints - 2; ++i ) + { + double angle = i * 2 * M_PI / ( theNbPoints - 2 ); + myUnitArrowPnts.push_back( gp_Pnt( headRadius * Cos( angle ), + headRadius * Sin( angle ), + 1. - headLength )); + } + myUnitArrowPnts.push_back( gp_Pnt( 0, 0, start )); + myUnitArrowPnts.push_back( gp_Pnt( 0, 0, 1 )); + + + // nodes of all arrows + + vtkPoints* aPoints = vtkPoints::New(); + aPoints->SetNumberOfPoints( theNbPoints * nbArrows ); + for ( int iP = 0, iA = 0; iA < nbArrows; ++iA ) + for ( int i = 0; i < theNbPoints; ++i, ++iP ) + aPoints->SetPoint( iP, + myUnitArrowPnts[i].X(), + myUnitArrowPnts[i].Y(), + myUnitArrowPnts[i].Z() ); + myGrid->SetPoints(aPoints); + aPoints->Delete(); + + // connectivity of all arrows + + const int theNbCells = ( theNbPoints - 1 ); // in one arrow + myGrid->Allocate( theNbCells * nbArrows ); + for ( int nP = 0, iA = 0; iA < nbArrows; ++iA, nP += theNbPoints ) + { + vtkIdType conn[3] = { theNbPoints - 1 + nP, // arrow end + theNbPoints - 3 + nP, // point on a circle + nP }; // point on a circle + for ( int i = 0; i < theNbCells-1; ++i ) + { + myGrid->InsertNextCell( VTK_TRIANGLE, 3, conn ); + conn[1] = conn[2]; + conn[2] = conn[2] + 1; + } + conn[1] = theNbPoints - 2 + nP; + myGrid->InsertNextCell( VTK_LINE, 2, conn ); + } + + myNbArrows = nbArrows; +} + +//================================================================================ +/*! + * \brief Set data to show moved/rotated/scaled arrows + * \param [in] axes - location and direction of the arrows + * \param [in] length - length of arrows + */ +//================================================================================ + +void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes, + double length ) +{ + vtkPoints* aPoints = myGrid->GetPoints(); + + for ( int iP = 0, iA = 0; iA < myNbArrows; ++iA ) + { + gp_Trsf trsf; + trsf.SetTransformation( gp_Ax3( axes[iA].Location(), axes[iA].Direction() ), gp::XOY() ); + + for ( size_t i = 0; i < myUnitArrowPnts.size(); ++i, ++iP ) + { + gp_Pnt p = myUnitArrowPnts[i].Scaled( gp::Origin(), length ); + p.Transform( trsf ); + aPoints->SetPoint( iP, p.X(), p.Y(), p.Z() ); + } + } + + myGrid->Modified(); +} + //================================================================================ /*! * \brief Set visibility @@ -252,7 +346,19 @@ void SMESHGUI_MeshEditPreview::SetColor(double R, double G, double B) * \brief Get preview actor */ //================================================================================ + SALOME_Actor* SMESHGUI_MeshEditPreview::GetActor() const { return myPreviewActor; } + +//================================================================================ +/*! + * \brief Returns the priewed vtkUnstructuredGrid + */ +//================================================================================ + +vtkUnstructuredGrid* SMESHGUI_MeshEditPreview::GetGrid() const +{ + return myGrid; +} diff --git a/src/SMESHGUI/SMESHGUI_MeshEditPreview.h b/src/SMESHGUI/SMESHGUI_MeshEditPreview.h index bd94152ea..7091999f3 100644 --- a/src/SMESHGUI/SMESHGUI_MeshEditPreview.h +++ b/src/SMESHGUI/SMESHGUI_MeshEditPreview.h @@ -27,8 +27,10 @@ #ifndef SMESHGUI_MESHEDITPREVIEW_H #define SMESHGUI_MESHEDITPREVIEW_H -// SMESH includes #include "SMESH_SMESHGUI.hxx" +#include +#include +#include class SVTK_ViewWindow; class vtkUnstructuredGrid; @@ -49,14 +51,27 @@ class SMESHGUI_EXPORT SMESHGUI_MeshEditPreview vtkUnstructuredGrid* myGrid; SALOME_Actor* myPreviewActor; + std::vector myUnitArrowPnts; + int myNbArrows; + public: SMESHGUI_MeshEditPreview( SVTK_ViewWindow* ); ~SMESHGUI_MeshEditPreview(); void SetData( const SMESH::MeshPreviewStruct* ); + void SetVisibility( bool ); void SetColor( double, double, double ); + + void SetArrowShapeAndNb( int nbArrows, + double headLength, + double headRadius, + double start=0.); + void SetArrows( const gp_Ax1* axes, + double length); + SALOME_Actor* GetActor() const; + vtkUnstructuredGrid* GetGrid() const; }; #endif // SMESHGUI_MESHEDITPREVIEW_H -- 2.39.2