/** * \file DataPoints.cpp * \brief Handling of data for anchor points segmentation * * Copyright 2007-2013 IMP Inventors. All rights reserved. * */ #include #include #include IMPMULTIFIT_BEGIN_NAMESPACE void DensityDataPoints::set_density(em::DensityMap *dmap) { algebra::BoundingBox3D bb = em::get_bounding_box(dmap); dens_.reset(new DensGrid(dmap->get_spacing(),bb)); em::emreal* d_data = dmap->get_data(); algebra::Vector3D loc; for(long l=0;lget_number_of_voxels();l++) { loc = dmap->get_location_by_voxel(l); (*dens_)[dens_->get_nearest_index(loc)]=d_data[l]; } } void DensityDataPoints::set_density(const DensGrid &dens) { algebra::BoundingBox3D bb = dens.get_bounding_box(); float spacing = dens.get_unit_cell()[0]; dens_.reset(new DensGrid(spacing,bb)); //copy data DensGrid::ExtendedIndex lb = dens.get_extended_index(bb.get_corner(0)), ub = dens.get_extended_index(bb.get_corner(1)); for (DensGrid::IndexIterator it= dens.indexes_begin(lb,ub); it != dens.indexes_end(lb, ub); ++it) { (*dens_)[*it]=dens[*it]; } } void DensityDataPoints::set_max_min_density_values() { max_value_=-INT_MAX; min_value_=INT_MAX; algebra::BoundingBox3D bb = dens_->get_bounding_box(); DensGrid::ExtendedIndex lb = dens_->get_extended_index(bb.get_corner(0)), ub = dens_->get_extended_index(bb.get_corner(1)); for (DensGrid::IndexIterator it= dens_->indexes_begin(lb,ub); it != dens_->indexes_end(lb, ub); ++it) { if ((*dens_)[*it]max_value_) max_value_=(*dens_)[*it]; } } DensityDataPoints::DensityDataPoints(em::DensityMap *dens, float density_threshold) : XYZDataPoints() { set_density(dens); // dens_=dens; threshold_ = density_threshold; set_max_min_density_values(); // max_value_ = dens->get_max_value(); // min_value_ = dens->get_min_value(); // algebra::Vector3Ds vecs = em::density2vectors(dens,threshold_); populate_data(); } void DensityDataPoints::populate_data() { algebra::Vector3Ds vecs; algebra::BoundingBox3D bb = dens_->get_bounding_box(); DensGrid::ExtendedIndex lb = dens_->get_extended_index(bb.get_corner(0)), ub = dens_->get_extended_index(bb.get_corner(1)); for (DensGrid::IndexIterator it= dens_->indexes_begin(lb,ub); it != dens_->indexes_end(lb, ub); ++it) { if ((*dens_)[*it]>threshold_) {vecs.push_back(dens_->get_center(*it));} } /*std::cout<< "Number of data points were found above the input threshold ("<< threshold_<<") is "<0, "No data points were found above the input threshold ("<< threshold_<<"). The maximum value is "<get_nearest_index( algebra::Vector3D(data_[p_ind][0], data_[p_ind][1],data_[p_ind][2]))] > (max_value_-min_value_)* statistics::internal::random_uniform()+min_value_) { found = true; } }while (!found && num_trails<150); //TODO - add to multifit param if (!found) { std::cerr<< "Could not sample DensityDataPoints." <<"Probably a problem with reading the map" <set_origin(dg.get_origin()); DensGrid::ExtendedIndex lb = dg.get_extended_index(bb.get_corner(0)), ub = dg.get_extended_index(bb.get_corner(1)); for (DensGrid::IndexIterator it= dg.indexes_begin(lb,ub); it != dg.indexes_end(lb, ub); ++it) { algebra::Vector3D cen=dg.get_center(*it); r_map->set_value(cen[0],cen[1],cen[2],dg[*it]); } return r_map; } IMPMULTIFIT_END_NAMESPACE