]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkStreamLineCreateColorInfo.cpp
#3110 creaVtk Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaVtk.git] / lib / creaVtk / vtkStreamLineCreateColorInfo.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 "vtkStreamLineCreateColorInfo.h"
29 #include "vtkIdList.h"
30 #include "vtkCellArray.h"
31 #include "vtkCharArray.h"
32 #include "vtkDoubleArray.h"
33 #include "vtkPointData.h"
34
35
36 vtkStreamLineCreateColorInfo::vtkStreamLineCreateColorInfo()
37 {
38         _StreamLinesIn = NULL;
39         _vtkidlist              = vtkIdList::New();
40
41 }
42
43 vtkStreamLineCreateColorInfo::~vtkStreamLineCreateColorInfo()
44 {
45 }
46
47 //---------------------------------------------
48 void vtkStreamLineCreateColorInfo::SetStreamLinesIn(vtkPolyData* streamlinein)
49 {
50         _StreamLinesIn = streamlinein;
51 }
52
53 //---------------------------------------------
54 vtkPolyData *vtkStreamLineCreateColorInfo::GetStreamLinesOut()
55 {
56         return _StreamLinesIn;
57 }
58
59 //---------------------------------------------
60 void vtkStreamLineCreateColorInfo::Run()
61 {
62         vtkCellArray    *vtkcellarray           = _StreamLinesIn->GetLines();
63         long int                nLinesCell                      = vtkcellarray->GetNumberOfCells(); 
64         long int                numberofids; 
65         long int                ii,jj,iLine;
66         double                  point1[3];
67         double                  point2[3];
68         long int                id,id1,id2;
69         double                  vx,vy,vz,mag;
70         double                  colorDirX,colorDirY,colorDirZ;
71
72 //EED 2017-01-01 Migration VTK7
73 #if VTK_MAJOR_VERSION <= 5
74         _StreamLinesIn->Update();
75 #else
76   //...
77 #endif
78
79         vtkCharArray    *mask                           = vtkCharArray::New();
80         vtkDoubleArray  *magnitud                       = vtkDoubleArray::New();
81         vtkDoubleArray  *velocity                       = vtkDoubleArray::New();
82         vtkDoubleArray  *colorDirection = vtkDoubleArray::New();
83
84         mask->SetName("creaMask");  // ... fill the colors array                        
85         mask->SetNumberOfComponents(1); //3d normals (ie x,y,z)
86         mask->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
87
88         magnitud->SetName("creaMagnitud");  // ... fill the colors array                        
89         magnitud->SetNumberOfComponents(1); //3d normals (ie x,y,z)
90         magnitud->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
91
92         velocity->SetName("creaVelocity");  // ... fill the colors array                        
93         velocity->SetNumberOfComponents(3); //3d normals (ie x,y,z)
94         velocity->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
95
96         colorDirection->SetName("creaColorDirection");  // ... fill the colors array                    
97         colorDirection->SetNumberOfComponents(3); //3d normals (ie x,y,z)
98         colorDirection->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
99
100
101         for (ii=0;ii<_StreamLinesIn->GetNumberOfPoints();ii++)
102         {
103                 mask->SetTuple1 (ii, 0);
104                 magnitud->SetTuple1 (ii, 0);
105                 velocity->SetTuple3 (ii, 0, 0, 0);
106                 colorDirection->SetTuple3 (ii, 0, 0, 0);
107         }
108
109         // FOR EACH LINE
110    ii=0;
111    for ( iLine=0 ; iLine<nLinesCell ; iLine++ )
112    {
113                 vtkcellarray->GetCell(ii, _vtkidlist );
114                 numberofids = _vtkidlist->GetNumberOfIds();
115         
116                 for (jj=0;jj<numberofids;jj++)
117                 {
118                         id = _vtkidlist->GetId(jj);
119                         if (jj-1>=0) {  id1 = _vtkidlist->GetId(jj-1); } else {id1=id;}
120                         if (jj+1<numberofids) {id2 = _vtkidlist->GetId(jj+1);} else {id2=id;}
121                         _StreamLinesIn->GetPoint( id1 ,point1);
122                         _StreamLinesIn->GetPoint( id2 ,point2);
123                         vx= point1[0]-point2[0];                
124                         vy= point1[1]-point2[1];
125                         vz= point1[2]-point2[2];
126                         mag= sqrt( vx*vx +vy*vy + vz*vz );
127                         colorDirX=fabs(vx/mag);
128                         colorDirY=fabs(vy/mag);
129                         colorDirZ=fabs(vz/mag);
130
131                 mask->SetTuple1 (id, 1);
132                 magnitud->SetTuple1 (id, mag);
133                 velocity->SetTuple3 (id, vx,vy,vz);
134                 colorDirection->SetTuple3 (id, colorDirX,colorDirY,colorDirZ);
135                 } // for jj
136
137                 ii=ii+numberofids+1;
138    } // for iLine
139
140         _StreamLinesIn->GetPointData()->AddArray( mask );
141         _StreamLinesIn->GetPointData()->AddArray( magnitud );
142         _StreamLinesIn->GetPointData()->AddArray( velocity );
143         _StreamLinesIn->GetPointData()->AddArray( colorDirection );
144
145 }
146
147 //---------------------------------------------
148 void vtkStreamLineCreateColorInfo::Process()
149 {
150         if (_StreamLinesIn!=NULL)
151         {
152                 Run();
153         }
154 }
155
156