Skip to content

Commit

Permalink
Half edge data structure (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
T-rvw authored Aug 12, 2023
1 parent 18432ba commit 7387f6a
Show file tree
Hide file tree
Showing 21 changed files with 880 additions and 11 deletions.
43 changes: 43 additions & 0 deletions examples/FbxToHEMToFbx/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "FbxConsumer.h"
#include "FbxProducer.h"
#include "Framework/Processor.h"
#include "HalfEdgeMesh/HalfEdgeMesh.h"
#include "Scene/SceneDatabase.h"
#include "Utilities/PerformanceProfiler.h"

int main(int argc, char** argv)
{
// argv[0] : exe name
// argv[1] : input file path
// argv[2] : output file path
if (argc != 3)
{
return 1;
}

const char* pInputFilePath = argv[1];
const char* pOutputFilePath = argv[2];

using namespace cdtools;
PerformanceProfiler profiler("ProgressiveMesh");

auto pSceneDatabase = std::make_unique<cd::SceneDatabase>();

// Generate a source mesh.
{
FbxProducer producer(pInputFilePath);
Processor processor(&producer, nullptr, pSceneDatabase.get());
processor.SetDumpSceneDatabaseEnable(false);
processor.Run();
}

{
for (const auto& mesh : pSceneDatabase->GetMeshes())
{
auto halfEdgeMesh = cd::HalfEdgeMesh::FromIndexedMesh(mesh);
assert(halfEdgeMesh.Validate());
}
}

return 0;
}
35 changes: 35 additions & 0 deletions private/HalfEdgeMesh/Edge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "HalfEdgeMesh/Edge.h"

#include "HalfEdgeMesh/Face.h"
#include "HalfEdgeMesh/HalfEdge.h"
#include "HalfEdgeMesh/Vertex.h"

namespace cd::hem
{

bool Edge::IsOnBoundary() const
{
return m_halfEdgeRef->GetFace()->IsBoundary() || m_halfEdgeRef->GetTwin()->GetFace()->IsBoundary();
}

Point Edge::Center() const
{
return (m_halfEdgeRef->GetVertex()->GetPosition() + m_halfEdgeRef->GetTwin()->GetVertex()->GetPosition()) * 0.5f;
}

Direction Edge::Normal() const
{
return Direction::Zero();
}

float Edge::Length() const
{
return (m_halfEdgeRef->GetVertex()->GetPosition() - m_halfEdgeRef->GetTwin()->GetVertex()->GetPosition()).Length();
}

bool Edge::Validate() const
{
return true;
}

}
68 changes: 68 additions & 0 deletions private/HalfEdgeMesh/Face.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "HalfEdgeMesh/Face.h"

#include "HalfEdgeMesh/HalfEdge.h"
#include "HalfEdgeMesh/Vertex.h"

namespace cd::hem
{

Point Face::Center() const
{
Point center(0.0f);
float vertexCount = 0.0f;

HalfEdgeCRef h = m_halfEdgeRef;
do
{
center += h->GetVertex()->GetPosition();
vertexCount += 1.0f;
h = h->GetNext();
} while (h != m_halfEdgeRef);

center /= vertexCount;
return center;
}

Direction Face::Normal() const
{
return Direction::Zero();
}

uint32_t Face::Degree() const
{
uint32_t degree = 0U;

HalfEdgeCRef h = m_halfEdgeRef;
do
{
++degree;
h = h->GetNext();
} while (h != m_halfEdgeRef);

return degree;
}

float Face::Area() const
{
float area = 0.0f;
HalfEdgeCRef h = m_halfEdgeRef;
Point v0 = h->GetVertex()->GetPosition();
h = h->GetNext();

do
{
Direction v1v0 = h->GetVertex()->GetPosition() - v0;
Direction v2v0 = h->GetNext()->GetVertex()->GetPosition() - v0;
area += v1v0.Cross(v2v0).Length() * 0.5f;
h = h->GetNext();
} while (h != m_halfEdgeRef);

return area;
}

bool Face::Validate() const
{
return true;
}

}
11 changes: 11 additions & 0 deletions private/HalfEdgeMesh/HalfEdge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "HalfEdgeMesh/HalfEdge.h"

namespace cd::hem
{

bool HalfEdge::Validate() const
{
return true;
}

}
Loading

0 comments on commit 7387f6a

Please sign in to comment.