|
[Sponsors] |
December 11, 2013, 12:29 |
Ray Tracing in OpenFOAM
|
#1 |
New Member
Matteo
Join Date: Sep 2013
Location: Milan, Italy
Posts: 9
Rep Power: 13 |
Hi OpenFOAMers!!
I'm looking for an algorithm to search the intersection between a line and cell faces of a mesh. I know Ray Tracing, which is quite similar to my problem, is an important field of study for graphic programmers, but I didn't find nothing practically interesting about CFD mesh applications. I've already searched in the forum but I didn't find nothing. Could anybody help me? Thank you a lot! Regards from Italy! |
|
December 11, 2013, 14:05 |
|
#2 |
New Member
Michael
Join Date: Sep 2012
Posts: 23
Rep Power: 14 |
There are a lot of functions in OF to find intersections of faces and lines/rays. Usually they are methods of indexedOctree classes. It only depends on, what you would like to intersect.
Boundary faces, triSurface faces, mesh faces? With lines (find intersection between start point and end point) or with rays (start point and vector)? Do you just need to find these intersections or are you really looking for a ray tracing algorithm, like monte carlo ray tracing? |
|
December 12, 2013, 07:53 |
|
#3 |
New Member
Matteo
Join Date: Sep 2013
Location: Milan, Italy
Posts: 9
Rep Power: 13 |
I'd like to know the intersection points of a line from a start point to an end point with every mesh faces at runtime.
The indexedOctree functions may be useful, but I'm having troubles with their use. Have you some advices about their application? Which headers have I to include? Is there a specific function that you suggest? |
|
December 12, 2013, 08:11 |
|
#4 |
New Member
Michael
Join Date: Sep 2012
Posts: 23
Rep Power: 14 |
Here are some code snippets I used to find all intersections of a line with all mesh faces. This is no complete working code.
Code:
#include "polyMesh.H" #include "meshTools.H" #include "treeDataFace.H" Code:
treeBoundBox allBb(mesh.points()); scalar bbTol = 1e-6 * allBb.avgDim(); point& bbMin = allBb.min(); bbMin.x() -= bbTol; bbMin.y() -= bbTol; bbMin.z() -= bbTol; point& bbMax = allBb.max(); bbMax.x() += 2*bbTol; bbMax.y() += 2*bbTol; bbMax.z() += 2*bbTol; indexedOctree<treeDataFace> faceTree ( treeDataFace(false, mesh_), allBb, // overall search domain 8, // maxLevel 10, // leafsize 3.0 // duplicity ); Code:
const point pStart = ...; // start point of line const point pEnd = ...; // end point of line const vector eVec(pEnd - pStart); // line vector const scalar eMag = mag(eVec); // edge length const vector tolVec = 1e-6*eVec; point p0 = pStart - tolVec; const point p1 = pEnd + tolVec; while(true) { pointIndexHit pHit = faceTree.findLine(p0, p1); if (pHit.hit()) { const label faceI = pHit.index(); // face label of hit face const point hitPoint = pHit.hitPoint(); // intersection point const vector& area = mesh_.faceAreas()[pHit.index()]; scalar typDim = Foam::sqrt(mag(area)); // stop search if new start point is near to edge end if ((mag(pHit.hitPoint() - pEnd)/typDim) < SMALL) { break; } // set new start point shortly after previous start point p0 = pHit.hitPoint() + tolVec; } else { // No hit. break; } } |
|
December 12, 2013, 09:54 |
|
#5 |
New Member
Matteo
Join Date: Sep 2013
Location: Milan, Italy
Posts: 9
Rep Power: 13 |
Thank you mirx.
Nice code, it works very well, I just add a list to save the hit points. Code:
DynamicList<pointIndexHit> pHitList; Code:
pHitList.append(pHit); |
|
December 12, 2013, 10:03 |
|
#6 |
New Member
Michael
Join Date: Sep 2012
Posts: 23
Rep Power: 14 |
There was a reason that I didn't use it. I wanted to run some extra code for every intersection I had found.
But you are right. findLineAny actually executes a similar while loop as the one I have posted. I think my loop was inspired by the one in findLineAny. So if you just need the intersections, I think you can use something like: Code:
const point pStart = ...; const point pEnd = ...; List<pointIndexHit> pHit(faceTree.findLineAny(pStart, pEnd)); |
|
December 12, 2013, 10:27 |
|
#7 |
New Member
Matteo
Join Date: Sep 2013
Location: Milan, Italy
Posts: 9
Rep Power: 13 |
I tried that but the list output seems to be not accepted:
Code:
error: no matching function for call to Foam::List<Foam::PointIndexHit<Foam::Vector<double> > >::List(Foam::pointIndexHit) List<pointIndexHit> pHit(faceTree.findLineAny(pStart, pEnd)); |
|
December 12, 2013, 10:36 |
|
#8 |
New Member
Michael
Join Date: Sep 2012
Posts: 23
Rep Power: 14 |
Oh sorry, my mistake. I confused Any with All. triSurfaceSearch has a method called fineLineAll.
Code:
void findLineAll ( const point& start, const point& end, List<pointIndexHit>& ) const; findLineAny returns any of the intersections, not all. |
|
December 12, 2013, 10:42 |
|
#9 |
New Member
Matteo
Join Date: Sep 2013
Location: Milan, Italy
Posts: 9
Rep Power: 13 |
OK! Thank you a lot for your useful replies!
Bye! P.S.: I said "Any", so it was my mistake! :-) |
|
May 16, 2014, 13:38 |
including header files
|
#10 |
New Member
Join Date: Apr 2012
Posts: 21
Rep Power: 14 |
Hey guys,
Is any body still interested in this ray tracing application in OpenFOAM? I am having trouble with including the header file "meshtools.H"--fatal error, no such file or directory. Do you have any comments? |
|
May 16, 2014, 14:04 |
|
#11 |
Senior Member
|
Hi,
it's meshTools.H not meshtools.h. Also you need Code:
-I$(LIB_SRC)/meshTools/lnInclude |
|
May 27, 2014, 18:04 |
|
#12 |
New Member
Join Date: Apr 2012
Posts: 21
Rep Power: 14 |
Thanks Alexeym!
I got it going! one more question: do you know how can i use findLineAll member function of triSurfaceSearch? |
|
May 28, 2014, 04:01 |
|
#13 |
Senior Member
|
Hi,
Looked through the documentation on the method, now I have doubts I've got your question right. You've got triSurface, you construct triSurfaceSearch, you call findLineAll. So what's your question? |
|
May 28, 2014, 04:32 |
|
#14 |
New Member
Michael
Join Date: Sep 2012
Posts: 23
Rep Power: 14 |
For a ray tracing application I think you will be interested in the first intersection of a ray with a surface. In this case you may use method findLine of indexedOctree<treeDataTriSurface>.
This is a short example how to use this method: Code:
const triSurface surf(runTime.constantPath()/"triSurface"/surfFileName); const vectorField& normals = surf.faceNormals(); const triSurfaceSearch querySurf(surf); const indexedOctree<treeDataTriSurface>& tree = querySurf.tree(); point searchStart(0, 0, 0); point searchEnd(1, 0, 0); pointIndexHit pHit = tree.findLine(searchStart, searchEnd); if ( pHit.hit() ) { point hitPoint = pHit.hitPoint(); label hitTriangle = pHit.index(); vector normal = normals[hitTriangle]; } |
|
February 22, 2015, 07:00 |
|
#15 |
New Member
Join Date: Feb 2015
Posts: 2
Rep Power: 0 |
Greetings! Hope someone will be able to give some hints on my issue. Thanks in advance.
I'm doing ray tracing, using octree: Code:
indexedOctree<treeDataFace> faceTree ( treeDataFace(false, mesh), allBb, // overall search domain 8, // maxLevel 10, // leafsize 3.0 // duplicity ); Code:
faceTree.findLine(p0, p1); Code:
treeDataFace(false, mesh), Code:
treeDataFace(false, "small part of the mesh"), |
|
December 8, 2015, 09:21 |
|
#16 | |
Member
David GISEN
Join Date: Jul 2009
Location: Germany
Posts: 70
Rep Power: 17 |
Quote:
Code:
undefined reference to `Foam::PrimitivePatch<Foam::labelledTri, Foam::List, Foam::Field<Foam::Vector<double> >, Foam::Vector<double> >::faceNormals() const' Cheers, David |
||
April 21, 2017, 11:58 |
|
#17 |
Member
Thomas Flint
Join Date: Jan 2016
Posts: 60
Rep Power: 10 |
Sinsi,
Did you ever find a method of restricting the search to a smaller part of the mesh? All the best, Tom treeDataFace(false, "small part of the mesh"), |
|
December 14, 2017, 14:14 |
|
#18 |
Member
Ashish Kumar
Join Date: Jun 2015
Posts: 33
Rep Power: 11 |
is it possible to search the intersection for the user specified cells?
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Superlinear speedup in OpenFOAM 13 | msrinath80 | OpenFOAM Running, Solving & CFD | 18 | March 3, 2015 06:36 |
OpenFOAM Foundation Releases OpenFOAMŪ Version 2.1.1 | opencfd | OpenFOAM Announcements from ESI-OpenCFD | 0 | May 31, 2012 10:07 |
OpenFOAM Training in Europe and USA | hjasak | OpenFOAM | 0 | August 8, 2008 06:33 |
question on ray tracing | Ramesh | Main CFD Forum | 3 | February 9, 2006 06:23 |
Looking for paper: Ray Tracing Complex Scenes | lemas | Main CFD Forum | 0 | September 9, 2003 08:38 |