Salome HOME
This commit was generated by cvs2git to create tag 'V1_4_0b2'.
[modules/kernel.git] / src / OBJECT / SALOME_Actor.cxx
1 //  SALOME OBJECT : implementation of interactive object visualization for OCC and VTK viewers
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_Actor.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 /*!
30   \class SALOME_Actor SALOME_Actor.h
31   \brief Abstract class of SALOME Objects in VTK.
32 */
33
34 #include "SALOME_Actor.h"
35 #include "SALOME_Transform.h"
36 #include "SALOME_TransformFilter.h"
37 #include "SALOME_PassThroughFilter.h"
38 #include "SALOME_GeometryFilter.h"
39  
40 // SALOME Includes
41 #include "utilities.h"
42
43 // VTK Includes
44 #include <vtkObjectFactory.h>
45 #include <vtkDataSetMapper.h>
46 #include <vtkPolyDataMapper.h>
47 #include <vtkTransformPolyDataFilter.h>
48
49 // For test
50 #include <vtkMapperCollection.h>
51 #include "vtkTimerLog.h"
52
53 using namespace std;
54
55 int SALOME_POINT_SIZE = 3;
56
57
58 vtkStandardNewMacro(SALOME_Actor);
59
60 void SALOME_Actor::AddToRender(vtkRenderer* theRenderer){
61   theRenderer->AddActor(this);
62 }
63 void SALOME_Actor::RemoveFromRender(vtkRenderer* theRenderer){
64   theRenderer->RemoveActor(this);
65 }
66
67
68 vtkPolyData* SALOME_Actor::GetPolyDataInput(){
69   return myPassFilter[3]->GetPolyDataOutput();
70 }
71
72 void SALOME_Actor::SetMapper(vtkMapper* theMapper){
73   if(theMapper){
74     myPassFilter[0]->SetInput(theMapper->GetInput());
75     myPassFilter[1]->SetInput(myPassFilter[0]->GetPolyDataOutput());
76     myTransformFilter->SetInput(myPassFilter[1]->GetPolyDataOutput());
77     myPassFilter[2]->SetInput(myTransformFilter->GetOutput());
78     myPassFilter[3]->SetInput(myPassFilter[2]->GetPolyDataOutput());
79     if(vtkDataSetMapper* aMapper = dynamic_cast<vtkDataSetMapper*>(theMapper))
80       aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
81     else if(vtkPolyDataMapper* aMapper = dynamic_cast<vtkPolyDataMapper*>(theMapper))
82       aMapper->SetInput(myPassFilter[3]->GetPolyDataOutput());
83   }
84   vtkLODActor::SetMapper(theMapper);
85 }
86
87 void SALOME_Actor::SetTransform(SALOME_Transform* theTransform){
88   myTransformFilter->SetTransform(theTransform);
89 }
90
91
92 unsigned long int SALOME_Actor::GetMTime(){
93   unsigned long mTime = this->Superclass::GetMTime();
94   unsigned long time = myTransformFilter->GetMTime();
95   mTime = ( time > mTime ? time : mTime );
96   return mTime;
97 }
98
99
100 void SALOME_Actor::SetRepresentation(int theMode) { 
101   switch(myRepresentation){
102   case 0 : 
103   case 2 : 
104     myProperty->DeepCopy(GetProperty());
105   }    
106   switch(theMode){
107   case 0 : 
108   case 2 : 
109     GetProperty()->DeepCopy(myProperty);
110     break;
111   default:
112     GetProperty()->SetAmbient(1.0);
113     GetProperty()->SetDiffuse(0.0);
114     GetProperty()->SetSpecular(0.0);
115   }
116   switch(theMode){
117   case 3 : 
118     myPassFilter[0]->SetInside(true);
119     GetProperty()->SetRepresentation(1);
120     break;
121   case 0 : 
122     GetProperty()->SetPointSize(SALOME_POINT_SIZE);  
123   default :
124     GetProperty()->SetRepresentation(theMode);
125     myPassFilter[0]->SetInside(false);
126   }
127   myRepresentation = theMode;
128 }
129 int SALOME_Actor::GetRepresentation(){ 
130   return myRepresentation;
131 }
132
133
134 SALOME_Actor::SALOME_Actor(){
135   PreviewProperty = NULL;
136   ispreselected = Standard_False;
137   myProperty = vtkProperty::New();
138   myRepresentation = 2;
139   myTransformFilter = SALOME_TransformFilter::New();
140   myPassFilter.push_back(SALOME_PassThroughFilter::New());
141   myPassFilter.push_back(SALOME_PassThroughFilter::New());
142   myPassFilter.push_back(SALOME_PassThroughFilter::New());
143   myPassFilter.push_back(SALOME_PassThroughFilter::New());
144 }
145
146 SALOME_Actor::~SALOME_Actor(){
147   myTransformFilter->Delete();
148   SetPreviewProperty(NULL);
149   for(int i = 0, iEnd = myPassFilter.size(); i < iEnd; i++)
150     if(myPassFilter[i] != NULL){
151       myPassFilter[i]->UnRegisterAllOutputs(); 
152       myPassFilter[i]->Delete();
153     }
154   myProperty->Delete();
155 }