File: pcm2rnm.cpp

package info (click to toggle)
freefem%2B%2B 3.61.1%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,108 kB
  • sloc: cpp: 141,214; ansic: 28,664; sh: 4,925; makefile: 3,142; fortran: 1,171; perl: 844; awk: 290; php: 199; pascal: 41; f90: 32
file content (117 lines) | stat: -rw-r--r-- 3,682 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/****************************************************************************/
/* This file is part of FreeFem++.                                          */
/*                                                                          */
/* FreeFem++ is free software: you can redistribute it and/or modify        */
/* it under the terms of the GNU Lesser General Public License as           */
/* published by the Free Software Foundation, either version 3 of           */
/* the License, or (at your option) any later version.                      */
/*                                                                          */
/* FreeFem++ is distributed in the hope that it will be useful,             */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            */
/* GNU Lesser General Public License for more details.                      */
/*                                                                          */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with FreeFem++. If not, see <http://www.gnu.org/licenses/>.        */
/****************************************************************************/
// SUMMARY : Tools to read ppm file
// LICENSE : LGPLv3
// ORG     : LJLL Universite Pierre et Marie Curie, Paris, FRANCE
// AUTHORS : Frederic Hecht
// E-MAIL  : frederic.hecht@sorbonne-universite.fr

// *INDENT-OFF* //
//ff-c++-LIBRARY-dep:
//ff-c++-cpp-dep: pcm.cpp
// *INDENT-ON* //

/*  use in freefem++ edp
 * see :
 * real[int,int] ff1("tt.pmm"); // read  image and set to an array.
 * real[int]  ff(ff1.nx*ff1.ny);
 * ff=ff1;
 */
// tools to read ppm file
/*  use in freefem++ edp file:
 * -----------------------------
 * complex[int,int] cc(1,1);
 * readpcm("tt.pcm",cc); // read  the flow image and set to un complex matrix array.
 * or
 * real[int,int] u(1,1),v(1,1);
 * readpcm("tt.pcm",u,v); // read the flow image and set to 2  real  matrix array.
 */
#include "pcm.hpp"
#include  <iostream>
#include  <cfloat>

using namespace std;
#include "error.hpp"
#include "AFunction.hpp"
using namespace std;

#include "RNM.hpp"
#include <cmath>

long read1 (const long &, const long &) {
	return 1;
}

KNM<Complex>*read_pcm (string *filename, KNM<Complex> *p) {
	PCM pcm(filename->c_str());

	p->resize(pcm.width, pcm.height);
	pcm_complex *pc = pcm.image;

	for (int j = 0; j < pcm.height; ++j) {
		for (int i = 0; i < pcm.width; ++i, pc++) {
			(*p)(i, j) = Complex(pc->r, pc->i);
		}
	}

	return p;
}

long read_pcm (string *const &filename, KNM<double> *const &u, KNM<double> *const &v) {
	PCM pcm(filename->c_str());

	cout << " pcm  " << filename->c_str() << " : " << pcm.width << " x " << pcm.height << endl;
	u->resize(pcm.width, pcm.height);
	v->resize(pcm.width, pcm.height);
	pcm_complex *pc;
	float x1 = -1e+30, x2 = -1e+30;

	for (int j = 0; j < pcm.height; ++j) {
		for (int i = 0; i < pcm.width; ++i) {
			pc = pcm.Get(i, j);
			if (pc) {
				(*u)(i, j) = pc->r;
				(*v)(i, j) = pc->i;

				x1 = max(x1, pc->r);
				x2 = max(x2, pc->i);
				if (i < 0 && j < 0) {
					cout << i << " " << j << " " << pc->r << " " << pc->i << endl;
				}
			}
		}
	}

	cout << " max uv : " << x1 << " " << x2 << endl;
	return pcm.width * pcm.height;
}

/*  class Init { public:
 * Init();
 * };
 *
 * $1 */
static void Load_Init () {
	cout << " load: init pcm2rmn  " << endl;

	Global.Add("readpcm", "(",
	           new OneOperator2<KNM<Complex> *, string *, KNM<Complex> *>(&read_pcm),
	           new OneOperator3_<long, string *, KNM<double> *, KNM<double> *>(&read_pcm)
	           );
}

LOADFUNC(Load_Init)