Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
// Exact close-pair hazard and connectedness test; same predicates as NumPy.
|
||||
// C ABI keeps this numerical hot loop independent of ROS and Python versions.
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
template<class T> int connected_grade(const T* p, int n) {
|
||||
if (n <= 0) return 0;
|
||||
@@ -21,3 +24,56 @@ template<class T> int connected_grade(const T* p, int n) {
|
||||
}
|
||||
extern "C" int terrain_connected_f32(const float* p,int n) {return connected_grade(p,n);}
|
||||
extern "C" int terrain_connected_f64(const double* p,int n) {return connected_grade(p,n);}
|
||||
|
||||
// Exact counterpart of terrain_costs._neighborhoods. Return source indices in
|
||||
// source order; Python retains the unchanged fitting and hazard predicates.
|
||||
template<class T> struct Neighborhoods {
|
||||
std::vector<T> points;
|
||||
std::map<std::pair<int64_t,int64_t>,std::vector<int>> cells;
|
||||
Neighborhoods(const T* p,int n): points(p,p+3*n) {
|
||||
for(int i=0;i<n;i++) cells[key(i)].push_back(i);
|
||||
}
|
||||
std::pair<int64_t,int64_t> key(int i) const {
|
||||
return {int64_t(std::floor(points[3*i]/T(0.4))),
|
||||
int64_t(std::floor(points[3*i+1]/T(0.4)))};
|
||||
}
|
||||
int query(int i,int* output) const {
|
||||
const auto k=key(i);
|
||||
int count=0;
|
||||
for(int dx=-1;dx<=1;dx++) for(int dy=-1;dy<=1;dy++) {
|
||||
const auto found=cells.find({k.first+dx,k.second+dy});
|
||||
if(found==cells.end()) continue;
|
||||
for(int j:found->second) {
|
||||
const T x=points[3*j]-points[3*i], y=points[3*j+1]-points[3*i+1];
|
||||
if(std::sqrt(x*x+y*y)<=T(0.4)) output[count++]=j;
|
||||
}
|
||||
}
|
||||
std::sort(output,output+count);
|
||||
return count;
|
||||
}
|
||||
// Batch the existing Python count/span rejection before allocating a
|
||||
// NumPy neighborhood per point. Relative subtraction and span retain T's
|
||||
// rounding, exactly as terrain[index-neighbors] - terrain[index] does.
|
||||
int screen(const int* indices,int n,int minimum,double maximum_span,int* output) const {
|
||||
std::vector<int> nearby(points.size()/3);
|
||||
int kept=0;
|
||||
for(int k=0;k<n;k++) {
|
||||
const int i=indices[k], count=query(i,nearby.data());
|
||||
if(count<minimum) continue;
|
||||
T low=points[3*nearby[0]+2]-points[3*i+2], high=low;
|
||||
for(int j=1;j<count;j++) {
|
||||
const T z=points[3*nearby[j]+2]-points[3*i+2];
|
||||
low=std::min(low,z); high=std::max(high,z);
|
||||
}
|
||||
if(double(T(high-low))<=maximum_span) output[kept++]=i;
|
||||
}
|
||||
return kept;
|
||||
}
|
||||
};
|
||||
#define NEIGHBOR_API(T,S) \
|
||||
extern "C" void* terrain_neighbors_create_##S(const T* p,int n) {return new Neighborhoods<T>(p,n);} \
|
||||
extern "C" int terrain_neighbors_query_##S(void* h,int i,int* out) {return static_cast<Neighborhoods<T>*>(h)->query(i,out);} \
|
||||
extern "C" int terrain_neighbors_screen_##S(void* h,const int* i,int n,int minimum,double span,int* out) {return static_cast<Neighborhoods<T>*>(h)->screen(i,n,minimum,span,out);} \
|
||||
extern "C" void terrain_neighbors_destroy_##S(void* h) {delete static_cast<Neighborhoods<T>*>(h);}
|
||||
NEIGHBOR_API(float,f32)
|
||||
NEIGHBOR_API(double,f64)
|
||||
|
||||
Reference in New Issue
Block a user