source: Sophya/trunk/SophyaLib/NTools/cimage.cc@ 3739

Last change on this file since 3739 was 3667, checked in by ansari, 16 years ago

Ajout instanciation explicite Image<int_1> Image<uint_1> et enregistrement PPFHandler de ces images dans ntoolsinit.cc , Reza 24/10/2009

File size: 5.8 KB
RevLine 
[1104]1// Classes image heritant de TMatrix<T>
2// R.Ansari, C.Magneville 07/2000
[220]3// LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
4
[2615]5#include "sopnamsp.h"
[244]6#include "machdefs.h"
[220]7#include <stdio.h>
[1104]8#include <stdlib.h>
9#include "pexceptions.h"
[220]10#include "cimage.h"
[1967]11#include "datatype.h"
12#include <typeinfo>
[220]13
[1390]14/*!
15 \class SOPHYA::Image
16 \ingroup NTools
17 This class specializes the Matrix class, for representing intensity
18 (or grey-level) images. It adds the possibility of defining pixel
19 size and offset. The convention for the acces operator is also
20 changed, compared to the matrix class.
21*/
22
23//! Default constructor - Pixel array not allocated
[220]24template <class T>
[1104]25Image<T>::Image()
26// Constructeur par defaut.
27 : TMatrix<T>()
[220]28{
[1104]29 SetOrg();
30 SetPixelSize();
[220]31}
32
[1390]33//! Constructor, with specification of the image size, pixel size and offsets
[220]34template <class T>
[1390]35Image<T>::Image(sa_size_t sizx, sa_size_t sizy, r_8 szpx, r_8 szpy, r_8 orgx, r_8 orgy)
[1104]36// Constructeur par defaut.
37 : TMatrix<T>(sizy, sizx)
[220]38{
[1104]39 SetOrg(orgx, orgy);
40 SetPixelSize(szpx, szpy);
[220]41}
42
[1390]43//! Copy constructor
[220]44template <class T>
[1104]45Image<T>::Image(const Image<T>& a)
46 : TMatrix<T>(a)
[220]47{
[1104]48 SetOrg(a.XOrg(), a.YOrg() );
49 SetPixelSize(a.XPixSize(), a.YPixSize());
[220]50}
51
[1390]52
53//! Copy constructor with possibility of duplicating the pixel array
54/*!
55 \param share : if true, the data is shared, duplicated if false.
56*/
[220]57template <class T>
[1104]58Image<T>::Image(const Image<T>& a, bool share)
59 : TMatrix<T>(a, share)
[220]60{
[1104]61 SetOrg(a.XOrg(), a.YOrg() );
62 SetPixelSize(a.XPixSize(), a.YPixSize());
[220]63}
[1390]64
65//! Destructor
[220]66template <class T>
67Image<T>::~Image()
68{
69}
70
[1159]71
72// --------------------------------------------------------
73// Les objets delegues pour la gestion de persistance
74// --------------------------------------------------------
75/*!
76 \class SOPHYA::FIO_Image
77 \ingroup Image
78 Class for persistent management of Image
79
80 */
81///////////////////////////////////////////////////////////
82
83//! Default constructor
84template <class T>
85FIO_Image<T>::FIO_Image()
86 : FIO_TArray<T>()
87{
88}
89
90
91//! Constructor from the file \b filename
92template <class T>
93FIO_Image<T>::FIO_Image(string const & filename)
94 : FIO_TArray<T>(filename)
95{
96}
97
98//! Constructor from the Image \b obj
99template <class T>
100FIO_Image<T>::FIO_Image(const Image<T> & obj)
101 : FIO_TArray<T>()
102{
[2885]103 this->dobj = new Image<T>(obj, true);
104 this->ownobj=true;
[1159]105}
106
107//! Connect with a Image \b obj
108template <class T>
109FIO_Image<T>::FIO_Image(Image<T> * obj)
110 : FIO_TArray<T>(obj)
111{
112}
113
114
115//! Connect Image \b o
116template <class T>
117void FIO_Image<T>::SetDataObj(AnyDataObj & o)
118{
119 Image<T> * po = dynamic_cast< Image<T> * >(&o);
[1967]120 if (po == NULL) {
121 char buff[160];
122 sprintf(buff,"FIO_Image<%s>::SetDataObj(%s) - Object type error ! ",
123 DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
124 throw TypeMismatchExc(PExcLongMessage(buff));
125 }
[2885]126 if (this->ownobj && this->dobj) delete this->dobj;
127 this->dobj = po; this->ownobj = false;
[1159]128}
129
130template <class T>
131void FIO_Image<T>::ReadSelf(PInPersist& is)
132{
[2885]133 if (this->dobj == NULL) this->dobj = new Image<T>;
134 Image<T> * img = dynamic_cast<Image<T> * > (this->dobj);
[1159]135// On lit les 3 premiers uint_4
136// 0: Numero de version, 1 : reserve
137 uint_4 itab[3];
138 is.Get(itab,3);
139
140// Image<T> part data
141 r_8 orgx, orgy;
142 is.Get(orgx);
143 is.Get(orgy);
144 img->SetOrg(orgx, orgy);
145 r_8 szx, szy;
146 is.Get(szx);
147 is.Get(szy);
148 img->SetPixelSize(szx, szy);
149
150// Reading the TArray part
151 FIO_TArray<T>::ReadSelf(is);
152}
153
154template <class T>
155void FIO_Image<T>::WriteSelf(POutPersist& os) const
156{
[2885]157 if (this->dobj == NULL) return;
158 Image<T> * img = dynamic_cast<Image<T> * > (this->dobj);
[1159]159// On ecrit 3 uint_4 ....
160 uint_4 itab[3];
161 itab[0] = 1; // Numero de version a 1
162 itab[1] = 0;
163 itab[2] = 0;
164 os.Put(itab,3);
165
166// Image<T> part data
167 os.Put(img->XOrg());
168 os.Put(img->XOrg());
169 os.Put(img->XPixSize());
170 os.Put(img->YPixSize());
171
172// Writing the TArray part
173 FIO_TArray<T>::WriteSelf(os);
174}
175
[1104]176///////////////////////////////////////////////////////////////
[220]177#ifdef __CXX_PRAGMA_TEMPLATES__
[3667]178#pragma define_template Image<uint_1>
[220]179#pragma define_template Image<uint_2>
[3526]180#pragma define_template Image<uint_4>
181#pragma define_template Image<uint_8>
[3667]182#pragma define_template Image<int_1>
[3220]183#pragma define_template Image<int_2>
[220]184#pragma define_template Image<int_4>
[1104]185#pragma define_template Image<int_8>
[220]186#pragma define_template Image<r_4>
[1104]187#pragma define_template Image<r_8>
[3220]188#pragma define_template Image< complex<r_4> >
189#pragma define_template Image< complex<r_8> >
[1159]190
[3661]191#pragma define_template FIO_Image<uint_1>
[1159]192#pragma define_template FIO_Image<uint_2>
[3526]193#pragma define_template FIO_Image<uint_4>
194#pragma define_template FIO_Image<uint_8>
[3661]195#pragma define_template FIO_Image<int_1>
[3220]196#pragma define_template FIO_Image<int_2>
[1159]197#pragma define_template FIO_Image<int_4>
198#pragma define_template FIO_Image<int_8>
199#pragma define_template FIO_Image<r_4>
200#pragma define_template FIO_Image<r_8>
[3220]201#pragma define_template FIO_Image< complex<r_4> >
202#pragma define_template FIO_Image< complex<r_8> >
[220]203#endif
204
[1104]205#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
[2870]206namespace SOPHYA {
[3667]207template class Image<uint_1>;
[220]208template class Image<uint_2>;
[3526]209template class Image<uint_4>;
210template class Image<uint_8>;
[3667]211template class Image<int_1>;
[3220]212template class Image<int_2>;
[220]213template class Image<int_4>;
[1104]214template class Image<int_8>;
[220]215template class Image<r_4>;
[1104]216template class Image<r_8>;
[3220]217template class Image< complex<r_4> >;
218template class Image< complex<r_8> >;
[1159]219
[3661]220template class FIO_Image<uint_1>;
[1159]221template class FIO_Image<uint_2>;
[3526]222template class FIO_Image<uint_4>;
223template class FIO_Image<uint_8>;
[3661]224template class FIO_Image<int_1>;
[3220]225template class FIO_Image<int_2>;
[1159]226template class FIO_Image<int_4>;
227template class FIO_Image<int_8>;
228template class FIO_Image<r_4>;
229template class FIO_Image<r_8>;
[3220]230template class FIO_Image< complex<r_4> >;
231template class FIO_Image< complex<r_8> >;
[2870]232}
[220]233#endif
Note: See TracBrowser for help on using the repository browser.