1 | // G. Le Meur 04/2000
|
---|
2 |
|
---|
3 | #include "sopnamsp.h"
|
---|
4 | #include "fiolocalmap.h"
|
---|
5 | #include "fioarr.h"
|
---|
6 | #include "pexceptions.h"
|
---|
7 | #include "fiondblock.h"
|
---|
8 | #include "datatype.h"
|
---|
9 | #include <typeinfo>
|
---|
10 |
|
---|
11 | //*******************************************************************
|
---|
12 | // class FIO_LocalMap<T>
|
---|
13 | // Les objets delegues pour la gestion de persistance
|
---|
14 | //*******************************************************************
|
---|
15 |
|
---|
16 | //++
|
---|
17 | template <class T>
|
---|
18 | FIO_LocalMap<T>::FIO_LocalMap()
|
---|
19 | //
|
---|
20 | //--
|
---|
21 | {
|
---|
22 | dobj= new LocalMap<T>;
|
---|
23 | ownobj= true;
|
---|
24 | }
|
---|
25 | //++
|
---|
26 | template <class T>
|
---|
27 | FIO_LocalMap<T>::FIO_LocalMap(string const& filename)
|
---|
28 | //
|
---|
29 | //--
|
---|
30 | {
|
---|
31 | dobj= new LocalMap<T>;
|
---|
32 | ownobj= true;
|
---|
33 | Read(filename);
|
---|
34 | }
|
---|
35 |
|
---|
36 | //++
|
---|
37 | template <class T>
|
---|
38 | FIO_LocalMap<T>::FIO_LocalMap(const LocalMap<T>& obj)
|
---|
39 | //
|
---|
40 | //--
|
---|
41 | {
|
---|
42 | dobj= new LocalMap<T>(obj, true);
|
---|
43 | ownobj= true;
|
---|
44 | }
|
---|
45 |
|
---|
46 | template <class T>
|
---|
47 | FIO_LocalMap<T>::FIO_LocalMap(LocalMap<T>* obj)
|
---|
48 | {
|
---|
49 | dobj= obj;
|
---|
50 | ownobj= false;
|
---|
51 | }
|
---|
52 |
|
---|
53 | //++
|
---|
54 | template <class T>
|
---|
55 | FIO_LocalMap<T>::~FIO_LocalMap()
|
---|
56 | //
|
---|
57 | //--
|
---|
58 | {
|
---|
59 | if (ownobj && dobj) delete dobj;
|
---|
60 | }
|
---|
61 |
|
---|
62 | //++
|
---|
63 | template <class T>
|
---|
64 | AnyDataObj* FIO_LocalMap<T>::DataObj()
|
---|
65 | //
|
---|
66 | //--
|
---|
67 | {
|
---|
68 | return(dobj);
|
---|
69 | }
|
---|
70 |
|
---|
71 | //++
|
---|
72 | template <class T>
|
---|
73 | void FIO_LocalMap<T>::SetDataObj(AnyDataObj & o)
|
---|
74 | //
|
---|
75 | //--
|
---|
76 | {
|
---|
77 | LocalMap<T> * po = dynamic_cast< LocalMap<T> * >(&o);
|
---|
78 | if (po == NULL) {
|
---|
79 | char buff[160];
|
---|
80 | sprintf(buff,"FIO_LocalMap<%s>::SetDataObj(%s) - Object type error ! ",
|
---|
81 | DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
|
---|
82 | throw TypeMismatchExc(PExcLongMessage(buff));
|
---|
83 | }
|
---|
84 | if (ownobj && dobj) delete dobj;
|
---|
85 | dobj = po; ownobj = false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | //++
|
---|
89 | template <class T>
|
---|
90 | void FIO_LocalMap<T>::ReadSelf(PInPersist& is)
|
---|
91 | //
|
---|
92 | //--
|
---|
93 | {
|
---|
94 |
|
---|
95 | if(dobj == NULL)
|
---|
96 | {
|
---|
97 | dobj= new LocalMap<T>;
|
---|
98 | ownobj= true;
|
---|
99 | }
|
---|
100 |
|
---|
101 | // Pour savoir s'il y avait un DVList Info associe
|
---|
102 | char strg[256];
|
---|
103 | is.GetLine(strg, 255);
|
---|
104 | bool hadinfo= false;
|
---|
105 | if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
|
---|
106 | if(hadinfo)
|
---|
107 | { // Lecture eventuelle du DVList Info
|
---|
108 | is >> dobj->Info();
|
---|
109 | }
|
---|
110 |
|
---|
111 | int_4 nSzX;
|
---|
112 | is.GetI4(nSzX);
|
---|
113 | // dobj->setSize_x(nSzX);
|
---|
114 |
|
---|
115 | int_4 nSzY;
|
---|
116 | is.GetI4(nSzY);
|
---|
117 | // dobj->setSize_y(nSzY);
|
---|
118 |
|
---|
119 | // int_4 nPix;
|
---|
120 | // is.GetI4(nPix);
|
---|
121 | // dobj->setNbPixels(nPix);
|
---|
122 | dobj->ReSize(nSzX, nSzY);
|
---|
123 | string ss("local mapping is done");
|
---|
124 | string sso;
|
---|
125 | is.GetStr(sso);
|
---|
126 | if(sso == ss)
|
---|
127 | {
|
---|
128 | // cout<<" ReadSelf:: local mapping"<<endl;
|
---|
129 |
|
---|
130 | double angleX, angleY;
|
---|
131 | is.GetR8(angleX);
|
---|
132 | is.GetR8(angleY);
|
---|
133 | dobj->SetSize(angleX, angleY);
|
---|
134 |
|
---|
135 |
|
---|
136 | int_4 x0, y0;
|
---|
137 | double theta, phi, angle;
|
---|
138 | is.GetR8(theta);
|
---|
139 | is.GetR8(phi);
|
---|
140 | is.GetI4(x0);
|
---|
141 | is.GetI4(y0);
|
---|
142 | is.GetR8(angle);
|
---|
143 | dobj->SetOrigin(theta, phi, x0, y0, angle);
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 | // On lit le DataBlock;
|
---|
148 | // FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
|
---|
149 | // On lit la matrice;
|
---|
150 | FIO_TArray<T> fio_nd(&dobj->Matrix());
|
---|
151 | fio_nd.Read(is);
|
---|
152 | }
|
---|
153 |
|
---|
154 | //++
|
---|
155 | template <class T>
|
---|
156 | void FIO_LocalMap<T>::WriteSelf(POutPersist& os) const
|
---|
157 | //
|
---|
158 | //--
|
---|
159 | {
|
---|
160 | if(dobj == NULL)
|
---|
161 | {
|
---|
162 | cout << " FIO_LocalMap::WriteSelf:: dobj= null " << endl;
|
---|
163 | return;
|
---|
164 | }
|
---|
165 |
|
---|
166 | char strg[256];
|
---|
167 | int_4 nSzX= dobj->Size_x();
|
---|
168 | int_4 nSzY= dobj->Size_y();
|
---|
169 |
|
---|
170 | if(dobj->ptrInfo())
|
---|
171 | {
|
---|
172 | sprintf(strg,"LocalMap: NPixX=%6d NPixY=%9d HasInfo",nSzX,nSzY);
|
---|
173 | os.PutLine(strg);
|
---|
174 | os << dobj->Info();
|
---|
175 | }
|
---|
176 | else
|
---|
177 | {
|
---|
178 | sprintf(strg,"LocalMap: NPixX=%6d NPixY=%9d ",nSzX,nSzY);
|
---|
179 | os.PutLine(strg);
|
---|
180 | }
|
---|
181 |
|
---|
182 | os.PutI4(nSzX);
|
---|
183 | os.PutI4(nSzY);
|
---|
184 |
|
---|
185 | if(dobj->LocalMap_isDone())
|
---|
186 | {
|
---|
187 | string ss("local mapping is done");
|
---|
188 | os.PutStr(ss);
|
---|
189 |
|
---|
190 | double angleX, angleY;
|
---|
191 | dobj->Aperture(angleX, angleY);
|
---|
192 | os.PutR8(angleX);
|
---|
193 | os.PutR8(angleY);
|
---|
194 |
|
---|
195 |
|
---|
196 | int_4 x0, y0;
|
---|
197 | double theta, phi, angle;
|
---|
198 | dobj->Origin(theta, phi, x0, y0, angle);
|
---|
199 | os.PutR8(theta);
|
---|
200 | os.PutR8(phi);
|
---|
201 | os.PutI4(x0);
|
---|
202 | os.PutI4(y0);
|
---|
203 | os.PutR8(angle);
|
---|
204 |
|
---|
205 | }
|
---|
206 | else
|
---|
207 | {
|
---|
208 | string ss("no local mapping");
|
---|
209 | os.PutStr(ss);
|
---|
210 | }
|
---|
211 |
|
---|
212 | // On ecrit le dataBlock
|
---|
213 | // FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
|
---|
214 | // On ecrit la matrice
|
---|
215 | FIO_TArray<T> fio_nd(&dobj->Matrix());
|
---|
216 | fio_nd.Write(os);
|
---|
217 | }
|
---|
218 |
|
---|
219 | #ifdef __CXX_PRAGMA_TEMPLATES__
|
---|
220 | #pragma define_template FIO_LocalMap<int_4>
|
---|
221 | #pragma define_template FIO_LocalMap<r_4>
|
---|
222 | #pragma define_template FIO_LocalMap<r_8>
|
---|
223 | #pragma define_template FIO_LocalMap< complex<r_4> >
|
---|
224 | #pragma define_template FIO_LocalMap< complex<r_8> >
|
---|
225 | #endif
|
---|
226 | #if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
|
---|
227 | namespace SOPHYA {
|
---|
228 | template class FIO_LocalMap<int_4>;
|
---|
229 | template class FIO_LocalMap<r_4>;
|
---|
230 | template class FIO_LocalMap<r_8>;
|
---|
231 | template class FIO_LocalMap< complex<r_4> >;
|
---|
232 | template class FIO_LocalMap< complex<r_8> >;
|
---|
233 | }
|
---|
234 | #endif
|
---|