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");
83 if ((_StreamLinesIn!=NULL) && (_ScalarArrayName!="") )
87 _newvtkcellarray->Initialize();
89 vtkCellArray *vtkcellarray = _StreamLinesIn->GetLines();
90 int nLinesCell = vtkcellarray->GetNumberOfCells();
91 // int vtkcellarraysize = vtkcellarray->GetSize();
94 vtkDataArray *scalarArray = _StreamLinesIn->GetPointData()->GetArray( _ScalarArrayName.c_str() );
97 vtkDoubleArray *newScalarArray = vtkDoubleArray::New();
98 newScalarArray->SetName( _ScalarArrayName.c_str() );
99 newScalarArray->SetNumberOfComponents(1);
105 for ( iLine=0 ; iLine<nLinesCell ; iLine++ )
107 vtkcellarray->GetCell(ii, _vtkidlist );
108 numberofids = _vtkidlist->GetNumberOfIds();
109 scalarValue = scalarArray->GetTuple1(iLine);
110 if ( ( scalarValue>=_ThresholdLower ) && ( scalarValue<=_ThresholdUpper ) )
112 _newvtkcellarray->InsertNextCell( _vtkidlist );
113 newScalarArray->InsertTuple1( iLineNew, scalarValue );
120 _newvtkpolydata->SetPoints( _StreamLinesIn->GetPoints() );
121 _newvtkpolydata->SetLines( _newvtkcellarray );
122 int iArrays,arraysSize = _StreamLinesIn->GetPointData()->GetNumberOfArrays();
123 for ( iArrays=0 ; iArrays<arraysSize ; iArrays++ )
125 _newvtkpolydata->GetPointData()->AddArray( _StreamLinesIn->GetPointData()->GetArray(iArrays) );
127 _newvtkpolydata->GetPointData()->RemoveArray( _ScalarArrayName.c_str() );
128 _newvtkpolydata->GetPointData()->AddArray( newScalarArray );
129 _newvtkpolydata->Update();
131 _StreamLinesOut = _newvtkpolydata;
137 // ------------------------------------------------------------------------
138 vtkPolyData* creaVtkStreamLineScalarSeg::GetStreamLinesOut()
140 return _StreamLinesOut;