Salome HOME
16983bf278d1978c61f3590d5ac8b5e6c1561aaf
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_VTKPrsBathymetry.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_VTKPrsBathymetry.h"
24
25 #include <HYDROData_Entity.h>
26
27 #include <SALOME_Actor.h>
28 #include <gp_XYZ.hxx>
29 #include <vtkPoints.h>
30 #include <vtkPolyData.h>
31 #include <vtkPolyDataMapper.h>
32 #include <vtkVertex.h>
33
34 #include <QString>
35
36 //=======================================================================
37 // name    : HYDROGUI_VTKPrsBathymetry
38 // Purpose : Constructor
39 //=======================================================================
40 HYDROGUI_VTKPrsBathymetry::HYDROGUI_VTKPrsBathymetry( const Handle(HYDROData_Bathymetry)& theObject )
41 : HYDROGUI_VTKPrs( theObject )
42 {
43 }
44
45 //=======================================================================
46 // name    : HYDROGUI_VTKPrsBathymetry
47 // Purpose : Destructor
48 //=======================================================================
49 HYDROGUI_VTKPrsBathymetry::~HYDROGUI_VTKPrsBathymetry()
50 {
51 }
52
53 //================================================================
54 // Function : compute
55 // Purpose  : 
56 //================================================================
57 void HYDROGUI_VTKPrsBathymetry::compute()
58 {
59   if ( !getObject().IsNull() )
60   {
61     Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
62     if ( !aBathymetry.IsNull() )
63     {
64       HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints();
65       int aNbPoints = anAltPoints.length();
66
67       HYDROData_Bathymetry::AltitudePoint anAltPnt;
68       vtkPoints* aPoints = vtkPoints::New();
69       aPoints->SetNumberOfPoints( aNbPoints );
70
71       vtkPolyData* aVertexGrid = vtkPolyData::New();
72       aVertexGrid->Allocate( aNbPoints );
73
74       vtkVertex* aVertex = vtkVertex::New();
75
76       for (int i = 0; i < aNbPoints; i++ )
77       {
78         anAltPnt = anAltPoints.at( i );
79         aPoints->InsertPoint( i, anAltPnt.X(), anAltPnt.Y(), anAltPnt.Z() );
80         aVertex->GetPointIds()->SetId( 0, i );
81         aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
82       }
83
84       aVertex->Delete();
85
86       aVertexGrid->SetPoints( aPoints );
87       vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New();
88       aMapper->SetInputData( aVertexGrid );
89       SALOME_Actor* anActor = SALOME_Actor::New();
90       anActor->SetMapper( aMapper );
91       anActor->setIO( getIO() );
92       //anActor->setName( aBathymetry->GetName().toLatin1() );
93       AddObject( anActor );
94       //anActor.AddPosition(0, 0, 6);
95       //anActor.GetProperty().SetDiffuseColor(1, 1, 1);
96     }
97   }
98 }