]> Creatis software - creaVtk.git/blob - bbtk_creaVtk_PKG/src/bbcreaVtkReadMHDPlane.cxx
#2711 creaVtk Feature New Normal - new Box ReadMHDPlane
[creaVtk.git] / bbtk_creaVtk_PKG / src / bbcreaVtkReadMHDPlane.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 "bbcreaVtkReadMHDPlane.h"
5 #include "bbcreaVtkPackage.h"
6
7 #include "stdio.h"
8
9 namespace bbcreaVtk
10 {
11
12 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaVtk,ReadMHDPlane)
13 BBTK_BLACK_BOX_IMPLEMENTATION(ReadMHDPlane,bbtk::AtomicBlackBox);
14 //===== 
15 // 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)
16 //===== 
17 void ReadMHDPlane::Process()
18 {
19
20 // THE MAIN PROCESSING METHOD BODY
21 //   Here we simply set the input 'In' value to the output 'Out'
22 //   And print out the output value
23 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
24 //    void bbSet{Input|Output}NAME(const TYPE&)
25 //    const TYPE& bbGet{Input|Output}NAME() const 
26 //    Where :
27 //    * NAME is the name of the input/output
28 //      (the one provided in the attribute 'name' of the tag 'input')
29 //    * TYPE is the C++ type of the input/output
30 //      (the one provided in the attribute 'type' of the tag 'input')
31
32 //    bbSetOutputOut( bbGetInputIn() );
33 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
34
35
36
37
38         long int newHeaderSize;
39         std::string newFileName=bbGetInputFileName()+"-OneSlice";
40
41     int sx,sy;
42     char mystring[250];
43     char strTmp[20];
44     FILE *ffOut = fopen(newFileName.c_str(),"w+");
45     FILE *ffIn  = fopen(bbGetInputFileName().c_str(),"r+");
46
47     while(!feof(ffIn))
48     {
49         strcpy(mystring,"\n");
50         fgets(mystring,250,ffIn);
51         if (strncmp("NDims",mystring,5)==0) {strcpy(mystring,"NDims = 2\n");}
52         if (strncmp("DimSize",mystring,6)==0) 
53         {
54                 sscanf(mystring,"%s %s %d %d",strTmp, strTmp, &sx, &sy);
55                 sprintf(mystring,"DimSize = %d %d\n",sx,sy);
56                 newHeaderSize = sx*sy*bbGetInputSlice();
57         }
58         if (strncmp("ElementType = MET_USHORT",mystring,24)==0) { newHeaderSize=newHeaderSize*2; }
59         if (strncmp("ElementType = MET_SHORT",mystring,23)==0) { newHeaderSize=newHeaderSize*2; }
60         if (strncmp("ElementType = MET_FLOAT",mystring,23)==0) { newHeaderSize=newHeaderSize*2; }
61         if (strncmp("Offset",mystring,6)==0) {strcpy(mystring,"Offset = 0 0 0\n");}
62         if (strncmp("HeaderSize",mystring,10)==0) {strcpy(mystring,"");}
63         if (strncmp("ElementDataFile",mystring,15)==0) 
64         {
65                 fprintf(ffOut,"HeaderSize = %ld\n\n", newHeaderSize );
66         }
67         fprintf(ffOut,mystring); 
68     }
69
70 /*
71    fprintf(ff,"ObjectType = Image\n");
72    fprintf(ff,"NDims = 2\n");
73    fprintf(ff,"BinaryData = True\n");
74    fprintf(ff,"BinaryDataByteOrderMSB = False\n");
75    fprintf(ff,"CompressedData = False\n");
76    fprintf(ff,"TransformMatrix = 1 0 0 0 1 0 0 0 1\n");
77    fprintf(ff,"CenterOfRotation = 0 0 0\n");
78    fprintf(ff,"ElementSpacing = 0.7 0.7 0.7\n");
79    fprintf(ff,"DimSize = 512 512\n");
80    fprintf(ff,"AnatomicalOrientation = ???\n");
81    fprintf(ff,"ElementType = MET_SHORT\n");
82    fprintf(ff,"ElementNumberOfChannels = 1\n");
83    fprintf(ff,"Offset = 0 0 0\n");
84    fprintf(ff,"HeaderSize = %ld\n", newHeaderSize );
85    fprintf(ff,"ElementDataFile = inspi1_ana.raw\n");
86 */
87
88    fclose(ffIn);
89    fclose(ffOut);
90
91
92    vtkMetaImageReader * reader = vtkMetaImageReader::New();
93    reader->SetFileName( newFileName.c_str() );
94    reader->Update();
95    
96    bbSetOutputOut( reader->GetOutput() );
97
98
99 }
100 //===== 
101 // 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)
102 //===== 
103 void ReadMHDPlane::bbUserSetDefaultValues()
104 {
105
106 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
107 //    Here we initialize the input 'In' to 0
108    bbSetInputFileName("");
109    bbSetInputSlice(0);
110   
111 }
112 //===== 
113 // 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)
114 //===== 
115 void ReadMHDPlane::bbUserInitializeProcessing()
116 {
117
118 //  THE INITIALIZATION METHOD BODY :
119 //    Here does nothing 
120 //    but this is where you should allocate the internal/output pointers 
121 //    if any 
122
123   
124 }
125 //===== 
126 // 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)
127 //===== 
128 void ReadMHDPlane::bbUserFinalizeProcessing()
129 {
130
131 //  THE FINALIZATION METHOD BODY :
132 //    Here does nothing 
133 //    but this is where you should desallocate the internal/output pointers 
134 //    if any
135   
136 }
137 }
138 // EO namespace bbcreaVtk
139
140