map.h 2.95 KB
Newer Older
1 2 3 4 5 6 7 8
#ifndef BIOEM_MAP_H
#define BIOEM_MAP_H

#include "defs.h"
#include <complex>
#include <math.h>

class bioem_param;
9
class bioem;
10 11 12 13

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

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

44
	mycomplex_t* RefMapsFFT;
45

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

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

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

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

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

82
class bioem_Probability_map
83 84
{
public:
85 86 87
	myfloat_t Total;
	myfloat_t Constoadd;
	myfloat_t max_prob;
88 89
	int max_prob_cent_x, max_prob_cent_y, max_prob_orient, max_prob_conv;
};
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
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;

	size_t get_size(size_t maps, size_t angles)
	{
		return(maps * (angles * sizeof(bioem_Probability_angle) + sizeof(bioem_Probability_map)));
	}

115
	void init(size_t maps, size_t angles, bioem& bio);
116 117 118 119 120 121 122 123

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

124
#endif