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