// Returns pair distance between two particles (including periodic images). void LAMMPS_Data::pair_distances(int step, int i, int j, Histogram &h) const { auto dump = _dump[step]; const Coord &ri = dump.scaled_coordinates[i]; const Coord &rj = dump.scaled_coordinates[j]; double dx = dump.dx*fabs(ri.x-rj.x); double dy = dump.dy*fabs(ri.y-rj.y); double dz = dump.dz*fabs(ri.z-rj.z); double dx2[] = {dx, dx-dump.dx}; double dy2[] = {dy, dy-dump.dy}; double dz2[] = {dz, dz-dump.dz}; for (int a=0; a<2; ++a) { dx2[a] *= dx2[a]; dy2[a] *= dy2[a]; dz2[a] *= dz2[a]; } for (int a=0; a<2; ++a) { for (int b=0; b<2; ++b) for (int c=0; c<2; ++c) h.add(sqrt(dx2[a] + dy2[b] + dz2[c])); } }
Template::Template(QString path){ width = -2; height = -2; for (int i = 0; i < TEMPLATES_COUNT; i++){ QString file = path + QString::number(i) + ".png"; cv::Mat im = cv::imread(file.toStdString()); cvtColor(im, images[i], CV_RGB2GRAY); if (width == -2){ width = images[i].cols; } else if (images[i].cols != width){ qDebug() << "Error : all templates must be the same size"; } if (height == -2){ height = images[i].rows; } else if (images[i].rows != height){ qDebug() << "Error : all templates must be the same size"; } std::vector<std::vector<cv::Point> > templateContours; std::vector<cv::Vec4i> hierarchy; findContours(images[i].clone(), templateContours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0)); if (templateContours.size() == 0){ qDebug() << "Error, template doesn't have a contour"; } else { cv::Moments imageMoments = moments(templateContours[0], false); massCenters[i] = cv::Point2f(imageMoments.m10/imageMoments.m00 , imageMoments.m01/imageMoments.m00); } cv::Mat firstHalf = cv::Mat(images[i].clone(), cv::Rect(0, 0, images[i].cols/2, images[i].rows)); cv::Mat secondHalf = cv::Mat(images[i].clone(), cv::Rect(images[i].cols/2, 0, images[i].cols/2, images[i].rows)); halfMassCenters[i][0] = getMassCenterFromImage(firstHalf); halfMassCenters[i][1] = getMassCenterFromImage(secondHalf); cv::Mat firstHalfHori = cv::Mat(images[i].clone(), cv::Rect(0, 0, images[i].cols, images[i].rows/2)); cv::Mat secondHalfHori = cv::Mat(images[i].clone(), cv::Rect(0, images[i].rows/2, images[i].cols, images[i].rows/2)); halfMassCentersHori[i][0] = getMassCenterFromImage(firstHalfHori); halfMassCentersHori[i][1] = getMassCenterFromImage(secondHalfHori); Histogram* hori = new Histogram(width); Histogram* verti = new Histogram(height); for (int x = 0; x < images[i].cols; x++){ for (int y = 0; y < images[i].rows; y++){ hori->add(x, images[i].at<uchar>(y, x)/255.0); verti->add(y ,images[i].at<uchar>(y, x)/255.0); } } histoHori[i] = hori; histoVerti[i] = verti; } }