]> Creatis software - creaVtk.git/blob - lib/creaVtk/creaVtkStreamLine.cpp
#2453 creaVtk Feature New Normal - Stream Lines segmentation by Scalars
[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                                 _tubefilter->SetInput( _polydata );
112                                 _tubefilter->SetRadius( GetScaleFactor() );     
113                                 _tubefilter->SetNumberOfSides(12);
114                                 _tubefilter->SetVaryRadiusToVaryRadiusOff();            
115                                 _tubefilter->Modified();
116                                 _tubefilter->Update();
117                                 _streamMapper2->SetInput( _tubefilter->GetOutput() );
118                         } 
119                         if (GetTypeForm()==1) 
120                         {
121                                 _ribbonfilter->SetInput( _polydata );
122                                 _ribbonfilter->SetWidth( GetScaleFactor() );    
123                                 _ribbonfilter->SetWidthFactor( GetScaleFactor()*10 );
124                                 _ribbonfilter->GlobalWarningDisplayOff ();  //EED this is to avoid the "BEVEL WARNING"
125                                 _ribbonfilter->Modified();
126                                 _ribbonfilter->Update();
127                                 _streamMapper2->SetInput( _ribbonfilter->GetOutput() );
128                         }                       
129                         if (GetTypeForm()==2) 
130                         {
131                                 _streamMapper2->SetInput( _polydata );
132                         }                       
133 //EED                   _streamMapper2->SetLookupTable(vGreenToRedLut);
134
135 /*                      
136 vtkDoubleArray* _velocity = vtkDoubleArray::New();
137 _velocity->SetName("velocity");  // ... fill the colors array                   
138 for (int ivelocity=0; ivelocity<=4000; ivelocity++ )
139 {
140         _velocity->InsertTuple3 (ivelocity, 1, 0, 0);
141 }
142 _polydata->GetPointData()->AddArray(_velocity);
143 */
144
145
146 //                      vtkFieldData    *data   = _polydata->GetFieldData();
147 //                      vtkDataArray    *da             = pointdata->GetArray("Normals");
148                         
149 //                      vtkPointData    *data   = _polydata->GetPointData();
150 //                      int i,sizeDa = data->GetNumberOfArrays();
151 //                      printf("EED creaVtkStreamLine::Process  sizeDa %d \n", sizeDa );
152 //                      for (i=0;i<sizeDa;i++)
153 //                      {
154 //                              printf("EED creaVtkStreamLine::Process-name %d, %s \n", i, data->GetArrayName(i) );
155 //                              data->GetArray(i)->Print(std::cout);
156 //                      }
157
158
159
160 /*
161 //EED
162  vtkPolyDataWriter *writer3 = vtkPolyDataWriter::New();
163  writer3->SetFileName( "/home/davila/Borrame/streamline-eed-c.vtk" );
164  writer3->SetInput( _polydata );
165  writer3->Write();
166 */
167
168                         
169 //                      vtkDataArray *nda = vtkDoubleArray::New();
170 //                      nda->DeepCopy(da);
171 //                      pointdata->AddArray( nda );
172 //                      bbGetInputIn()->GetPointData()->AddArray( nda );                        
173
174
175
176
177 //Config 0   (nothing)
178 //                      _streamMapper2->ScalarVisibilityOff();
179
180
181 //Config 1   (Normals)
182 //                      _streamMapper2->ScalarVisibilityOn();
183 //                      _streamMapper2->SetScalarModeToUsePointFieldData();
184 //                      _streamMapper2->SetLookupTable( _LutEED );
185 //                      _streamMapper2->SelectColorArray( "Normals" );
186
187
188
189 //Config 2   Orientation vectors
190                         _streamMapper2->ScalarVisibilityOn();
191                         _streamMapper2->SetScalarModeToUsePointFieldData();
192                         _streamMapper2->SetLookupTable( _LutEED );
193
194                         if (_colorlaw==0)
195                         {
196                                 _LutEED->SetVectorModeToRGBColors();
197                                 _streamMapper2->SelectColorArray( "creaColorDirection" );
198                         }
199                         if (_colorlaw==1)
200                         {
201 //                              _LutEED->SetVectorModeToMagnitude();
202                                 vtkLookupTable *lookuptable = vtkLookupTable::New();
203                                 _streamMapper2->SetLookupTable( lookuptable );
204                                 _streamMapper2->SelectColorArray( "creaMagnitud" );
205                         }
206                         if (_colorlaw==2)
207                         {
208
209                                 _streamMapper2->SelectColorArray( "xx" );
210                                 _actor->GetProperty()->SetColor(_colorR,_colorG,_colorB);
211                         }
212
213 /*
214          _vtkglyph->SetInput( GetDataObject() );  
215          _vtkglyph->SetSource( _vtkarrowsource->GetOutput() );
216          _vtkglyph->SetScaleModeToScaleByVector();
217          _vtkglyph->SetColorModeToColorByVector();
218          _vtkglyph->SetScaleFactor( GetScaleFactor() );
219          _vtkglyph->Update();
220          _pdm->SetInput( _vtkglyph->GetOutput());
221          _pdm->SetScalarModeToUsePointFieldData();
222          _pdm->SetLookupTable( _LutEED );
223          _pdm->SelectColorArray( "GlyphVector" );
224 */
225
226
227
228
229
230
231 //Config 3   Position
232 //   ???????
233                         
234                         _actor->SetMapper( _streamMapper2 );
235                         _actor->GetProperty()->SetOpacity( GetOpacity() );
236                 }// _active
237         
238         VisibilityActor(); 
239    } // polydata
240
241
242
243
244
245