每一步重新三角测量点(在CGAL中)

时间:2016-05-30 17:17:53

标签: simulation cgal triangulation

我想模拟N个步骤的粒子系统。在每个步骤中,构建这些点的periodioc三角剖分。在每个步骤中粒子的坐标都会发生变化,因此,我需要删除(或删除)上一步的三角测量并创建一个新的三角测量。从搜索手册中,我发现了这个功能:

void remove(Vertex_handle v) 并尝试了这个:

typedef Triangulation::Vertex_iterator Vi;
for(int istep=0; istep<N_step; istep++)

    {\\make triangulation
    Triangulation T(points.begin(), points.end(), domain);

    \\some parts of the code which change array of *points*
    for (Vi vi = T.vertices_begin(); vi != T.vertices_end(); vi++){

    Vertex_handle v = vi;

    T.remove(v);\\remove triangulation by removing vertices
            }
     }

但这会导致分段错误。有N个顶点,分段错误用于删除(第N + 1)个顶点! ),也许这是由于三角测量的周期性。

现在,我有两个问题:1)如何通过 remove()函数删除周期性三角测量中的顶点?

2)是否有另一种有效的方法来删除先前的三角测量并创建新的三角测量?

编辑:代码如下,包含代码的主要部分,并显示我要做的事情:

//--------------

#include <cstdlib>       
#include <iostream>
#include <fstream>
#include <cmath>
#include <ctime>        
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Periodic_2_Delaunay_triangulation_2.h>
#include <CGAL/Periodic_2_triangulation_traits_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>

using namespace std;

//******************CGAL_prerequisite************************/
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Periodic_2_triangulation_traits_2<Kernel> Gt;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned int, Gt> Vb;
typedef CGAL::Periodic_2_triangulation_face_base_2<Gt> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Periodic_2_Delaunay_triangulation_2<Gt, Tds> Triangulation;

typedef Triangulation::Point Point;
typedef Triangulation::Edge_iterator Edge_iterator;
typedef Triangulation::Vertex_handle Vertex_handle;
typedef Triangulation::Vertex_circulator Vertex_circulator;
typedef Triangulation::Iso_rectangle Iso_rectangle;
typedef Triangulation::Vertex_iterator Vi;

typedef std::vector<std::pair<Point, unsigned> > Vector;

/*********************Simulation_parameters*****************/
const int N = 16;            
double L = 4;        //linear size of the square 
double S = 0.5;         //0.5
double dt = 1.0;        
int N_step = 100;

ofstream output("traj_2D.xyz");

int main(){

Iso_rectangle domain(0,0,L,L);

Vector points;

vector<vector<double> > dir;\\an array for 2D velocities of each particle
dir.resize(N);
for(int i=0; i<N; i++){dir[i].resize(2);}

vector<vector<double> > pos;\\an array for 2D initial positions
pos.resize(N);
for(int i=0; i<N; i++){pos[i].resize(2);}


/*****initialize_positions*****/
\\some part of the code
/*****initialize_velocities*****/
\\some part of the code   


  for (int i = 0; i < N; i++)
       points.push_back(make_pair(Point(pos[i][0], pos[i][1]), i));  

/********************************************************************
*********************************************************************/

for(int istep = 0; istep < N_step; istep++)
     {
      Triangulation T(points.begin(), points.end(), domain); 


      \\update positions and apply periodic boundary conditons
        for (int i = 0; i < N; i++) {

             points[i].first = Point(points[i].first.x()+S*dir[i][0]*dt , points[i].first.y()+S*dir[i][1]*dt);


            // use periodic boundary conditions
            if (points[i].first.x() < 0)
                points[i].first=Point(points[i].first.x()+L, points[i].first.y());
            if (points[i].first.y() < 0)
                points[i].first=Point(points[i].first.x(), points[i].first.y()+L);
            if (points[i].first.x() > L)
                points[i].first=Point(points[i].first.x()-L, points[i].first.y());
            if (points[i].first.y() > L)
                points[i].first=Point(points[i].first.x(), points[i].first.y()+L);

                                 }
          \\write the updated positions to a file
            for(int s = 0;s < N;s++){
             output<<points[s].first.x()<<"  "<<points[s].first.y()<<"  "<<"0.0"<<endl;}
     T.clear();
                 }    
return 0;}
//*****************************************************************************************************

0 个答案:

没有答案