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 /*=========================================================================
30 Module: $RCSfile: bbvtkFlip.cxx,v $
32 Date: $Date: 2012/11/16 08:51:58 $
33 Version: $Revision: 1.5 $
34 =========================================================================*/
42 #include "bbvtkFlip.h"
43 #include "bbvtkPackage.h"
47 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Flip)
48 BBTK_BLACK_BOX_IMPLEMENTATION(Flip,bbtk::AtomicBlackBox);
50 //---------------------------------------------------------------------
52 void Flip::bbUserSetDefaultValues()
54 //std::cout << "-------- entree ds Flip::bbUserSetDefaultValues()\n" << std::endl;
62 //---------------------------------------------------------------------
64 void Flip::bbUserInitializeProcessing()
66 //std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
69 //---------------------------------------------------------------------
71 void Flip::bbUserFinalizeProcessing()
73 //std::cout << "-------- entree ds Flip::bbUserFinalizeProcessing()\n" << std::endl;
74 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
80 bbSetOutputOut(mImageOut);
83 //---------------------------------------------------------------------
86 /// - receives a vtkImageData*imageIn, flips it
87 /// - exports a vtkImageData*
93 if (bbGetInputIn()!=NULL)
101 mImageOut = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
102 mImageOut->Initialize();
103 mImageOut->SetScalarType( bbGetInputIn()->GetScalarType() );
104 mImageOut->SetSpacing( bbGetInputIn()->GetSpacing() );
105 mImageOut->SetDimensions( bbGetInputIn()->GetDimensions() );
106 mImageOut->SetNumberOfScalarComponents( bbGetInputIn()->GetNumberOfScalarComponents() );
107 mImageOut->AllocateScalars();
110 // int outputdims[3];
111 bbGetInputIn()->GetDimensions (inputdims);
112 bbGetInputIn()->Update();
113 int nbScalComp = bbGetInputIn()->GetNumberOfScalarComponents();
114 int scalarSize = bbGetInputIn()->GetScalarSize();
115 int lineSize = inputdims[0]*scalarSize*nbScalComp;
116 int planeSize = inputdims[1]*lineSize;
117 int volumeSize = inputdims[2]*planeSize;
118 char *pixelsIn = (char *)bbGetInputIn()->GetScalarPointer();
119 char *pixelsOut = (char *)mImageOut->GetScalarPointer();
127 if ( (bbGetInputAxis()=="O") || (bbGetInputAxis()=="o") )
129 pixelsIn = (char *)bbGetInputIn()->GetScalarPointer(0,0,0);
130 pixelsOut = (char *)mImageOut->GetScalarPointer(0,0,0);
131 memcpy(pixelsOut, pixelsIn, volumeSize );
132 } else if ( (bbGetInputAxis()=="X") || (bbGetInputAxis()=="x") )
135 for(k=0; k<inputdims[2]; k++) // iterate planes
137 for(j=0; j<inputdims[1]; j++) // iterates rows
139 for(i=0; i<inputdims[0]; i++) // iterates columns
141 pixelsIn = (char *)bbGetInputIn()->GetScalarPointer(i,j,k);
142 pixelsOut = (char *)mImageOut->GetScalarPointer(inputdims[0]-1-i,j,k);
143 memcpy(pixelsOut, pixelsIn, scalarSize );
148 } else if ( (bbGetInputAxis()=="Z") || (bbGetInputAxis()=="z") ) {
150 for(k=0; k<inputdims[2]; k++) // iterate planes
152 for(j=0; j<inputdims[1]; j++) // iterates rows
154 for(i=0; i<inputdims[0]; i++) // iterates columns
156 pixelsIn = (char *)bbGetInputIn()->GetScalarPointer(i,j,k);
157 pixelsOut = (char *)mImageOut->GetScalarPointer(i,j,inputdims[2]-1-k);
158 memcpy(pixelsOut, pixelsIn, scalarSize );
165 for(k=0; k<inputdims[2]; k++) // iterate planes
167 debPlanIn = pixelsIn+k*planeSize;
168 debPlanOut = pixelsOut+k*planeSize;
169 for(j=0; j<inputdims[1]; j++) // iterates rows
171 lineIn = debPlanIn+j*lineSize;
172 lineOut = debPlanOut+(inputdims[1]-1-j)*lineSize;
173 memcpy(lineOut, lineIn, lineSize);
178 mImageOut->Modified();
179 bbSetOutputOut( mImageOut );