Skip to content

Commit

Permalink
- update
Browse files Browse the repository at this point in the history
  • Loading branch information
billbillbilly committed Oct 30, 2023
1 parent 393b012 commit cc5ed4e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS)
91 changes: 48 additions & 43 deletions src/multiLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,57 +19,62 @@ Rcpp::List multiLabel(Rcpp::NumericMatrix &vpts,
const int vptnum = vpts.rows();
Rcpp::List output(vptnum);
#ifdef _WIN32
#pragma omp parallel shared(output, dsm_list, max_dis, vpth, h, vptnum) num_threads(workers)
#pragma omp for
for (int i = 0; i < vptnum; i++) {
const Rcpp::NumericMatrix sub_dsm = dsm_list[i];
int vx = vpts(i,0);
int vy = vpts(i,1);
const double vz = vpts(i,2) + vpth;
#ifdef _OPENMP
#pragma omp parallel for num_threads(workers)
#else
#pragma omp parallel for num_threads(1)
#endif
for (int i = 0; i < vptnum; i++) {
const Rcpp::NumericMatrix sub_dsm = dsm_list[i];
int vx = vpts(i,0);
int vy = vpts(i,1);
const double vz = vpts(i,2) + vpth;

Rcpp::NumericVector zl;
Rcpp::NumericVector xl;
Rcpp::NumericVector yl;
Rcpp::NumericVector zl;
Rcpp::NumericVector xl;
Rcpp::NumericVector yl;

const int sub_rows = sub_dsm.nrow();
const int sub_cols = sub_dsm.ncol();
const int sub_rows = sub_dsm.nrow();
const int sub_cols = sub_dsm.ncol();

int steps;
Rcpp::IntegerMatrix visible(sub_rows, sub_cols);
for (int j = 0; j < sub_rows; j++) {
for (int k = 0; k < sub_cols; k++) {
steps = sqrt((vx-k)*(vx-k) + (vy-j)*(vy-j));
const double z = sub_dsm(j,k) + h;
if (steps <= max_dis) {
Rcpp::NumericVector sequence(steps);
std::iota(sequence.begin(), sequence.end(), 1);
xl = vx + sequence * (k-vx)/steps;
yl = vy + sequence * (j-vy)/steps;
int steps;
Rcpp::IntegerMatrix visible(sub_rows, sub_cols);
for (int j = 0; j < sub_rows; j++) {
for (int k = 0; k < sub_cols; k++) {
steps = sqrt((vx-k)*(vx-k) + (vy-j)*(vy-j));
const double z = sub_dsm(j,k) + h;
if (steps <= max_dis) {
Rcpp::NumericVector sequence(steps);
std::iota(sequence.begin(), sequence.end(), 1);
xl = vx + sequence * (k-vx)/steps;
yl = vy + sequence * (j-vy)/steps;

if(vz<z) {
zl = vz + sequence/steps*fabs(vz-z);
} else if (vz>z) {
zl = vz - sequence/steps*fabs(vz-z);
} else if (vz==z) {
zl = vz + 0*sequence;
}
int temp = 1;
for (int p = 0; p < steps; p++) {
const double d = zl[p] - sub_dsm(yl[p],xl[p]);
if (d < 0) {
temp = 0;
break;
}
}
visible(j,k) = temp;
} else {
visible(j,k) = 0;
if(vz<z) {
zl = vz + sequence/steps*fabs(vz-z);
} else if (vz>z) {
zl = vz - sequence/steps*fabs(vz-z);
} else if (vz==z) {
zl = vz + 0*sequence;
}
int temp = 1;
for (int p = 0; p < steps; p++) {
const double d = zl[p] - sub_dsm(yl[p],xl[p]);
if (d < 0) {
temp = 0;
break;
}
}
visible(j,k) = temp;
} else {
visible(j,k) = 0;
}
#pragma omp critical
output[i] = visible;
}
}
#pragma omp critical
{
output[i] = visible;
}
}
#endif
return output;
}
Expand Down
Binary file modified src/viewscape.so
Binary file not shown.

0 comments on commit cc5ed4e

Please sign in to comment.