Commit 5ccd357d authored by karius's avatar karius

cleaned up working version of ccl

parent f0762f81
......@@ -634,7 +634,7 @@ Density Density::difference_map_density_threshold(float threshold0,float thresho
return difference_map;
}
void Density::to_mrc_write_only(thrust::device_vector<uint> & td_labels,const uint & label, const char * mrc_path){
void Density::to_mrc_write_only(thrust::device_vector<uint> & td_labels,const uint & label, const char * mrc_path, uint log_2_dim){
CMrcReader reader(mrc_path);
from_device();
reader.header.cella.x = h_coord_dim[0];
......@@ -647,10 +647,14 @@ void Density::to_mrc_write_only(thrust::device_vector<uint> & td_labels,const ui
float * masked_data = (float *) malloc(h_pixel_vol()*sizeof(float));
thrust::host_vector<uint> th_labels(td_labels.size());
th_labels = td_labels;
uint * h_labels = thrust::raw_pointer_cast(&th_labels[0]);
for (int i=0;i<th_labels.size();i++){
//printf("%u %u %i %f\n",th_labels[i],label,i,masked_data[i]);
if (th_labels[i] == label){
uint3 label_index;
uint padding_dim[3] = {log_2_dim,log_2_dim,log_2_dim};
uint label_linear_address;
for (uint i=0;i<h_pixel_vol();i++){
// printf("%u %u %u\n",i,label_linear_address,label);
label_index = linear_to_index_space(i,h_pixel_dim);
label_linear_address = index_to_linear_space(label_index,&padding_dim[0]);
if (th_labels[label_linear_address] == label){
masked_data[i] = h_data[i];
} else {
masked_data[i] = 0;
......
......@@ -83,7 +83,7 @@ public:
__host__ Density density_limits_above(float thresold,uint3 tolerance = {2,2,2});
__host__ Density difference_map_density_threshold(float threshold0,float threshold1, thrust::device_vector<uint>& td_on_surface);
__host__ Density only_linear_indeces(thrust::device_vector<uint>& td_on_surface);
__host__ void to_mrc_write_only(thrust::device_vector<uint> & td_linear_indices,const uint & label, const char * mrc_path);
__host__ void to_mrc_write_only(thrust::device_vector<uint> & td_linear_indices,const uint & label, const char * mrc_path, uint log_2_dim);
__host__ Density cut_and_binarize(float threshold,float above_value,float below_value,uint3 tolerance);
__host__ Particles particles_from_density(const thrust::device_vector<uint>& td_linear_indices);
__host__ uint3 linear_to_index_space(const uint &linear_index, uint * const &pixel_dim);
......
......@@ -672,39 +672,6 @@ void calc_label_volume_offset(size_t label,size_t num_partitions,float * h_dim,f
}
}
__global__
void label(float4 * d_data, size_t * labels, float * d_coord_dim,
size_t coord_offset,size_t label_volume,size_t label0,
size_t partition_count){
int tid = blockIdx.x*blockDim.x+threadIdx.x;
if (tid >= label_volume)
return;
float cube_dim[3] = {d_coord_dim[0]/powf(2.0,partition_count),
d_coord_dim[1]/powf(2.0,partition_count),
d_coord_dim[2]/powf(2.0,partition_count)};
float cube_offset[3];
size_t base_label;
size_t coord_index = tid + coord_offset;
calc_label_volume_offset(label0,partition_count,d_coord_dim,cube_offset);
//base_label = __float2int_rd(
// (particles.d_data[coord_index].x-particles.d_bounding_box[0]-cube_offset[0])/cube_dim[0])*1+
// __float2int_rd(
// (particles.d_data[coord_index].y-particles.d_bounding_box[1]-cube_offset[1])/cube_dim[1])*2+
// __float2int_rd(
// (particles.d_data[coord_index].z-particles.d_bounding_box[2]-cube_offset[2])/cube_dim[2])*4;
base_label = __float2int_rd((d_data[coord_index].x-cube_offset[0])/cube_dim[0])*1+
__float2int_rd((d_data[coord_index].y-cube_offset[1])/cube_dim[1])*2+
__float2int_rd((d_data[coord_index].z-cube_offset[2])/cube_dim[2])*4;
if (d_data[coord_index].x > 95.9569 && d_data[coord_index].x < 95.957){
printf("%f %f %f %f %f %f\n",d_data[coord_index].x,d_data[coord_index].y,d_data[coord_index].z, cube_dim[0],cube_dim[1],cube_dim[2]);
printf("");
}
labels[coord_index] = label0*8+base_label;
}
Labeler::Labeler(){}
Labeler::~Labeler(){}
......@@ -769,12 +736,13 @@ std::map<uint,uint> Labeler::label_occurrence(thrust::device_vector<uint> & td_l
}
void Labeler::unique_labels_to_mrc(Density density,thrust::device_vector<uint> & td_labels){
void Labeler::unique_labels_to_mrc(Density density,thrust::device_vector<uint> & td_labels,uint log_2_dim){
//TODO: uses pointlessly much memory, especially the occurrences, maybe make this less dumb
std::map<uint,uint> ret;
thrust::sort(td_labels.begin(), td_labels.end());
thrust::device_vector<uint> td_labels_copy(td_labels.size());
thrust::copy(td_labels.begin(),td_labels.end(),td_labels_copy.begin());
thrust::sort(td_labels.begin(), td_labels.end());
// cudaDeviceSynchronize();
int num_bins = td_labels.back() + 1;
thrust::device_vector<uint> td_labels_unique(num_bins);
thrust::device_vector<uint>::iterator unique_end = thrust::unique_copy(td_labels.begin(), td_labels.end(), td_labels_unique.begin());
......@@ -811,7 +779,7 @@ void Labeler::unique_labels_to_mrc(Density density,thrust::device_vector<uint> &
label = unique_labels[i];
if (label != max_label){
fname = fname_s + std::to_string(label) + std::string(".mrc");
density.to_mrc_write_only(td_labels,label,fname.c_str());
density.to_mrc_write_only(td_labels_copy,label,fname.c_str(),log_2_dim);
}
}
}
......
......@@ -40,7 +40,7 @@ class Labeler {
public:
Labeler();
virtual ~Labeler();
void unique_labels_to_mrc(Density density,thrust::device_vector<uint> & td_labels);
void unique_labels_to_mrc(Density density,thrust::device_vector<uint> & td_labels,uint log_2_dim);
void ccl(Density density, int * d_seg_data,uint * d_labels, uint log_2_dim);
static std::map<uint,uint> label_occurrence(thrust::device_vector<uint> & td_labels, uint * d_pixel_dim, uint * d_pixel_dim_padding);
};
......
No preview for this file type
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment