2017-06-15 7 views
1

三角形ライブラリはVS2015 x64で動作しますか?VS2015 x64を持つ三角形ライブラリ

私はLinuxで作業していますが、VS2015 x64用のウィンドウに変換していますが、poolalloc funcのメモリの問題によりエラーが発生します。

しかし、私は問題が何であるかの感覚を得ることはありません。この関数の終わりにtrangle.cppユーザFUNC

void computeDelaunayTriangulation (vector<support_pt> p_support, vector<triangle_segment>* tri_ptr){ 
// input/output structure for triangulation  
    struct triangulateio in, out; 
    int k; 

    // inputs 
    in.numberofpoints = p_support.size(); 
    in.pointlist = (float*)malloc(in.numberofpoints*2*sizeof(float)); 
    k=0; 
    for (int i=0; i< p_support.size(); i++){ 
     in.pointlist[k++] = p_support[i].x; 
     in.pointlist[k++] = p_support[i].y; 
    } 

    in.numberofpointattributes = 0; 
    in.pointattributelist  = NULL; 
    in.pointmarkerlist   = NULL; 
    in.numberofsegments  = 0; 
    in.numberofholes   = 0; 
    in.numberofregions   = 0; 
    in.regionlist    = NULL; 

    // outputs 
    out.pointlist    = NULL; 
    out.pointattributelist  = NULL; 
    out.pointmarkerlist  = NULL; 
    out.trianglelist   = NULL; 
    out.triangleattributelist = NULL; 
    out.neighborlist   = NULL; 
    out.segmentlist   = NULL; 
    out.segmentmarkerlist  = NULL; 
    out.edgelist    = NULL; 
    out.edgemarkerlist   = NULL; 


    // do triangulation (z=zero-based, n=neighbors, Q=quiet, B=no boundary markers) 
    char parameters[] = "zQB"; 
    //printf("triangulate\n"); 
    triangulate(parameters, &in, &out, NULL); 

    ..... 
} 

triangle.cpp三角形主FUNC

void triangulate(char *triswitches, struct triangulateio *in, 
      struct triangulateio *out, struct triangulateio *vorout) 
{ 
    struct mesh m; 
    struct behavior b; 
    float *holearray;    /* Array of holes. */ 
    float *regionarray; /* Array of regional attributes and area constraints. */ 

    triangleinit(&m); 
    parsecommandline(1, &triswitches, &b); 
    m.steinerleft = b.steiner; 

    transfernodes(&m, &b, in->pointlist, in->pointattributelist, 
       in->pointmarkerlist, in->numberofpoints, 
       in->numberofpointattributes); 
    ..... 
} 

void OptimizeMatches(MatrixXf& feat, MatrixXf& feat_ref, MatrixXi& match_idx, MatrixXf& match_dist, std::vector<Matrix3f>& trans_mat, std::vector<Matrix3f>& inv_mat, std::vector<Matrix3f>& trans_mat_ref, std::vector<Matrix3f>& inv_mat_ref, 
    MatrixXf* belief_ptr, MatrixXi* label_ptr, std::vector<match_list>* match_ptr, std::vector<triangle_segment>* triangle_ptr) { 

    int num_nodes = (int)feat.cols(); 
    int num_matches = (int)match_idx.rows(); 

    // build graph using delaunay triangulation 
    std::vector<support_pt> p_support; 
    p_support.resize(num_nodes); 
    for(int i = 0; i < num_nodes; i++){ 
     p_support[i].x = feat(0,i); 
     p_support[i].y = feat(1,i); 
    } 
    std::vector<triangle_segment>& T = *triangle_ptr; 
    computeDelaunayTriangulation(p_support, &T); 

    ............ 

} 

、poolalloc機能は、メモリアドレスを割り当てます頂点ループ。このメモリアドレスは無効で、アクセス違反が発生します。

void transfernodes(struct mesh *m, struct behavior *b, float *pointlist, 
       float *pointattriblist, int *pointmarkerlist, 
       int numberofpoints, int numberofpointattribs) 
{ 
    vertex vertexloop; 
    float x, y; 
    int i, j; 
    int coordindex; 
    int attribindex; 

    m->invertices = numberofpoints; 
    m->mesh_dim = 2; 
    m->nextras = numberofpointattribs; 
    m->readnodefile = 0; 
    if (m->invertices < 3) { 
     printf("Error: Input must have at least three input vertices.\n"); 
     triexit(1); 
    } 
    if (m->nextras == 0) { 
     b->weighted = 0; 
    } 

    initializevertexpool(m, b); 

    /* Read the vertices. */ 
    coordindex = 0; 
    attribindex = 0; 
    for (i = 0; i < m->invertices; i++) { 
     vertexloop = (vertex) poolalloc(&m->vertices); 
     //vertexloop = (vertex) &m->vertices; 
     /* Read the vertex coordinates. */ 
     x = vertexloop[0] = pointlist[coordindex++]; 
     y = vertexloop[1] = pointlist[coordindex++]; 


    .... 
} 

これはpoolalloc funcを

int *poolalloc(struct memorypool *pool) 
{ 
    int *newitem; 
    int **newblock; 
    unsigned long alignptr; 

    /* First check the linked list of dead items. If the list is not */ 
    /* empty, allocate an item from the list rather than a fresh one. */ 
    if (pool->deaditemstack != (int *)NULL) { 
     newitem = pool->deaditemstack;    /* Take first item in list. */ 
     pool->deaditemstack = *(int **)pool->deaditemstack; 
    } 
    else { 
     /* Check if there are any free items left in the current block. */ 
     if (pool->unallocateditems == 0) { 
      /* Check if another block must be allocated. */ 
      if (*(pool->nowblock) == (int *)NULL) { 
       /* Allocate a new block of items, pointed to by the previous block. */ 
       newblock = (int **)trimalloc(pool->itemsperblock * pool->itembytes + 
        (int) sizeof(int *) + 
        pool->alignbytes); 
       *(pool->nowblock) = (int *)newblock; 
       /* The next block pointer is NULL. */ 
       *newblock = (int *)NULL; 
      } 

      /* Move to the new block. */ 
      pool->nowblock = (int **) *(pool->nowblock); 
      /* Find the first item in the block. */ 
      /* Increment by the size of (int *). */ 
      alignptr = (unsigned long) (pool->nowblock + 1); 
      /* Align the item on an `alignbytes'-byte boundary. */ 
      pool->nextitem = (int *) 
       (alignptr + (unsigned long) pool->alignbytes - 
       (alignptr % (unsigned long) pool->alignbytes)); 
      /* There are lots of unallocated items left in this block. */ 
      pool->unallocateditems = pool->itemsperblock; 
     } 

     /* Allocate a new item. */ 
     newitem = pool->nextitem; 
     /* Advance `nextitem' pointer to next free item in block. */ 
     pool->nextitem = (int *)((char *)pool->nextitem + pool->itembytes); 
     pool->unallocateditems--; 
     pool->maxitems++; 
    } 
    pool->items++; 
    return newitem; 
} 

答えて

1

OKですが、私はこの同じ問題を解決しました。

triangle.cのコードは、sizeof(long)が8であるとみなし、ポインタの型としてunsigned longを使用します。しかし、sizeof(long)はVSで4に等しいので、unsigned longはx64のポインタの型にはなりません。

私はtriangle.cの "long"を "__int64"に置き換え、コードは機能します。