]> Creatis software - creaVtk.git/blob - lib/creaVtk/creaVtkStreamLineScalarSeg.cpp
#3110 creaVtk Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaVtk.git] / lib / creaVtk / creaVtkStreamLineScalarSeg.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 "creaVtkStreamLineScalarSeg.h"
29 #include "vtkPointData.h"
30 #include "vtkDataArray.h"
31 #include "vtkDoubleArray.h"
32
33
34 // ------------------------------------------------------------------------
35 creaVtkStreamLineScalarSeg::creaVtkStreamLineScalarSeg()
36 {
37         _vtkidlist              = vtkIdList::New();
38    _newvtkpolydata      = vtkPolyData::New();   
39    _newvtkcellarray     = vtkCellArray::New();  
40 }
41
42 // ------------------------------------------------------------------------
43 creaVtkStreamLineScalarSeg::~creaVtkStreamLineScalarSeg()
44 {
45 }
46
47 // ------------------------------------------------------------------------
48 void creaVtkStreamLineScalarSeg::SetScalarStreamLinesIn( vtkPolyData* polydata)
49 {
50         _StreamLinesIn = polydata;
51 }
52
53 // ------------------------------------------------------------------------
54 void creaVtkStreamLineScalarSeg::SetScalarArrayName( std::string name)
55 {
56         _ScalarArrayName = name;
57 }
58
59 // ------------------------------------------------------------------------
60 void creaVtkStreamLineScalarSeg::SetThresholdLower( double value)
61 {
62         _ThresholdLower = value;        
63 }
64
65 // ------------------------------------------------------------------------
66 void creaVtkStreamLineScalarSeg::SetThresholdUpper( double value )
67 {
68         _ThresholdUpper = value;        
69 }
70
71 // ------------------------------------------------------------------------
72 void creaVtkStreamLineScalarSeg::Process()
73 {
74         if (_ScalarArrayName=="")
75         {
76                 printf(".\n ");
77                 printf(".\n ");
78                 printf("BBTK Warnning! ScalarArrayName is empty in creaVtkStreamLineScalarSeg \n");
79                 printf(".\n ");
80                 printf(".\n ");
81         }
82         if ((_StreamLinesIn!=NULL) && (_ScalarArrayName!="") )
83         {
84                 int iLine;
85                 _newvtkcellarray->Initialize();
86                 vtkCellArray    *vtkcellarray           = _StreamLinesIn->GetLines();
87                 int                     nLinesCell                      = vtkcellarray->GetNumberOfCells(); 
88 //      int                             vtkcellarraysize        = vtkcellarray->GetSize();
89                 int                     numberofids; 
90                 int                     ii;
91                 vtkDataArray    *scalarArray            = _StreamLinesIn->GetPointData()->GetArray( _ScalarArrayName.c_str() );
92                 vtkDoubleArray  *newScalarArray         = vtkDoubleArray::New();
93                 newScalarArray->SetName( _ScalarArrayName.c_str() );            
94                 newScalarArray->SetNumberOfComponents(1); 
95         // FOR EACH LINE
96                 double scalarValue;
97                 long int iLineNew = 0;
98                 ii=0;
99                 for ( iLine=0 ; iLine<nLinesCell ; iLine++ )
100                 {
101                         vtkcellarray->GetCell(ii, _vtkidlist );
102                         numberofids = _vtkidlist->GetNumberOfIds();
103                         scalarValue = scalarArray->GetTuple1(iLine);
104                         if ( ( scalarValue>=_ThresholdLower ) && ( scalarValue<=_ThresholdUpper ) )
105                         {
106                                 _newvtkcellarray->InsertNextCell( _vtkidlist );
107                                 newScalarArray->InsertTuple1( iLineNew, scalarValue );
108                                 iLineNew++;
109                         } // if Threshold
110                         ii=ii+numberofids+1;
111                 } // for iLine
112                 _newvtkpolydata->SetPoints( _StreamLinesIn->GetPoints() );
113                 _newvtkpolydata->SetLines( _newvtkcellarray );
114                 int iArrays,arraysSize = _StreamLinesIn->GetPointData()->GetNumberOfArrays();
115                 for ( iArrays=0 ; iArrays<arraysSize ; iArrays++ )
116                 {       
117                         _newvtkpolydata->GetPointData()->AddArray( _StreamLinesIn->GetPointData()->GetArray(iArrays) );
118                 } // iArrays
119                 _newvtkpolydata->GetPointData()->RemoveArray( _ScalarArrayName.c_str() );
120                 _newvtkpolydata->GetPointData()->AddArray( newScalarArray );
121 //EED 2017-01-01 Migration VTK7
122 #if VTK_MAJOR_VERSION <= 5
123                 _newvtkpolydata->Update();
124 #else
125                 _newvtkcellarray->Modified();
126                 _newvtkpolydata->Modified();
127 //              _newvtkpolydata->BuildCells();
128 #endif
129                 _StreamLinesOut = _newvtkpolydata;
130         } // _StreamLinesIn
131
132 }
133
134 // ------------------------------------------------------------------------
135 vtkPolyData* creaVtkStreamLineScalarSeg::GetStreamLinesOut()
136 {
137         return _StreamLinesOut;
138 }
139
140