Chaste Release::3.1
|
00001 /* 00002 00003 Copyright (c) 2005-2012, University of Oxford. 00004 All rights reserved. 00005 00006 University of Oxford means the Chancellor, Masters and Scholars of the 00007 University of Oxford, having an administrative office at Wellington 00008 Square, Oxford OX1 2JD, UK. 00009 00010 This file is part of Chaste. 00011 00012 Redistribution and use in source and binary forms, with or without 00013 modification, are permitted provided that the following conditions are met: 00014 * Redistributions of source code must retain the above copyright notice, 00015 this list of conditions and the following disclaimer. 00016 * Redistributions in binary form must reproduce the above copyright notice, 00017 this list of conditions and the following disclaimer in the documentation 00018 and/or other materials provided with the distribution. 00019 * Neither the name of the University of Oxford nor the names of its 00020 contributors may be used to endorse or promote products derived from this 00021 software without specific prior written permission. 00022 00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 00034 */ 00035 00036 00037 #ifndef _ABSTRACTMESHREADER_HPP_ 00038 #define _ABSTRACTMESHREADER_HPP_ 00039 00040 #include <string> 00041 #include <vector> 00042 #include <set> 00043 #include <cassert> 00044 #include <boost/iterator/iterator_facade.hpp> 00045 #include "Exception.hpp" 00046 00051 struct ElementData 00052 { 00053 std::vector<unsigned> NodeIndices; 00054 double AttributeValue; 00055 unsigned ContainingElement; 00056 }; 00057 00070 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM> 00071 class AbstractMeshReader 00072 { 00073 00074 public: 00075 00076 virtual ~AbstractMeshReader() 00077 {} 00078 00080 virtual unsigned GetNumElements() const =0; 00081 00083 virtual unsigned GetNumNodes() const =0; 00084 00086 virtual unsigned GetNumFaces() const =0; 00087 00089 virtual unsigned GetNumCableElements() const; 00090 00092 virtual unsigned GetNumElementAttributes() const; 00093 00095 virtual unsigned GetNumFaceAttributes() const; 00096 00098 virtual unsigned GetNumCableElementAttributes() const; 00099 00107 virtual std::vector<double> GetNodeAttributes(); 00108 00110 unsigned GetNumEdges() const; 00111 00113 virtual std::vector<double> GetNextNode()=0; 00114 00116 virtual void Reset()=0; 00117 00119 virtual ElementData GetNextElementData()=0; 00120 00122 virtual ElementData GetNextFaceData()=0; 00123 00125 virtual ElementData GetNextCableElementData(); 00126 00128 ElementData GetNextEdgeData(); 00129 00130 00137 virtual std::vector<double> GetNode(unsigned index); 00138 00145 virtual ElementData GetElementData(unsigned index); 00146 00153 virtual ElementData GetFaceData(unsigned index); 00154 00161 ElementData GetEdgeData(unsigned index); 00162 00170 virtual std::vector<unsigned> GetContainingElementIndices(unsigned index); 00171 00175 virtual std::string GetMeshFileBaseName(); 00176 00183 virtual bool IsFileFormatBinary(); 00184 00192 virtual bool HasNclFile(); 00193 00194 // Iterator classes 00195 00199 class ElementIterator : public boost::iterator_facade<ElementIterator, const ElementData, 00200 boost::single_pass_traversal_tag> 00201 { 00202 public: 00206 ElementIterator() 00207 : mIndex(UNSIGNED_UNSET), 00208 mpIndices(NULL), 00209 mpReader(NULL) 00210 { 00211 } 00212 00223 explicit ElementIterator(unsigned index, 00224 AbstractMeshReader* pReader) 00225 : mIndex(index), 00226 mpIndices(NULL), 00227 mpReader(pReader) 00228 { 00229 CacheData(mIndex, true); 00230 } 00231 00239 ElementIterator(const std::set<unsigned>& rIndices, 00240 AbstractMeshReader* pReader); 00241 00245 unsigned GetIndex() const 00246 { 00247 return mIndex; 00248 } 00249 00250 private: 00251 friend class boost::iterator_core_access; 00252 00260 void CacheData(unsigned index, bool firstRead = false); 00261 00265 void increment(); 00266 00271 bool equal(const ElementIterator& rOther) const 00272 { 00273 return mIndex == rOther.mIndex; 00274 } 00275 00282 const ElementData& dereference() const 00283 { 00284 assert(mpReader); 00285 assert(mIndex < mpReader->GetNumElements()); 00286 // This was cached in increment() 00287 return mLastDataRead; 00288 } 00289 00291 unsigned mIndex; 00292 00294 const std::set<unsigned>* mpIndices; 00295 00297 std::set<unsigned>::const_iterator mIndicesIterator; 00298 00300 AbstractMeshReader* mpReader; 00301 00303 ElementData mLastDataRead; 00304 }; 00305 00313 ElementIterator GetElementIteratorBegin(); 00314 00324 ElementIterator GetElementIteratorBegin(const std::set<unsigned>& rIndices); 00325 00329 ElementIterator GetElementIteratorEnd(); 00330 00331 00336 00337 class NodeIterator : public boost::iterator_facade<NodeIterator, const std::vector<double>, 00338 boost::single_pass_traversal_tag> 00339 { 00340 public: 00344 NodeIterator() 00345 : mIndex(UNSIGNED_UNSET), 00346 mpIndices(NULL), 00347 mpReader(NULL) 00348 { 00349 } 00350 00361 explicit NodeIterator(unsigned index, 00362 AbstractMeshReader* pReader) 00363 : mIndex(index), 00364 mpIndices(NULL), 00365 mpReader(pReader) 00366 { 00367 CacheData(mIndex, true); 00368 } 00369 00377 NodeIterator(const std::set<unsigned>& rIndices, 00378 AbstractMeshReader* pReader); 00379 00383 unsigned GetIndex() const 00384 { 00385 return mIndex; 00386 } 00387 00388 private: 00389 friend class boost::iterator_core_access; 00390 00398 void CacheData(unsigned index, bool firstRead = false); 00399 00403 void increment(); 00404 00409 bool equal(const NodeIterator& rOther) const 00410 { 00411 return mIndex == rOther.mIndex; 00412 } 00413 00420 const std::vector<double>& dereference() const 00421 { 00422 assert(mpReader); 00423 assert(mIndex < mpReader->GetNumNodes()); 00424 // This was cached in increment() 00425 return mLastDataRead; 00426 } 00427 00429 unsigned mIndex; 00430 00432 const std::set<unsigned>* mpIndices; 00433 00435 std::set<unsigned>::const_iterator mIndicesIterator; 00436 00438 AbstractMeshReader* mpReader; 00439 00441 std::vector<double> mLastDataRead; 00442 }; 00443 00451 NodeIterator GetNodeIteratorBegin(); 00452 00462 NodeIterator GetNodeIteratorBegin(const std::set<unsigned>& rIndices); 00463 00467 NodeIterator GetNodeIteratorEnd(); 00468 }; 00469 00470 #endif //_ABSTRACTMESHREADER_HPP_