Back to index

salome-med  6.5.0
PointLocator.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MEDNormalizedUnstructuredMesh.txx"
00021 #include "MEDMEM_Mesh.hxx"
00022 #include "MEDMEM_Exception.hxx"
00023 #include "PointLocatorAlgos.txx"
00024 #include "PointLocator.hxx"
00025 
00026 #include <list>
00027 
00028 MEDMEM::PointLocator::PointLocator(const MEDMEM::MESH& mesh)
00029 {
00030   int meshdim=mesh.getMeshDimension();
00031   int spacedim=mesh.getSpaceDimension();
00032   if (meshdim != spacedim) throw MEDMEM::MEDEXCEPTION("Locator is not implemented for meshdim != spacedim");
00033   switch (meshdim)
00034       {
00035       case 2:
00036         _medmesh = new MEDNormalizedUnstructuredMesh<2,2> (&mesh);
00037         _point_locator=new INTERP_KERNEL::PointLocatorAlgos<MEDNormalizedUnstructuredMesh<2,2> >(*(static_cast<MEDNormalizedUnstructuredMesh<2,2>* >(_medmesh)));
00038         break;
00039       case 3:
00040         _medmesh = new MEDNormalizedUnstructuredMesh<3,3> (&mesh);
00041         _point_locator=new INTERP_KERNEL::PointLocatorAlgos<MEDNormalizedUnstructuredMesh<3,3> >(*(static_cast<MEDNormalizedUnstructuredMesh<3,3>* >(_medmesh)));
00042         break;
00043       }
00044 }
00045 
00046 MEDMEM::PointLocator::~PointLocator()
00047 {
00048   delete _medmesh;
00049   delete _point_locator;
00050 }
00051 
00052 std::list<int> MEDMEM::PointLocator::locate(const double* x)
00053 {
00054   return _point_locator->locates(x,1e-12);
00055 }
00056 
00057 MEDMEM::PointLocatorInSimplex::PointLocatorInSimplex(const MEDMEM::MESH& mesh)
00058 {
00059   int meshdim=mesh.getMeshDimension();
00060   int spacedim=mesh.getSpaceDimension();
00061   if (meshdim != spacedim) throw MEDMEM::MEDEXCEPTION("Locator is not implemented for meshdim != spacedim");
00062   switch (meshdim)
00063       {
00064       case 2:
00065         _medmesh = new MEDNormalizedUnstructuredMesh<2,2> (&mesh);
00066         _point_locator=new INTERP_KERNEL::PointLocatorInSimplex<MEDNormalizedUnstructuredMesh<2,2> >(*(static_cast<MEDNormalizedUnstructuredMesh<2,2>* >(_medmesh)));
00067         break;
00068       case 3:
00069         _medmesh = new MEDNormalizedUnstructuredMesh<3,3> (&mesh);
00070         _point_locator=new INTERP_KERNEL::PointLocatorInSimplex<MEDNormalizedUnstructuredMesh<3,3> >(*(static_cast<MEDNormalizedUnstructuredMesh<3,3>* >(_medmesh)));
00071         break;
00072       }
00073 }
00074 
00075 void MEDMEM::PointLocatorInSimplex::getNodeWightsInSimplex( const std::vector<const double*>& nodes,
00076                                                             const double* p, double* weghts )
00077 {
00078   INTERP_KERNEL::barycentric_coords( nodes, p, weghts );
00079 }