Commit d7e88028 authored by mattijs's avatar mattijs
Browse files

removed octreeDataFaceList; created generic PrimitivePatch search one

parent dd746d4e
......@@ -49,7 +49,6 @@ perfectInterface/perfectInterface.C
boundaryMesh/boundaryMesh.C
boundaryPatch/boundaryPatch.C
boundaryMesh/octreeDataFaceList.C
setUpdater/setUpdater.C
meshModifiers = meshCut/meshModifiers
......
......@@ -29,11 +29,12 @@ License
#include "polyMesh.H"
#include "repatchPolyTopoChanger.H"
#include "faceList.H"
#include "octree.H"
#include "octreeDataFaceList.H"
#include "indexedOctree.H"
#include "treeDataPrimitivePatch.H"
#include "triSurface.H"
#include "SortableList.H"
#include "OFstream.H"
#include "uindirectPrimitivePatch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -892,6 +893,17 @@ Foam::labelList Foam::boundaryMesh::getNearest
<< endl;
}
uindirectPrimitivePatch leftPatch
(
UIndirectList<face>(mesh(), leftFaces),
mesh().points()
);
uindirectPrimitivePatch rightPatch
(
UIndirectList<face>(mesh(), rightFaces),
mesh().points()
);
// Overall bb
treeBoundBox overallBb(mesh().localPoints());
......@@ -911,29 +923,35 @@ Foam::labelList Foam::boundaryMesh::getNearest
bbMax.z() += 2*tol;
// Create the octrees
octree<octreeDataFaceList> leftTree
indexedOctree
<
treeDataPrimitivePatch<face, UIndirectList, const pointField&>
> leftTree
(
overallBb,
octreeDataFaceList
treeDataPrimitivePatch<face, UIndirectList, const pointField&>
(
mesh(),
leftFaces
false, // cacheBb
leftPatch
),
1,
20,
10
overallBb,
10, // maxLevel
10, // leafSize
3.0 // duplicity
);
octree<octreeDataFaceList> rightTree
indexedOctree
<
treeDataPrimitivePatch<face, UIndirectList, const pointField&>
> rightTree
(
overallBb,
octreeDataFaceList
treeDataPrimitivePatch<face, UIndirectList, const pointField&>
(
mesh(),
rightFaces
false, // cacheBb
rightPatch
),
1,
20,
10
overallBb,
10, // maxLevel
10, // leafSize
3.0 // duplicity
);
if (debug)
......@@ -953,7 +971,7 @@ Foam::labelList Foam::boundaryMesh::getNearest
treeBoundBox tightest;
const scalar searchDim = mag(searchSpan);
const scalar searchDimSqr = magSqr(searchSpan);
forAll(nearestBFaceI, patchFaceI)
{
......@@ -982,50 +1000,25 @@ Foam::labelList Foam::boundaryMesh::getNearest
}
// Search right tree
tightest.min() = ctr - searchSpan;
tightest.max() = ctr + searchSpan;
scalar rightDist = searchDim;
label rightI = rightTree.findNearest(ctr, tightest, rightDist);
pointIndexHit rightInfo = rightTree.findNearest(ctr, searchDimSqr);
// Search left tree. Note: could start from rightDist bounding box
// instead of starting from top.
tightest.min() = ctr - searchSpan;
tightest.max() = ctr + searchSpan;
scalar leftDist = searchDim;
label leftI = leftTree.findNearest(ctr, tightest, leftDist);
pointIndexHit leftInfo = leftTree.findNearest(ctr, searchDimSqr);
if (rightI == -1)
{
// No face found in right tree.
if (leftI == -1)
{
// No face found in left tree.
nearestBFaceI[patchFaceI] = -1;
}
else
{
// Found in left but not in right. Choose left regardless if
// correct sign. Note: do we want this?
nearestBFaceI[patchFaceI] = leftFaces[leftI];
}
}
else
if (rightInfo.hit())
{
if (leftI == -1)
{
// Found in right but not in left. Choose right regardless if
// correct sign. Note: do we want this?
nearestBFaceI[patchFaceI] = rightFaces[rightI];
}
else
if (leftInfo.hit())
{
// Found in both trees. Compare normals.
label rightFaceI = rightFaces[rightInfo.index()];
label leftFaceI = leftFaces[leftInfo.index()];
label rightDist = mag(rightInfo.hitPoint()-ctr);
label leftDist = mag(leftInfo.hitPoint()-ctr);
scalar rightSign = n & ns[rightFaces[rightI]];
scalar leftSign = n & ns[leftFaces[leftI]];
scalar rightSign = n & ns[rightFaceI];
scalar leftSign = n & ns[leftFaceI];
if
(
......@@ -1036,11 +1029,11 @@ Foam::labelList Foam::boundaryMesh::getNearest
// Both same sign. Choose nearest.
if (rightDist < leftDist)
{
nearestBFaceI[patchFaceI] = rightFaces[rightI];
nearestBFaceI[patchFaceI] = rightFaceI;
}
else
{
nearestBFaceI[patchFaceI] = leftFaces[leftI];
nearestBFaceI[patchFaceI] = leftFaceI;
}
}
else
......@@ -1059,11 +1052,11 @@ Foam::labelList Foam::boundaryMesh::getNearest
// Different sign and nearby. Choosing matching normal
if (rightSign > 0)
{
nearestBFaceI[patchFaceI] = rightFaces[rightI];
nearestBFaceI[patchFaceI] = rightFaceI;
}
else
{
nearestBFaceI[patchFaceI] = leftFaces[leftI];
nearestBFaceI[patchFaceI] = leftFaceI;
}
}
else
......@@ -1071,15 +1064,38 @@ Foam::labelList Foam::boundaryMesh::getNearest
// Different sign but faraway. Choosing nearest.
if (rightDist < leftDist)
{
nearestBFaceI[patchFaceI] = rightFaces[rightI];
nearestBFaceI[patchFaceI] = rightFaceI;
}
else
{
nearestBFaceI[patchFaceI] = leftFaces[leftI];
nearestBFaceI[patchFaceI] = leftFaceI;
}
}
}
}
else
{
// Found in right but not in left. Choose right regardless if
// correct sign. Note: do we want this?
label rightFaceI = rightFaces[rightInfo.index()];
nearestBFaceI[patchFaceI] = rightFaceI;
}
}
else
{
// No face found in right tree.
if (leftInfo.hit())
{
// Found in left but not in right. Choose left regardless if
// correct sign. Note: do we want this?
nearestBFaceI[patchFaceI] = leftFaces[leftInfo.index()];
}
else
{
// No face found in left tree.
nearestBFaceI[patchFaceI] = -1;
}
}
}
......
......@@ -50,6 +50,7 @@ indexedOctree/treeDataCell.C
indexedOctree/treeDataEdge.C
indexedOctree/treeDataFace.C
indexedOctree/treeDataPoint.C
indexedOctree/treeDataPrimitivePatchName.C
indexedOctree/treeDataTriSurface.C
searchableSurface = searchableSurface
......
......@@ -23,26 +23,22 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::octreeDataFaceList
Foam::treeDataPrimitivePatch
Description
Holds data for octree to work on list of faces on a bMesh
(= PrimitivePatch which holds faces, not references them)
Same as octreeDataFace except for that.
Encapsulation of data needed to search on PrimitivePatches
SourceFiles
octreeDataFaceList.C
treeDataPrimitivePatch.C
\*---------------------------------------------------------------------------*/
#ifndef octreeDataFaceList_H
#define octreeDataFaceList_H
#ifndef treeDataPrimitivePatch_H
#define treeDataPrimitivePatch_H
#include "PrimitivePatch.H"
//#include "indexedOctree.H"
#include "treeBoundBoxList.H"
#include "faceList.H"
#include "point.H"
#include "className.H"
#include "bMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -50,97 +46,98 @@ namespace Foam
{
// Forward declaration of classes
template<class Type> class octree;
template<class Type> class indexedOctree;
/*---------------------------------------------------------------------------*\
Class octreeDataFaceList Declaration
Class treeDataPrimitivePatchName Declaration
\*---------------------------------------------------------------------------*/
class octreeDataFaceList
{
// Static data
TemplateName(treeDataPrimitivePatch);
//- tolerance on linear dimensions
static scalar tol;
/*---------------------------------------------------------------------------*\
Class treeDataPrimitivePatch Declaration
\*---------------------------------------------------------------------------*/
// Static function
static inline label nexti(label max, label i)
{
return (i + 1) % max;
}
template
<
class Face,
template<class> class FaceList,
class PointField,
class PointType=point
>
class treeDataPrimitivePatch
:
public treeDataPrimitivePatchName
{
// Static data
//- tolerance on linear dimensions
static scalar tolSqr;
// Private data
//- the mesh
const bMesh& mesh_;
//- Underlying geometry
const PrimitivePatch<Face, FaceList, PointField, PointType>& patch_;
//- labels (in mesh indexing) of faces
labelList faceLabels_;
//- Whether to precalculate and store face bounding box
const bool cacheBb_;
//- bbs for all above faces
treeBoundBoxList allBb_;
//- face bounding boxes (valid only if cacheBb_)
treeBoundBoxList bbs_;
// Private Member Functions
//- Set allBb to tight fitting bounding box
void calcBb();
//- Calculate face bounding box
static treeBoundBox calcBb(const pointField&, const face&);
public:
//- Initialise all member data
void update();
// Declare name of the class and its debug switch
ClassName("octreeDataFaceList");
public:
// Constructors
//- Construct from all faces in bMesh.
octreeDataFaceList(const bMesh& mesh);
//- Construct from selected faces in bMesh.
octreeDataFaceList(const bMesh& mesh, const labelList& faceLabels);
//- Construct as copy
octreeDataFaceList(const octreeDataFaceList&);
// Destructor
~octreeDataFaceList();
//- Construct from patch.
treeDataPrimitivePatch
(
const bool cacheBb,
const PrimitivePatch<Face, FaceList, PointField, PointType>&
);
// Member Functions
// Access
const bMesh& mesh() const
{
return mesh_;
}
const labelList& faceLabels() const
label size() const
{
return faceLabels_;
return patch_.size();
}
const treeBoundBoxList& allBb() const
{
return allBb_;
}
//- Get representative point cloud for all shapes inside
// (one point per shape)
pointField points() const;
label size() const
{
return allBb_.size();
}
// Search
//- Get type of sample
label getSampleType
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
label getVolumeType
(
const octree<octreeDataFaceList>&,
const indexedOctree
<
treeDataPrimitivePatch
<
Face,
FaceList,
PointField,
PointType
>
>&,
const point&
) const;
......@@ -151,60 +148,48 @@ public:
const treeBoundBox& sampleBb
) const;
//- Does shape at index contain sample
bool contains
(
const label index,
const point& sample
) const;
//- Segment (from start to end) intersection with shape
// at index. If intersects returns true and sets intersectionPoint
bool intersects
(
const label index,
const point& start,
const point& end,
point& intersectionPoint
) const;
//- Sets newTightest to bounding box (and returns true) if
// nearer to sample than tightest bounding box. Otherwise
// returns false.
bool findTightest
//- Calculates nearest (to sample) point in shape.
// Returns actual point and distance (squared)
void findNearest
(
const label index,
const labelList& indices,
const point& sample,
treeBoundBox& tightest
scalar& nearestDistSqr,
label& nearestIndex,
point& nearestPoint
) const;
//- Given index get unit normal and calculate (numerical) sign
// of sample.
// Used to determine accuracy of calcNearest or inside/outside.
scalar calcSign
//- Calculates nearest (to line) point in shape.
// Returns point and distance (squared)
void findNearest
(
const label index,
const point& sample,
vector& n
) const;
const labelList& indices,
const linePointRef& ln,
treeBoundBox& tightest,
label& minIndex,
point& linePoint,
point& nearestPoint
) const
{
notImplemented
(
"treeDataPrimitivePatch::findNearest"
"(const labelList&, const linePointRef&, ..)"
);
}
//- Calculates nearest (to sample) point in shape.
// Returns point and mag(nearest - sample). Returns GREAT if
// sample does not project onto (triangle decomposition) of face.
scalar calcNearest
//- Calculate intersection of shape with ray. Sets result
// accordingly
bool intersects
(
const label index,
const point& sample,
point& nearest
const point& start,
const point& end,
point& result
) const;
// Edit
// Write
//- Write shape at index
void write(Ostream& os, const label index) const;
};
......@@ -214,6 +199,11 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "treeDataPrimitivePatch.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "treeDataPrimitivePatch.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::treeDataPrimitivePatchName, 0);
// ************************************************************************* //
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment