ChastePoint.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 
00030 #ifndef _CHASTEPOINT_HPP_
00031 #define _CHASTEPOINT_HPP_
00032 
00033 #include "ChasteSerialization.hpp"
00034 #include "UblasVectorInclude.hpp"
00035 #include <vector>
00036 
00037 
00041 template<unsigned DIM>
00042 class ChastePoint
00043 {
00045     friend class boost::serialization::access;
00052     template<class Archive>
00053     void serialize(Archive & archive, const unsigned int version)
00054     {
00055         //archive & mLocation; //earlier versions of boost are unable to do this. See #1709
00056     }
00057 
00058 private:
00059 
00061     c_vector<double, DIM> mLocation;
00062 
00063 public:
00064 
00079     ChastePoint(double v1=0, double v2=0, double v3=0);
00080 
00088     ChastePoint(std::vector<double> coords);
00089 
00095     ChastePoint(c_vector<double, DIM> location);
00096 
00100     c_vector<double, DIM>& rGetLocation();
00101 
00107     double operator[] (unsigned i) const;
00108 
00114     double GetWithDefault(unsigned i, double def=0.0) const;
00115 
00122     void SetCoordinate(unsigned i, double value);
00123 
00130     bool IsSamePoint(const ChastePoint<DIM>& rPoint) const;
00131 };
00132 
00133 
00134 #include "SerializationExportWrapper.hpp"
00135 // Declare identifier for the serializer
00136 EXPORT_TEMPLATE_CLASS_SAME_DIMS(ChastePoint)
00137 
00138 namespace boost
00139 {
00140 namespace serialization
00141 {
00142 
00143 template<class Archive, unsigned SPACE_DIM>
00144 inline void save_construct_data(
00145     Archive & ar, const ChastePoint<SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00146 {
00147     for (unsigned i = 0; i < SPACE_DIM; i ++)
00148     {
00149         //we archive coordinates of mLocation one by one
00150         //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
00151         double coord = t->GetWithDefault(i);
00152         ar & coord;
00153     }
00154 }
00155 
00160 template<class Archive,unsigned SPACE_DIM>
00161 inline void load_construct_data(
00162     Archive & ar, ChastePoint<SPACE_DIM> * t, const unsigned int file_version)
00163 {
00164     std::vector<double> coords;
00165     coords.resize(SPACE_DIM);
00166     for (unsigned i=0; i<SPACE_DIM; i++)
00167     {
00168         double coordinate;
00169         ar & coordinate;//resume coordinates one by one
00170         coords[i] = coordinate;
00171     }
00172     //use constructor with standard vectors to re-build the object
00173      ::new(t)ChastePoint<SPACE_DIM>(coords);
00174 }
00175 }
00176 } // namespace ...
00177 
00178 
00184 template<>
00185 class ChastePoint<0>
00186 {
00187 public:
00196     ChastePoint(double v1=0, double v2=0, double v3=0);
00197 
00204     double operator[] (unsigned i) const;
00205 };
00206 
00207 #endif //_CHASTEPOINT_HPP_
Generated on Thu Dec 22 13:00:16 2011 for Chaste by  doxygen 1.6.3