map.h 3.23 KB
Newer Older
1
2
3
4
#ifndef BIOEM_MAP_H
#define BIOEM_MAP_H

#include "defs.h"
5
#include "param.h"
6
7
#include <complex>
#include <math.h>
David Rohr's avatar
David Rohr committed
8
#include <boost/concept_check.hpp>
9
10

class bioem_param;
11
class bioem;
12
13
14
15

class bioem_RefMap
{
public:
16
17
	bioem_RefMap()
	{
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
		maps = NULL;
		RefMapsFFT = NULL;
		sum_RefMap = NULL;
		sumsquare_RefMap = NULL;
	}

	void freePointers()
	{
		if (maps) free(maps);
		if (sum_RefMap) free(sum_RefMap);
		if (sumsquare_RefMap) free(sumsquare_RefMap);
		if (RefMapsFFT) delete[] RefMapsFFT;
		maps = NULL;
		sum_RefMap = NULL;
		sumsquare_RefMap = NULL;
33
34
		RefMapsFFT = NULL;
	}
35
	int readRefMaps(bioem_param& param, const char* filemap);
36
	int precalculate(bioem_param& param, bioem& bio);
37
	int PreCalculateMapsFFT(bioem_param& param);
38

David Rohr's avatar
David Rohr committed
39
40
41
42
43
44
	int  read_int(int *currlong, FILE *fin, int swap);
	int  read_float(float *currfloat, FILE *fin, int swap);
	int  read_float_empty (FILE *fin);
	int  read_char_float (float *currfloat, FILE *fin) ;
	int  test_mrc (const char *vol_file, int swap);
	int  read_MRC(const char* filename,bioem_param& param);
45

46
	mycomplex_t* RefMapsFFT;
47

David Rohr's avatar
David Rohr committed
48
	bool readMRC,readMultMRC;
49
50

	int ntotRefMap;
51
52
53
54
55
	int numPixels;
	int refMapSize;
	myfloat_t* maps;
	myfloat_t* sum_RefMap;
	myfloat_t* sumsquare_RefMap;
56

57
58
59
	__host__ __device__ inline myfloat_t get(int map, int x, int y) const {return(maps[map * refMapSize + x * numPixels + y]);}
	__host__ __device__ inline const myfloat_t* getp(int map, int x, int y) const {return(&maps[map * refMapSize + x * numPixels]);}
	__host__ __device__ inline myfloat_t* getmap(int map) {return(&maps[map * refMapSize]);}
60
61
};

62
class bioem_RefMap_Mod : public bioem_RefMap
63
64
{
public:
65
	__host__ __device__ inline myfloat_t get(int map, int x, int y) const {return(maps[(x * numPixels + y) * ntotRefMap + map]);}
66

67
	void init(const bioem_RefMap& map)
68
	{
69
		maps = (myfloat_t*) malloc(map.refMapSize * map.ntotRefMap * sizeof(myfloat_t));
70
		#pragma omp parallel for
71
		for (int i = 0; i < map.ntotRefMap; i++)
72
		{
73
			for (int j = 0; j < map.numPixels; j++)
74
			{
75
				for (int k = 0; k < map.numPixels; k++)
76
				{
77
					maps[(j * map.numPixels + k) * map.ntotRefMap + i] = map.get(i, j, k);
78
79
80
81
82
83
				}
			}
		}
	}
};

84
class bioem_Probability_map
85
86
{
public:
87
88
	myfloat_t Total;
	myfloat_t Constoadd;
David Rohr's avatar
David Rohr committed
89
90
91
92
93
	
	class bioem_Probability_map_max
	{
	public:
		int max_prob_cent_x, max_prob_cent_y, max_prob_orient, max_prob_conv;
94
                myfloat_t max_prob_norm,max_prob_mu;
David Rohr's avatar
David Rohr committed
95
	} max;
96
};
97

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
class bioem_Probability_angle
{
public:
	myfloat_t forAngles;
	myfloat_t ConstAngle;
};

class bioem_Probability
{
public:
	int nMaps;
	int nAngles;
	__device__ __host__ bioem_Probability_map& getProbMap(int map) {return(ptr_map[map]);}
	__device__ __host__ bioem_Probability_angle& getProbAngle(int map, int angle) {return(ptr_angle[angle * nMaps + map]);}

	void* ptr;
	bioem_Probability_map* ptr_map;
	bioem_Probability_angle* ptr_angle;

117
	static size_t get_size(size_t maps, size_t angles, bool writeAngles)
118
	{
119
120
121
		size_t size = sizeof(bioem_Probability_map);
		if (writeAngles) size += angles * sizeof(bioem_Probability_angle);
		return(maps * size);
122
123
	}

124
	void init(size_t maps, size_t angles, bioem& bio);
David Rohr's avatar
David Rohr committed
125
	void copyFrom(bioem_Probability* from, bioem& bio);
126
127
128
129
130
131
132
133

	void set_pointers()
	{
		ptr_map = (bioem_Probability_map*) ptr;
		ptr_angle = (bioem_Probability_angle*) (&ptr_map[nMaps]);
	}
};

134
#endif