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 "vtkImageDataStrucPoints.h"
29 #include "vtkStructuredPointsWriter.h"
32 vtkImageDataStrucPoints::vtkImageDataStrucPoints()
34 _structuredPoints=NULL;
37 vtkImageDataStrucPoints::~vtkImageDataStrucPoints()
41 void vtkImageDataStrucPoints::joinComponents(vtkImageData* imageX, vtkImageData* imageY, vtkImageData* imageZ,
42 vtkImageData* Data1, vtkImageData* Data2, vtkImageData* Data3 ,
43 vtkImageData* Data4, vtkImageData* Data5, vtkImageData* Data6 )
45 if ((imageX!=NULL) && (imageY!=NULL) && (imageZ!=NULL) )
49 //EED 2017-01-01 Migration VTK7
50 #if VTK_MAJOR_VERSION <= 5
52 imageY->GetWholeExtent(ext);
54 imageY->GetExtent(ext);
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];
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");
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;
97 for( i = 0 ; i < sizeimage ; i++ )
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++;}
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); }
114 _structuredPoints = vtkStructuredPoints::New();
115 _structuredPoints->SetDimensions(dim[0], dim[1], dim[2]);
116 _structuredPoints->SetSpacing(spc);
118 //EED 2017-01-01 Migration VTK7
119 #if VTK_MAJOR_VERSION <= 5
120 _structuredPoints->SetScalarTypeToDouble();
121 _structuredPoints->SetNumberOfScalarComponents(3);
123 vtkInformation* info=_structuredPoints->GetInformation();
124 vtkDataObject::SetPointDataActiveScalarInfo(info, VTK_DOUBLE, 3);
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();
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);
153 printf("EED Warnning! vtkImageDataStrucPoints::joinComponents imageX or image Y or image Z is EMPTY\n");
154 _structuredPoints=NULL;
155 } // imageX imageY imageZ
158 vtkStructuredPoints* vtkImageDataStrucPoints::getStructuredPoints()
160 return _structuredPoints;