void autotrim(boost::shared_ptr<pcl::PointCloud<PointT>> &cloud, double &clip_N, double &clip_S, double &clip_E, double &clip_W, double tolerance) { struct bound_box bbox; getMinMax(*cloud, bbox); double resolution = 0.003; int length_x = (int)((bbox.E - bbox.W) / resolution + 0.5); int length_y = (int)((bbox.N - bbox.S) / resolution + 0.5); std::vector<int> x_array(length_x, 0); std::vector<int> y_array(length_y, 0); unsigned int idx; for(typename pcl::PointCloud<PointT>::iterator it = cloud->begin(); it!= cloud->end(); it++){ idx = int((it->x - bbox.W) / resolution); if (idx < x_array.size()) x_array[idx] += 1; idx = int((it->y - bbox.S) / resolution); if (idx < y_array.size()) y_array[idx] += 1; } int median_x = median(x_array); int median_y = median(y_array); clip_N = 0; clip_S = 0; clip_E = 0; clip_W = 0; for (int i = 0; i < x_array.size(); i++) { if (x_array[i] < tolerance * median_x) { clip_W = (i + 1) * resolution; } else break; } for (int i = x_array.size() - 1; i >= 0; i--) { if (x_array[i] < tolerance * median_x) { clip_E = (x_array.size() - i) * resolution; } else break; } for (int i = 0; i < y_array.size(); i++) { if (y_array[i] < tolerance * median_y) { clip_S = (i + 1) * resolution; } else break; } for (int i = y_array.size() - 1; i >= 0; i--) { if (y_array[i] < tolerance * median_y) { clip_N = (y_array.size() - i) * resolution; } else break; } //std::cout << clip_N << " " << clip_S << " " << clip_E << " " << clip_W << std::endl; }
OpenMS::Interfaces::SpectrumPtr MzMLSpectrumDecoder::decodeBinaryData(std::vector<BinaryData>& data_) { Internal::MzMLHandlerHelper::decodeBase64Arrays(data_); OpenMS::Interfaces::SpectrumPtr sptr(new OpenMS::Interfaces::Spectrum); //look up the precision and the index of the intensity and m/z array bool x_precision_64 = true; bool int_precision_64 = true; SignedSize x_index = -1; SignedSize int_index = -1; Internal::MzMLHandlerHelper::computeDataProperties_(data_, x_precision_64, x_index, "m/z array"); Internal::MzMLHandlerHelper::computeDataProperties_(data_, int_precision_64, int_index, "intensity array"); //Abort if no m/z or intensity array is present if (int_index == -1 || x_index == -1) { // Warning ... return sptr; } // Error if intensity or m/z is encoded as int32|64 - they should be float32|64! if ((data_[x_index].ints_32.size() > 0) || (data_[x_index].ints_64.size() > 0)) { //fatalError(LOAD, "Encoding m/z array as integer is not allowed!"); } if ((data_[int_index].ints_32.size() > 0) || (data_[int_index].ints_64.size() > 0)) { //fatalError(LOAD, "Encoding intensity array as integer is not allowed!"); } // Warn if the decoded data has a different size than the defaultArrayLength Size mz_size = x_precision_64 ? data_[x_index].floats_64.size() : data_[x_index].floats_32.size(); Size int_size = int_precision_64 ? data_[int_index].floats_64.size() : data_[int_index].floats_32.size(); // Check if int-size and mz-size are equal if (mz_size != int_size) { std::cout << "Warning, intensity and m/z array length are unequal" << std::endl; return sptr; } Size default_array_length_ = mz_size; // maybe some checks here about internal consistency e.g. with defaultArrayLength ... //create meta data arrays and reserve enough space for the content if (data_.size() > 2) { // --> TODO the other arrays ... create and resize those ... } // Copy meta data from m/z and intensity binary // We don't have this as a separate location => store it in spectrum // --> maybe TODO OpenMS::Interfaces::BinaryDataArrayPtr intensity_array(new OpenMS::Interfaces::BinaryDataArray); OpenMS::Interfaces::BinaryDataArrayPtr x_array(new OpenMS::Interfaces::BinaryDataArray); for (Size n = 0; n < default_array_length_; n++) { DoubleReal xcoord = x_precision_64 ? data_[x_index].floats_64[n] : data_[x_index].floats_32[n]; DoubleReal intensity = int_precision_64 ? data_[int_index].floats_64[n] : data_[int_index].floats_32[n]; x_array->data.push_back(xcoord); intensity_array->data.push_back(intensity); // TODO the other arrays } sptr->setMZArray(x_array); sptr->setIntensityArray(intensity_array); return sptr; }