1 /*=========================================================================
3 Module: $RCSfile: bbvtkFlip.cxx,v $
5 Date: $Date: 2012/07/09 13:03:17 $
6 Version: $Revision: 1.3 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
37 #include "bbvtkFlip.h"
38 #include "bbvtkPackage.h"
42 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Flip)
43 BBTK_BLACK_BOX_IMPLEMENTATION(Flip,bbtk::AtomicBlackBox);
45 //---------------------------------------------------------------------
47 void Flip::bbUserSetDefaultValues()
49 //std::cout << "-------- entree ds Flip::bbUserSetDefaultValues()\n" << std::endl;
56 //---------------------------------------------------------------------
58 void Flip::bbUserInitializeProcessing()
60 //std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
61 //bbUserFinalizeProcessing();
62 mImageOut = vtkImageData::New(); // Alloc depends on bbGetInputIn().size()
65 //---------------------------------------------------------------------
67 void Flip::bbUserFinalizeProcessing()
69 //std::cout << "-------- entree ds Flip::bbUserFinalizeProcessing()\n" << std::endl;
70 // WTF? we never enter here // JPR bbUserFinalizeProcessing() JPR
73 // mImageOut->Delete();
76 bbSetOutputOut(mImageOut);
79 //---------------------------------------------------------------------
82 /// - receives a vtkImageData*imageIn, flips it
83 /// - exports a vtkImageData*
88 vtkImageData* imageIn = bbGetInputIn();
89 vtkImageData * mImageOut = flip(imageIn);
91 // Devrait etre dans bbUserFinalizeProcessing() ? // JPR
92 bbSetOutputOut(mImageOut);
96 vtkImageData * Flip::flip(vtkImageData *imageIn)
100 imageIn->GetDimensions (inputdims);
102 int nbScalComp = imageIn->GetNumberOfScalarComponents();
103 int scalarSize = imageIn->GetScalarSize();
104 int lineSize = inputdims[0]*scalarSize*nbScalComp;
105 int planeSize = inputdims[1]*lineSize;
106 char *pixelsIn = (char *)imageIn->GetScalarPointer();
108 char *temp = (char *)malloc(lineSize);
112 for(int k=0; k<inputdims[2]; k++) { // iterate on planes
113 debPlan = pixelsIn+k*planeSize;
114 for(int j=0; j<inputdims[1]/2; j++) { // iterates on rows
115 line1 = debPlan+j*lineSize;
116 line2 = debPlan+(inputdims[1]-1-j)*lineSize;
117 memcpy(temp, line2, lineSize);
118 memcpy(line2, line1, lineSize);
119 memcpy(line1, temp, lineSize);