AbstractMeshReader.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 
00180     virtual unsigned GetOrderOfElements();
00181 
00185     virtual unsigned GetOrderOfBoundaryElements();
00186 
00190     virtual bool GetReadContainingElementOfBoundaryElement();
00191 
00192 
00199     virtual bool IsFileFormatBinary();
00200 
00207     virtual bool HasNclFile();
00208 
00215     virtual bool HasNodePermutation();
00216 
00223     virtual const std::vector<unsigned>& rGetNodePermutation();
00224 
00225 
00226     // Iterator classes
00227 
00231     class ElementIterator : public boost::iterator_facade<ElementIterator, const ElementData,
00232                                                           boost::single_pass_traversal_tag>
00233     {
00234     public:
00238         ElementIterator()
00239             : mIndex(UNSIGNED_UNSET),
00240               mpIndices(NULL),
00241               mpReader(NULL)
00242         {
00243         }
00244 
00255         ElementIterator(unsigned index, AbstractMeshReader* pReader)
00256             : mIndex(index),
00257               mpIndices(NULL),
00258               mpReader(pReader)
00259         {
00260             CacheData(mIndex, true);
00261         }
00262 
00270         ElementIterator(const std::set<unsigned>& rIndices,
00271                         AbstractMeshReader* pReader);
00272 
00276         unsigned GetIndex() const
00277         {
00278             return mIndex;
00279         }
00280 
00281     private:
00282         friend class boost::iterator_core_access;
00283 
00291         void CacheData(unsigned index, bool firstRead = false);
00292 
00296         void increment();
00297 
00302         bool equal(const ElementIterator& rOther) const
00303         {
00304             return mIndex == rOther.mIndex;
00305         }
00306 
00314         const ElementData& dereference() const
00315         {
00316             assert(mpReader);
00317             assert(mIndex < mpReader->GetNumElements());
00318             // This was cached in increment()
00319             return mLastDataRead;
00320         }
00321 
00323         unsigned mIndex;
00324 
00326         const std::set<unsigned>* mpIndices;
00327 
00329         std::set<unsigned>::const_iterator mIndicesIterator;
00330 
00332         AbstractMeshReader* mpReader;
00333 
00335         ElementData mLastDataRead;
00336     };
00337 
00345     ElementIterator GetElementIteratorBegin();
00346 
00356     ElementIterator GetElementIteratorBegin(const std::set<unsigned>& rIndices);
00357 
00361     ElementIterator GetElementIteratorEnd();
00362 
00363 
00368 
00369     class NodeIterator : public boost::iterator_facade<NodeIterator, const std::vector<double>,
00370                                                        boost::single_pass_traversal_tag>
00371     {
00372     public:
00376         NodeIterator()
00377             : mIndex(UNSIGNED_UNSET),
00378               mpIndices(NULL),
00379               mpReader(NULL)
00380         {
00381         }
00382 
00393         NodeIterator(unsigned index, AbstractMeshReader* pReader)
00394             : mIndex(index),
00395               mpIndices(NULL),
00396               mpReader(pReader)
00397         {
00398             CacheData(mIndex, true);
00399         }
00400 
00408         NodeIterator(const std::set<unsigned>& rIndices,
00409                         AbstractMeshReader* pReader);
00410 
00414         unsigned GetIndex() const
00415         {
00416             return mIndex;
00417         }
00418 
00419     private:
00420         friend class boost::iterator_core_access;
00421 
00429         void CacheData(unsigned index, bool firstRead = false);
00430 
00434         void increment();
00435 
00440         bool equal(const NodeIterator& rOther) const
00441         {
00442             return mIndex == rOther.mIndex;
00443         }
00444 
00451         const std::vector<double>& dereference() const
00452         {
00453             assert(mpReader);
00454             assert(mIndex < mpReader->GetNumNodes());
00455             // This was cached in increment()
00456             return mLastDataRead;
00457         }
00458 
00460         unsigned mIndex;
00461 
00463         const std::set<unsigned>* mpIndices;
00464 
00466         std::set<unsigned>::const_iterator mIndicesIterator;
00467 
00469         AbstractMeshReader* mpReader;
00470 
00472         std::vector<double> mLastDataRead;
00473     };
00474 
00482     NodeIterator GetNodeIteratorBegin();
00483 
00493     NodeIterator GetNodeIteratorBegin(const std::set<unsigned>& rIndices);
00494 
00498     NodeIterator GetNodeIteratorEnd();
00499 };
00500 
00501 #endif //_ABSTRACTMESHREADER_HPP_

Generated by  doxygen 1.6.2