1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_VTKPrsBathymetry.h"
21 #include <HYDROData_Entity.h>
22 #include <HYDROData_Tool.h>
24 #include <SALOME_Actor.h>
26 #include <vtkDoubleArray.h>
27 #include <vtkPoints.h>
28 #include <vtkPolyData.h>
29 #include <vtkPointData.h>
30 #include <vtkPolyDataMapper.h>
31 #include <vtkVertex.h>
32 #include <vtkScalarBarActor.h>
37 \brief Maximum Z value used in bathymetry presentation.
39 This value is used instead of invalid values.
43 //=======================================================================
44 // name : HYDROGUI_VTKPrsBathymetry
45 // Purpose : Constructor
46 //=======================================================================
47 HYDROGUI_VTKPrsBathymetry::HYDROGUI_VTKPrsBathymetry( const Handle(HYDROData_Bathymetry)& theObject )
48 : HYDROGUI_VTKPrs( theObject )
52 //=======================================================================
53 // name : HYDROGUI_VTKPrsBathymetry
54 // Purpose : Destructor
55 //=======================================================================
56 HYDROGUI_VTKPrsBathymetry::~HYDROGUI_VTKPrsBathymetry()
60 //================================================================
63 //================================================================
64 void HYDROGUI_VTKPrsBathymetry::compute()
66 HYDROGUI_VTKPrs::compute();
68 if ( !getObject().IsNull() )
70 Handle(HYDROData_Bathymetry) aBathymetry = Handle(HYDROData_Bathymetry)::DownCast( getObject() );
71 if ( !aBathymetry.IsNull() )
73 HYDROData_Bathymetry::AltitudePoints anAltPoints = aBathymetry->GetAltitudePoints();
74 int aNbPoints = anAltPoints.size();
76 HYDROData_Bathymetry::AltitudePoint anAltPnt;
77 vtkPoints* aPoints = vtkPoints::New();
78 aPoints->SetNumberOfPoints( aNbPoints );
80 vtkPolyData* aVertexGrid = vtkPolyData::New();
81 aVertexGrid->Allocate( aNbPoints );
83 vtkDoubleArray* aZValues = vtkDoubleArray::New();
84 aZValues->Allocate( aNbPoints );
86 vtkVertex* aVertex = vtkVertex::New();
89 int anInvalidZ = InvalidZValue();
90 for (int i = 0; i < aNbPoints; i++ )
92 anAltPnt = anAltPoints[i];
94 if ( ValuesLessEquals( aZ, anInvalidZ ) )
96 aZ = Z_MAX; // If Z value is invalid then use Z_MAX
98 aPoints->InsertPoint( i, anAltPnt.X, anAltPnt.Y, aZ );
99 aVertex->GetPointIds()->SetId( 0, i );
100 aVertexGrid->InsertNextCell( aVertex->GetCellType(), aVertex->GetPointIds());
101 aZValues->InsertNextValue( aZ );
106 aVertexGrid->SetPoints( aPoints );
107 aVertexGrid->GetPointData()->SetScalars( aZValues );
109 // Update the lookup table range if this bathymetry is out of it
112 aZValues->GetRange( myInternalZRange );
113 double* aGlobalRange = myLookupTable->GetRange();
114 // If the global range is not yet initialized or the current one is out of scope then update the global
115 bool anIsUpdated = false;
116 if ( ValuesEquals( aGlobalRange[0], anInvalidZ ) || ( aGlobalRange[0] > myInternalZRange[0] ) )
118 aGlobalRange[0] = myInternalZRange[0];
122 if ( ValuesEquals( aGlobalRange[1], anInvalidZ ) || ( aGlobalRange[1] < myInternalZRange[1] ) )
124 aGlobalRange[1] = myInternalZRange[1];
130 myLookupTable->SetRange( aGlobalRange );
131 myLookupTable->Build();
134 myMapper->SetScalarRange( aGlobalRange );
135 myMapper->ScalarVisibilityOn();
136 myMapper->SetScalarModeToUsePointData();
137 myMapper->SetLookupTable( myLookupTable );
140 myMapper->SetInputData( aVertexGrid );
142 SALOME_Actor* anActor = getActor<SALOME_Actor>(this);
143 anActor->SetMapper( myMapper.GetPointer() );
144 anActor->setIO( getIO() );
145 AddObject( anActor );
147 aVertexGrid->Delete();