meshmash / Plankton

A C# half-edge mesh data structure, and components for using this in Grasshopper/Rhino
http://meshmash.github.io/Plankton
GNU Lesser General Public License v3.0
216 stars 66 forks source link

Adjacent Faces through Halfedge Index #50

Closed mmedinav18 closed 4 years ago

mmedinav18 commented 5 years ago

Hi,

I am following one of your advices from a prevoius thread (https://github.com/meshmash/Plankton/issues/41) to get adjacent faces of a halfedge. The issue I am having is that while it works at times, there are times that an error comes out with the index being out of range. I dug a bit deeper and I noticed that the index value for the startVertex = -1, which is what is causing the error. I've been reading the source code to try to identify how to work around the issue, but truly don't know how to fix it. Could you please explain why the start vertex index comes out as -1?

mmedinav18 commented 5 years ago

Also, I noticed that the face index =-1. I've attached an image of the code I am working with for better understanding. Knit Systems - Microsoft Visual Studio  8_2_2019 3_45_22 PM

pearswj commented 5 years ago

-1 for PlanktonHalfedge.StartVertex sounds like a bug. Plankton should maintain the StartVertex property for you, unless you directly create/modify the halfedges yourself. How are you constructing the PlanktonMesh? Are you using PlanktonFaceList.AddFace()? AFaceIndex of -1 is normal and just means that the half edge has no adjacent face, i.e. it's on a boundary.

mmedinav18 commented 5 years ago

So what I am doing to create the Plankton mesh is basically get the vertices from a remeshed geometry. I am using geometry3dSharp library to remesh this geometry, then use the vertices to create the Plankton mesh vertices and I use planktonMesh.Faces.AddFace(a,b,c,d). The indices for the faces I've gottent them from a function from the other library. For clarification I've included what I am doing in the image below. For the faceindex of -1, I am not quite sure if that's correct since at the moment I am using a sphere, so no boundary.

Hope it makes sense.

Knit Systems - Microsoft Visual Studio  8_2_2019 4_25_55 PM

pearswj commented 4 years ago

Sorry for the late reply. It looks like you're trying to quadrangulate a triangular mesh. I would try building the plankton mesh directly from the triangular faces and check that it comes through correctly.