Pathfinding in real 3D environments (e.g Buildings) - c++

Is there a pathfinding algorithm also suited for real 3D environments e.g. real Buildings with multiple stairs etc. A C++ library or open implementation would be splendid ;-)
One solution I saw was Djikstra but I wonder whether there is something more optimal.
Normal A* would not work better then Djikstra since the distance heuristic does not work well (Position one floor above destination).
Another solution that I'm currently pondering is the mapping of the 3d environment on a 2d graph. So if there is some available C++ implementation/library going this way it would be helpful too.

If the path has to take into account the ability to navigate through obstacles (i.e. the movement is that of some entity with known volume in space), then I'd recommend looking into the literature on robot motion planning. The notion of a configuration space allows you to handle changes in pose in order to deal with obstacles. See the classic textbook by Jean-Claude Latombe
For simpler scenarios, you can probably make do with path planning algorithms used in first person computer games, which are similar to Dijkstra, A* (example)

For an approximation algorithm you can easily map the 3d to a 1d curve and traverse an octree with a gray code. That way you can reorder each path. I don't know if there is a guarantee to be within the optimum solution but it must be better then any heuristic method.

Related

A C++ alternative to Matlab's fmincon optimisation? Need a quicker easy alternative [duplicate]

We're currently using Matlab's fmincon function to do non-linear optimization for a project I'm working on. We need to port that part of the project to C++ in order to integrate it with other parts of the project. Is there a good way to compile the fmincon function into a library that we can use in C++? Or, is there already a library available somewhere that implements fmincon?
If neither of the above are an option, what optimization libraries are available that would be fairly easy to switch to from fmincon?
Background info:
We're trying to optimize a waypoint flight path of a UAV to follow a given waypoint camera path along the ground as closely as possible. The waypoints between the two paths correspond temporally, so the camera gimbal will be pointed at the i-th camera waypoint when the UAV arrives at the i-th flight path waypoint. The flight path segments will all be the same length since the UAV flies at a constant speed. The turn radius is also constrained by an upper bound. There are no constraints on the camera path, so its segments may be longer or shorter than the flight path segments and it may have sharp turns. The cost function is the sum-squared distance between corresponding flight waypoints and camera waypoints (ignoring altitude differences).
Most of the time, libraries out there won't try to be a black box magic one-size-fits-all optimization tool like fmincon is- instead they'll require you to provide more detail and make more choices on your own, which is simpler for them and should result in your software being faster. You can certainly use the MATLAB Engine or MATLAB Compiler to call fmincon from your program, but most likely your software will run a good deal faster (and you can avoid purchasing the MATLAB Compiler) if you can use a little more knowledge about the structure your optimization problem has and call an appropriate algorithm.
Your background info doesn't describe what you're doing - esp. what your feasible set is- clearly enough for me to be able to tell you what to use, so all I can do is point you in the direction of relevant resources.
Wikipedia's page on optimization links to lists of optimization software- most importantly, it describes more specific kinds of optimization problems (for instance, can you formulate your problem as quadratic programming with linear constraints?) and software appropriate for each situation.
Boyd's book on convex optimization and the linked course materials & videos are really good resources.

Fast organised point cloud registration

I have been looking for methods to register (align) organized point clouds with normal information.
I could only find generic point cloud registration methods (for example in PCL).
I am using Microsoft Kinect to get my point clouds, but the problem is that they are quite big.
What I would like to know:
Is there are fast ways to register organized point clouds?
Are there down-sampling methods that are very fast (and may also
be using the fact that the point clouds are organized)?
I was also thinking about using OpenCV filters, since an organized
point cloud could be though of as an image with gray values (2D matrix with depth values). For example using the openCV resize method on the matrix, and some derivative type filters (because edges are important for me in the scene). Is that a good idea?
Also, down-sampling looks like a data-parallel problem, which could be a great candidate for GPU implementation. Do you know about any such implementation?
What I have done so far is the following.
- Several down-sampling methods (Random, Voxel-based, Uniform), but the problem with all of them is that they all took a lot of time (in PCL). Best was Voxel-based.
- Then did ICP, which ran pretty fast and accurate enough for me on the down-sampled point clouds.
So for me, currently, a good solution would be a fast way of down-sampling my point clouds. For example a GPU-based implementation for it.
Thinking of an organized point cloud as an image with greyvalues (simple 2D matrix) turns out to be a good idea.
Downsampling methods for 2D matrices implemented on GPU are available in, for example, OpenCV cuda.
Also, it is easy to implement your own fast downsampling methods on 2D matrices, depending on how important accuracy is. For example, just simply take every kth element. You can do, if needed, averaging at these elements to blur, or derivative type filters to sharpen (edge enhancement). You can come up with special picking methods, depending on information about the frames (e.g. if you know your objects tend to be in the center, then you can pick more points around the area).
All these three above will give faster results and probably "more-tuned" to your problem (especially #3). "More-tuned" implies less robust.

C++ - fastest sorting algorithm for objects based on distance

I'm trying to make a game or 3D application using openGL. The game/program will have many objects in them and drawn to the screen(around 7000 of them). When I render them, I would need to calculate the distance between the camera and the object and sort them in order to correctly render the objects within the scene. Knowing this, what is the best way to sort them? I really want the sorting to be done really fast, but I've heard there are "trade off" for them, so what algorithm should I use to get the best performance out of it?
Any help would be greatly appreciated.
Edit: a lot of people are talking about the z-buffer/depth buffer. This doesn't work in some cases like a few people talked about. This is why I asked this question.
Sorting by distance doesn't solve the transparency problem perfectly. Consider the situation where two transparent surfaces intersect and each has a part which is closer to you. Perhaps rare in games, but still something to consider if you don't want an occasional glitched look to your renderer.
The better solution is order-independent transparency. With the latest graphics hardware supporting atomic operations, you can use an A-buffer to do this with little memory overhead and in a single pass so it is pretty efficient. See for example this article.
The issue of sorting your scene is still a valid one, though, even if it isn't for transparency -- it is still useful to sort opaque objects front to back to to allow depth testing to discard unseen fragments. For this, Vaughn provided the great solution of BSP trees -- these have been used for this purpose for as long as 3D games have been around.
Use http://en.wikipedia.org/wiki/Insertion_sort which has O(n) complexity for nearly sorted arrrays.
In your case by exploiting temporal cohesion insertion sort gives fastest results.
It is used for http://en.wikipedia.org/wiki/Sweep_and_prune
From link above:
In many applications, the configuration of physical bodies from one time step to the next changes very little. Many of the objects may not move at all. Algorithms have been designed so that the calculations done in a preceding time step can be reused in the current time step, resulting in faster completion of the calculation.
So in such cases insertion sort is best(or similar sorts with O(n) at best case)

Which library for voxel data structure?

I'm working in C++ with large voxel grids in a scientific context and I'm trying to decide, which library to use. Only a fraction of the voxel grid holds values - but might be several per voxel (e.g. struct), which are determined by raytracing. I'm not trying to render anything, but I have to determine the potential number of rays passing though the entire target area, thus an awful lot of ray-box computations will have to be caluculated and preferebly very fast...
So far, I found
OpenVDB http://www.openvdb.org/
Field3d http://sites.google.com/site/field3d/
The latter appeals a bit more, because it seems simpler/easier to use.
My question is: Which of them would be more suited if put to use in tasks, which are not aimed at rendering/visualization? Which one is faster/better when computing a lot of ray-box-intersections (no viewpoint-dependent culling possible)? Suggestions, anyone?
In any case, I want to use an existing C++ library and not write a kdTree/Octree etc. myself. Don't have the time for inventing the wheel anew.
I would advise
OpenSceneGraph
Ogre3D
VTK
I have personally used the first two. However, VTK is also a popular alternative. All three of them support voxel based rendering.

test if square overlaps poly in c++ w/ directx (optional)

how would I go about checking to see if a triangular poly is present within a square area? (I.E. picture a grid of squares overlaying a group of 2d polys.)
Or even better, how can I determine the percentage of one of these squares that is occupied by a given poly (if at all).
I've used directx before but can't seem to find the right combination of functions in their documentation. - Though it feels like something with ray-tracing might be relevant.
I use c++ and can use directx if helpful.
Thanks for any suggestions or ideas. :)
You might consider the clipper library for doing generic 2D polygon clipping, area computation, intersection testing, etc. It is fairly compact and easy to deal with, and has decent examples of how to use it.
It is an implementation of the Vatti clipping algorithm and will handle many odd edge cases (which may be overkill for you)
There are a few ways to do this and it's essentially a clipping problem.
One way is to use the Cohen–Sutherland algorithm: http://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland
You would run the algorithm 3 times (once for each triangle edge).
You can then find the percentage of area occupied by calculating area(clipped_triangle) / area(square_region).
You might consider the clipper library for doing generic 2D polygon clipping, area computation, intersection testing, etc. It is fairly compact and easy to deal with, and has decent examples of how to use it.
It is an implementation of the Vatti clipping algorithm and will handle many odd edge cases (which may be overkill for you)
Can ho celadon city - vinhomes central park