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

#include "defs.h"
5
#include "param.h"
6 7 8 9
#include <complex>
#include <math.h>

class bioem_param;
10
class bioem;
11 12 13 14

class bioem_RefMap
{
public:
15 16
	bioem_RefMap()
	{
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
		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;
32 33
		RefMapsFFT = NULL;
	}
34
	int readRefMaps(bioem_param& param, const char* filemap);
35
	int precalculate(bioem_param& param, bioem& bio);
36
	int PreCalculateMapsFFT(bioem_param& param);
37

David Rohr's avatar
David Rohr committed
38 39 40 41 42 43
	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);
44

45
	mycomplex_t* RefMapsFFT;
46

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

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

56 57 58
	__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]);}
59 60
};

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

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

83
class bioem_Probability_map
84 85
{
public:
86 87 88
	myfloat_t Total;
	myfloat_t Constoadd;
	myfloat_t max_prob;
89 90
	int max_prob_cent_x, max_prob_cent_y, max_prob_orient, max_prob_conv;
};
91

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
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;

111
	static size_t get_size(size_t maps, size_t angles, bool writeAngles)
112
	{
113 114 115
		size_t size = sizeof(bioem_Probability_map);
		if (writeAngles) size += angles * sizeof(bioem_Probability_angle);
		return(maps * size);
116 117
	}

118
	void init(size_t maps, size_t angles, bioem& bio);
David Rohr's avatar
David Rohr committed
119
	void copyFrom(bioem_Probability* from, bioem& bio);
120 121 122 123 124 125 126 127

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

128
#endif