]> Creatis software - creaVtk.git/blob - lib/creaVtk/creaVtkStreamLine.cpp
#3110 creaVtk Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaVtk.git] / lib / creaVtk / creaVtkStreamLine.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sante)
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 #include "creaVtkStreamLine.h"
29
30 #include "vtkPointData.h"
31 #include "vtkRenderWindow.h"
32 #include "vtkProperty.h"
33 #include "vtkPolyDataWriter.h"
34
35
36 creaVtkStreamLine::creaVtkStreamLine()
37 {
38 //      _source                 = vtkPointSource::New();
39 //      _vPointWidget   = vtkPointWidget::New();
40         _streamMapper2 = vtkPolyDataMapper::New();
41         _tubefilter             = vtkTubeFilter::New();
42         _ribbonfilter   = vtkRibbonFilter::New();
43 }
44
45
46 //---------------------------------------------
47 creaVtkStreamLine::~creaVtkStreamLine()
48 {
49 }
50
51
52 //---------------------------------------------
53 void creaVtkStreamLine::SetPolyData( vtkPolyData* polydata)
54 {
55         _polydata = polydata;
56 }
57
58 //---------------------------------------------
59 void creaVtkStreamLine::Process()
60 {
61
62         if (_polydata!=NULL)
63         {
64                 if (_active==true)
65                 {
66 /*
67                         //---------------------------Stream Lines-----------------------
68                         _vPointWidget->SetInput( (vtkDataSet*) GetDataObject() );
69                         if (_firsttime==true)
70                         {
71                                 _firsttime=false;
72                                 _vPointWidget->AllOff();
73                                 _vPointWidget->PlaceWidget();
74                                 _vPointWidget->SetInteractor( GetRenderer()->GetRenderWindow()->GetInteractor() );
75                                 _source->SetNumberOfPoints(1000);
76                                 _source->SetRadius(5.0);
77                         }
78 //EED1                  _vPointWidget->On();
79                                 
80                         double c[3];
81                         _vPointWidget->GetPosition(c);
82                         _source->SetCenter( c );
83                         _source->Update();
84                         
85                         _streamer->SetInput( GetDataObject() );
86 //EED1  _streamer->SetSource( _source->GetOutput() );
87                         _streamer->SetSource( _sourcePoints );
88                         _streamer->SetIntegratorTypeToRungeKutta45();
89 //EED                   _streamer->SetMaximumPropagation(500000);
90                         _streamer->SetMaximumPropagation(500);
91 //EED           _streamer->SetMaximumPropagationUnitToTimeUnit();
92                         _streamer->SetInitialIntegrationStep (0.001);
93 //EED                   _streamer->SetInitialIntegrationStepUnitToCellLengthUnit();
94                         _streamer->SetIntegrationDirectionToBoth();
95                         //EED   streamer->ComputeVorticityOn ();
96                         _streamer->Update();
97 //                      _streamer->Print(std::cout);
98 //                      _streamer->GetOutput()->Print(std::cout);
99
100
101 //EED 3aout2011
102                         _tubefilter->SetInput( _streamer->GetOutput() );
103                         _ribbonfilter->SetInput(_streamer->GetOutput());
104 */
105
106                         _polydata->Modified();
107
108
109                         if (GetTypeForm()==0) 
110                         {
111 //EED 2017-01-01 Migration VTK7
112 #if VTK_MAJOR_VERSION <= 5
113                                 _tubefilter->SetInput( _polydata );
114 #else
115                                 _tubefilter->SetInputData( _polydata );
116 #endif
117                                 _tubefilter->SetRadius( GetScaleFactor() );     
118                                 _tubefilter->SetNumberOfSides(12);
119                                 _tubefilter->SetVaryRadiusToVaryRadiusOff();            
120                                 _tubefilter->Modified();
121                                 _tubefilter->Update();
122 //EED 2017-01-01 Migration VTK7
123 #if VTK_MAJOR_VERSION <= 5
124                                 _streamMapper2->SetInput( _tubefilter->GetOutput() );
125 #else
126                                 _streamMapper2->SetInputData( _tubefilter->GetOutput() );
127 #endif
128                         } 
129                         if (GetTypeForm()==1) 
130                         {
131 //EED 2017-01-01 Migration VTK7
132 #if VTK_MAJOR_VERSION <= 5
133                                 _ribbonfilter->SetInput( _polydata );
134 #else
135                                 _ribbonfilter->SetInputData( _polydata );
136 #endif
137                                 _ribbonfilter->SetWidth( GetScaleFactor() );    
138                                 _ribbonfilter->SetWidthFactor( GetScaleFactor()*10 );
139                                 _ribbonfilter->GlobalWarningDisplayOff ();  //EED this is to avoid the "BEVEL WARNING"
140                                 _ribbonfilter->Modified();
141                                 _ribbonfilter->Update();
142
143 //EED 2017-01-01 Migration VTK7
144 #if VTK_MAJOR_VERSION <= 5
145                                 _streamMapper2->SetInput( _ribbonfilter->GetOutput() );
146 #else
147                                 _streamMapper2->SetInputData( _ribbonfilter->GetOutput() );
148 #endif
149                         }                       
150                         if (GetTypeForm()==2) 
151                         {
152 //EED 2017-01-01 Migration VTK7
153 #if VTK_MAJOR_VERSION <= 5
154                                 _streamMapper2->SetInput( _polydata );
155 #else
156                                 _streamMapper2->SetInputData( _polydata );
157 #endif
158                         }                       
159 //EED                   _streamMapper2->SetLookupTable(vGreenToRedLut);
160
161 /*                      
162 vtkDoubleArray* _velocity = vtkDoubleArray::New();
163 _velocity->SetName("velocity");  // ... fill the colors array                   
164 for (int ivelocity=0; ivelocity<=4000; ivelocity++ )
165 {
166         _velocity->InsertTuple3 (ivelocity, 1, 0, 0);
167 }
168 _polydata->GetPointData()->AddArray(_velocity);
169 */
170
171
172 //                      vtkFieldData    *data   = _polydata->GetFieldData();
173 //                      vtkDataArray    *da             = pointdata->GetArray("Normals");
174                         
175 //                      vtkPointData    *data   = _polydata->GetPointData();
176 //                      int i,sizeDa = data->GetNumberOfArrays();
177 //                      printf("EED creaVtkStreamLine::Process  sizeDa %d \n", sizeDa );
178 //                      for (i=0;i<sizeDa;i++)
179 //                      {
180 //                              printf("EED creaVtkStreamLine::Process-name %d, %s \n", i, data->GetArrayName(i) );
181 //                              data->GetArray(i)->Print(std::cout);
182 //                      }
183
184
185
186 /*
187 //EED
188  vtkPolyDataWriter *writer3 = vtkPolyDataWriter::New();
189  writer3->SetFileName( "/home/davila/Borrame/streamline-eed-c.vtk" );
190  writer3->SetInput( _polydata );
191  writer3->Write();
192 */
193
194                         
195 //                      vtkDataArray *nda = vtkDoubleArray::New();
196 //                      nda->DeepCopy(da);
197 //                      pointdata->AddArray( nda );
198 //                      bbGetInputIn()->GetPointData()->AddArray( nda );                        
199
200
201
202
203 //Config 0   (nothing)
204 //                      _streamMapper2->ScalarVisibilityOff();
205
206
207 //Config 1   (Normals)
208 //                      _streamMapper2->ScalarVisibilityOn();
209 //                      _streamMapper2->SetScalarModeToUsePointFieldData();
210 //                      _streamMapper2->SetLookupTable( _LutEED );
211 //                      _streamMapper2->SelectColorArray( "Normals" );
212
213
214
215 //Config 2   Orientation vectors
216                         _streamMapper2->ScalarVisibilityOn();
217                         _streamMapper2->SetScalarModeToUsePointFieldData();
218                         _streamMapper2->SetLookupTable( _LutEED );
219
220                         if (_colorlaw==0)
221                         {
222                                 _LutEED->SetVectorModeToRGBColors();
223                                 _streamMapper2->SelectColorArray( "creaColorDirection" );
224                         }
225                         if (_colorlaw==1)
226                         {
227 //                              _LutEED->SetVectorModeToMagnitude();
228                                 vtkLookupTable *lookuptable = vtkLookupTable::New();
229                                 _streamMapper2->SetLookupTable( lookuptable );
230                                 _streamMapper2->SelectColorArray( "creaMagnitud" );
231                         }
232                         if (_colorlaw==2)
233                         {
234
235                                 _streamMapper2->SelectColorArray( "xx" );
236                                 _actor->GetProperty()->SetColor(_colorR,_colorG,_colorB);
237                         }
238
239 /*
240          _vtkglyph->SetInput( GetDataObject() );  
241          _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
242          _vtkglyph->SetScaleModeToScaleByVector();
243          _vtkglyph->SetColorModeToColorByVector();
244          _vtkglyph->SetScaleFactor( GetScaleFactor() );
245          _vtkglyph->Update();
246          _pdm->SetInput( _vtkglyph->GetOutput());
247          _pdm->SetScalarModeToUsePointFieldData();
248          _pdm->SetLookupTable( _LutEED );
249          _pdm->SelectColorArray( "GlyphVector" );
250 */
251
252
253
254
255
256
257 //Config 3   Position
258 //   ???????
259                         
260                         _actor->SetMapper( _streamMapper2 );
261                         _actor->GetProperty()->SetOpacity( GetOpacity() );
262                 }// _active
263         
264         VisibilityActor(); 
265    } // polydata
266
267
268
269
270
271