00001 #include "orthomesh.h" 00002 00003 00004 OrthoVerticeAccessor::OrthoVerticeAccessor(const OrthoMesh &mesh,unsigned index) 00005 :m_mesh(&mesh) 00006 { 00007 assert(index < mesh.numRawVertices()); 00008 m_index=index; 00009 m_mesh->getVerticePositionFromIndex(index,m_i,m_j,m_k); 00010 } 00011 00012 00013 00014 void OrthoVerticeAccessor::operator++(int) 00015 { 00016 assert(this->isValid()); 00017 assert(m_index < m_mesh->numRawVertices()); 00018 m_index++; 00019 if (m_i == m_mesh->_nElemX) 00020 { 00021 m_i=0; 00022 if (m_j == m_mesh->_nElemY) 00023 { 00024 m_j=0; 00025 m_k++; 00026 } 00027 else 00028 m_j++; 00029 } 00030 else 00031 m_i++; 00032 00033 } 00034 00035 Point3D OrthoVerticeAccessor::getPoint() 00036 { 00037 assert(isValid()); 00038 Point3D p = m_mesh->getP(); 00039 p[0]+=m_i*m_mesh->getDX()[0]; 00040 p[1]+=m_j*m_mesh->getDX()[1]; 00041 p[2]+=m_k*m_mesh->getDX()[2]; 00042 00043 return p; 00044 00045 } 00046 00047 00048 bool OrthoVerticeAccessor::isValid() 00049 { 00050 if (m_index >= m_mesh->numRawVertices()) 00051 return false; 00052 if (m_i > m_mesh->_nElemX) 00053 return false; 00054 if (m_j > m_mesh->_nElemY) 00055 return false; 00056 if (m_k > m_mesh->_nElemZ) 00057 return false; 00058 return true; 00059 } 00060 00061 00062 00063 00064 unsigned OrthoVerticeAccessor::index_left() const 00065 { 00066 if (m_i==0 ) 00067 return -1; 00068 else 00069 return m_index-1; 00070 } 00071 00072 00073 00074 unsigned OrthoVerticeAccessor::index_right() const 00075 { 00076 if (m_i==m_mesh->_nElemX ) 00077 return -1; 00078 else 00079 return m_index+1; 00080 } 00081 00082 unsigned OrthoVerticeAccessor::index_bottom() const 00083 { 00084 if (m_k==0 ) 00085 return -1; 00086 else 00087 return m_index-(m_mesh->_ZVStride); 00088 } 00089 00090 unsigned OrthoVerticeAccessor::index_up() const 00091 { 00092 00093 if (m_k==m_mesh->_nElemZ ) 00094 return -1; 00095 else 00096 return m_index+m_mesh->_ZVStride; 00097 } 00098 00099 unsigned OrthoVerticeAccessor::index_front() const 00100 { 00101 if (m_j==0) 00102 { 00103 return -1; 00104 } 00105 else 00106 return m_index-m_mesh->_YVStride; 00107 00108 } 00109 00110 unsigned OrthoVerticeAccessor::index_back() const 00111 { 00112 00113 if (m_j==m_mesh->_nElemY) 00114 return -1; 00115 else 00116 return m_index+m_mesh->_YVStride; 00117 } 00118 00119 00120 bool OrthoVerticeAccessor::at_boundary() const 00121 { 00122 if (m_i ==0 || m_j==0 || m_k==0 || m_i == m_mesh->_nElemX || m_j == m_mesh->_nElemY || m_k == m_mesh->_nElemZ ) 00123 return 1; 00124 else 00125 return 0; 00126 }