1 // Copyright (C) 2007-2020 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 <SALOME_Actor.h>
26 #include <SMDS_Mesh.hxx>
27 #include <SVTK_ViewWindow.h>
29 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
31 #include <vtkActor2D.h>
32 #include <vtkDataSetMapper.h>
33 #include <vtkLabeledDataMapper.h>
34 #include <vtkMaskPoints.h>
35 #include <vtkPointData.h>
36 #include <vtkProperty2D.h>
37 #include <vtkRenderer.h>
38 #include <vtkSelectVisiblePoints.h>
39 #include <vtkTextProperty.h>
40 #include <vtkUnstructuredGrid.h>
42 // Extracted from SMESHGUI_MergeDlg.cxx
44 SMESHGUI_IdPreview::SMESHGUI_IdPreview(SVTK_ViewWindow* theViewWindow):
45 myViewWindow(theViewWindow)
47 myIdGrid = vtkUnstructuredGrid::New();
49 // Create and display actor
50 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
51 aMapper->SetInputData( myIdGrid );
53 myIdActor = SALOME_Actor::New();
54 myIdActor->SetInfinitive(true);
55 myIdActor->VisibilityOff();
56 myIdActor->PickableOff();
58 myIdActor->SetMapper( aMapper );
61 myViewWindow->AddActor(myIdActor);
63 //Definition of points numbering pipeline
64 myPointsNumDataSet = vtkUnstructuredGrid::New();
66 myPtsMaskPoints = vtkMaskPoints::New();
67 myPtsMaskPoints->SetInputData(myPointsNumDataSet);
68 myPtsMaskPoints->SetOnRatio(1);
70 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
71 myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
72 myPtsSelectVisiblePoints->SelectInvisibleOff();
73 myPtsSelectVisiblePoints->SetTolerance(0.1);
75 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
76 myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
77 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
79 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
80 aPtsTextProp->SetFontFamilyToTimes();
81 static int aPointsFontSize = 12;
82 aPtsTextProp->SetFontSize(aPointsFontSize);
83 aPtsTextProp->SetBold(1);
84 aPtsTextProp->SetItalic(0);
85 aPtsTextProp->SetShadow(0);
86 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
87 aPtsTextProp->Delete();
89 myIsPointsLabeled = false;
91 myPointLabels = vtkActor2D::New();
92 myPointLabels->SetMapper(myPtsLabeledDataMapper);
93 myPointLabels->GetProperty()->SetColor(1,1,1);
94 myPointLabels->SetVisibility(myIsPointsLabeled);
96 AddToRender(myViewWindow->getRenderer());
99 void SMESHGUI_IdPreview::SetPointsData ( SMDS_Mesh* theMesh,
100 const TColStd_MapOfInteger & theNodesIdMap )
102 vtkPoints* aPoints = vtkPoints::New();
103 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
106 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
107 for( int i = 0; idIter.More(); idIter.Next(), i++ )
109 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
110 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
111 myIDs.push_back(idIter.Key());
114 myIdGrid->SetPoints(aPoints);
118 myIdActor->GetMapper()->Update();
121 void SMESHGUI_IdPreview::SetElemsData( const std::vector<int> & theElemsIdMap,
122 const std::list<gp_XYZ> & aGrCentersXYZ )
124 vtkPoints* aPoints = vtkPoints::New();
125 aPoints->SetNumberOfPoints( theElemsIdMap.size() );
126 myIDs = theElemsIdMap;
128 std::list<gp_XYZ>::const_iterator coordIt = aGrCentersXYZ.begin();
129 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ )
130 aPoints->SetPoint( i, coordIt->X(), coordIt->Y(), coordIt->Z() );
132 myIdGrid->SetPoints(aPoints);
135 myIdActor->GetMapper()->Update();
138 void SMESHGUI_IdPreview::AddToRender(vtkRenderer* theRenderer)
140 myIdActor->AddToRender(theRenderer);
142 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
143 theRenderer->AddActor2D(myPointLabels);
146 void SMESHGUI_IdPreview::RemoveFromRender(vtkRenderer* theRenderer)
148 myIdActor->RemoveFromRender(theRenderer);
150 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
151 theRenderer->RemoveActor(myPointLabels);
154 void SMESHGUI_IdPreview::SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible )
156 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
158 if ( myIsPointsLabeled ) {
159 myPointsNumDataSet->ShallowCopy(myIdGrid);
160 vtkDataSet *aDataSet = myPointsNumDataSet;
161 int aNbElem = myIDs.size();
162 vtkIntArray *anArray = vtkIntArray::New();
163 anArray->SetNumberOfValues( aNbElem );
164 for ( int i = 0; i < aNbElem; i++ )
165 anArray->SetValue( i, myIDs[i] );
166 aDataSet->GetPointData()->SetScalars( anArray );
168 myPtsMaskPoints->SetInputData( aDataSet );
169 myPointLabels->SetVisibility( theIsActorVisible );
172 myPointLabels->SetVisibility( false );
176 SMESHGUI_IdPreview::~SMESHGUI_IdPreview()
178 RemoveFromRender(myViewWindow->getRenderer());
182 myViewWindow->RemoveActor(myIdActor);
185 //Deleting of points numbering pipeline
186 //---------------------------------------
187 myPointsNumDataSet->Delete();
189 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
190 myPtsLabeledDataMapper->Delete();
192 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
193 myPtsSelectVisiblePoints->Delete();
195 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
196 myPtsMaskPoints->Delete();
198 myPointLabels->Delete();
200 // myTimeStamp->Delete();