MeshInterface.h
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 #ifndef MESH_INTERFACE_H
00025 #define MESH_INTERFACE_H
00026
00027 #include <Mod/Mesh/App/Core/Elements.h>
00028 #include <Mod/Mesh/App/Core/Iterator.h>
00029 #include <Mod/Mesh/App/Core/MeshKernel.h>
00030 #include <Base/Vector3D.h>
00031
00032 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
00033 #error
00034 namespace Mesh
00035 {
00036
00041 template <class Kernel>
00042 class Interface : public Kernel
00043 {
00044 public:
00045 Interface()
00046 {
00047 }
00048
00049 Interface(const MeshCore::MeshKernel& kernel)
00050 {
00051 copy(kernel);
00052 }
00053
00054 ~Interface()
00055 {
00056 }
00057
00058 void copy(const MeshCore::MeshKernel& kernel_In)
00059 {
00060 this->clear();
00061 std::vector<Kernel::VertexHandle> vertex_handles;
00062 vertex_handles.reserve(kernel_In.CountPoints());
00063 MeshCore::MeshPointIterator it(kernel_In);
00064 for (it.Init(); it.More(); it.Next()) {
00065 vertex_handles.push_back(this->add_vertex(Kernel::Point(it->x, it->y, it->z)));
00066 }
00067
00068 const MeshCore::MeshFacetArray& ary = kernel_In.GetFacets();
00069 for (MeshCore::MeshFacetArray::_TConstIterator it = ary.begin(); it != ary.end(); ++it) {
00070 this->add_face(vertex_handles[it->_aulPoints[0]], vertex_handles[it->_aulPoints[1]], vertex_handles[it->_aulPoints[2]]);
00071 }
00072 vertex_handles.clear();
00073 }
00074
00075 void release(MeshCore::MeshKernel& kernel_Out)
00076 {
00077 MeshCore::MeshFacetArray facets;
00078 MeshCore::MeshPointArray points;
00079
00080 facets.reserve(this->n_faces());
00081 points.reserve(this->n_vertices());
00082
00083
00084 Kernel::ConstVertexIter v_it, v_end(this->vertices_end());
00085 for (v_it=this->vertices_begin(); v_it!=v_end; ++v_it) {
00086 Kernel::Point p = this->point(v_it);
00087 points.push_back(Base::Vector3f(p[0], p[1], p[2]));
00088 }
00089
00090
00091 Kernel::ConstFaceIter f_it, f_end(this->faces_end());
00092 for (f_it=this->faces_begin(); f_it!=f_end; ++f_it) {
00093 MeshCore::MeshFacet face;
00094 int i=0;
00095 for (Kernel::ConstFaceVertexIter fv_it=this->cfv_iter(f_it); fv_it; ++fv_it) {
00096 face._aulPoints[i++] = fv_it.handle().idx();
00097 }
00098
00099 facets.push_back(face);
00100 }
00101
00102
00103
00104 for (f_it=this->faces_begin(); f_it!=f_end; ++f_it) {
00105
00106 for (Kernel::ConstFaceHalfedgeIter fh_it=this->cfh_iter(f_it); fh_it; ++fh_it) {
00107
00108 Kernel::HalfedgeHandle hh = this->opposite_halfedge_handle(fh_it);
00109 if (hh.is_valid()) {
00110
00111 Kernel::FaceHandle fh = this->face_handle(hh);
00112 Kernel::VertexHandle vh = this->to_vertex_handle(hh);
00113 for (int j=0; j<3; j++) {
00114
00115 if (facets[f_it.handle().idx()]._aulPoints[j] == vh.idx()) {
00116 facets[f_it.handle().idx()]._aulNeighbours[j] = fh.idx();
00117 break;
00118 }
00119 }
00120 }
00121 }
00122 }
00123
00124 this->clear();
00125 kernel_Out.Adopt(points, facets, false);
00126 }
00127 };
00128
00129 }
00130
00131
00132 #endif // MESH_INTERFACE_H