halfedge icon indicating copy to clipboard operation
halfedge copied to clipboard

same question

Open XuankeShi opened this issue 5 years ago • 8 comments

you can try the data: std::vector ver = { -0.5f, 1.f, 0.f, 0.5f, 1.f, 0.f, 1.f, 0.f, 0.f, 0.5f, -1.f, 0.f, -0.5f, -1.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.f }; std::vector tri = { 1, 2, 7, 7, 2 ,3, 3, 4, 7, 7, 4, 5, 7, 5, 6, 7, 6, 1 }; for(auto &a : tri) { a--; }

XuankeShi avatar Oct 21 '20 09:10 XuankeShi

i think i have understand your code.

XuankeShi avatar Oct 21 '20 09:10 XuankeShi

So does it work for you now?

yig avatar Oct 21 '20 10:10 yig

i can run the code . but i think the code can't sovle the question which tiangles index is out of order.

you can try this obj file . i only change 1 triangle index sequence.
provide your email. i can send it to you

------------------ 原始邮件 ------------------ 发件人: "yig/halfedge" <[email protected]>; 发送时间: 2020年10月21日(星期三) 晚上6:07 收件人: "yig/halfedge"<[email protected]>; 抄送: "Xuanke Shi"<[email protected]>;"Author"<[email protected]>; 主题: Re: [yig/halfedge] same question (#2)

So does it work for you now?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

XuankeShi avatar Oct 21 '20 10:10 XuankeShi

I can compile the following file via c++ -o example example.cpp trimesh.cpp -std=c++11. It runs and prints:

neighbors of vertex 0:  5 6 1
neighbors of vertex 1:  0 6 2
neighbors of vertex 2:  1 6 3
neighbors of vertex 3:  2 6 4
neighbors of vertex 4:  3 6 5
neighbors of vertex 5:  4 6 0
neighbors of vertex 6:  0 5 4 3 2 1

example.cpp:

#include <iostream>
#include <vector>
#include "trimesh.h"
// #include "trimesh.cpp"

/*
$ ./example
neighbors of vertex 0:  5 6 1
neighbors of vertex 1:  0 6 2
neighbors of vertex 2:  1 6 3
neighbors of vertex 3:  2 6 4
neighbors of vertex 4:  3 6 5
neighbors of vertex 5:  4 6 0
neighbors of vertex 6:  0 5 4 3 2 1
*/

int main( int argc, char* argv[] )
{
    std::vector<float> ver = {
    -0.5f, 1.f, 0.f,
    0.5f, 1.f, 0.f,
    1.f, 0.f, 0.f,
    0.5f, -1.f, 0.f,
    -0.5f, -1.f, 0.f,
    -1.f, 0.f, 0.f,
    0.f, 0.f, 0.f
    };
    std::vector<long> triangles = {
    1, 2, 7,
    7, 2 ,3,
    3, 4, 7,
    7, 4, 5,
    7, 5, 6,
    7, 6, 1
    };
    for(auto &a : triangles) {
    a--;
    }
    
    std::vector< trimesh::edge_t > edges;
    trimesh::unordered_edges_from_triangles( triangles.size()/3, reinterpret_cast<const trimesh::triangle_t*>( &triangles[0] ), edges );
    
    trimesh::trimesh_t mesh;
    mesh.build( ver.size()/3, triangles.size()/3, reinterpret_cast<const trimesh::triangle_t*>( &triangles[0] ), edges.size(), &edges[0] );
    
    // Use 'mesh' to walk the connectivity.
    std::vector< trimesh::index_t > neighs;
    for( int vi = 0; vi < ver.size()/3; ++vi )
    {
        mesh.vertex_vertex_neighbors( vi, neighs );
        
        std::cout << "neighbors of vertex " << vi << ": ";
        for( int i = 0; i < neighs.size(); ++i )
        {
            std::cout << ' ' << neighs.at(i);
        }
        std::cout << '\n';
    }
    
    return 0;
}

yig avatar Oct 21 '20 12:10 yig

I can compile the following file via c++ -o example example.cpp trimesh.cpp -std=c++11. It runs and prints:

neighbors of vertex 0:  5 6 1
neighbors of vertex 1:  0 6 2
neighbors of vertex 2:  1 6 3
neighbors of vertex 3:  2 6 4
neighbors of vertex 4:  3 6 5
neighbors of vertex 5:  4 6 0
neighbors of vertex 6:  0 5 4 3 2 1

example.cpp:

#include <iostream>
#include <vector>
#include "trimesh.h"
// #include "trimesh.cpp"

/*
$ ./example
neighbors of vertex 0:  5 6 1
neighbors of vertex 1:  0 6 2
neighbors of vertex 2:  1 6 3
neighbors of vertex 3:  2 6 4
neighbors of vertex 4:  3 6 5
neighbors of vertex 5:  4 6 0
neighbors of vertex 6:  0 5 4 3 2 1
*/

int main( int argc, char* argv[] )
{
    std::vector<float> ver = {
    -0.5f, 1.f, 0.f,
    0.5f, 1.f, 0.f,
    1.f, 0.f, 0.f,
    0.5f, -1.f, 0.f,
    -0.5f, -1.f, 0.f,
    -1.f, 0.f, 0.f,
    0.f, 0.f, 0.f
    };
    std::vector<long> triangles = {
    1, 2, 7,
    7, 2 ,3,
    3, 4, 7,
    7, 4, 5,
    7, 5, 6,
    7, 6, 1
    };
    for(auto &a : triangles) {
    a--;
    }
    
    std::vector< trimesh::edge_t > edges;
    trimesh::unordered_edges_from_triangles( triangles.size()/3, reinterpret_cast<const trimesh::triangle_t*>( &triangles[0] ), edges );
    
    trimesh::trimesh_t mesh;
    mesh.build( ver.size()/3, triangles.size()/3, reinterpret_cast<const trimesh::triangle_t*>( &triangles[0] ), edges.size(), &edges[0] );
    
    // Use 'mesh' to walk the connectivity.
    std::vector< trimesh::index_t > neighs;
    for( int vi = 0; vi < ver.size()/3; ++vi )
    {
        mesh.vertex_vertex_neighbors( vi, neighs );
        
        std::cout << "neighbors of vertex " << vi << ": ";
        for( int i = 0; i < neighs.size(); ++i )
        {
            std::cout << ' ' << neighs.at(i);
        }
        std::cout << '\n';
    }
    
    return 0;
}

sorry , i made a mistake. maybe u can try the triangles as follows, it means the triangles' normal direction are different. std::vector triangles = { 1, 2, 7, 2, 7 ,3, 3, 4, 7, 7, 4, 5, 7, 5, 6, 7, 6, 1 };

XuankeShi avatar Oct 21 '20 18:10 XuankeShi

If the triangles have inconsistent orientation, you can't use a halfedge data structure. What happens when you try it?

On Oct 21, 2020, at 2:42 PM, 史璇珂 [email protected] wrote:

I can compile the following file via c++ -o example example.cpp trimesh.cpp -std=c++11. It runs and prints:

neighbors of vertex 0: 5 6 1 neighbors of vertex 1: 0 6 2 neighbors of vertex 2: 1 6 3 neighbors of vertex 3: 2 6 4 neighbors of vertex 4: 3 6 5 neighbors of vertex 5: 4 6 0 neighbors of vertex 6: 0 5 4 3 2 1 example.cpp:

#include #include #include "trimesh.h" // #include "trimesh.cpp"

/* $ ./example neighbors of vertex 0: 5 6 1 neighbors of vertex 1: 0 6 2 neighbors of vertex 2: 1 6 3 neighbors of vertex 3: 2 6 4 neighbors of vertex 4: 3 6 5 neighbors of vertex 5: 4 6 0 neighbors of vertex 6: 0 5 4 3 2 1 */

int main( int argc, char* argv[] ) { std::vector ver = { -0.5f, 1.f, 0.f, 0.5f, 1.f, 0.f, 1.f, 0.f, 0.f, 0.5f, -1.f, 0.f, -0.5f, -1.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.f }; std::vector triangles = { 1, 2, 7, 7, 2 ,3, 3, 4, 7, 7, 4, 5, 7, 5, 6, 7, 6, 1 }; for(auto &a : triangles) { a--; }

std::vector< trimesh::edge_t > edges;
trimesh::unordered_edges_from_triangles( triangles.size()/3, reinterpret_cast<const trimesh::triangle_t*>( &triangles[0] ), edges );

trimesh::trimesh_t mesh;
mesh.build( ver.size()/3, triangles.size()/3, reinterpret_cast<const trimesh::triangle_t*>( &triangles[0] ), edges.size(), &edges[0] );

// Use 'mesh' to walk the connectivity.
std::vector< trimesh::index_t > neighs;
for( int vi = 0; vi < ver.size()/3; ++vi )
{
    mesh.vertex_vertex_neighbors( vi, neighs );
    
    std::cout << "neighbors of vertex " << vi << ": ";
    for( int i = 0; i < neighs.size(); ++i )
    {
        std::cout << ' ' << neighs.at(i);
    }
    std::cout << '\n';
}

return 0;

} sorry , i made a mistake. maybe u can try the triangles as follows, it means the triangles' normal direction are different. std::vector triangles = { 1, 2, 7, 2, 7 ,3, 3, 4, 7, 7, 4, 5, 7, 5, 6, 7, 6, 1 };

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/yig/halfedge/issues/2#issuecomment-713794783, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACC7XU76Q52W2DIY22DJYTSL4TR7ANCNFSM4SZRJY6Q.

yig avatar Oct 21 '20 18:10 yig

If the triangles have inconsistent orientation, the code runs error because the directed edge are same. i think your implemention is a simplified version,it has some limitation for example ,in the obj file.you can change the triangles' index sequence by yourself. but it should not influence the initialization of the halfedge structure.

XuankeShi avatar Oct 21 '20 18:10 XuankeShi

If the triangles have inconsistent orientation, the code runs error because the directed edge are same. i think your implemention is a simplified version,it has some limitation for example ,in the obj file.you can change the triangles' index sequence by yourself. but it should not influence the initialization of the halfedge structure.

Maybe you're right, i firstly touch the halfedge data structure. thanks for your reply.

XuankeShi avatar Oct 22 '20 08:10 XuankeShi