1 // Copyright (C) 2007-2015 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_MapOfInteger.hxx>
30 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
32 #include <vtkActor2D.h>
33 #include <vtkDataSetMapper.h>
34 #include <vtkLabeledDataMapper.h>
35 #include <vtkMaskPoints.h>
36 #include <vtkPointData.h>
37 #include <vtkProperty2D.h>
38 #include <vtkRenderer.h>
39 #include <vtkSelectVisiblePoints.h>
40 #include <vtkTextProperty.h>
41 #include <vtkUnstructuredGrid.h>
43 // Extracted from SMESHGUI_MergeDlg.cxx
45 SMESHGUI_IdPreview::SMESHGUI_IdPreview(SVTK_ViewWindow* theViewWindow):
46 myViewWindow(theViewWindow)
48 myIdGrid = vtkUnstructuredGrid::New();
50 // Create and display actor
51 vtkDataSetMapper* aMapper = vtkDataSetMapper::New();
52 aMapper->SetInputData( myIdGrid );
54 myIdActor = SALOME_Actor::New();
55 myIdActor->SetInfinitive(true);
56 myIdActor->VisibilityOff();
57 myIdActor->PickableOff();
59 myIdActor->SetMapper( aMapper );
62 myViewWindow->AddActor(myIdActor);
64 //Definition of points numbering pipeline
65 myPointsNumDataSet = vtkUnstructuredGrid::New();
67 myPtsMaskPoints = vtkMaskPoints::New();
68 myPtsMaskPoints->SetInputData(myPointsNumDataSet);
69 myPtsMaskPoints->SetOnRatio(1);
71 myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New();
72 myPtsSelectVisiblePoints->SetInputConnection(myPtsMaskPoints->GetOutputPort());
73 myPtsSelectVisiblePoints->SelectInvisibleOff();
74 myPtsSelectVisiblePoints->SetTolerance(0.1);
76 myPtsLabeledDataMapper = vtkLabeledDataMapper::New();
77 myPtsLabeledDataMapper->SetInputConnection(myPtsSelectVisiblePoints->GetOutputPort());
78 myPtsLabeledDataMapper->SetLabelModeToLabelScalars();
80 vtkTextProperty* aPtsTextProp = vtkTextProperty::New();
81 aPtsTextProp->SetFontFamilyToTimes();
82 static int aPointsFontSize = 12;
83 aPtsTextProp->SetFontSize(aPointsFontSize);
84 aPtsTextProp->SetBold(1);
85 aPtsTextProp->SetItalic(0);
86 aPtsTextProp->SetShadow(0);
87 myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp);
88 aPtsTextProp->Delete();
90 myIsPointsLabeled = false;
92 myPointLabels = vtkActor2D::New();
93 myPointLabels->SetMapper(myPtsLabeledDataMapper);
94 myPointLabels->GetProperty()->SetColor(1,1,1);
95 myPointLabels->SetVisibility(myIsPointsLabeled);
97 AddToRender(myViewWindow->getRenderer());
100 void SMESHGUI_IdPreview::SetPointsData ( SMDS_Mesh* theMesh,
101 const TColStd_MapOfInteger & theNodesIdMap )
103 vtkPoints* aPoints = vtkPoints::New();
104 aPoints->SetNumberOfPoints(theNodesIdMap.Extent());
107 TColStd_MapIteratorOfMapOfInteger idIter( theNodesIdMap );
108 for( int i = 0; idIter.More(); idIter.Next(), i++ )
110 const SMDS_MeshNode* aNode = theMesh->FindNode(idIter.Key());
111 aPoints->SetPoint( i, aNode->X(), aNode->Y(), aNode->Z() );
112 myIDs.push_back(idIter.Key());
115 myIdGrid->SetPoints(aPoints);
119 myIdActor->GetMapper()->Update();
122 void SMESHGUI_IdPreview::SetElemsData( const std::vector<int> & theElemsIdMap,
123 const std::list<gp_XYZ> & aGrCentersXYZ )
125 vtkPoints* aPoints = vtkPoints::New();
126 aPoints->SetNumberOfPoints( theElemsIdMap.size() );
127 myIDs = theElemsIdMap;
129 std::list<gp_XYZ>::const_iterator coordIt = aGrCentersXYZ.begin();
130 for( int i = 0; coordIt != aGrCentersXYZ.end(); coordIt++, i++ )
131 aPoints->SetPoint( i, coordIt->X(), coordIt->Y(), coordIt->Z() );
133 myIdGrid->SetPoints(aPoints);
136 myIdActor->GetMapper()->Update();
139 void SMESHGUI_IdPreview::AddToRender(vtkRenderer* theRenderer)
141 myIdActor->AddToRender(theRenderer);
143 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
144 theRenderer->AddActor2D(myPointLabels);
147 void SMESHGUI_IdPreview::RemoveFromRender(vtkRenderer* theRenderer)
149 myIdActor->RemoveFromRender(theRenderer);
151 myPtsSelectVisiblePoints->SetRenderer(theRenderer);
152 theRenderer->RemoveActor(myPointLabels);
155 void SMESHGUI_IdPreview::SetPointsLabeled( bool theIsPointsLabeled, bool theIsActorVisible )
157 myIsPointsLabeled = theIsPointsLabeled && myIdGrid->GetNumberOfPoints();
159 if ( myIsPointsLabeled ) {
160 myPointsNumDataSet->ShallowCopy(myIdGrid);
161 vtkDataSet *aDataSet = myPointsNumDataSet;
162 int aNbElem = myIDs.size();
163 vtkIntArray *anArray = vtkIntArray::New();
164 anArray->SetNumberOfValues( aNbElem );
165 for ( int i = 0; i < aNbElem; i++ )
166 anArray->SetValue( i, myIDs[i] );
167 aDataSet->GetPointData()->SetScalars( anArray );
169 myPtsMaskPoints->SetInputData( aDataSet );
170 myPointLabels->SetVisibility( theIsActorVisible );
173 myPointLabels->SetVisibility( false );
177 SMESHGUI_IdPreview::~SMESHGUI_IdPreview()
179 RemoveFromRender(myViewWindow->getRenderer());
183 myViewWindow->RemoveActor(myIdActor);
186 //Deleting of points numbering pipeline
187 //---------------------------------------
188 myPointsNumDataSet->Delete();
190 //myPtsLabeledDataMapper->RemoveAllInputs(); //vtk 5.0 porting
191 myPtsLabeledDataMapper->Delete();
193 //myPtsSelectVisiblePoints->UnRegisterAllOutputs(); //vtk 5.0 porting
194 myPtsSelectVisiblePoints->Delete();
196 //myPtsMaskPoints->UnRegisterAllOutputs(); //vtk 5.0 porting
197 myPtsMaskPoints->Delete();
199 myPointLabels->Delete();
201 // myTimeStamp->Delete();