]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuContourToControlPoints.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuContourToControlPoints.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #ifdef _USE_VTK_
27 #ifdef _USE_ITK_
28
29 #include "bbmaracasvisuContourToControlPoints.h"
30 #include "bbcreaMaracasVisuPackage.h"
31 namespace bbcreaMaracasVisu
32 {
33
34 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ContourToControlPoints)
35 //BBTK_USER_BLACK_BOX_IMPLEMENTATION(ContourToControlPoints,bbtk::AtomicBlackBox);
36 BBTK_BLACK_BOX_IMPLEMENTATION(ContourToControlPoints,bbtk::AtomicBlackBox);
37
38 //------------------------------------------------------------
39 void ContourToControlPoints::Process()
40 {
41                 if ( bbGetInputSampling() >= 3.0 )
42                 {
43                         OutContourX.clear();
44                         OutContourY.clear();
45                         OutContourZ.clear();
46                         _ext2D->SetContour( bbGetInputInContourX(),bbGetInputInContourY(),bbGetInputInContourZ() );
47                         _ext2D->SetSamplingControlPoints( bbGetInputSampling() );
48                         _ext2D->GetSamplingControlPoints( &OutContourX,&OutContourY,&OutContourZ );
49                 }
50                 if(bbGetInputSampling() == 2.0)
51                 {
52                         OutContourX.clear();
53                         OutContourY.clear();
54                         OutContourZ.clear();
55                         _ext2D->SetContour( bbGetInputInContourX(),bbGetInputInContourY(),bbGetInputInContourZ() );
56                         _ext2D->GetControlPoints( &OutContourX,&OutContourY,&OutContourZ );
57                 }
58                 
59                 //Liberates the memory from the VTK's objects. Always must do that!!    
60                 if ( bbGetInputLoadContour()== 1 )
61                 {
62                         if (_imagedata!=NULL)
63                         {
64                                 _imagedata->Delete();
65                         }
66                         KeyContourX.clear();
67                         KeyContourY.clear();
68                         KeyContourZ.clear();
69                         KeySizes.clear();
70                         FILE* fd;
71                         fd = fopen("C:/bbtk_JS/data/SavedContours.txt","r"); 
72                         _propgdata->ReadKeyContour( fd );
73                         fclose(fd);
74                         _propgdata->GetKeyContours(&KeyContourX,&KeyContourY,&KeyContourZ,&KeySizes);
75                         if(KeySizes.size() == 1)
76                         {
77                                 //Method for 2D
78                         //      _imagedata = _propgdata->method_RBF(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
79                         }
80                         if(KeySizes.size() >= 2)
81                         {
82                                 //Method for 3D
83                                 //_imagedata = _propgdata->method_RBF_3D(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
84                         //      _imagedata = _propgdata->method_RBF_3D_ThinPlate(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
85                         }
86                 }
87                 if ( bbGetInputLoadContour()== 2 )
88                 {
89                         if (_imagedata!=NULL)
90                         {
91                                 _imagedata->Delete();
92                         }
93                         FILE* fd;
94                         fd = fopen("C:/bbtk_JS/data/SavedManualPoints.txt","r"); 
95                         _propgdata->ReadKeyContour( fd );
96                         fclose(fd);
97                         _propgdata->GetKeyContours(&KeyContourX,&KeyContourY,&KeyContourZ,&KeySizes);
98                         if(KeySizes.size() == 1)
99                         {
100                                 //Method for 2D
101                         //      _imagedata = _propgdata->method_RBF(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
102                         }
103                         if(KeySizes.size() >= 2)
104                         {
105                                 //Method for 3D
106                                 //_imagedata = _propgdata->method_RBF_3D(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
107                         //      _imagedata = _propgdata->method_RBF_3D_ThinPlate(bbGetInputRadRBF(),&KeyContourX,&KeyContourY,&KeyContourZ);
108                         }
109                 }
110
111                 if ( bbGetInputLoadContour()== 3 )
112                 {
113                         if (_imagedata!=NULL)
114                         {
115                                 _imagedata->Delete();
116                         }
117                         vtkImageData *itemp = vtkImageData::New();
118                         _contprop->appendContour();
119                         _contprop->setInterpolationNumber(300);
120                         itemp = _contprop->GetKeyContours(&KeyContourX,&KeyContourY,&KeyContourZ,&KeySizes);
121                         if(KeySizes.size() == 1)
122                         {
123                         }
124                         if(KeySizes.size() >= 2)
125                         {
126                                 //Method for 3D
127                                 _imagedata = itemp;
128                                 _contprop->resetAppend();
129                                 _contprop->appendContour(&KeyContourX,&KeyContourY,&KeyContourZ);
130                                 //_contprop->GetContour(bbGetInputSlice(),&OutContourX,&OutContourY,&OutContourZ);
131                                 _contprop->GetControlPoints(bbGetInputSlice(),&OutContourX,&OutContourY,&OutContourZ);
132                                 printf("\n Size OutContourX = %d",(int)(OutContourX.size()));
133                         }
134                 }
135
136                 bbSetOutputControlPointX( &OutContourX );
137                 bbSetOutputControlPointY( &OutContourY );
138                 bbSetOutputControlPointZ( &OutContourZ );
139                 bbSetOutputImagePropg( _imagedata );
140 }
141         
142         
143 //------------------------------------------------------------
144 void ContourToControlPoints::bbUserSetDefaultValues()
145 {
146                 bbSetInputSampling(5.0);
147                 bbSetInputSlice(0);
148                 bbSetInputInContourX(NULL);
149                 bbSetInputInContourY(NULL);
150                 bbSetInputInContourZ(NULL);
151                 bbSetInputRadRBF(1000.0);
152                 bbSetInputOption(1);
153                 bbSetInputLoadContour(0);
154
155                 _contprop       = NULL;
156                 _propgdata      = NULL;
157                 _imagedata      = NULL;
158                 _ext2D          = NULL;
159         
160                 _fd = NULL;
161                 pos = 0;
162 }
163
164         
165         //-----------------------------------------------------------------     
166         void ContourToControlPoints::bbUserInitializeProcessing()
167         {
168                 _contprop       = new ContourPropagation();
169                 _propgdata      = new PropContour();
170                 _imagedata      = vtkImageData::New();
171                 _ext2D          = new ExtractControlPoints2D();
172         }
173         
174         //-----------------------------------------------------------------     
175         void ContourToControlPoints::bbUserFinalizeProcessing()
176         {
177                 if (_contprop!=NULL) delete _contprop;
178                 if (_propgdata!=NULL) delete _propgdata;
179                 if (_imagedata!=NULL) _imagedata->Delete();
180                 if (_ext2D!=NULL) delete _ext2D;
181
182                 _contprop       = NULL;
183                 _propgdata      = NULL;
184                 _imagedata      = NULL;
185                 _ext2D          = NULL;
186         }
187         
188         //-----------------------------------------------------------------     
189
190         
191
192 }
193 // EO namespace bbcreaMaracasVisu
194
195 #endif //_USE_ITK_
196 #endif //_USE_VTK_