Mesh/App/Segment.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <algorithm>
00027 # include <sstream>
00028 #endif
00029
00030
00031 #include "Core/MeshKernel.h"
00032
00033 #include "Segment.h"
00034 #include "Mesh.h"
00035 #include "MeshPy.h"
00036
00037 using namespace Mesh;
00038
00039 Segment::Segment(MeshObject* mesh, bool mod) : _mesh(mesh), _modifykernel(mod)
00040 {
00041 }
00042
00043 Segment::Segment(MeshObject* mesh, const std::vector<unsigned long>& inds, bool mod)
00044 : _mesh(mesh), _indices(inds), _modifykernel(mod)
00045 {
00046 if (_modifykernel)
00047 _mesh->updateMesh(inds);
00048 }
00049
00050 void Segment::addIndices(const std::vector<unsigned long>& inds)
00051 {
00052 _indices.insert(_indices.end(), inds.begin(), inds.end());
00053 std::sort(_indices.begin(), _indices.end());
00054 _indices.erase(std::unique(_indices.begin(), _indices.end()), _indices.end());
00055 if (_modifykernel)
00056 _mesh->updateMesh(inds);
00057 }
00058
00059 void Segment::removeIndices(const std::vector<unsigned long>& inds)
00060 {
00061
00062 std::vector<unsigned long> result;
00063 std::set<unsigned long> s1(_indices.begin(), _indices.end());
00064 std::set<unsigned long> s2(inds.begin(), inds.end());
00065 std::set_difference(s1.begin(), s1.end(), s2.begin(), s2.end(),
00066 std::back_insert_iterator<std::vector<unsigned long> >(result));
00067
00068 _indices = result;
00069 if (_modifykernel)
00070 _mesh->updateMesh();
00071 }
00072
00073 const std::vector<unsigned long>& Segment::getIndices() const
00074 {
00075 return _indices;
00076 }
00077
00078 const Segment& Segment::operator = (const Segment& s)
00079 {
00080
00081 if (this != &s)
00082 this->_indices = s._indices;
00083 if (_modifykernel)
00084 _mesh->updateMesh();
00085 return *this;
00086 }
00087
00088 bool Segment::operator == (const Segment& s) const
00089 {
00090 return this->_indices == s._indices;
00091 }
00092
00093
00094
00095 Segment::const_facet_iterator::const_facet_iterator(const Segment* segm, std::vector<unsigned long>::const_iterator it)
00096 : _segment(segm), _f_it(segm->_mesh->getKernel()), _it(it)
00097 {
00098 this->_f_it.Set(0);
00099 this->_f_it.Transform(_segment->_mesh->getTransform());
00100 this->_facet.Mesh = _segment->_mesh;
00101 }
00102
00103 Segment::const_facet_iterator::const_facet_iterator(const Segment::const_facet_iterator& fi)
00104 : _segment(fi._segment), _facet(fi._facet), _f_it(fi._f_it), _it(fi._it)
00105 {
00106 }
00107
00108 Segment::const_facet_iterator::~const_facet_iterator()
00109 {
00110 }
00111
00112 Segment::const_facet_iterator& Segment::const_facet_iterator::operator=(const Segment::const_facet_iterator& fi)
00113 {
00114 this->_segment = fi._segment;
00115 this->_facet = fi._facet;
00116 this->_f_it = fi._f_it;
00117 this->_it = fi._it;
00118 return *this;
00119 }
00120
00121 void Segment::const_facet_iterator::dereference()
00122 {
00123 this->_f_it.Set(*_it);
00124 this->_facet.MeshCore::MeshGeomFacet::operator = (*_f_it);
00125 this->_facet.Index = *_it;
00126 const MeshCore::MeshFacet& face = _f_it.GetReference();
00127 for (int i=0; i<3;i++) {
00128 this->_facet.PIndex[i] = face._aulPoints[i];
00129 this->_facet.NIndex[i] = face._aulNeighbours[i];
00130 }
00131 }
00132
00133 const Facet& Segment::const_facet_iterator::operator*() const
00134 {
00135 const_cast<const_facet_iterator*>(this)->dereference();
00136 return this->_facet;
00137 }
00138
00139 const Facet* Segment::const_facet_iterator::operator->() const
00140 {
00141 const_cast<const_facet_iterator*>(this)->dereference();
00142 return &(this->_facet);
00143 }
00144
00145 bool Segment::const_facet_iterator::operator==(const Segment::const_facet_iterator& fi) const
00146 {
00147 return (this->_segment == fi._segment) && (this->_it == fi._it);
00148 }
00149
00150 bool Segment::const_facet_iterator::operator!=(const Segment::const_facet_iterator& fi) const
00151 {
00152 return !operator==(fi);
00153 }
00154
00155 Segment::const_facet_iterator& Segment::const_facet_iterator::operator++()
00156 {
00157 ++(this->_it);
00158 return *this;
00159 }
00160
00161 Segment::const_facet_iterator& Segment::const_facet_iterator::operator--()
00162 {
00163 --(this->_it);
00164 return *this;
00165 }