Salome HOME
refs #1461: draft patch for some simple acceleration
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_VTKPrs.h
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.
6 //
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.
11 //
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
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #ifndef HYDROGUI_VTKPrs_H
20 #define HYDROGUI_VTKPrs_H
21
22 #include <HYDROData_Entity.h>
23 #include <HYDROData_AltitudeObject.h>
24
25 #include <SALOME_InteractiveObject.hxx>
26 #include <SVTK_Prs.h>
27 #include <vtkActorCollection.h>
28
29 class vtkMapper;
30
31 template <class ActorType> ActorType* getActor(SVTK_Prs* thePrs);
32
33 /**
34  * Get a VTK actor of the given presentation. Create a new one if there is no actor yet.
35  */
36 template <class ActorType>
37 ActorType* getActor(SVTK_Prs* thePrs)
38 {
39   ActorType* anActor = 0;
40   vtkActorCollection* aContent = thePrs->GetObjects();
41   if ( aContent )
42   {
43     // Remove old actor because of the problem of GEOM_Actor updating.
44     //anActor = dynamic_cast<ActorType*>( aContent->GetLastActor() );
45     aContent->RemoveAllItems();
46   }
47   if ( !anActor )
48   {
49     anActor = ActorType::New();
50     thePrs->AddObject( anActor );
51     anActor->Delete();
52   }
53   return anActor;
54 }
55
56
57 /*
58   Class       : HYDROGUI_VTKPrs
59   Description : Base class for all HYDRO presentation in VTK viewer
60 */
61 class HYDROGUI_VTKPrs : public SVTK_Prs
62 {
63 public:
64   HYDROGUI_VTKPrs( const Handle(HYDROData_Entity)& theObject );
65   virtual ~HYDROGUI_VTKPrs();
66
67   virtual void                     compute();
68   virtual bool                     needScalarBar() { return false; }
69
70   static double InvalidZValue() { return HYDROData_AltitudeObject::GetInvalidAltitude(); }
71
72 public:
73   Handle(HYDROData_Entity)         getObject() const { return myObject; }
74   Handle(SALOME_InteractiveObject) getIO() const { return myIO; }
75
76   bool                             getIsToUpdate() const { return myIsToUpdate; }
77   void                             setIsToUpdate( bool theState ) { myIsToUpdate = theState; }
78   /**
79    * \brief Set the range of Z values for the color mapping.
80    */
81   virtual void                     setZRange( double theRange[] );
82   /**
83    * \brief Get the range of Z values for the color mapping.
84    */
85   virtual double*                 getZRange() { return myZRange; }
86   /**
87    * \brief Get an actual Z values range of the presented object.
88    */
89   virtual double*                 getInternalZRange() { return myInternalZRange; }
90
91 protected:
92   virtual vtkMapper*               mapper() { return 0; }
93
94   double                           myInternalZRange[2]; //!< Actual Z values range of the presented object
95
96 private:
97   Handle(HYDROData_Entity)         myObject;
98   Handle(SALOME_InteractiveObject) myIO;
99   bool                             myIsToUpdate;
100   double                           myZRange[2];         //!< Imposed Z values range for colors mapping
101 };
102
103 #endif