Back to index

salome-med  6.5.0
MED_CoordUtils.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : 
00024 //  Author : 
00025 //  Module : 
00026 //  $Header: /home/server/cvs/MED/MED_SRC/src/MEDWrapper/Base/MED_CoordUtils.cxx,v 1.6.2.1.6.2.10.1 2012-04-13 08:48:43 vsr Exp $
00027 //
00028 #include "MED_CoordUtils.hxx"
00029 #include "MED_Utilities.hxx"
00030  
00031 namespace MED
00032 {
00033 
00034   enum ECoordName{eX, eY, eZ, eNone};
00035 
00036   template<ECoordName TCoordId>
00037   TFloat 
00038   GetCoord(const TCCoordSlice& theCoordSlice)
00039   {
00040     return theCoordSlice[TCoordId];
00041   }
00042 
00043   template<>
00044   TFloat 
00045   GetCoord<eNone>(const TCCoordSlice& theCoordSlice)
00046   {
00047     return 0.0;
00048   }
00049   
00050   TGetCoord
00051   aXYZGetCoord[3] = {
00052     &GetCoord<eX>, 
00053     &GetCoord<eY>, 
00054     &GetCoord<eZ>
00055   };
00056   
00057   TGetCoord
00058   aXYGetCoord[3] = {
00059     &GetCoord<eX>, 
00060     &GetCoord<eY>, 
00061     &GetCoord<eNone>
00062   };
00063   
00064   TGetCoord
00065   aYZGetCoord[3] = {
00066     &GetCoord<eNone>,
00067     &GetCoord<eX>, 
00068     &GetCoord<eY>
00069   };
00070   
00071   TGetCoord 
00072   aXZGetCoord[3] = {
00073     &GetCoord<eX>, 
00074     &GetCoord<eNone>,
00075     &GetCoord<eY>
00076   };
00077   
00078   
00079   TGetCoord 
00080   aXGetCoord[3] = {
00081     &GetCoord<eX>, 
00082     &GetCoord<eNone>,
00083     &GetCoord<eNone>
00084   };
00085   
00086   TGetCoord
00087   aYGetCoord[3] = {
00088     &GetCoord<eNone>,
00089     &GetCoord<eX>, 
00090     &GetCoord<eNone>
00091   };
00092 
00093   TGetCoord
00094   aZGetCoord[3] = {
00095     &GetCoord<eNone>,
00096     &GetCoord<eNone>,
00097     &GetCoord<eX>
00098   };
00099 
00100   
00101   //---------------------------------------------------------------
00102   TCoordHelper
00103   ::TCoordHelper(TGetCoord* theGetCoord):
00104     myGetCoord(theGetCoord)
00105   {}
00106 
00107   TFloat 
00108   TCoordHelper
00109   ::GetCoord(TCCoordSlice& theCoordSlice, 
00110              TInt theCoordId)
00111   {
00112     return (*myGetCoord[theCoordId])(theCoordSlice);
00113   }
00114 
00115 
00116   //---------------------------------------------------------------
00117   PCoordHelper
00118   GetCoordHelper(PNodeInfo theNodeInfo)
00119   {
00120     PCoordHelper aCoordHelper;
00121     {
00122       PMeshInfo aMeshInfo = theNodeInfo->GetMeshInfo();
00123       TInt aMeshDimension = aMeshInfo->GetDim();
00124       bool anIsDimPresent[3] = {false, false, false};
00125       for(int iDim = 0; iDim < aMeshDimension; iDim++){
00126         // PAL16857(SMESH not conform to the MED convention) ->
00127         // 1D - always along X
00128         // 2D - always in XOY plane
00129         anIsDimPresent[iDim] = iDim < aMeshDimension;
00130 //      std::string aName = theNodeInfo->GetCoordName(iDim);
00131 //         if ( aName.size() > 1 ) // PAL12148, aName has size 8 or 16
00132 //           aName = aName.substr(0,1);
00133 //      if(aName == "x" || aName == "X")
00134 //        anIsDimPresent[eX] = true;
00135 //      else if(aName == "y" || aName == "Y")
00136 //        anIsDimPresent[eY] = true;
00137 //      else if(aName == "z" || aName == "Z")
00138 //        anIsDimPresent[eZ] = true;
00139       }
00140 
00141       switch(aMeshDimension){
00142       case 3:
00143         aCoordHelper.reset(new TCoordHelper(aXYZGetCoord));
00144         break;
00145       case 2:
00146         if(anIsDimPresent[eY] && anIsDimPresent[eZ])
00147           aCoordHelper.reset(new TCoordHelper(aYZGetCoord));
00148         else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
00149           aCoordHelper.reset(new TCoordHelper(aXZGetCoord));
00150         else
00151           aCoordHelper.reset(new TCoordHelper(aXYGetCoord));
00152         break;
00153       case 1:
00154         if(anIsDimPresent[eY])
00155           aCoordHelper.reset(new TCoordHelper(aYGetCoord));
00156         else if(anIsDimPresent[eZ])
00157           aCoordHelper.reset(new TCoordHelper(aZGetCoord));
00158         else
00159           aCoordHelper.reset(new TCoordHelper(aXGetCoord));
00160         break;
00161       }
00162     }
00163     return aCoordHelper;
00164   }
00165 }