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