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 "vtkStreamLineCreateColorInfo.h"
29 #include "vtkIdList.h"
30 #include "vtkCellArray.h"
31 #include "vtkCharArray.h"
32 #include "vtkDoubleArray.h"
33 #include "vtkPointData.h"
36 vtkStreamLineCreateColorInfo::vtkStreamLineCreateColorInfo()
38 _StreamLinesIn = NULL;
39 _vtkidlist = vtkIdList::New();
43 vtkStreamLineCreateColorInfo::~vtkStreamLineCreateColorInfo()
47 //---------------------------------------------
48 void vtkStreamLineCreateColorInfo::SetStreamLinesIn(vtkPolyData* streamlinein)
50 _StreamLinesIn = streamlinein;
53 //---------------------------------------------
54 vtkPolyData *vtkStreamLineCreateColorInfo::GetStreamLinesOut()
56 return _StreamLinesIn;
59 //---------------------------------------------
60 void vtkStreamLineCreateColorInfo::Run()
62 vtkCellArray *vtkcellarray = _StreamLinesIn->GetLines();
63 long int nLinesCell = vtkcellarray->GetNumberOfCells();
70 double colorDirX,colorDirY,colorDirZ;
72 _StreamLinesIn->Update();
73 vtkCharArray *mask = vtkCharArray::New();
74 vtkDoubleArray *magnitud = vtkDoubleArray::New();
75 vtkDoubleArray *velocity = vtkDoubleArray::New();
76 vtkDoubleArray *colorDirection = vtkDoubleArray::New();
78 mask->SetName("creaMask"); // ... fill the colors array
79 mask->SetNumberOfComponents(1); //3d normals (ie x,y,z)
80 mask->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
82 magnitud->SetName("creaMagnitud"); // ... fill the colors array
83 magnitud->SetNumberOfComponents(1); //3d normals (ie x,y,z)
84 magnitud->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
86 velocity->SetName("creaVelocity"); // ... fill the colors array
87 velocity->SetNumberOfComponents(3); //3d normals (ie x,y,z)
88 velocity->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
90 colorDirection->SetName("creaColorDirection"); // ... fill the colors array
91 colorDirection->SetNumberOfComponents(3); //3d normals (ie x,y,z)
92 colorDirection->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
95 for (ii=0;ii<_StreamLinesIn->GetNumberOfPoints();ii++)
97 mask->SetTuple1 (ii, 0);
98 magnitud->SetTuple1 (ii, 0);
99 velocity->SetTuple3 (ii, 0, 0, 0);
100 colorDirection->SetTuple3 (ii, 0, 0, 0);
105 for ( iLine=0 ; iLine<nLinesCell ; iLine++ )
107 vtkcellarray->GetCell(ii, _vtkidlist );
108 numberofids = _vtkidlist->GetNumberOfIds();
110 for (jj=0;jj<numberofids;jj++)
112 id = _vtkidlist->GetId(jj);
113 if (jj-1>=0) { id1 = _vtkidlist->GetId(jj-1); } else {id1=id;}
114 if (jj+1<numberofids) {id2 = _vtkidlist->GetId(jj+1);} else {id2=id;}
115 _StreamLinesIn->GetPoint( id1 ,point1);
116 _StreamLinesIn->GetPoint( id2 ,point2);
117 vx= point1[0]-point2[0];
118 vy= point1[1]-point2[1];
119 vz= point1[2]-point2[2];
120 mag= sqrt( vx*vx +vy*vy + vz*vz );
121 colorDirX=fabs(vx/mag);
122 colorDirY=fabs(vy/mag);
123 colorDirZ=fabs(vz/mag);
125 mask->SetTuple1 (id, 1);
126 magnitud->SetTuple1 (id, mag);
127 velocity->SetTuple3 (id, vx,vy,vz);
128 colorDirection->SetTuple3 (id, colorDirX,colorDirY,colorDirZ);
134 _StreamLinesIn->GetPointData()->AddArray( mask );
135 _StreamLinesIn->GetPointData()->AddArray( magnitud );
136 _StreamLinesIn->GetPointData()->AddArray( velocity );
137 _StreamLinesIn->GetPointData()->AddArray( colorDirection );
141 //---------------------------------------------
142 void vtkStreamLineCreateColorInfo::Process()
144 if (_StreamLinesIn!=NULL)