]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkFlip.cxx
4a9bcd201f0f333457fccaecb3e86f2e547664d6
[bbtk.git] / packages / vtk / src / bbvtkFlip.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkFlip.cxx,v $
4   Language:  C++
5   Date:      $Date: 2012/08/06 11:49:20 $
6   Version:   $Revision: 1.4 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
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.
20 *
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
25 *  liability. 
26 *
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 * ------------------------------------------------------------------------ */                                                                         
30
31 /**
32  *  \file 
33  *  \brief 
34  */
35
36 #ifdef _USE_VTK_
37 #include "bbvtkFlip.h"
38 #include "bbvtkPackage.h"
39
40 namespace bbvtk
41 {
42    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,Flip)
43    BBTK_BLACK_BOX_IMPLEMENTATION(Flip,bbtk::AtomicBlackBox);
44
45 //---------------------------------------------------------------------
46
47    void Flip::bbUserSetDefaultValues() 
48    { 
49       //std::cout << "-------- entree ds Flip::bbUserSetDefaultValues()\n" << std::endl;
50       
51       bbSetInputIn(NULL); 
52       mImageOut = NULL;
53       bbSetOutputOut(NULL);
54    }
55
56 //---------------------------------------------------------------------
57
58    void Flip::bbUserInitializeProcessing() 
59    {
60        //std::cout << "-------- entree ds Flip::bbUserInitalizeProcessing()\n" << std::endl;
61    }
62   
63 //---------------------------------------------------------------------
64
65    void Flip::bbUserFinalizeProcessing() 
66    {
67             //std::cout << "-------- entree ds Flip::bbUserFinalizeProcessing()\n" << std::endl;
68    // WTF? we never enter here // JPR  bbUserFinalizeProcessing()  JPR  
69       if (mImageOut!=NULL)
70       {
71         mImageOut->Delete();
72         mImageOut=NULL;
73       }
74       bbSetOutputOut(mImageOut);          
75    }
76
77 //---------------------------------------------------------------------
78  
79  ///  :
80  ///  - receives a vtkImageData*imageIn, flips it
81  ///  - exports a vtkImageData*  
82  ///  
83  ///
84 void Flip::Process()
85 {
86         
87         if (bbGetInputIn()!=NULL)
88         {
89                 if (mImageOut!=NULL)
90                 {
91                         mImageOut->Delete();
92                         mImageOut=NULL;
93                 } // if mImageOut
94         
95                 mImageOut = vtkImageData::New();  // Alloc depends on  bbGetInputIn().size()  
96                 mImageOut->Initialize();
97                 mImageOut->SetScalarType(  bbGetInputIn()->GetScalarType() );
98                 mImageOut->SetSpacing(   bbGetInputIn()->GetSpacing()  );
99                 mImageOut->SetDimensions(   bbGetInputIn()->GetDimensions()  );
100                 mImageOut->SetNumberOfScalarComponents( bbGetInputIn()->GetNumberOfScalarComponents() );
101                 mImageOut->AllocateScalars();
102         
103                 int inputdims[3];
104                 //   int outputdims[3];
105                 bbGetInputIn()->GetDimensions (inputdims);
106                 bbGetInputIn()->Update();
107                 int nbScalComp  = bbGetInputIn()->GetNumberOfScalarComponents();
108                 int scalarSize  = bbGetInputIn()->GetScalarSize();
109                 int lineSize    = inputdims[0]*scalarSize*nbScalComp;      
110                 int planeSize   = inputdims[1]*lineSize;
111                 char *pixelsIn  = (char *)bbGetInputIn()->GetScalarPointer();
112                 char *pixelsOut = (char *)mImageOut->GetScalarPointer();
113         
114                 char *lineIn;
115                 char *lineOut;
116                 char *debPlanIn;
117                 char *debPlanOut;
118                 int j,k;
119                 for(k=0; k<inputdims[2]; k++)  // iterate on planes
120                 {  
121                         debPlanIn       = pixelsIn+k*planeSize;
122                         debPlanOut      = pixelsOut+k*planeSize;
123                         for(j=0; j<inputdims[1]; j++)  // iterates on rows
124                         { 
125                                 lineIn = debPlanIn+j*lineSize;
126                                 lineOut = debPlanOut+(inputdims[1]-1-j)*lineSize;
127                                 memcpy(lineOut,  lineIn, lineSize);
128                         }       // for j
129                 } // for k
130         
131                 bbSetOutputOut( mImageOut  );           
132         } // bbGetInputIn
133
134 }
135
136
137 }//namespace bbtk
138
139 #endif // _USE_VTK_