From 0368b0a293ab3c21684b0049fdcb24ca38e1e830 Mon Sep 17 00:00:00 2001 From: rnv Date: Fri, 28 Sep 2012 07:30:34 +0000 Subject: [PATCH] Implementation of the "21459: EDF 1495 SMESH: Manipulation of discrete elements with attributes" issue: visualization of the 0D and balls elements. --- src/OBJECT/Makefile.am | 7 +- src/OBJECT/SMESH_Actor.cxx | 65 ++++++++-- src/OBJECT/SMESH_ActorDef.h | 3 + src/OBJECT/SMESH_SVTKActor.cxx | 184 +++++++++++++++++++++++++++++ src/OBJECT/SMESH_SVTKActor.h | 82 +++++++++++++ src/SMESHGUI/SMESHGUI_GroupDlg.cxx | 4 +- 6 files changed, 333 insertions(+), 12 deletions(-) create mode 100644 src/OBJECT/SMESH_SVTKActor.cxx create mode 100644 src/OBJECT/SMESH_SVTKActor.h diff --git a/src/OBJECT/Makefile.am b/src/OBJECT/Makefile.am index 31cb50d27..59cf1400c 100644 --- a/src/OBJECT/Makefile.am +++ b/src/OBJECT/Makefile.am @@ -37,7 +37,9 @@ salomeinclude_HEADERS = \ SMESH_FaceOrientationFilter.h \ SMESH_ScalarBarActor.h \ SMESH_NodeLabelActor.h \ - SMESH_CellLabelActor.h + SMESH_CellLabelActor.h \ + SMESH_SVTKActor.h + # Libraries targets @@ -52,7 +54,8 @@ dist_libSMESHObject_la_SOURCES = \ SMESH_FaceOrientationFilter.cxx \ SMESH_ScalarBarActor.cxx \ SMESH_NodeLabelActor.cxx \ - SMESH_CellLabelActor.cxx + SMESH_CellLabelActor.cxx \ + SMESH_SVTKActor.cxx libSMESHObject_la_CPPFLAGS = \ $(QT_INCLUDES) \ diff --git a/src/OBJECT/SMESH_Actor.cxx b/src/OBJECT/SMESH_Actor.cxx index 4daba11f8..1a6eba84d 100644 --- a/src/OBJECT/SMESH_Actor.cxx +++ b/src/OBJECT/SMESH_Actor.cxx @@ -37,6 +37,7 @@ #include "VTKViewer_ExtractUnstructuredGrid.h" #include "VTKViewer_FramedTextActor.h" #include "SALOME_InteractiveObject.hxx" +#include "SMESH_SVTKActor.h" #include "SUIT_Session.h" #include "SUIT_ResourceMgr.h" @@ -127,6 +128,12 @@ SMESH_ActorDef::SMESH_ActorDef() myIsPointsVisible = false; myIsEntityModeCache = false; + myHighlightActor = SMESH_SVTKActor::New(); + myHighlightActor->Initialize(); + + myPreHighlightActor = SMESH_SVTKActor::New(); + myPreHighlightActor->Initialize(); + myIsShrinkable = false; myIsShrunk = false; @@ -318,7 +325,7 @@ SMESH_ActorDef::SMESH_ActorDef() //Definition 0D device of the actor (ball elements) //----------------------------------------------- myBallProp = vtkProperty::New(); - SMESH::GetColor( "SMESH", "ball_elem_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 0 ) ); + SMESH::GetColor( "SMESH", "ball_elem_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 85, 255 ) ); myBallProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); myBallProp->SetPointSize(aBallElemSize); @@ -330,9 +337,7 @@ SMESH_ActorDef::SMESH_ActorDef() myBallActor->SetProperty(myBallProp); myBallActor->SetRepresentation(SMESH_DeviceActor::eSurface); aFilter = myBallActor->GetExtractUnstructuredGrid(); - //aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints); aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); - aFilter->RegisterCellsWithType(VTK_VERTEX); aFilter->RegisterCellsWithType(VTK_POLY_VERTEX); //my0DExtProp = vtkProperty::New(); @@ -410,13 +415,17 @@ SMESH_ActorDef::SMESH_ActorDef() myHighlightProp->SetLineWidth(aLineWidth); myHighlightProp->SetRepresentation(1); + myBallHighlightProp = vtkProperty::New(); + myBallHighlightProp->DeepCopy(myHighlightProp); + myBallHighlightProp->SetPointSize(aBallElemSize); + + myOutLineProp = vtkProperty::New(); myOutLineProp->SetAmbient(1.0); myOutLineProp->SetDiffuse(0.0); myOutLineProp->SetSpecular(0.0); SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 70, 0 ) ); myOutLineProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); - myOutLineProp->SetPointSize(aElem0DSize); // ?? myOutLineProp->SetLineWidth(aLineWidth); myOutLineProp->SetRepresentation(1); @@ -430,6 +439,10 @@ SMESH_ActorDef::SMESH_ActorDef() myPreselectProp->SetLineWidth(aLineWidth); myPreselectProp->SetRepresentation(1); + myBallPreselectProp = vtkProperty::New(); + myBallPreselectProp->DeepCopy(myPreselectProp); + myBallPreselectProp->SetPointSize(aBallElemSize); + myHighlitableActor = SMESH_DeviceActor::New(); myHighlitableActor->SetUserMatrix(aMatrix); myHighlitableActor->PickableOff(); @@ -499,6 +512,8 @@ SMESH_ActorDef::SMESH_ActorDef() my2dHistogram = 0; #endif + SetBallSize(aBallElemSize); + Set0DSize(aElem0DSize); } @@ -555,6 +570,9 @@ SMESH_ActorDef::~SMESH_ActorDef() myImplicitBoolean->Delete(); myTimeStamp->Delete(); + myBallHighlightProp->Delete(); + myBallPreselectProp->Delete(); + } void SMESH_ActorDef::Delete() @@ -957,6 +975,9 @@ SetControlMode(eControl theMode, void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){ + + //myHighlightActor->AddToRender(theRenderer); + theRenderer->AddActor(myBaseActor); theRenderer->AddActor(myNodeExtActor); theRenderer->AddActor(my1DExtActor); @@ -1307,10 +1328,10 @@ void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){ myNodeActor->VisibilityOn(); } - if(myEntityMode & e0DElements){ + if(myEntityMode & e0DElements && GetRepresentation() != ePoint ){ my0DActor->VisibilityOn(); } - if(myEntityMode & eBallElem){ + if(myEntityMode & eBallElem && GetRepresentation() != ePoint ){ myBallActor->VisibilityOn(); } @@ -1492,6 +1513,8 @@ void SMESH_ActorDef::SetRepresentation (int theMode) int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge); int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face); int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume); + int aNb0Ds = myVisualObj->GetNbEntities(SMDSAbs_0DElement); + int aNbBalls = myVisualObj->GetNbEntities(SMDSAbs_Ball); if (theMode < 0) { myRepresentation = eSurface; @@ -1503,10 +1526,10 @@ void SMESH_ActorDef::SetRepresentation (int theMode) } else { switch (theMode) { case eEdge: - if (!aNbFaces && !aNbVolumes && !aNbEdges) return; + if (!aNbFaces && !aNbVolumes && !aNbEdges && !aNb0Ds && !aNbBalls) return; break; case eSurface: - if (!aNbFaces && !aNbVolumes) return; + if (!aNbFaces && !aNbVolumes && !aNb0Ds && !aNbBalls) return; break; } myRepresentation = theMode; @@ -1633,9 +1656,12 @@ void SMESH_ActorDef::UpdateHighlight(){ { if(myIsHighlighted) { myHighlitableActor->SetProperty(myHighlightProp); + myBallActor->SetProperty(myBallHighlightProp); }else if(myIsPreselected){ myHighlitableActor->SetProperty(myPreselectProp); + myBallActor->SetProperty(myBallPreselectProp); } else if(anIsVisible){ + myBallActor->SetProperty(myBallProp); (myRepresentation == eSurface) ? myHighlitableActor->SetProperty(myOutLineProp) : myHighlitableActor->SetProperty(myEdgeProp); } @@ -1781,6 +1807,8 @@ void SMESH_ActorDef::SetOpacity(vtkFloatingPointType theValue){ myNodeProp->SetOpacity(theValue); my1DProp->SetOpacity(theValue); + my0DProp->SetOpacity(theValue); + myBallProp->SetOpacity(theValue); } @@ -1871,6 +1899,7 @@ void SMESH_ActorDef::GetBallColor(vtkFloatingPointType& r,vtkFloatingPointType& void SMESH_ActorDef::SetHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ myHighlightProp->SetColor(r,g,b); + myBallHighlightProp->SetColor(r,g,b); Modified(); } @@ -1880,6 +1909,7 @@ void SMESH_ActorDef::GetHighlightColor(vtkFloatingPointType& r,vtkFloatingPointT void SMESH_ActorDef::SetPreHighlightColor(vtkFloatingPointType r,vtkFloatingPointType g,vtkFloatingPointType b){ myPreselectProp->SetColor(r,g,b); + myBallPreselectProp->SetColor(r,g,b); Modified(); } @@ -1908,6 +1938,16 @@ void SMESH_ActorDef::SetLineWidth(vtkFloatingPointType theVal){ void SMESH_ActorDef::Set0DSize(vtkFloatingPointType theVal){ my0DProp->SetPointSize(theVal); + myHighlightProp->SetPointSize(theVal); + myPreselectProp->SetPointSize(theVal); + + if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) { + aCustom->Set0DSize(theVal); + } + if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) { + aCustom->Set0DSize(theVal); + } + Modified(); } @@ -1917,6 +1957,15 @@ vtkFloatingPointType SMESH_ActorDef::Get0DSize(){ void SMESH_ActorDef::SetBallSize(vtkFloatingPointType theVal){ myBallProp->SetPointSize(theVal); + myBallHighlightProp->SetPointSize(theVal); + myBallPreselectProp->SetPointSize(theVal); + if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myHighlightActor )) { + aCustom->SetBallSize(theVal); + } + if(SMESH_SVTKActor* aCustom = SMESH_SVTKActor::SafeDownCast( myPreHighlightActor )) { + aCustom->SetBallSize(theVal); + } + Modified(); } diff --git a/src/OBJECT/SMESH_ActorDef.h b/src/OBJECT/SMESH_ActorDef.h index b346e68b4..09bec1848 100644 --- a/src/OBJECT/SMESH_ActorDef.h +++ b/src/OBJECT/SMESH_ActorDef.h @@ -243,6 +243,9 @@ class SMESH_ActorDef : public SMESH_Actor vtkProperty* myHighlightProp; vtkProperty* myOutLineProp; vtkProperty* myPreselectProp; + + vtkProperty* myBallHighlightProp; + vtkProperty* myBallPreselectProp; SMESH_DeviceActor* myHighlitableActor; diff --git a/src/OBJECT/SMESH_SVTKActor.cxx b/src/OBJECT/SMESH_SVTKActor.cxx new file mode 100644 index 000000000..b86c81d54 --- /dev/null +++ b/src/OBJECT/SMESH_SVTKActor.cxx @@ -0,0 +1,184 @@ +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// + +// SMESH OBJECT : interactive object for SMESH visualization +// File : SMESH_SVTKActor.cxx +// Author : Roman NIKOLAEV +// Module : SMESH +// + +#include "SMESH_SVTKActor.h" + +#include +#include + + +#include +#include +#include +#include +#include +#include +#include + +vtkStandardNewMacro(SMESH_SVTKActor); + +/*! + Constructor +*/ +SMESH_SVTKActor::SMESH_SVTKActor(): + my0DGrid(vtkUnstructuredGrid::New()), + myBallGrid(vtkUnstructuredGrid::New()) +{ + my0DActor = SVTK_DeviceActor::New(); + myBallActor = SVTK_DeviceActor::New(); + + myBallActor->SetResolveCoincidentTopology(false); + myBallActor->SetCoincident3DAllowed(true); + myBallActor->PickableOff(); + my0DActor->SetResolveCoincidentTopology(false); + my0DActor->SetCoincident3DAllowed(true); + my0DActor->PickableOff(); + + my0DGrid->Allocate(); + myBallGrid->Allocate(); +} + +/*! + Constructor +*/ +SMESH_SVTKActor::~SMESH_SVTKActor() { + my0DActor->Delete(); + myBallActor->Delete(); + my0DGrid->Delete(); + myBallGrid->Delete(); +} + +/*! + Publishes the actor in all its internal devices +*/ +void SMESH_SVTKActor::AddToRender(vtkRenderer* theRenderer) { + Superclass::AddToRender(theRenderer); + float a0D = my0DActor->GetProperty()->GetPointSize(); + float aBall = myBallActor->GetProperty()->GetPointSize(); + my0DActor->GetProperty()->DeepCopy(GetProperty()); + myBallActor->GetProperty()->DeepCopy(GetProperty()); + my0DActor->GetProperty()->SetPointSize(a0D); + myBallActor->GetProperty()->SetPointSize(aBall); + theRenderer->AddActor(my0DActor); + theRenderer->AddActor(myBallActor); + +} + +/*! + Removes the actor from all its internal devices +*/ +void +SMESH_SVTKActor +::RemoveFromRender(vtkRenderer* theRenderer) +{ + Superclass::RemoveFromRender(theRenderer); + theRenderer->RemoveActor( myBallActor ); + theRenderer->RemoveActor( my0DActor ); +} + +void +SMESH_SVTKActor +::MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) +{ + myUnstructuredGrid->Initialize(); + myUnstructuredGrid->Allocate(); + + my0DGrid->Initialize(); + my0DGrid->Allocate(); + + myBallGrid->Initialize(); + myBallGrid->Allocate(); + + vtkDataSet *aSourceDataSet = theMapActor->GetInput(); + SVTK::CopyPoints( GetSource(), aSourceDataSet ); + SVTK::CopyPoints( myBallGrid, aSourceDataSet ); + SVTK::CopyPoints( my0DGrid, aSourceDataSet ); + + int aNbOfParts = theMapIndex.Extent(); + for(int ind = 1; ind <= aNbOfParts; ind++){ + int aPartId = theMapIndex( ind ); + if(vtkCell* aCell = theMapActor->GetElemCell(aPartId)) + { +#if VTK_XVERSION > 50700 + if (aCell->GetCellType() != VTK_POLYHEDRON) +#endif + if(aCell->GetCellType() == VTK_VERTEX ) { + my0DGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + } else if(aCell->GetCellType() == VTK_POLY_VERTEX ) { + myBallGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + } else { + myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); + } +#if VTK_XVERSION > 50700 + else + { + vtkPolyhedron *polyhedron = dynamic_cast(aCell); + if (!polyhedron) + throw SALOME_Exception(LOCALIZED ("not a polyhedron")); + vtkIdType *pts = polyhedron->GetFaces(); + myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),pts[0], pts+1); + } +#endif + } + + UnShrink(); + if(theMapActor->IsShrunk()){ + SetShrinkFactor(theMapActor->GetShrinkFactor()); + SetShrink(); + } + + myMapIndex = theMapIndex; + } +} + +void +SMESH_SVTKActor +::Initialize() +{ + Superclass::Initialize(); + my0DActor->SetInput(my0DGrid); + myBallActor->SetInput(myBallGrid); +} + + +void SMESH_SVTKActor::SetVisibility( int theVisibility ) { + Superclass::SetVisibility( theVisibility ); + my0DActor->SetVisibility( theVisibility ); + myBallActor->SetVisibility( theVisibility ); +} + + +void SMESH_SVTKActor::Set0DSize(float theSize) { + my0DActor->GetProperty()->SetPointSize(theSize); +} + +void SMESH_SVTKActor::SetBallSize(float theSize) { + myBallActor->GetProperty()->SetPointSize(theSize); +} + diff --git a/src/OBJECT/SMESH_SVTKActor.h b/src/OBJECT/SMESH_SVTKActor.h new file mode 100644 index 000000000..54b3ad305 --- /dev/null +++ b/src/OBJECT/SMESH_SVTKActor.h @@ -0,0 +1,82 @@ +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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 +// + +// SMESH OBJECT : interactive object for SMESH visualization +// File : SMESH_SVTKActor.h +// Author : Roman NIKOLAEV +// Module : SMESH +// +#ifndef SMESH_SVTKACTOR_H +#define SMESH_SVTKACTOR_H + +#include "SMESH_Object.h" +#include + + +class SVTK_Actor; +class vtkUnstructureGrid; +class vtkDataSetMapper; + +class SMESHOBJECT_EXPORT SMESH_SVTKActor : public SVTK_Actor { + +public: + static SMESH_SVTKActor* New(); + + vtkTypeMacro(SMESH_SVTKActor, SVTK_Actor); + + void SetBallSize(float theSize); + void Set0DSize(float theSize); + + //! To publish the actor an all its internal devices + virtual + void + AddToRender(vtkRenderer* theRendere); + + virtual void SetVisibility( int theVisibility ); + + //! Initialiaze the instance completely + virtual void + Initialize(); + + //! Allow to recostruct selected cells from source SALOME_Actor and map of subindexes + virtual void + MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex); + + + //! To remove the actor an all its internal devices + virtual + void + RemoveFromRender(vtkRenderer* theRendere); + + protected: + SVTK_DeviceActor* my0DActor; + SVTK_DeviceActor* myBallActor; + + vtkUnstructuredGrid* my0DGrid; + vtkUnstructuredGrid* myBallGrid; + + SMESH_SVTKActor(); + virtual ~SMESH_SVTKActor(); +}; + +#endif diff --git a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx index 1b6f8cda7..2a1cb2f5a 100644 --- a/src/SMESHGUI/SMESHGUI_GroupDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_GroupDlg.cxx @@ -805,7 +805,7 @@ void SMESHGUI_GroupDlg::setSelectionMode (int theMode) if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : EdgeSelection); break; case grpBallSelection: - //if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : BallSelection); + if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : CellSelection); break; case grpFaceSelection: if ( aViewWindow ) aViewWindow->SetSelectionMode(isSelectAll ? ActorSelection : FaceSelection); @@ -1759,7 +1759,7 @@ void SMESHGUI_GroupDlg::onAdd() break; case grpBallSelection: aType = SMESH::BALL; - //mySelector->SetSelectionMode(BallSelection); + mySelector->SetSelectionMode(CellSelection); break; case grpEdgeSelection: aType = SMESH::EDGE; -- 2.30.2