Commit c2d3bab0 authored by laurence's avatar laurence
Browse files

ENH: Merge searchableSurface and indexedOctree volumeType

parent bfd30ea0
......@@ -31,6 +31,7 @@ Description
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "triSurfaceSearch.H"
#include "argList.H"
#include "OFstream.H"
#include "IFstream.H"
......@@ -40,6 +41,7 @@ Description
#include "indexedOctree.H"
#include "treeDataTriSurface.H"
#include "Random.H"
#include "volumeType.H"
using namespace Foam;
......@@ -242,26 +244,16 @@ int main(int argc, char *argv[])
// Read surface to select on
triSurface selectSurf(surfName);
// bb of surface
treeBoundBox bb(selectSurf.localPoints());
// Random number generator
Random rndGen(354543);
// search engine
indexedOctree<treeDataTriSurface> selectTree
triSurfaceSearch searchSelectSurf
(
treeDataTriSurface
(
selectSurf,
indexedOctree<treeDataTriSurface>::perturbTol()
),
bb.extend(rndGen, 1e-4), // slightly randomize bb
8, // maxLevel
10, // leafsize
3.0 // duplicity
selectSurf,
indexedOctree<treeDataTriSurface>::perturbTol(),
8
);
const indexedOctree<treeDataTriSurface>& selectTree =
searchSelectSurf.tree();
// Check if face (centre) is in outside or inside.
forAll(facesToSubset, faceI)
{
......@@ -269,14 +261,13 @@ int main(int argc, char *argv[])
{
const point fc(surf1[faceI].centre(surf1.points()));
indexedOctree<treeDataTriSurface>::volumeType t =
selectTree.getVolumeType(fc);
volumeType t = selectTree.getVolumeType(fc);
if
(
outside
? (t == indexedOctree<treeDataTriSurface>::OUTSIDE)
: (t == indexedOctree<treeDataTriSurface>::INSIDE)
? (t == volumeType::OUTSIDE)
: (t == volumeType::INSIDE)
)
{
facesToSubset[faceI] = true;
......
......@@ -605,6 +605,7 @@ $(interpolationWeights)/splineInterpolationWeights/splineInterpolationWeights.C
algorithms/indexedOctree/indexedOctreeName.C
algorithms/indexedOctree/treeDataCell.C
algorithms/indexedOctree/volumeType.C
algorithms/dynamicIndexedOctree/dynamicIndexedOctreeName.C
......
......@@ -334,15 +334,14 @@ void Foam::dynamicIndexedOctree<Type>::recursiveSubDivision
// Recurses to determine status of lowest level boxes. Level above is
// combination of octants below.
template<class Type>
typename Foam::dynamicIndexedOctree<Type>::volumeType
Foam::dynamicIndexedOctree<Type>::calcVolumeType
Foam::volumeType Foam::dynamicIndexedOctree<Type>::calcVolumeType
(
const label nodeI
) const
{
const node& nod = nodes_[nodeI];
volumeType myType = UNKNOWN;
volumeType myType = volumeType::UNKNOWN;
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
{
......@@ -359,7 +358,7 @@ Foam::dynamicIndexedOctree<Type>::calcVolumeType
{
// Contents. Depending on position in box might be on either
// side.
subType = MIXED;
subType = volumeType::MIXED;
}
else
{
......@@ -378,13 +377,13 @@ Foam::dynamicIndexedOctree<Type>::calcVolumeType
// Combine sub node types into type for treeNode. Result is 'mixed' if
// types differ among subnodes.
if (myType == UNKNOWN)
if (myType == volumeType::UNKNOWN)
{
myType = subType;
}
else if (subType != myType)
{
myType = MIXED;
myType = volumeType::MIXED;
}
}
return myType;
......@@ -392,8 +391,7 @@ Foam::dynamicIndexedOctree<Type>::calcVolumeType
template<class Type>
typename Foam::dynamicIndexedOctree<Type>::volumeType
Foam::dynamicIndexedOctree<Type>::getVolumeType
Foam::volumeType Foam::dynamicIndexedOctree<Type>::getVolumeType
(
const label nodeI,
const point& sample
......@@ -403,22 +401,22 @@ Foam::dynamicIndexedOctree<Type>::getVolumeType
direction octant = nod.bb_.subOctant(sample);
volumeType octantType = volumeType(nodeTypes_.get((nodeI<<3)+octant));
volumeType octantType = volumeType::type(nodeTypes_.get((nodeI<<3)+octant));
if (octantType == INSIDE)
if (octantType == volumeType::INSIDE)
{
return octantType;
}
else if (octantType == OUTSIDE)
else if (octantType == volumeType::OUTSIDE)
{
return octantType;
}
else if (octantType == UNKNOWN)
else if (octantType == volumeType::UNKNOWN)
{
// Can happen for e.g. non-manifold surfaces.
return octantType;
}
else if (octantType == MIXED)
else if (octantType == volumeType::MIXED)
{
labelBits index = nod.subNodes_[octant];
......@@ -447,7 +445,7 @@ Foam::dynamicIndexedOctree<Type>::getVolumeType
<< "Empty subnode has invalid volume type MIXED."
<< abort(FatalError);
return UNKNOWN;
return volumeType::UNKNOWN;
}
}
else
......@@ -462,14 +460,13 @@ Foam::dynamicIndexedOctree<Type>::getVolumeType
<< "Node has invalid volume type " << octantType
<< abort(FatalError);
return UNKNOWN;
return volumeType::UNKNOWN;
}
}
template<class Type>
typename Foam::dynamicIndexedOctree<Type>::volumeType
Foam::dynamicIndexedOctree<Type>::getSide
Foam::volumeType Foam::dynamicIndexedOctree<Type>::getSide
(
const vector& outsideNormal,
const vector& vec
......@@ -477,11 +474,11 @@ Foam::dynamicIndexedOctree<Type>::getSide
{
if ((outsideNormal&vec) >= 0)
{
return OUTSIDE;
return volumeType::OUTSIDE;
}
else
{
return INSIDE;
return volumeType::INSIDE;
}
}
......@@ -2582,15 +2579,14 @@ const Foam::labelList& Foam::dynamicIndexedOctree<Type>::findIndices
// Determine type (inside/outside/mixed) per node.
template<class Type>
typename Foam::dynamicIndexedOctree<Type>::volumeType
Foam::dynamicIndexedOctree<Type>::getVolumeType
Foam::volumeType Foam::dynamicIndexedOctree<Type>::getVolumeType
(
const point& sample
) const
{
if (nodes_.empty())
{
return UNKNOWN;
return volumeType::UNKNOWN;
}
if (nodeTypes_.size() != 8*nodes_.size())
......@@ -2598,7 +2594,7 @@ Foam::dynamicIndexedOctree<Type>::getVolumeType
// Calculate type for every octant of node.
nodeTypes_.setSize(8*nodes_.size());
nodeTypes_ = UNKNOWN;
nodeTypes_ = volumeType::UNKNOWN;
calcVolumeType(0);
......@@ -2611,21 +2607,21 @@ Foam::dynamicIndexedOctree<Type>::getVolumeType
forAll(nodeTypes_, i)
{
volumeType type = volumeType(nodeTypes_.get(i));
volumeType type = volumeType::type(nodeTypes_.get(i));
if (type == UNKNOWN)
if (type == volumeType::UNKNOWN)
{
nUNKNOWN++;
}
else if (type == MIXED)
else if (type == volumeType::MIXED)
{
nMIXED++;
}
else if (type == INSIDE)
else if (type == volumeType::INSIDE)
{
nINSIDE++;
}
else if (type == OUTSIDE)
else if (type == volumeType::OUTSIDE)
{
nOUTSIDE++;
}
......
......@@ -43,6 +43,7 @@ SourceFiles
#include "HashSet.H"
#include "labelBits.H"
#include "PackedList.H"
#include "volumeType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -83,16 +84,6 @@ public:
// Data types
//- volume types
enum volumeType
{
UNKNOWN = 0,
MIXED = 1,
INSIDE = 2,
OUTSIDE = 3
};
//- Tree node. Has up pointer and down pointers.
class node
{
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -57,13 +57,13 @@ Foam::dynamicTreeDataPoint::shapePoints() const
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
Foam::label Foam::dynamicTreeDataPoint::getVolumeType
Foam::volumeType Foam::dynamicTreeDataPoint::getVolumeType
(
const dynamicIndexedOctree<dynamicTreeDataPoint>& oc,
const point& sample
) const
{
return dynamicIndexedOctree<dynamicTreeDataPoint>::UNKNOWN;
return volumeType::UNKNOWN;
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -43,6 +43,7 @@ SourceFiles
#include "pointField.H"
#include "treeBoundBox.H"
#include "linePointRef.H"
#include "volumeType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -92,7 +93,7 @@ public:
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
label getVolumeType
volumeType getVolumeType
(
const dynamicIndexedOctree<dynamicTreeDataPoint>&,
const point&
......
......@@ -356,15 +356,14 @@ Foam::label Foam::indexedOctree<Type>::compactContents
// Recurses to determine status of lowest level boxes. Level above is
// combination of octants below.
template<class Type>
typename Foam::indexedOctree<Type>::volumeType
Foam::indexedOctree<Type>::calcVolumeType
Foam::volumeType Foam::indexedOctree<Type>::calcVolumeType
(
const label nodeI
) const
{
const node& nod = nodes_[nodeI];
volumeType myType = UNKNOWN;
volumeType myType = volumeType::UNKNOWN;
for (direction octant = 0; octant < nod.subNodes_.size(); octant++)
{
......@@ -381,7 +380,7 @@ Foam::indexedOctree<Type>::calcVolumeType
{
// Contents. Depending on position in box might be on either
// side.
subType = MIXED;
subType = volumeType::MIXED;
}
else
{
......@@ -389,10 +388,7 @@ Foam::indexedOctree<Type>::calcVolumeType
// of its bounding box.
const treeBoundBox subBb = nod.bb_.subBbox(octant);
subType = volumeType
(
shapes_.getVolumeType(*this, subBb.midpoint())
);
subType = shapes_.getVolumeType(*this, subBb.midpoint());
}
// Store octant type
......@@ -400,13 +396,13 @@ Foam::indexedOctree<Type>::calcVolumeType
// Combine sub node types into type for treeNode. Result is 'mixed' if
// types differ among subnodes.
if (myType == UNKNOWN)
if (myType == volumeType::UNKNOWN)
{
myType = subType;
}
else if (subType != myType)
{
myType = MIXED;
myType = volumeType::MIXED;
}
}
return myType;
......@@ -414,8 +410,7 @@ Foam::indexedOctree<Type>::calcVolumeType
template<class Type>
typename Foam::indexedOctree<Type>::volumeType
Foam::indexedOctree<Type>::getVolumeType
Foam::volumeType Foam::indexedOctree<Type>::getVolumeType
(
const label nodeI,
const point& sample
......@@ -425,22 +420,22 @@ Foam::indexedOctree<Type>::getVolumeType
direction octant = nod.bb_.subOctant(sample);
volumeType octantType = volumeType(nodeTypes_.get((nodeI<<3)+octant));
volumeType octantType = volumeType::type(nodeTypes_.get((nodeI<<3)+octant));
if (octantType == INSIDE)
if (octantType == volumeType::INSIDE)
{
return octantType;
}
else if (octantType == OUTSIDE)
else if (octantType == volumeType::OUTSIDE)
{
return octantType;
}
else if (octantType == UNKNOWN)
else if (octantType == volumeType::UNKNOWN)
{
// Can happen for e.g. non-manifold surfaces.
return octantType;
}
else if (octantType == MIXED)
else if (octantType == volumeType::MIXED)
{
labelBits index = nod.subNodes_[octant];
......@@ -469,7 +464,7 @@ Foam::indexedOctree<Type>::getVolumeType
<< "Empty subnode has invalid volume type MIXED."
<< abort(FatalError);
return UNKNOWN;
return volumeType::UNKNOWN;
}
}
else
......@@ -484,14 +479,13 @@ Foam::indexedOctree<Type>::getVolumeType
<< "Node has invalid volume type " << octantType
<< abort(FatalError);
return UNKNOWN;
return volumeType::UNKNOWN;
}
}
template<class Type>
typename Foam::indexedOctree<Type>::volumeType
Foam::indexedOctree<Type>::getSide
Foam::volumeType Foam::indexedOctree<Type>::getSide
(
const vector& outsideNormal,
const vector& vec
......@@ -499,11 +493,11 @@ Foam::indexedOctree<Type>::getSide
{
if ((outsideNormal&vec) >= 0)
{
return OUTSIDE;
return volumeType::OUTSIDE;
}
else
{
return INSIDE;
return volumeType::INSIDE;
}
}
......@@ -2972,23 +2966,29 @@ const Foam::labelList& Foam::indexedOctree<Type>::findIndices
// Determine type (inside/outside/mixed) per node.
template<class Type>
typename Foam::indexedOctree<Type>::volumeType
Foam::indexedOctree<Type>::getVolumeType
Foam::volumeType Foam::indexedOctree<Type>::getVolumeType
(
const point& sample
) const
{
if (nodes_.empty())
{
return UNKNOWN;
return volumeType::UNKNOWN;
}
// // If the sample is not within the octree, then have to query shapes
// // directly
// if (!nodes_[0].bb_.contains(sample))
// {
// return volumeType(shapes_.getVolumeType(*this, sample));
// }
if (nodeTypes_.size() != 8*nodes_.size())
{
// Calculate type for every octant of node.
nodeTypes_.setSize(8*nodes_.size());
nodeTypes_ = UNKNOWN;
nodeTypes_ = volumeType::UNKNOWN;
calcVolumeType(0);
......@@ -3001,21 +3001,21 @@ Foam::indexedOctree<Type>::getVolumeType
forAll(nodeTypes_, i)
{
volumeType type = volumeType(nodeTypes_.get(i));
volumeType type = volumeType::type(nodeTypes_.get(i));
if (type == UNKNOWN)
if (type == volumeType::UNKNOWN)
{
nUNKNOWN++;
}
else if (type == MIXED)
else if (type == volumeType::MIXED)
{
nMIXED++;
}
else if (type == INSIDE)
else if (type == volumeType::INSIDE)
{
nINSIDE++;
}
else if (type == OUTSIDE)
else if (type == volumeType::OUTSIDE)
{
nOUTSIDE++;
}
......
......@@ -42,6 +42,7 @@ SourceFiles
#include "HashSet.H"
#include "labelBits.H"
#include "PackedList.H"
#include "volumeType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -74,16 +75,6 @@ public:
// Data types
//- volume types
enum volumeType
{
UNKNOWN = 0,
MIXED = 1,
INSIDE = 2,
OUTSIDE = 3
};
//- Tree node. Has up pointer and down pointers.
class node
{
......
......@@ -38,6 +38,7 @@ SourceFiles
#include "polyMesh.H"
#include "treeBoundBoxList.H"
#include "volumeType.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -196,7 +197,7 @@ public:
//- Get type (inside,outside,mixed,unknown) of point w.r.t. surface.
// Only makes sense for closed surfaces.
label getVolumeType
volumeType getVolumeType
(
const indexedOctree<treeDataCell>&,
const point&
......@@ -207,7 +208,7 @@ public:
"treeDataCell::getVolumeType"
"(const indexedOctree<treeDataCell>&, const point&)"
);
return -1;
return volumeType::UNKNOWN;
}
//- Does (bb of) shape at index overlap bb
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "volumeType.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
template<>
const char* Foam::NamedEnum
<
Foam::volumeType,
4
>::names[] =
{
"unknown",
"mixed",
"inside",
"outside"
};
}
const Foam::NamedEnum<Foam::volumeType, 4> Foam::volumeType::names;