]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkFlip.cxx
Feature #1774
[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       mImageOut = NULL;
58       bbSetOutputOut(NULL);
59    }
60
61 //---------------------------------------------------------------------
62
63    void Flip::bbUserInitializeProcessing() 
64    {
65        //std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
66    }
67   
68 //---------------------------------------------------------------------
69
70    void Flip::bbUserFinalizeProcessing() 
71    {
72             //std::cout << "-------- entree ds Flip::bbUserFinalizeProcessing()\n" << std::endl;
73    // WTF? we never enter here // JPR  bbUserFinalizeProcessing()  JPR  
74       if (mImageOut!=NULL)
75       {
76         mImageOut->Delete();
77         mImageOut=NULL;
78       }
79       bbSetOutputOut(mImageOut);          
80    }
81
82 //---------------------------------------------------------------------
83  
84  ///  :
85  ///  - receives a vtkImageData*imageIn, flips it
86  ///  - exports a vtkImageData*  
87  ///  
88  ///
89 void Flip::Process()
90 {
91         
92         if (bbGetInputIn()!=NULL)
93         {
94                 if (mImageOut!=NULL)
95                 {
96                         mImageOut->Delete();
97                         mImageOut=NULL;
98                 } // if mImageOut
99         
100                 mImageOut = vtkImageData::New();  // Alloc depends on  bbGetInputIn().size()  
101                 mImageOut->Initialize();
102                 mImageOut->SetScalarType(  bbGetInputIn()->GetScalarType() );
103                 mImageOut->SetSpacing(   bbGetInputIn()->GetSpacing()  );
104                 mImageOut->SetDimensions(   bbGetInputIn()->GetDimensions()  );
105                 mImageOut->SetNumberOfScalarComponents( bbGetInputIn()->GetNumberOfScalarComponents() );
106                 mImageOut->AllocateScalars();
107         
108                 int inputdims[3];
109                 //   int outputdims[3];
110                 bbGetInputIn()->GetDimensions (inputdims);
111                 bbGetInputIn()->Update();
112                 int nbScalComp  = bbGetInputIn()->GetNumberOfScalarComponents();
113                 int scalarSize  = bbGetInputIn()->GetScalarSize();
114                 int lineSize    = inputdims[0]*scalarSize*nbScalComp;      
115                 int planeSize   = inputdims[1]*lineSize;
116                 char *pixelsIn  = (char *)bbGetInputIn()->GetScalarPointer();
117                 char *pixelsOut = (char *)mImageOut->GetScalarPointer();
118         
119                 char *lineIn;
120                 char *lineOut;
121                 char *debPlanIn;
122                 char *debPlanOut;
123                 int j,k;
124                 for(k=0; k<inputdims[2]; k++)  // iterate on planes
125                 {  
126                         debPlanIn       = pixelsIn+k*planeSize;
127                         debPlanOut      = pixelsOut+k*planeSize;
128                         for(j=0; j<inputdims[1]; j++)  // iterates on rows
129                         { 
130                                 lineIn = debPlanIn+j*lineSize;
131                                 lineOut = debPlanOut+(inputdims[1]-1-j)*lineSize;
132                                 memcpy(lineOut,  lineIn, lineSize);
133                         }       // for j
134                 } // for k
135         
136                 bbSetOutputOut( mImageOut  );           
137         } // bbGetInputIn
138
139 }
140
141
142 }//namespace bbtk
143
144 #endif // _USE_VTK_