]> Creatis software - creaVtk.git/blob - lib/creaVtk/vtkImageDataStrucPoints.cpp
0649c5e85e1e2b64d24e223f712c67c4f8324b48
[creaVtk.git] / lib / creaVtk / vtkImageDataStrucPoints.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 "vtkImageDataStrucPoints.h"
29 #include "vtkStructuredPointsWriter.h"
30
31
32 vtkImageDataStrucPoints::vtkImageDataStrucPoints()
33 {
34 }
35
36 vtkImageDataStrucPoints::~vtkImageDataStrucPoints()
37 {
38 }
39
40 void vtkImageDataStrucPoints::joinComponents(vtkImageData* imageX,  vtkImageData* imageY,   vtkImageData* imageZ, 
41                                                                                          vtkImageData* Data1,   vtkImageData* Data2,    vtkImageData* Data3 ,
42                                                                                          vtkImageData* Data4,   vtkImageData* Data5,    vtkImageData* Data6  )
43 {
44 printf("EED vtkImageDataStrucPoints::joinComponents Start \n");
45
46         if ((imageX!=NULL) && (imageY!=NULL) && (imageZ!=NULL) )
47         { 
48                         int ext[6];
49                         imageY->Modified();
50                 //EED 2017-01-01 Migration VTK7
51                 #if VTK_MAJOR_VERSION <= 5
52                         imageY->Update();
53                         imageY->GetWholeExtent(ext);
54                 #else
55                         imageY->GetExtent(ext);
56                 #endif
57                         int dim[3];
58                         double spc[3];
59                         dim[0]=ext[1]-ext[0]+1;
60                         dim[1]=ext[3]-ext[2]+1;
61                         dim[2]=ext[5]-ext[4]+1; 
62                         imageY->GetSpacing(spc);
63                         double *ptrX=NULL,  *ptrY=NULL,  *ptrZ=NULL;
64                         double *ptrD1=NULL, *ptrD2=NULL, *ptrD3=NULL, *ptrD4=NULL, *ptrD5=NULL, *ptrD6=NULL;
65                         
66                         if (imageX!=NULL)  ptrX  = (double *)imageX->GetScalarPointer();
67                         if (imageY!=NULL)  ptrY  = (double *)imageY->GetScalarPointer();
68                         if (imageZ!=NULL)  ptrZ  = (double *)imageZ->GetScalarPointer();
69                         if (Data1 !=NULL)  ptrD1 = (double *)Data1->GetScalarPointer();
70                         if (Data2 !=NULL)  ptrD2 = (double *)Data2->GetScalarPointer();
71                         if (Data3 !=NULL)  ptrD3 = (double *)Data3->GetScalarPointer();
72                         if (Data4 !=NULL)  ptrD4 = (double *)Data4->GetScalarPointer();
73                         if (Data5 !=NULL)  ptrD5 = (double *)Data5->GetScalarPointer();
74                         if (Data6 !=NULL)  ptrD6 = (double *)Data6->GetScalarPointer();
75
76                         long int sizeimage = dim[0]*dim[1]*dim[2];
77                         int components=3;
78                 //      if ((Data1!=NULL) && (Data2==NULL) && (Data3==NULL) && (Data4==NULL) && (Data5==NULL) && (Data6==NULL) )  { components=4; }
79                 //      if ((Data1!=NULL) && (Data2!=NULL) && (Data3!=NULL) && (Data4==NULL) && (Data5==NULL) && (Data6==NULL) )  { components=6; }
80                 //      if ((Data1!=NULL) && (Data2!=NULL) && (Data3!=NULL) && (Data4!=NULL) && (Data5!=NULL) && (Data6!=NULL) )  { components=9; }
81                         vtkDoubleArray *array =  vtkDoubleArray::New();
82                         array->SetNumberOfTuples(sizeimage);
83                         array->SetNumberOfComponents(components);
84                         array->Allocate(sizeimage*components, 100 ); // ???
85                         array->SetName("velocity");
86
87                         vtkDoubleArray *array2 =  vtkDoubleArray::New();
88                         array2->SetNumberOfTuples(sizeimage);
89                         array2->SetNumberOfComponents(1);
90                         array2->Allocate(sizeimage*1, 100 ); // ???
91                         array2->SetName("angle");
92
93                 printf("EED Warnning .... vtkImageDataStrucPoints::joinComponents  Limpiar este codigo ........ \n");
94                 printf("EED Warnning .... vtkImageDataStrucPoints::joinComponents  Limpiar este codigo ........ \n");
95                 printf("EED Warnning .... vtkImageDataStrucPoints::joinComponents  Limpiar este codigo ........ \n");
96                 printf("EED Warnning .... vtkImageDataStrucPoints::joinComponents  Limpiar este codigo ........ \n");
97                 printf("EED Warnning .... vtkImageDataStrucPoints::joinComponents  Limpiar este codigo ........ \n");
98                 printf("EED Warnning .... vtkImageDataStrucPoints::joinComponents  Limpiar este codigo ........ \n");
99
100                         double vx,vy,vz,d1=0,d2=0,d3=0,d4=0,d5=0,d6=0;
101                         int i;
102                         for( i = 0 ; i < sizeimage ; i++ )
103                         {
104                                 if (ptrX !=NULL)        { vx = *ptrX;   ptrX++; }       else { vx=0; }
105                                 if (ptrY !=NULL)        { vy = *ptrY;   ptrY++; }       else { vy=0; }
106                                 if (ptrZ !=NULL)        { vz = *ptrZ;   ptrZ++; }       else { vz=0; }
107                                 if (ptrD1!=NULL)        { d1 = *ptrD1;  ptrD1++;} 
108                                 if (ptrD2!=NULL)        { d2 = *ptrD2;  ptrD2++;} 
109                                 if (ptrD3!=NULL)        { d3 = *ptrD3;  ptrD3++;} 
110                                 if (ptrD4!=NULL)        { d4 = *ptrD4;  ptrD4++;} 
111
112                                 if (components==3)      { array->SetTuple3(i,vx,vy,vz);                         }
113                                 if (components==3)      { array2->SetTuple1(i,d1);                      }
114                 //      if (components==4)      { array->SetTuple4(i,vx,vy,vz,d1);                      }
115                 //      if (components==6)      { array->SetTuple6(i,vx,vy,vz,d1,d2,d3);        }
116                 //      if (components==9)      { array->SetTuple9(i,vx,vy,vz,d1,d2,d3,d4,d5,d6); }
117                         } // for i
118
119                         _structuredPoints = vtkStructuredPoints::New();
120                         _structuredPoints->SetDimensions(dim[0], dim[1], dim[2]);
121                         _structuredPoints->SetSpacing(spc);
122
123                 //EED 2017-01-01 Migration VTK7
124                 #if VTK_MAJOR_VERSION <= 5
125                         _structuredPoints->SetScalarTypeToDouble();
126                         _structuredPoints->SetNumberOfScalarComponents(3);
127                 #else
128                         vtkInformation* info=_structuredPoints->GetInformation();
129                         vtkDataObject::SetPointDataActiveScalarInfo(info, VTK_DOUBLE, 3);
130
131                 #endif
132
133                         _structuredPoints->GetPointData()->SetVectors(array);
134                         _structuredPoints->GetPointData()->AddArray(array2);
135                         _structuredPoints->GetPointData()->SetNumberOfTuples(sizeimage);
136                         _structuredPoints->Modified();
137                 //EED 2017-01-01 Migration VTK7
138                 #if VTK_MAJOR_VERSION <= 5
139                         _structuredPoints->Update();
140                 #else
141                   //...
142                 #endif
143
144                 /*
145                         _structuredPoints->Print(cout);
146                    vtkStructuredPointsWriter *writer2 = vtkStructuredPointsWriter::New();
147                         writer2->SetFileName("/home/davila/tmp/VectorfromCal_EED_ups.vtk");
148                         //writer->SetFileTypeToBinary();
149                         writer2->SetFileTypeToASCII();
150                         writer2->SetTensorsName("VectorfromCal");
151                         writer2->SetFieldDataName("GlyphVector");
152                         writer2->SetScalarsName("Scalar");
153                         writer2->SetInput(_structuredPoints);  
154                         writer2->Write();  
155                 */
156
157         } else { 
158                 printf("EED Warnning!  vtkImageDataStrucPoints::joinComponents  imageX or image Y or image Z is EMPTY\n");
159         } // imageX imageY imageZ
160
161
162
163 printf("EED vtkImageDataStrucPoints::joinComponents End\n");
164
165 }
166
167 vtkStructuredPoints* vtkImageDataStrucPoints::getStructuredPoints()
168 {
169                 return _structuredPoints;
170 }
171