]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkFlip.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / vtk / src / bbvtkFlip.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbvtkFlip.cxx,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:58 $
33   Version:   $Revision: 1.5 $
34 =========================================================================*/
35
36 /**
37  *  \file 
38  *  \brief 
39  */
40
41 #ifdef _USE_VTK_
42 #include "bbvtkFlip.h"
43 #include "bbvtkPackage.h"
44
45 namespace bbvtk
46 {
47    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Flip)
48    BBTK_BLACK_BOX_IMPLEMENTATION(Flip,bbtk::AtomicBlackBox);
49
50 //---------------------------------------------------------------------
51
52    void Flip::bbUserSetDefaultValues() 
53    { 
54       //std::cout << "-------- entree ds Flip::bbUserSetDefaultValues()\n" << std::endl;
55       
56       bbSetInputIn(NULL); 
57       bbSetInputAxis("Y"); 
58       mImageOut = NULL;
59       bbSetOutputOut(NULL);
60    }
61
62 //---------------------------------------------------------------------
63
64    void Flip::bbUserInitializeProcessing() 
65    {
66        //std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
67    }
68   
69 //---------------------------------------------------------------------
70
71    void Flip::bbUserFinalizeProcessing() 
72    {
73             //std::cout << "-------- entree ds Flip::bbUserFinalizeProcessing()\n" << std::endl;
74    // WTF? we never enter here // JPR  bbUserFinalizeProcessing()  JPR  
75       if (mImageOut!=NULL)
76       {
77         mImageOut->Delete();
78         mImageOut=NULL;
79       }
80       bbSetOutputOut(mImageOut);          
81    }
82
83 //---------------------------------------------------------------------
84  
85  ///  :
86  ///  - receives a vtkImageData*imageIn, flips it
87  ///  - exports a vtkImageData*  
88  ///  
89  ///
90 void Flip::Process()
91 {
92         
93         if (bbGetInputIn()!=NULL)
94         {
95                 if (mImageOut!=NULL)
96                 {
97                         mImageOut->Delete();
98                         mImageOut=NULL;
99                 } // if mImageOut
100         
101                 mImageOut = vtkImageData::New();  // Alloc depends on  bbGetInputIn().size()  
102                 mImageOut->Initialize();
103                 mImageOut->SetSpacing(   bbGetInputIn()->GetSpacing()  );
104                 mImageOut->SetDimensions(   bbGetInputIn()->GetDimensions()  );
105
106 //EED 2017-01-01 Migration VTK7
107 #if (VTK_MAJOR_VERSION <= 5) 
108                 mImageOut->SetScalarType(  bbGetInputIn()->GetScalarType() );
109                 mImageOut->SetNumberOfScalarComponents( bbGetInputIn()->GetNumberOfScalarComponents() );
110                 mImageOut->AllocateScalars();
111 #endif
112 #if (VTK_MAJOR_VERSION >= 6) 
113                 mImageOut->AllocateScalars(bbGetInputIn()->GetScalarType() , bbGetInputIn()->GetNumberOfScalarComponents());
114 #endif
115         
116                 int inputdims[3];
117                 //   int outputdims[3];
118                 bbGetInputIn()->GetDimensions (inputdims);
119
120 //EED 2017-01-01 Migration VTK7
121 #if (VTK_MAJOR_VERSION <= 5) 
122                 bbGetInputIn()->Update();
123 #endif
124 #if (VTK_MAJOR_VERSION >= 6) 
125                 // ..
126 #endif
127
128                 int nbScalComp  = bbGetInputIn()->GetNumberOfScalarComponents();
129                 int scalarSize  = bbGetInputIn()->GetScalarSize();
130                 int lineSize    = inputdims[0]*scalarSize*nbScalComp;      
131                 int planeSize   = inputdims[1]*lineSize;
132                 int volumeSize  = inputdims[2]*planeSize;
133                 char *pixelsIn  = (char *)bbGetInputIn()->GetScalarPointer();
134                 char *pixelsOut = (char *)mImageOut->GetScalarPointer();
135         
136                 char *lineIn;
137                 char *lineOut;
138                 char *debPlanIn;
139                 char *debPlanOut;
140                 int i,j,k;
141                 
142                 if ( (bbGetInputAxis()=="O") || (bbGetInputAxis()=="o") )
143                 {  
144                         pixelsIn = (char *)bbGetInputIn()->GetScalarPointer(0,0,0);
145                         pixelsOut = (char *)mImageOut->GetScalarPointer(0,0,0);
146                         memcpy(pixelsOut,  pixelsIn, volumeSize );
147                 } else if ( (bbGetInputAxis()=="X") || (bbGetInputAxis()=="x") )
148                 {  
149
150                         for(k=0; k<inputdims[2]; k++)  // iterate  planes
151                         {  
152                                 for(j=0; j<inputdims[1]; j++)  // iterates  rows
153                                 { 
154                                         for(i=0; i<inputdims[0]; i++)  // iterates  columns
155                                         { 
156                                                 pixelsIn = (char *)bbGetInputIn()->GetScalarPointer(i,j,k);
157                                                 pixelsOut = (char *)mImageOut->GetScalarPointer(inputdims[0]-1-i,j,k);
158                                                 memcpy(pixelsOut,  pixelsIn, scalarSize );
159                                         }       // for i
160                                 }       // for j
161                         } // for k
162
163                 } else if ( (bbGetInputAxis()=="Z") || (bbGetInputAxis()=="z") )  {  
164
165                         for(k=0; k<inputdims[2]; k++)  // iterate  planes
166                         {  
167                                 for(j=0; j<inputdims[1]; j++)  // iterates  rows
168                                 { 
169                                         for(i=0; i<inputdims[0]; i++)  // iterates  columns
170                                         { 
171                                                 pixelsIn = (char *)bbGetInputIn()->GetScalarPointer(i,j,k);
172                                                 pixelsOut = (char *)mImageOut->GetScalarPointer(i,j,inputdims[2]-1-k);
173                                                 memcpy(pixelsOut,  pixelsIn, scalarSize );
174                                         }       // for i
175                                 }       // for j
176                         } // for k
177
178                 } else {  
179
180                         for(k=0; k<inputdims[2]; k++)  // iterate  planes
181                         {  
182                                 debPlanIn       = pixelsIn+k*planeSize;
183                                 debPlanOut      = pixelsOut+k*planeSize;
184                                 for(j=0; j<inputdims[1]; j++)  // iterates  rows
185                                 { 
186                                         lineIn = debPlanIn+j*lineSize;
187                                         lineOut = debPlanOut+(inputdims[1]-1-j)*lineSize;
188                                         memcpy(lineOut,  lineIn, lineSize);
189                                 }       // for j
190                         } // for k
191
192                 } //if
193                 mImageOut->Modified();
194                 bbSetOutputOut( mImageOut  );           
195         } // bbGetInputIn
196
197 }
198
199
200 }//namespace bbtk
201
202 #endif // _USE_VTK_