1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESHGUI_IdPreview.h"
25 #include <SMDS_Mesh.hxx>
27 #include <SALOME_Actor.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SVTK_ViewWindow.h>
32 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
34 #include <vtkActor2D.h>
35 #include <vtkDataSetMapper.h>
36 #include <vtkLabeledDataMapper.h>
37 #include <vtkMaskPoints.h>
38 #include <vtkPointData.h>
39 #include <vtkProperty2D.h>
40 #include <vtkRenderer.h>
41 #include <vtkSelectVisiblePoints.h>
42 #include <vtkTextProperty.h>
43 #include <vtkUnstructuredGrid.h>
45 // Extracted from SMESHGUI_MergeDlg.cxx
47 SMESHGUI_IdPreview::SMESHGUI_IdPreview(SVTK_ViewWindow* theViewWindow):
48 myViewWindow(theViewWindow)
50 myIdGrid = vtkUnstructuredGrid::New();
52 // Create and display actor
53 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
54 aMapper->SetInputData( myIdGrid );
56 myIdActor = SALOME_Actor::New();
57 myIdActor->SetInfinitive(true);
58 myIdActor->VisibilityOff();
59 myIdActor->PickableOff();
61 myIdActor->SetMapper( aMapper );
64 myViewWindow->AddActor(myIdActor);
66 //Definition of points numbering pipeline
67 myPointsNumDataSet = vtkUnstructuredGrid::New();
69 myPtsMaskPoints = vtkMaskPoints::New();
70 myPtsMaskPoints->SetInputData(myPointsNumDataSet);
71 myPtsMaskPoints->SetOnRatio(1);
73 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
74 myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
75 myPtsSelectVisiblePoints->SelectInvisibleOff();
76 myPtsSelectVisiblePoints->SetTolerance(0.1);
78 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
79 myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
80 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
82 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
83 aPtsTextProp->SetFontFamilyToTimes();
84 int aPointsFontSize = 12;
85 if ( SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr() )
86 if ( mgr->hasValue( "SMESH", "numbering_node_font" ) )
88 QFont f = mgr->fontValue( "SMESH", "numbering_node_font" );
89 aPointsFontSize = f.pointSize();
91 aPtsTextProp->SetFontSize(aPointsFontSize);
92 aPtsTextProp->SetBold(1);
93 aPtsTextProp->SetItalic(0);
94 aPtsTextProp->SetShadow(0);
95 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
96 aPtsTextProp->Delete();
98 myIsPointsLabeled = false;
100 myPointLabels = vtkActor2D::New();
101 myPointLabels->SetMapper(myPtsLabeledDataMapper);
102 myPointLabels->GetProperty()->SetColor(1,1,1);
103 myPointLabels->SetVisibility(myIsPointsLabeled);
105 AddToRender(myViewWindow->getRenderer());
108 void SMESHGUI_IdPreview::SetPointsData ( SMDS_Mesh* theMesh,
109 const SVTK_TVtkIDsMap & theNodesIdMap )
111 vtkPoints* aPoints = vtkPoints::New();
112 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
115 SVTK_TVtkIDsMapIterator idIter( theNodesIdMap );
116 for( int i = 0; idIter.More(); idIter.Next(), i++ )
118 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
119 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
120 myIDs.push_back(idIter.Key());
123 myIdGrid->SetPoints(aPoints);
127 myIdActor->GetMapper()->Update();
130 void SMESHGUI_IdPreview::SetElemsData( const std::vector<int> & theElemsIdMap,
131 const std::list<gp_XYZ> & aGrCentersXYZ )
133 vtkPoints* aPoints = vtkPoints::New();
134 aPoints->SetNumberOfPoints( theElemsIdMap.size() );
135 myIDs = theElemsIdMap;
137 std::list<gp_XYZ>::const_iterator coordIt = aGrCentersXYZ.begin();
138 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ )
139 aPoints->SetPoint( i, coordIt->X(), coordIt->Y(), coordIt->Z() );
141 myIdGrid->SetPoints(aPoints);
144 myIdActor->GetMapper()->Update();
147 void SMESHGUI_IdPreview::AddToRender(vtkRenderer* theRenderer)
149 myIdActor->AddToRender(theRenderer);
151 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
152 theRenderer->AddActor2D(myPointLabels);
155 void SMESHGUI_IdPreview::RemoveFromRender(vtkRenderer* theRenderer)
157 myIdActor->RemoveFromRender(theRenderer);
159 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
160 theRenderer->RemoveActor(myPointLabels);
163 void SMESHGUI_IdPreview::SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible )
165 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
167 if ( myIsPointsLabeled ) {
168 myPointsNumDataSet->ShallowCopy(myIdGrid);
169 vtkDataSet *aDataSet = myPointsNumDataSet;
170 int aNbElem = myIDs.size();
171 vtkIntArray *anArray = vtkIntArray::New();
172 anArray->SetNumberOfValues( aNbElem );
173 for ( int i = 0; i < aNbElem; i++ )
174 anArray->SetValue( i, myIDs[i] );
175 aDataSet->GetPointData()->SetScalars( anArray );
177 myPtsMaskPoints->SetInputData( aDataSet );
178 myPointLabels->SetVisibility( theIsActorVisible );
181 myPointLabels->SetVisibility( false );
185 SMESHGUI_IdPreview::~SMESHGUI_IdPreview()
187 RemoveFromRender(myViewWindow->getRenderer());
191 myViewWindow->RemoveActor(myIdActor);
194 //Deleting of points numbering pipeline
195 //---------------------------------------
196 myPointsNumDataSet->Delete();
198 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
199 myPtsLabeledDataMapper->Delete();
201 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
202 myPtsSelectVisiblePoints->Delete();
204 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
205 myPtsMaskPoints->Delete();
207 myPointLabels->Delete();
209 // myTimeStamp->Delete();