]> Creatis software - creaVtk.git/blobdiff - lib/creaVtk/vtkStreamLineCreateColorInfo.cpp
#2446 creaVtk Feature New Normal - Stream Tracer, Stream Line (interface, widget)
[creaVtk.git] / lib / creaVtk / vtkStreamLineCreateColorInfo.cpp
diff --git a/lib/creaVtk/vtkStreamLineCreateColorInfo.cpp b/lib/creaVtk/vtkStreamLineCreateColorInfo.cpp
new file mode 100644 (file)
index 0000000..c088d5e
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+#                        pour la Sante)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and
+#  abiding by the rules of distribution of free software. You can  use,
+#  modify and/ or redistribute the software under the terms of the CeCILL-B
+#  license as circulated by CEA, CNRS and INRIA at the following URL
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability.
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------
+*/
+
+#include "vtkStreamLineCreateColorInfo.h"
+#include "vtkIdList.h"
+#include "vtkCellArray.h"
+#include "vtkCharArray.h"
+#include "vtkDoubleArray.h"
+#include "vtkPointData.h"
+
+
+vtkStreamLineCreateColorInfo::vtkStreamLineCreateColorInfo()
+{
+       _StreamLinesIn = NULL;
+       _vtkidlist              = vtkIdList::New();
+
+}
+
+vtkStreamLineCreateColorInfo::~vtkStreamLineCreateColorInfo()
+{
+}
+
+//---------------------------------------------
+void vtkStreamLineCreateColorInfo::SetStreamLinesIn(vtkPolyData* streamlinein)
+{
+       _StreamLinesIn = streamlinein;
+}
+
+//---------------------------------------------
+vtkPolyData *vtkStreamLineCreateColorInfo::GetStreamLinesOut()
+{
+       return _StreamLinesIn;
+}
+
+//---------------------------------------------
+void vtkStreamLineCreateColorInfo::Run()
+{
+       vtkCellArray    *vtkcellarray           = _StreamLinesIn->GetLines();
+       long int                nLinesCell                      = vtkcellarray->GetNumberOfCells(); 
+       long int                numberofids; 
+       long int                ii,jj,iLine;
+       double                  point1[3];
+       double                  point2[3];
+       long int                id,id1,id2;
+       double                  vx,vy,vz,mag;
+       double                  colorDirX,colorDirY,colorDirZ;
+
+       _StreamLinesIn->Update();
+       vtkCharArray    *mask                           = vtkCharArray::New();
+       vtkDoubleArray  *magnitud                       = vtkDoubleArray::New();
+       vtkDoubleArray  *velocity                       = vtkDoubleArray::New();
+       vtkDoubleArray  *colorDirection = vtkDoubleArray::New();
+
+       mask->SetName("creaMask");  // ... fill the colors array                        
+       mask->SetNumberOfComponents(1); //3d normals (ie x,y,z)
+       mask->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
+
+       magnitud->SetName("creaMagnitud");  // ... fill the colors array                        
+       magnitud->SetNumberOfComponents(1); //3d normals (ie x,y,z)
+       magnitud->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
+
+       velocity->SetName("creaVelocity");  // ... fill the colors array                        
+       velocity->SetNumberOfComponents(3); //3d normals (ie x,y,z)
+       velocity->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
+
+       colorDirection->SetName("creaColorDirection");  // ... fill the colors array                    
+       colorDirection->SetNumberOfComponents(3); //3d normals (ie x,y,z)
+       colorDirection->SetNumberOfTuples(_StreamLinesIn->GetNumberOfPoints());
+
+
+       for (ii=0;ii<_StreamLinesIn->GetNumberOfPoints();ii++)
+       {
+               mask->SetTuple1 (ii, 0);
+               magnitud->SetTuple1 (ii, 0);
+               velocity->SetTuple3 (ii, 0, 0, 0);
+               colorDirection->SetTuple3 (ii, 0, 0, 0);
+       }
+
+       // FOR EACH LINE
+   ii=0;
+   for ( iLine=0 ; iLine<nLinesCell ; iLine++ )
+   {
+               vtkcellarray->GetCell(ii, _vtkidlist );
+               numberofids = _vtkidlist->GetNumberOfIds();
+       
+               for (jj=0;jj<numberofids;jj++)
+               {
+                       id = _vtkidlist->GetId(jj);
+                       if (jj-1>=0) {  id1 = _vtkidlist->GetId(jj-1); } else {id1=id;}
+                       if (jj+1<numberofids) {id2 = _vtkidlist->GetId(jj+1);} else {id2=id;}
+                       _StreamLinesIn->GetPoint( id1 ,point1);
+                       _StreamLinesIn->GetPoint( id2 ,point2);
+                       vx= point1[0]-point2[0];                
+                       vy= point1[1]-point2[1];
+                       vz= point1[2]-point2[2];
+                       mag= sqrt( vx*vx +vy*vy + vz*vz );
+                       colorDirX=fabs(vx/mag);
+                       colorDirY=fabs(vy/mag);
+                       colorDirZ=fabs(vz/mag);
+
+               mask->SetTuple1 (id, 1);
+               magnitud->SetTuple1 (id, mag);
+               velocity->SetTuple3 (id, vx,vy,vz);
+               colorDirection->SetTuple3 (id, colorDirX,colorDirY,colorDirZ);
+}
+
+               ii=ii+numberofids+1;
+       } // for iLine
+
+               _StreamLinesIn->GetPointData()->AddArray( mask );
+               _StreamLinesIn->GetPointData()->AddArray( magnitud );
+               _StreamLinesIn->GetPointData()->AddArray( velocity );
+               _StreamLinesIn->GetPointData()->AddArray( colorDirection );
+
+}
+
+//---------------------------------------------
+void vtkStreamLineCreateColorInfo::Process()
+{
+       if (_StreamLinesIn!=NULL)
+       {
+               Run();
+       }
+}
+
+