2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
28 #include "creaVtkStreamLineScalarSeg.h"
29 #include "vtkPointData.h"
30 #include "vtkDataArray.h"
31 #include "vtkDoubleArray.h"
34 // ------------------------------------------------------------------------
35 creaVtkStreamLineScalarSeg::creaVtkStreamLineScalarSeg()
37 _vtkidlist = vtkIdList::New();
38 _newvtkpolydata = vtkPolyData::New();
39 _newvtkcellarray = vtkCellArray::New();
42 // ------------------------------------------------------------------------
43 creaVtkStreamLineScalarSeg::~creaVtkStreamLineScalarSeg()
47 // ------------------------------------------------------------------------
48 void creaVtkStreamLineScalarSeg::SetScalarStreamLinesIn( vtkPolyData* polydata)
50 _StreamLinesIn = polydata;
53 // ------------------------------------------------------------------------
54 void creaVtkStreamLineScalarSeg::SetScalarArrayName( std::string name)
56 _ScalarArrayName = name;
59 // ------------------------------------------------------------------------
60 void creaVtkStreamLineScalarSeg::SetThresholdLower( double value)
62 _ThresholdLower = value;
65 // ------------------------------------------------------------------------
66 void creaVtkStreamLineScalarSeg::SetThresholdUpper( double value )
68 _ThresholdUpper = value;
71 // ------------------------------------------------------------------------
72 void creaVtkStreamLineScalarSeg::Process()
74 if (_ScalarArrayName=="")
78 printf("BBTK Warnning! ScalarArrayName is empty in creaVtkStreamLineScalarSeg \n");
82 if ((_StreamLinesIn!=NULL) && (_ScalarArrayName!="") )
85 _newvtkcellarray->Initialize();
86 vtkCellArray *vtkcellarray = _StreamLinesIn->GetLines();
87 int nLinesCell = vtkcellarray->GetNumberOfCells();
88 // int vtkcellarraysize = vtkcellarray->GetSize();
91 vtkDataArray *scalarArray = _StreamLinesIn->GetPointData()->GetArray( _ScalarArrayName.c_str() );
92 vtkDoubleArray *newScalarArray = vtkDoubleArray::New();
93 newScalarArray->SetName( _ScalarArrayName.c_str() );
94 newScalarArray->SetNumberOfComponents(1);
97 long int iLineNew = 0;
99 for ( iLine=0 ; iLine<nLinesCell ; iLine++ )
101 vtkcellarray->GetCell(ii, _vtkidlist );
102 numberofids = _vtkidlist->GetNumberOfIds();
103 scalarValue = scalarArray->GetTuple1(iLine);
104 if ( ( scalarValue>=_ThresholdLower ) && ( scalarValue<=_ThresholdUpper ) )
106 _newvtkcellarray->InsertNextCell( _vtkidlist );
107 newScalarArray->InsertTuple1( iLineNew, scalarValue );
112 _newvtkpolydata->SetPoints( _StreamLinesIn->GetPoints() );
113 _newvtkpolydata->SetLines( _newvtkcellarray );
114 int iArrays,arraysSize = _StreamLinesIn->GetPointData()->GetNumberOfArrays();
115 for ( iArrays=0 ; iArrays<arraysSize ; iArrays++ )
117 _newvtkpolydata->GetPointData()->AddArray( _StreamLinesIn->GetPointData()->GetArray(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();
125 _newvtkcellarray->Modified();
126 _newvtkpolydata->Modified();
127 // _newvtkpolydata->BuildCells();
129 _StreamLinesOut = _newvtkpolydata;
134 // ------------------------------------------------------------------------
135 vtkPolyData* creaVtkStreamLineScalarSeg::GetStreamLinesOut()
137 return _StreamLinesOut;