]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPiecewiseFunction.cxx
*** empty log message ***
[bbtk.git] / packages / vtk / src / bbvtkPiecewiseFunction.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbvtkPiecewiseFunction.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/16 12:48:10 $
6   Version:   $Revision: 1.1 $
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
37
38 #ifdef _USE_VTK_
39
40
41 #include "bbvtkPiecewiseFunction.h"
42 #include "bbvtkPackage.h"
43
44 namespace bbvtk
45 {
46
47
48    BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PiecewiseFunction)
49    BBTK_BLACK_BOX_IMPLEMENTATION(PiecewiseFunction,bbtk::AtomicBlackBox);
50
51
52
53
54
55    void PiecewiseFunction::bbUserConstructor() 
56    { 
57      Init();
58      // Identity function
59      std::vector<float> x,y;
60      x.push_back(0);
61      x.push_back(1);
62      y.push_back(0);
63      y.push_back(1);
64      bbSetInputX(x);
65      bbSetInputY(y);
66    }
67    void PiecewiseFunction::bbUserCopyConstructor(bbtk::BlackBox::Pointer) 
68    { 
69      Init();
70    }
71
72    void PiecewiseFunction::Init() 
73    { 
74      bbSetOutputOut(vtkPiecewiseFunction::New());
75    }
76
77    void PiecewiseFunction::bbUserDestructor() 
78    { 
79      bbGetOutputOut()->Delete();
80    }
81 //---------------------------------------------------------------------
82
83    void PiecewiseFunction::Process()
84    {
85      if ( ( bbGetInputStatus("X") != bbtk::UPTODATE ) || 
86           ( bbGetInputStatus("Y") != bbtk::UPTODATE ) )
87        {
88          if  ( bbGetInputX().size() != bbGetInputY().size() ) 
89            bbtkError(bbGetFullName()
90                      <<" : input vectors X and Y do not have the same size"); 
91          if  ( bbGetInputX().size() < 2 ) 
92            bbtkError(bbGetFullName()
93                      <<" : input vectors X and Y have a size < 2"); 
94          bbGetOutputOut()->RemoveAllPoints ();
95          //      std::cout << bbGetInputX().size()<< ","<< bbGetInputY().size()<< std::endl;
96          std::vector<float>::const_iterator x,y;
97          std::vector<float> X = bbGetInputX(); 
98          std::vector<float> Y = bbGetInputY(); 
99          for (x = X.begin(), y = Y.begin();
100               x != X.end(),  y != Y.end();
101               ++x, ++y )
102            {
103              //              std::cout << *x << " -> " << *y << std::endl;
104              bbGetOutputOut()->AddPoint(*x,*y);
105            }
106        }
107    }
108
109 }//namespace bbtk
110
111 #endif // _USE_VTK_
112