]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbcreaMaracasVisuReadCreaContourFile.cxx
a3fafa05cd0c2bdf934e2af9406a66bb790954c5
[creaMaracasVisu.git] / bbtk / src / bbcreaMaracasVisuReadCreaContourFile.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbcreaMaracasVisuReadCreaContourFile.h"
5 #include "bbcreaMaracasVisuPackage.h"
6 namespace bbcreaMaracasVisu
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ReadCreaContourFile)
10 BBTK_BLACK_BOX_IMPLEMENTATION(ReadCreaContourFile,bbtk::AtomicBlackBox);
11 //===== 
12 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
13 //===== 
14 void ReadCreaContourFile::Process()
15 {
16
17 // THE MAIN PROCESSING METHOD BODY
18 //   Here we simply set the input 'In' value to the output 'Out'
19 //   And print out the output value
20 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
21 //    void bbSet{Input|Output}NAME(const TYPE&)
22 //    const TYPE& bbGet{Input|Output}NAME() const 
23 //    Where :
24 //    * NAME is the name of the input/output
25 //      (the one provided in the attribute 'name' of the tag 'input')
26 //    * TYPE is the C++ type of the input/output
27 //      (the one provided in the attribute 'type' of the tag 'input')
28
29 //    bbSetOutputOut( bbGetInputIn() );
30 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
31   
32         if (bbGetInputFileNameRoi().compare("")==0)
33         {
34                 printf("EED Warnning!  ReadCreaContourFile::Process  FileNameRoi  EMPTY\n");
35         }  else {
36                 char tmp[255];
37                 FILE *ff= fopen(bbGetInputFileNameRoi().c_str(),"r");
38                 if (ff==NULL)
39                 {
40                         printf("EED Warnning!  ReadCreaContourFile::Process  Wrong file %s\n", bbGetInputFileNameRoi().c_str() );       
41                 } else {
42                         fscanf(ff,"%s",tmp);  // --CreaContour--
43                         std::string tmpStr(tmp);
44                         if (tmpStr.compare("--CreaContour--")==0 )
45                         {
46                                 int iContour,iControlPoint;
47                                 int dimX, dimY,dimZ;
48                                 int NumberOfContours;
49                                 double x,y,z,zz;
50                                 int TypeModel;
51                                 int NumberOfControlPoints;
52
53
54                                 std::vector<double> LstX;
55                                 std::vector<double> LstY;
56                                 std::vector<double> LstZ;
57                                 std::vector<int>        LstIndexs;
58
59                                 fscanf(ff,"%s",tmp);    // version
60                                 fscanf(ff,"%s",tmp);    // 
61                                 fscanf(ff,"%s",tmp);    // ImageDimensions
62                                 fscanf(ff,"%d",&dimX);  // 
63                                 fscanf(ff,"%d",&dimY);  // 
64                                 fscanf(ff,"%d",&dimZ);  // 
65                                 fscanf(ff,"%s",tmp);    // ImageSpacing
66                                 fscanf(ff,"%s",tmp);    // 
67                                 fscanf(ff,"%s",tmp);    // 
68                                 fscanf(ff,"%s",tmp);    // 
69                                 fscanf(ff,"%s",tmp);    // NumberOfContours
70                                 fscanf(ff,"%d",&NumberOfContours);  // 
71                                 for (iContour=0 ; iContour<NumberOfContours ; iContour++)
72                                 {
73                                         fscanf(ff,"%s",tmp);  // Instant
74                                         fscanf(ff,"%s",tmp);  // 
75                                         fscanf(ff,"%s",tmp);  zz=atof(tmp); // zz
76                                         fscanf(ff,"%s",tmp);  // 
77                                         fscanf(ff,"%s",tmp);  // 
78                                         fscanf(ff,"%s",tmp);  // 
79                                         fscanf(ff,"%s",tmp);  // 
80                                         fscanf(ff,"%s",tmp);  // TypeModel
81                                         fscanf(ff,"%d",&TypeModel);  // 
82                                         if ((TypeModel==1) || (TypeModel==6)  )
83                                         {
84                                                 fscanf(ff,"%s",tmp);  // NumberOfControlPoints
85                                                 fscanf(ff,"%d",&NumberOfControlPoints);  // 
86                                                 LstIndexs.push_back( NumberOfControlPoints );
87                                                 for (iControlPoint=0 ;  iControlPoint<NumberOfControlPoints ; iControlPoint++) 
88                                                 {
89                                                         fscanf(ff,"%s",tmp);  x=atof(tmp); // x
90                                                         fscanf(ff,"%s",tmp);  y=atof(tmp); // y
91                                                         fscanf(ff,"%s",tmp);  z=atof(tmp); // z
92                                                         if (bbGetInputFromDirection()==0)  // XY
93                                                         {
94                                                                 LstX.push_back(x);
95                                                                 LstY.push_back(y);
96                                                                 LstZ.push_back(zz);
97                                                         } // if FromDirection
98                                                         if (bbGetInputFromDirection()==1)  // YZ
99                                                         {
100                                                                 LstX.push_back(zz);
101                                                                 LstY.push_back(x);
102                                                                 LstZ.push_back(y);
103                                                         } // if FromDirection
104                                                         if (bbGetInputFromDirection()==2)  // XZ
105                                                         {
106                                                                 LstX.push_back(x);
107                                                                 LstY.push_back(zz);
108                                                                 LstZ.push_back( (y*(-1)) + (dimY-1) );
109                                                         } // if FromDirection
110                                                 } // iControlPoint
111                                         } // TypeModel
112                                         fscanf(ff,"%s",tmp);  // TypeView
113                                         fscanf(ff,"%s",tmp);  // 
114
115                                 } // for i  NumberOfContours
116                                 fclose(ff);
117                         bbSetOutputLstX( LstX );
118                         bbSetOutputLstY( LstY );
119                         bbSetOutputLstZ( LstZ );
120                         bbSetOutputLstIndexs( LstIndexs );
121
122                         } else {
123                                                 printf("EED Warnning!  ReadCreaContourFile::Process  %s is not a creaContour .roi file\n",bbGetInputFileNameRoi() );
124                         } // if --CreaContour--
125                 } // if ff
126         } // if FileNameRoi
127
128 }
129 //===== 
130 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
131 //===== 
132 void ReadCreaContourFile::bbUserSetDefaultValues()
133 {
134
135 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
136 //    Here we initialize the input 'In' to 0
137    bbSetInputFileNameRoi("");
138    bbSetInputFromDirection(0);
139   
140 }
141 //===== 
142 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
143 //===== 
144 void ReadCreaContourFile::bbUserInitializeProcessing()
145 {
146
147 //  THE INITIALIZATION METHOD BODY :
148 //    Here does nothing 
149 //    but this is where you should allocate the internal/output pointers 
150 //    if any 
151
152   
153 }
154 //===== 
155 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
156 //===== 
157 void ReadCreaContourFile::bbUserFinalizeProcessing()
158 {
159
160 //  THE FINALIZATION METHOD BODY :
161 //    Here does nothing 
162 //    but this is where you should desallocate the internal/output pointers 
163 //    if any
164   
165 }
166 }
167 // EO namespace bbcreaMaracasVisu
168
169