28 if (crresHeight >
MIN_INF)
return crresHeight;
31 for (
int i = xpos - 1; i >= 0; i--) {
33 if (crresHeight >
MIN_INF)
return crresHeight;
36 for (
int j = ypos - 1; j >= 0; j--) {
38 if (crresHeight >
MIN_INF)
return crresHeight;
43 if (crresHeight >
MIN_INF)
return crresHeight;
46 return findHeightValByNeighbor(p, cloth);
50 queue<Particle *> nqueue;
51 vector<Particle *> pbacklist;
53 for (
size_t i = 0; i < neiborsize; i++) {
59 while (!nqueue.empty()) {
60 Particle *pneighbor = nqueue.front();
62 pbacklist.push_back(pneighbor);
64 for (
int i = 0; i < pbacklist.size(); i++)
65 pbacklist[i]->isVisited =
false;
66 while (!nqueue.empty()) {
74 for (
size_t i = 0; i < nsize; i++) {
88 std::vector<double> &heightVal,
93 for (
int i = 0; i < pc.size(); i++) {
94 double pc_x = pc[i].x;
95 double pc_z = pc[i].z;
99 int col = int(deltaX / cloth.
step_x + 0.5);
100 int row = int(deltaZ / cloth.
step_y + 0.5);
101 if (col >= 0 && row >= 0) {
106 double pc2particleDist =
108 if (pc2particleDist < pt.
tmpDist) {
116 heightVal.resize(cloth.
getSize());
118 for (
int i = 0; i < cloth.
getSize(); i++) {
123 heightVal[i] = nearestHeight;
125 heightVal[i] = findHeightValByScanline(&pcur, cloth);
128 }
catch (
const std::bad_alloc &) {
140 #include <CGAL/Orthogonal_k_neighbor_search.h>
141 #include <CGAL/Search_traits_2.h>
142 #include <CGAL/Simple_cartesian.h>
143 #include <CGAL/point_generators_2.h>
145 typedef CGAL::Simple_cartesian<double> K;
146 typedef K::Point_2 Point_d;
147 typedef CGAL::Search_traits_2<K> TreeTraits;
148 typedef CGAL::Orthogonal_k_neighbor_search<TreeTraits> Neighbor_search;
149 typedef Neighbor_search::Tree Tree;
153 std::vector<double>& heightVal,
159 std::map<std::string, double> mapstring;
160 std::list<Point_d> points_2d;
162 for (
size_t i = 0; i < pc.size(); i++) {
163 std::ostringstream ostrx, ostrz;
166 mapstring.insert(std::pair<std::string, double>(
167 ostrx.str() + ostrz.str(), pc[i].y));
168 points_2d.push_back(Point_d(pc[i].x, pc[i].z));
170 Tree tree(points_2d.begin(), points_2d.end());
172 heightVal.resize(cloth.
getSize());
173 for (
int i = 0; i < cloth.
getSize(); i++) {
175 Point_d query(particle.
pos.
x, particle.
pos.
z);
176 Neighbor_search search(tree, query, KNN);
177 double search_max = 0;
178 for (Neighbor_search::iterator it = search.begin();
179 it != search.end(); it++) {
180 std::ostringstream ostrx, ostrz;
181 ostrx << it->first.x();
182 ostrz << it->first.y();
183 double y = mapstring[ostrx.str() + ostrz.str()];
184 if (y > search_max || it == search.begin())
189 heightVal[i] = search_max;
191 }
catch (
const std::bad_alloc&) {
206 #include <SimpleCloud.h>
210 static bool ComputeMaxNeighborAltitude(
212 void** additionalParameters,
216 std::vector<double>& heightVal =
217 *(std::vector<double>*)additionalParameters[1];
220 unsigned KNN = *(
unsigned*)additionalParameters[3];
232 for (
unsigned i = 0; i < pointCount; i++) {
241 double search_max = heightVal[particleIndex];
242 for (
unsigned k = 0; k <
std::min(KNN, n); ++k) {
244 if (std::isnan(search_max) || pc[pointIndex].y > search_max) {
245 search_max = pc[pointIndex].y;
248 heightVal[particleIndex] = search_max;
256 std::vector<double>& heightVal,
258 cloudViewer::SimpleCloud particlePoints;
259 if (!particlePoints.reserve(
static_cast<unsigned>(cloth.
getSize()))) {
263 for (
int i = 0; i < cloth.
getSize(); i++) {
265 particlePoints.addPoint(
272 FILE* fp = fopen(
"particle.asc",
"wt");
273 for (
unsigned i = 0; i < particlePoints.size(); i++) {
274 const CCVector3* P = particlePoints.getPoint(i);
275 fprintf(fp,
"%f %f %f\n", P->
x, P->
y, P->
z);
280 cloudViewer::SimpleCloud pcPoints;
281 if (!pcPoints.reserve(
static_cast<unsigned>(pc.size()))) {
285 for (
size_t i = 0; i < pc.size(); i++) {
292 FILE* fp = fopen(
"points.asc",
"wt");
293 for (
unsigned i = 0; i < pcPoints.size(); i++) {
294 const CCVector3* P = pcPoints.getPoint(i);
295 fprintf(fp,
"%f %f %f\n", P->
x, P->
y, P->
z);
301 heightVal.resize(cloth.
getSize(),
302 std::numeric_limits<double>::quiet_NaN());
308 &particlePoints, &pcPoints, particleOctree, cloudOctree,
318 void* additionalParameters[] = {(
void*)(&pc), (
void*)(&heightVal),
319 (
void*)(cloudOctree), (
void*)(&KNN)};
322 particleOctree->findBestLevelForAGivenPopulationPerCell(
323 std::max<unsigned>(2, KNN));
327 int result = particleOctree->executeFunctionForAllCellsAtLevel(
328 octreeLevel, ComputeMaxNeighborAltitude, additionalParameters,
329 true, 0,
"Rasterization", QThread::idealThreadCount());
334 delete particleOctree;
341 }
catch (
const std::bad_alloc&) {
Vector3Tpl< PointCoordinateType > CCVector3
Default 3D Vector.
float PointCoordinateType
Type of the coordinates of a (N-D) point.
#define SQUARE_DIST(x1, y1, x2, y2)
Particle & getParticleByIndex(int index)
Particle & getParticle(int x, int y)
double nearestPointHeight
std::vector< int > correspondingLidarPointList
std::size_t nearestPointIndex
std::vector< Particle * > neighborsList
static double findHeightValByNeighbor(Particle *p, Cloth &cloth)
static bool RasterTerrain(Cloth &cloth, const wl::PointCloud &pc, std::vector< double > &heightVal, unsigned KNN=1)
static double findHeightValByScanline(Particle *p, Cloth &cloth)
The octree structure used throughout the library.
void getCellPos(CellCode code, unsigned char level, Tuple3i &cellPos, bool isCodeTruncated) const
unsigned findNearestNeighborsStartingFromCell(NearestNeighboursSearchStruct &nNSS, bool getOnlyPointsWithValidScalar=false) const
void computeCellCenter(CellCode code, unsigned char level, CCVector3 ¢er, bool isCodeTruncated=false) const
unsigned size() const override
Returns the number of points.
virtual unsigned getPointGlobalIndex(unsigned localIndex) const
const CCVector3 * getPoint(unsigned index) const override
Returns the ith point.
ReferenceCloud * points
Set of points lying inside this cell.
unsigned char level
Cell level of subdivision.
CellCode truncatedCode
Truncated cell code.