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 
00036 #include <vector>
00037 
00038 #include "Exception.hpp"
00039 
00043 template<unsigned DIM>
00044 class ChastePoint
00045 {
00047     friend class boost::serialization::access;
00054     template<class Archive>
00055     void serialize(Archive & archive, const unsigned int version)
00056     {
00057         //archive & mLocation; //earlier versions of boost are unable to do this. See #1709
00058     }
00059     
00060 private:
00061 
00063     c_vector<double, DIM> mLocation;
00064 
00065 public:
00066 
00081     ChastePoint(double v1=0, double v2=0, double v3=0);
00082 
00090     ChastePoint(std::vector<double> coords);
00091 
00097     ChastePoint(c_vector<double, DIM> location);
00098 
00102     c_vector<double, DIM>& rGetLocation();
00103 
00109     double operator[] (unsigned i) const;
00110     
00116     double GetWithDefault(unsigned i, double def=0.0) const;
00117 
00124     void SetCoordinate(unsigned i, double value);
00125 
00132     bool IsSamePoint(const ChastePoint<DIM>& rPoint) const;
00133 };
00134 
00135 
00136 #include "SerializationExportWrapper.hpp"
00137 // Declare identifier for the serializer
00138 EXPORT_TEMPLATE_CLASS_SAME_DIMS(ChastePoint)
00139 
00140 namespace boost
00141 {
00142 namespace serialization
00143 {
00144 
00145 template<class Archive, unsigned SPACE_DIM>
00146 inline void save_construct_data(
00147     Archive & ar, const ChastePoint<SPACE_DIM> * t, const BOOST_PFTO unsigned int file_version)
00148 {
00149     for (unsigned i = 0; i < SPACE_DIM; i ++)
00150     {
00151         //we archive coordinates of mLocation one by one
00152         //this is because earlier version of boost (<1.40, I think) cannot archive c_vectors
00153         double coord = t->GetWithDefault(i);
00154         ar & coord;
00155     }
00156 }
00157 
00162 template<class Archive,unsigned SPACE_DIM>
00163 inline void load_construct_data(
00164     Archive & ar, ChastePoint<SPACE_DIM> * t, const unsigned int file_version)
00165 {
00166     std::vector<double> coords;
00167     coords.resize(SPACE_DIM);
00168     for (unsigned i = 0 ; i < SPACE_DIM; i ++)
00169     {
00170         double coordinate;
00171         ar & coordinate;//resume coordinates one by one
00172         coords[i] = coordinate;
00173     }
00174     //use constructor with standard vectors to re-build the object
00175      ::new(t)ChastePoint<SPACE_DIM>(coords);
00176 }
00177 }
00178 } // namespace ...
00179 
00183 template<>
00184 class ChastePoint<0>
00185 {
00186 public:
00187 
00196     ChastePoint(double v1=0, double v2=0, double v3=0)
00197     {
00198     }
00199 
00205     double operator[] (unsigned i) const
00206     {
00207         EXCEPTION("Zero-dimensional point has no data");
00208     }
00209 };
00210 
00211 
00212 #endif //_CHASTEPOINT_HPP_

Generated on Mon Apr 18 11:35:35 2011 for Chaste by  doxygen 1.5.5