Chaste  Release::3.4
ChastePoint.cpp
1 /*
2 
3 Copyright (c) 2005-2016, University of Oxford.
4 All rights reserved.
5 
6 University of Oxford means the Chancellor, Masters and Scholars of the
7 University of Oxford, having an administrative office at Wellington
8 Square, Oxford OX1 2JD, UK.
9 
10 This file is part of Chaste.
11 
12 Redistribution and use in source and binary forms, with or without
13 modification, are permitted provided that the following conditions are met:
14  * Redistributions of source code must retain the above copyright notice,
15  this list of conditions and the following disclaimer.
16  * Redistributions in binary form must reproduce the above copyright notice,
17  this list of conditions and the following disclaimer in the documentation
18  and/or other materials provided with the distribution.
19  * Neither the name of the University of Oxford nor the names of its
20  contributors may be used to endorse or promote products derived from this
21  software without specific prior written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 
34 */
35 
36 #include "ChastePoint.hpp"
37 #include "Exception.hpp"
38 
40 // Implementation
42 
43 template<unsigned DIM>
44 ChastePoint<DIM>::ChastePoint(double v1, double v2, double v3)
45 {
46  if (DIM > 0)
47  {
48  mLocation[0] = v1;
49  }
50  if (DIM > 1)
51  {
52  mLocation[1] = v2;
53  }
54  if (DIM > 2)
55  {
56  mLocation[2] = v3;
57  }
58 }
59 
60 template<unsigned DIM>
61 ChastePoint<DIM>::ChastePoint(std::vector<double> coords)
62 {
63  for (unsigned i=0; i<DIM; i++)
64  {
65  mLocation(i) = coords.at(i);
66  }
67 }
68 
69 template<unsigned DIM>
70 ChastePoint<DIM>::ChastePoint(c_vector<double, DIM> location)
71  : mLocation(location)
72 {
73 }
74 
75 template<unsigned DIM>
76 c_vector<double, DIM>& ChastePoint<DIM>::rGetLocation()
77 {
78  return mLocation;
79 }
80 
81 template<unsigned DIM>
82 const c_vector<double, DIM>& ChastePoint<DIM>::rGetLocation() const
83 {
84  return mLocation;
85 }
86 
87 template<unsigned DIM>
88 double ChastePoint<DIM>::operator[] (unsigned i) const
89 {
90  assert(i<DIM);
91  return mLocation(i);
92 }
93 
94 template<unsigned DIM>
95 double ChastePoint<DIM>::GetWithDefault(unsigned i, double def) const
96 {
97  if (i<DIM)
98  {
99  return mLocation(i);
100  }
101  else
102  {
103  return def;
104  }
105 }
106 
107 template<unsigned DIM>
108 void ChastePoint<DIM>::SetCoordinate(unsigned i, double value)
109 {
110  assert(i < DIM);
111  mLocation(i) = value;
112 }
113 
114 template<unsigned DIM>
116 {
117  bool returned_value = true;
118  for (unsigned dim=0; dim<DIM; dim++)
119  {
120  if (rPoint[dim] != mLocation[dim])
121  {
122  returned_value = false;
123  break;
124  }
125  }
126  return returned_value;
127 }
128 
129 // Methods of the 0d version
130 
131 ChastePoint<0>::ChastePoint(double v1, double v2, double v3)
132 {
133 }
134 
135 double ChastePoint<0>::operator[] (unsigned i) const
136 {
137  EXCEPTION("Zero-dimensional point has no data");
138 }
139 
141 // Explicit instantiation
143 
144 template class ChastePoint<1>;
145 template class ChastePoint<2>;
146 template class ChastePoint<3>;
147 
148 // Serialization for Boost >= 1.36
151 
c_vector< double, DIM > & rGetLocation()
Definition: ChastePoint.cpp:76
double GetWithDefault(unsigned i, double def=0.0) const
Definition: ChastePoint.cpp:95
#define EXCEPTION(message)
Definition: Exception.hpp:143
double operator[](unsigned i) const
Definition: ChastePoint.cpp:88
#define EXPORT_TEMPLATE_CLASS_SAME_DIMS(CLASS)
void SetCoordinate(unsigned i, double value)
ChastePoint(double v1=0, double v2=0, double v3=0)
Definition: ChastePoint.cpp:44
bool IsSamePoint(const ChastePoint< DIM > &rPoint) const