$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

boundaryShapes3D.hh

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #ifndef BOUNDARY_SHAPES_3D_HH
00026 #define BOUNDARY_SHAPES_3D_HH
00027 
00028 #include <limits>
00029 #include "offLattice/boundaryShapes3D.h"
00030 
00031 namespace plb {
00032 
00033 template<typename T, class SurfaceData>
00034 BoundaryShapeIntersection3D<T,SurfaceData>::BoundaryShapeIntersection3D()
00035 { }
00036 
00037 template<typename T, class SurfaceData>
00038 BoundaryShapeIntersection3D<T,SurfaceData>::BoundaryShapeIntersection3D (
00039         BoundaryShapeIntersection3D<T,SurfaceData> const& rhs )
00040 {
00041     components.resize(rhs.components.size());
00042     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00043         components[iComponent] = rhs.components[iComponent]->clone();
00044     }
00045 }
00046 
00047 template<typename T, class SurfaceData>
00048 BoundaryShapeIntersection3D<T,SurfaceData>&
00049     BoundaryShapeIntersection3D<T,SurfaceData>::operator=(BoundaryShapeIntersection3D<T,SurfaceData> const& rhs)
00050 {
00051     BoundaryShapeIntersection3D<T,SurfaceData>(rhs).swap(*this);
00052     return *this;
00053 }
00054 
00055 template<typename T, class SurfaceData>
00056 BoundaryShapeIntersection3D<T,SurfaceData>::~BoundaryShapeIntersection3D() {
00057     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00058         delete components[iComponent];
00059     }
00060 }
00061 
00062 template<typename T, class SurfaceData>
00063 void BoundaryShapeIntersection3D<T,SurfaceData>::swap(BoundaryShapeIntersection3D<T,SurfaceData>& rhs) {
00064     components.swap(rhs.components);
00065 }
00066 
00067 template<typename T, class SurfaceData>
00068 void BoundaryShapeIntersection3D<T,SurfaceData>::addComponent(BoundaryShape3D<T,SurfaceData>* component)
00069 {
00070     components.push_back(component);
00071 }
00072 
00073 template<typename T, class SurfaceData>
00074 bool BoundaryShapeIntersection3D<T,SurfaceData>::isInside(Array<T,3> const& location) const {
00075     bool isInside = true;
00076     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00077         if (! components[iComponent]->isInside(location) ) {
00078             isInside = false;
00079         }
00080     }
00081     return isInside;
00082 }
00083 
00084 template<typename T, class SurfaceData>
00085 bool BoundaryShapeIntersection3D<T,SurfaceData>::isInside(Array<T,3> const& location, T epsilon) const
00086 {
00087     bool isInside = true;
00088     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00089         if (! components[iComponent]->isInside(location,epsilon) ) {
00090             isInside = false;
00091         }
00092     }
00093     return isInside;
00094 }
00095 
00096 template<typename T, class SurfaceData>
00097 bool BoundaryShapeIntersection3D<T,SurfaceData>::pointOnSurface (
00098         Array<T,3> const& fromPoint, Array<T,3> const& direction,
00099         Array<T,3>& locatedPoint, T& distance,
00100         Array<T,3>& wallNormal, SurfaceData& surfaceData,
00101         OffBoundary::Type& bdType, plint& id ) const
00102 {
00103     bool doesIntersect = false;
00104     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00105         Array<T,3> positionOnWall;
00106         T newDistance;
00107         Array<T,3> newWallNormal;
00108         SurfaceData newSurfaceData;
00109         OffBoundary::Type newBdType;
00110         if( components[iComponent]->pointOnSurface (
00111                 fromPoint, direction,
00112                 positionOnWall, newDistance, newWallNormal,
00113                 newSurfaceData, newBdType, id ) )
00114         {
00115             if (!doesIntersect || (doesIntersect && newDistance<distance) ) {
00116                 locatedPoint = positionOnWall;
00117                 distance = newDistance;
00118                 wallNormal = newWallNormal;
00119                 surfaceData = newSurfaceData;
00120                 bdType = newBdType;
00121             }
00122             doesIntersect = true;
00123         }
00124     }
00125     return doesIntersect;
00126 }
00127 
00128 template<typename T, class SurfaceData>
00129 bool BoundaryShapeIntersection3D<T,SurfaceData>::intersectsSurface (
00130         Array<T,3> const& p1, Array<T,3> const& p2, plint& id ) const
00131 {
00132     bool doesIntersect = false;
00133     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00134         Array<T,3> positionOnWall;
00135         T newDistance;
00136         Array<T,3> newWallNormal;
00137         SurfaceData newSurfaceData;
00138         OffBoundary::Type newBdType;
00139         if( components[iComponent]->pointOnSurface (
00140                 p1, p2-p1, positionOnWall, newDistance, newWallNormal,
00141                 newSurfaceData, newBdType, id ) )
00142         {
00143             doesIntersect = true;
00144         }
00145     }
00146     return doesIntersect;
00147 }
00148 
00149 template<typename T, class SurfaceData>
00150 bool BoundaryShapeIntersection3D<T,SurfaceData>::distanceToSurface (
00151         Array<T,3> const& point, T& distance, bool& isBehind ) const
00152 {
00153     bool surfaceFound = false;
00154     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00155         T newDistance;
00156         bool newIsBehind;
00157         if( components[iComponent]->distanceToSurface (
00158                 point, newDistance, newIsBehind ) )
00159         {
00160             if (!surfaceFound || (surfaceFound && newDistance<distance) ) {
00161                 distance = newDistance;
00162                 isBehind = newIsBehind;
00163             }
00164             surfaceFound = true;
00165         }
00166     }
00167     return surfaceFound;
00168 }
00169 
00170 template<typename T, class SurfaceData>
00171 plint BoundaryShapeIntersection3D<T,SurfaceData>::getTag(plint id) const
00172 {
00173     for (pluint iComponent=0; iComponent<components.size(); ++iComponent) {
00174         plint tag = components[iComponent]->getTag(id);
00175         if (tag>=0) {
00176             return tag;
00177         }
00178     }
00179     return -1;
00180 }
00181 
00182 template<typename T, class SurfaceData>
00183 BoundaryShapeIntersection3D<T,SurfaceData>* BoundaryShapeIntersection3D<T,SurfaceData>::clone() const
00184 {
00185     return new BoundaryShapeIntersection3D<T,SurfaceData>(*this);
00186 }
00187 
00188 }  // namespace plb
00189 
00190 #endif  // BOUNDARY_SHAPES_3D_H