Find all the faces between a source and a target faces - cgal

I've used the CGAL::Surface_mesh_shortest_path before to find the exact shortest path in a topological manner. But now I want something simpler that seem to be missing from the library that is finding the logical path from one face to another, returning a list of the faces in between.
Is there any way to do it without having to implement a tree search from scratch?

CGAL offers a class Dual as a wrapper around a mesh. As the name suggests you obtain a dual graph. If your mesh has boundaries you have to filter them out with a boost::filtered_graph. Now you can run boost::dijkstra_shortest_paths. Now for any vertex the predecessor map will lead you to the source vertex.
You can find a self contained example here.
You probably can add a visitor so that you stops by throwing an exception as soon the shortest path algorithm reaches your target vertex.

Related

Writing CGAL Efficient Ransac detected planes to file

I've been successfully testing CGAL Efficient RANSAC using this provided example to detect planes in a point cloud. The only piece missing from the CGAL Efficient RANSAC examples is a way to write the detected planes into a mesh (something like what polyfit offers at the end of this example)
I've noted that I can use the planes() method from Efficient_RANSAC to get an iterator of Plane but I'm a bit lost after that. Do I need to read all points from each plane and try and manually create a mesh from it ?
Thanks in advance for any help

ANSYS Meshing Issue - How To Mesh Complicated Geometry (~80,000 Faces)?

I am attempting to mesh a complicated design (~80,000 faces) for a microchannel heat sink, as pictured, and I would appreciate some advice. I have tried a range of different mesh controls (especially face sizing and body sizing), mesh settings and element sizes, and all have failed to produce a working mesh. The most common errors are shown in the linked picture, in particular the one regarding "The following surfaces cannot be meshed with acceptable quality. Try using a different element size or virtual topology." However, I have already reduced the element size to 2x10^-6 m, which takes two days to resolve before failure.
Unfortunately I cannot alter the geometry significantly, as it is imported from generation in SolidWORKS as either a STEP or an x.t file. As such, any advice for how I can successfully mesh the geometry for CFD analysis in FLUENT would be greatly appreciated.
I can provide more details or the geometry file itself if required.
Thanks in advance.
Meshing Attempt
Probably your cad design is not clean at all. But it is impossible to notice from this image. If you don't have control over the geometry source it is trouble. Because you might ask somebody else about check and fix something. First check you can do with your model it's trying to reduce the number of elements until the minimum possible value. Then if the mesh runs properly you can relay in the surfaces of your cad model. After that, you can refine the mesh, but the refining process is something that you have to do following some error criteria. If you are also the designer why not try to simplify a bit the geometry if you consider it is really hard to mesh? Meshing properly is a hard task, you should go step-by-step until you reach some solution. Also, you must not allow the preprocessor mesh automatically, without giving some criteria. Probably the first thing you have to answer even before apply any mesh is, what is your Reynolds number? And what is the most valuable result in which you can base the goodness of your discretization?
Thank you for your suggestions. In the end I solved the issue by importing the original mesh generated by COMSOL into SpaceClaim, then employing both the "Smooth" and "Reduce Faces" tools in tandem to simplify the geometry, before finally using SolidWORKS to turn the smoothed mesh into a solid body. This body retained many of the same features as the original, but was much less complex, having two orders of magnitude fewer faces. In turn, this permitted both meshing and heat transfer analysis in FLUENT.

CGAL cut cube with arbitrary surface

I'm new to CGAL and I'm trying to cut a cube with an arbitrary surface mesh in 3d (no self intersections, not closed/no volume). The goal is to get a volume which consists of one "side" of the cut cube, closed by the part of the surface inside the cube.
The surface itself consists of unordered triangles which should have the same winding order (consistent normal directions) but have no neighborhood information and could contain same points multiple times for different triangles.
I tried to use the clip function, like:
CGAL::Polygon_mesh_processing::clip(cube,surface,true);
Which of course does not work because the surface is not closed (as far as I understood). But It shows the idea on how the operation should work.
Boolean operations (https://doc.cgal.org/latest/Polygon_mesh_processing/index.html#title14)) cannot be used for this as well since they are calculated on volumes and the surface has no volume.
I also thought about extending the outside of the surface so that it is closed. This, however, does not seem like a good approach.
Sadly, my research on similar problems was not successful.
I'm pretty sure that there is a nice way to do this in CGAL. Maybe someone with more experience in CGAL knows how to do this.
What would be the best approach for getting this volume?
Regards
EDIT:
By removing redundant points in my surface mesh I was able to get clip to work. Nevertheless, I do not always get the right side of the volume, even though the winding order should yield normals which point to the outside.
Is it necessary to calculate the normals and pass them as an extra parameter (see here) of the surface before the cut in order to always get the same "inner" side of the volume?
Also, the clip function seems to be quite slow. I have to do this cut for a very high number of cubes and different surfaces.
I use CGAL as header only lib and without GMP and MPFR, since it crashed my other application. How big is the speedup using these libraries and are there any other tricks which can be used to speedup computation, e.g. using parallelization?
I saw that CGAL uses Intel's TBB which. But in the header files which are included by the clipping algorithm CGAL_LINKED_WITH_TBB is not tested.
Thanks
It was a problem with the clipping mesh. Clipping could not be done properly. I increased it size and now it always intersects the volume.

Conditions for binary search to succeed in finding nearest neighbor on array of 3D points?

I have a ordered array of 3D points. The points represent a path in 3D space.
Given an arbitrary point I want to find the nearest point on the path.
If the path was relatively straight this would be trivial application of binary search, but since the path can have arbitrary curvature(looping back on itself) binary search may fail to find the nearest point.
My question is as follows:
What is the least strict constraint under which binary search will succeed to find the nearest point? Is it monotomic in each dimension? Is it related to the paths curvature? etc...
It depends a little on whether your path is given or whether you are free to use any path you like.
Let's assume your path is given.
To answer your question: A simple binary search cannot be guaranteed to find the closest point. Imagine your path is a circle that is cut open at one place. The first and last point of your curve (the circle) will always be very close, but no binary search can fix that. As #Yann Vernier suggested, you can use spatial searches for that, search for "nearest neighbor query", these can usually be done with spatial indexes such as kd-tree, quadtree or R-Tree. You can find Java implementations here.
In case the path is not predefined, you can order the points with a z-curve (morton order) or Hilbert curve (the curves being your path). This gives you a linear ordering which can searched with a binary search. This does not always give the closest point, but it is very fast, space efficient and will often give you the closest point. Hilbert curve is more likely to give you the closest point than z-curve, but it is harder to calculate.

Finding centre line of a pipe using python

I am currently writing a code in Python for flows through pipes. In this regard, I have to find a centre line passing thorough a 3D pipe geometry defined by a nastran mesh (cells with three or four edges whose coordinates i can access). I am using the pyNastran module in Python to get all the relevant data and functions.
My question is what would be the most efficient way of finding the centre line of the pipe. The pipe is a 3d pipe with bends in all direction. ( I have all the coordinates of every single point on the mesh in an array)
That is not so easy topic :-/ Problem is that center line is not local property.
For sure, each point on center line corresponds to one slice through pipe or simpler to one perimeter on pipe surface. For any kind of defining that relation on local characteristics, it is easy to find example with bendings or changing pipe diameter that produces 'strange' result.
One way to solve it is to look for topics that have similar properties that are needed here. Like we want slices to be 'parallel' and to uniformly pass through pipe. On one project we used heat diffusion/transfer to tackle a problem. Idea is to put boundary conditions, on one pipe side set boundary condition 1 and on the other side boundary condition 0. Heat will transfer from one side to the other and isoterm will have good properties.
After that, choose center line discterization (on [0-1]), for each point find isoterm on that temperature and find center of mass of that isoterm. Connecting these centers will produce center line.
It is possible to make diffusion on 3D (volume) and 2D (surface) case. It is probably faster to do it on surface.