]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataToActor.cxx
569bcb25b0832dad19bc1e3dc9f4a38ab9cd4687
[bbtk.git] / packages / vtk / src / bbvtkPolyDataToActor.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbvtkPolyDataToActor.cxx,v $
31   Language:  C++
32   Date:      $Date: 2009/05/28 08:55:44 $
33   Version:   $Revision: 1.15 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41
42 #ifdef _USE_VTK_
43
44 #include "vtkProperty.h"
45 #include "vtkLinearTransform.h"
46 #include "vtkCleanPolyData.h"
47
48 #include "bbvtkPolyDataToActor.h"
49 #include "bbvtkPackage.h"
50
51 #include "vtkRenderWindow.h"
52
53 namespace bbvtk
54 {
55    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataToActor)
56    BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataToActor,bbtk::AtomicBlackBox);
57
58    void PolyDataToActor::bbUserSetDefaultValues() 
59    { 
60            actorAdded=false;
61            std::vector<double> colour;
62            colour.push_back(1.0);
63            colour.push_back(1.0);
64            colour.push_back(0.5);
65            bbSetInputColour(colour);
66            bbSetInputActive(true);
67            bbSetInputIn(NULL);
68            bbSetInputRenderer(NULL);
69            bbSetInputTransform(NULL);
70            bbSetInputOpacity(1);
71            bbSetInputRepresentation(2);
72            bbSetInputLineWidth(1);
73            bbSetInputScalarVisibility(false);
74            polydatamapper = NULL;
75            vtkactor       = NULL;
76    }
77
78
79         //---------------------------------------------------------------------
80    void PolyDataToActor::bbUserInitializeProcessing() 
81    {     
82      polydatamapper = vtkPolyDataMapper::New();
83      vtkactor       = vtkActor::New();
84
85 //     polydatamapper->SetInput(marchingcubes->GetOutput());
86      vtkactor->SetMapper(polydatamapper);
87
88 //     polydatamapper->ImmediateModeRenderingOn();
89    }
90
91         //---------------------------------------------------------------------
92         void PolyDataToActor::bbUserFinalizeProcessing() 
93         { 
94                 if (polydatamapper!=NULL)
95                 {
96                         polydatamapper->Delete();
97                         polydatamapper=NULL;
98                 }
99                 if (vtkactor!=NULL)
100                 {
101                         vtkactor->Delete();
102                         vtkactor=NULL;
103                 }               
104         }
105         
106         
107 //---------------------------------------------------------------------
108
109         void PolyDataToActor::DoProcess()
110         {
111
112 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
113 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
114 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
115 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
116 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
117 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
118 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
119 printf("EED WARNNIN!!!!! PolyDataToActor::DoProcess For better transparent ...  Clean this code in the correct part ..........\n");
120 //https://stackoverflow.com/questions/47528086/problems-with-rendering-transparent-objects-in-vtk
121 //https://itk.org/Wiki/VTK/Depth_Peeling
122 bbGetInputRenderer()->SetUseDepthPeeling(1);
123 bbGetInputRenderer()->SetOcclusionRatio(0.1);
124 bbGetInputRenderer()->SetMaximumNumberOfPeels(100);
125 bbGetInputRenderer()->GetRenderWindow()->SetMultiSamples(0);
126 bbGetInputRenderer()->GetRenderWindow()->SetAlphaBitPlanes(1);
127
128
129                 if (bbGetInputActive()==true)
130                 {
131
132
133 //EED 2017-01-01 Migration VTK7
134 #if VTK_MAJOR_VERSION <= 5
135                          polydatamapper->SetInput( bbGetInputIn() );
136 #else
137                          polydatamapper->SetInputData( bbGetInputIn() );  
138 #endif
139
140                          vtkactor->GetProperty()->SetRepresentation( bbGetInputRepresentation() );
141
142                         if (bbGetInputRepresentation()==0)
143                         {
144                                  vtkactor->GetProperty()->SetAmbient(1);
145                                  vtkactor->GetProperty()->SetDiffuse(1);
146                                  vtkactor->GetProperty()->SetSpecular(0);
147 printf("EED WARNNING!  PolyDataToActor::DoProcess  which is the default values of Ambient, Diffuse, Specular for points option? \n");
148                         } else if (bbGetInputRepresentation()==1)
149                         {
150                                  vtkactor->GetProperty()->SetAmbient(1);
151                                  vtkactor->GetProperty()->SetDiffuse(1);
152                                  vtkactor->GetProperty()->SetSpecular(0);
153                         } else if (bbGetInputRepresentation()==2)
154                         {
155                                  vtkactor->GetProperty()->SetAmbient(0);
156                                  vtkactor->GetProperty()->SetDiffuse(1);
157                                  vtkactor->GetProperty()->SetSpecular(0);
158                         }
159
160                          vtkactor->GetProperty()->SetLineWidth( bbGetInputLineWidth() );
161                            
162                          vtkactor->GetProperty()->SetColor( bbGetInputColour()[0],  
163                                                         bbGetInputColour()[1], 
164                                                         bbGetInputColour()[2] );
165                                   
166                          vtkactor->GetProperty()->SetOpacity( bbGetInputOpacity() );
167
168                          
169                          if ( bbGetInputTransform()!=NULL )
170                          {
171                                 vtkactor->SetUserTransform( bbGetInputTransform() );
172                          }
173
174                          bbSetOutputOut( vtkactor );
175
176                          // Interface Update
177                          if ((actorAdded==false) && (bbGetInputRenderer()!=NULL ))
178                          {
179                            actorAdded=true;
180                            bbGetInputRenderer()->AddActor( vtkactor );
181                          }  // actorAdded
182
183                          if (bbGetInputScalarVisibility()==true )
184                          {
185                                  polydatamapper->ScalarVisibilityOn();
186                          } else {
187                                  polydatamapper->ScalarVisibilityOff();
188                          } // ScalarVisibility
189                 } else {
190                          // Interface Update
191                          if ((actorAdded==true) && (bbGetInputRenderer()!=NULL ))
192                          {
193                            actorAdded=false;
194                            bbGetInputRenderer()->RemoveActor( vtkactor );
195                          }  // actorAdded
196                 } // Active
197         }
198
199
200
201 } // EO namespace bbtk
202
203 #endif //_USE_VTK_
204