6b6b4d530fac706ddf664dedb534ee74dc13df68
[ctsim.git] / include / imagefile.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **      Name:         imagefile.h
5 **      Purpose:      imagefile class header
6 **      Programmer:   Kevin Rosenberg
7 **      Date Started: June 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: imagefile.h,v 1.19 2000/12/04 04:15:48 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifndef IMAGEFILE_H
29 #define IMAGEFILE_H
30
31 #ifndef MSVC\r
32 #include <unistd.h>\r
33 #endif\r
34 #include <string>
35 #include <sys/types.h>
36 #include <fstream>
37 #include <iostream>
38 #include "ctsupport.h"
39 #include "fnetorderstream.h"
40 #include "array2dfile.h"
41
42 using namespace std;
43
44 #ifdef HAVE_MPI
45 #include <mpi++.h>
46 #endif
47
48 class F32Image : public Array2dFile
49 {
50 public:
51   F32Image (int nx, int ny)
52       : Array2dFile::Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32)
53   {
54   }
55
56   F32Image (void)
57       : Array2dFile::Array2dFile()
58   {
59       setPixelFormat (Array2dFile::PIXEL_FLOAT32);
60       setPixelSize (sizeof(kfloat32));
61   }
62
63   kfloat32** getArray (void)
64       { return (kfloat32**) (m_arrayData); }
65
66   const kfloat32* const * getArray (void) const
67        { return (const kfloat32**) (m_arrayData); }
68
69 #ifdef HAVE_MPI
70   MPI::Datatype getMPIDataType (void) const
71       { return MPI::FLOAT; }
72 #endif
73
74  private:
75   F32Image (const F32Image& rhs);             //copy constructor
76   F32Image& operator= (const F32Image& rhs);  // assignment operator
77 };
78
79
80 class F64Image : public Array2dFile
81 {
82  public:
83
84   F64Image (int nx, int ny)
85       : Array2dFile::Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64)
86   {
87   }
88
89   F64Image (void)
90       : Array2dFile::Array2dFile ()
91   {
92       setPixelFormat (PIXEL_FLOAT64);
93       setPixelSize (sizeof(kfloat64));
94   }
95
96   kfloat64** getArray (void)
97       { return (kfloat64**) (m_arrayData); }
98
99   const kfloat64* const * getArray (void) const
100       { return (const kfloat64**) (m_arrayData); }
101
102 #ifdef HAVE_MPI
103   MPI::Datatype getMPIDataType (void) const
104       { return MPI::DOUBLE; }
105 #endif
106  private:
107   F64Image (const F64Image& rhs);             //copy constructor
108   F64Image& operator= (const F64Image& rhs);  // assignment operator
109 };
110
111 #undef IMAGEFILE_64_BITS
112 #ifdef IMAGEFILE_64_BITS
113 typedef F64Image   ImageFileBase;
114 typedef kfloat64   ImageFileValue;
115 typedef kfloat64*  ImageFileColumn;
116 typedef kfloat64** ImageFileArray;
117 typedef const kfloat64* const * ImageFileArrayConst;
118 #else
119 typedef F32Image   ImageFileBase;
120 typedef kfloat32   ImageFileValue;
121 typedef kfloat32*  ImageFileColumn;
122 typedef kfloat32** ImageFileArray;
123 typedef const kfloat32* const * ImageFileArrayConst;
124 #endif
125
126
127 class ImageFile : public ImageFileBase
128 {
129  public:
130   ImageFile (int nx, int ny)
131       : ImageFileBase (nx, ny)
132   {}
133
134   ImageFile (void)
135       : ImageFileBase ()
136   {}
137
138   void filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param);
139
140   void statistics (double& min, double& max, double& mean, double& mode, double& median, double& stddev) const;
141
142   void getMinMax (double& min, double& max) const;
143
144   void printStatistics (ostream& os) const;
145
146   bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const;
147
148   bool printComparativeStatistics (const ImageFile& imComp, ostream& os) const;
149
150   int display (void) const;
151
152   int displayScaling (const int scaleFactor, ImageFileValue pmin, ImageFileValue pmax) const;
153
154 #if HAVE_PNG
155   void writeImagePNG (const char *outfile, int bitdepth, int nxcell, int nycell, double densmin, double densmax);
156 #endif
157 #if HAVE_GD
158   void writeImageGIF (const char *outfile, int nxcell, int nycell, double densmin, double densmax);
159 #endif
160   void writeImagePGM (const char *outfile, int nxcell, int nycell, double densmin, double densmax);
161   void writeImagePGMASCII (const char *outfile, int nxcell, int nycell, double densmin, double densmax);
162 };
163
164
165 #endif