Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:03:13+00:00 2026-05-26T17:03:13+00:00

Here’s some context: I’m working on an assignment to collapse an edge in a

  • 0

Here’s some context:
I’m working on an assignment to collapse an edge in a mesh that is stored half-edge data structure. This is the immediately relevant code.

    System.out.println("Initial Size: " +heds.faces.size());
    if (! heds.faces.remove(currentHE.twin.leftFace));
    {
        System.out.println("We have a twin problem");
            //this will always print 
    }
    // Yet this will always be 1 less than the initial
    System.out.println("After twin removal: " +heds.faces.size());

    if ( !heds.faces.remove(currentHE.leftFace)) 
    {
        System.out.println("We have a problem");
    }
    System.out.println("Third: " +heds.faces.size());

So the problem is that “We have a twin problem” always prints, and it should not, yet, “After twin removal” will always be one less than the initial size.

Here’s the rest of the info if you feel you need it.
heds is defined in a class “HEDS” (half edge data structure):

     public HEDS( PolygonSoup soup ) {
    HalfEdge potentialTwin;
    HalfEdge[] currHalfEdges;
    Vertex curr, next;      
    for (int[] face : soup.faceList)
    {
        currHalfEdges = new HalfEdge[face.length];
        for (int i = 0; i < face.length; i++)
        {
            HalfEdge he = new HalfEdge();

            curr = soup.vertexList.get(face[i]);
            next = soup.vertexList.get(face[(i+1)%face.length]);

            he.tail = curr;
            he.head = next;
            currHalfEdges[i] = he;
            halfEdges.put(face[i]+","+face[(i+1)%face.length], he);

            potentialTwin = halfEdges.get(face[(i+1)%face.length]+","+face[i]);

            if (potentialTwin != null)
            {
                he.twin = potentialTwin;
                potentialTwin.twin = he;
            }       
        }
        for (int i = 0; i < currHalfEdges.length; i++)
        {

            currHalfEdges[i].next = currHalfEdges[(i+1)%currHalfEdges.length];
        }

        faces.add(new Face(currHalfEdges[0]));
    }

    // Checking if every half-edge's face was propery defined
    Iterator<Entry<String, HalfEdge>> it = halfEdges.entrySet().iterator();
    while (it.hasNext())
    {
        Map.Entry<String, HalfEdge> pairs = (Map.Entry<String, HalfEdge>)it.next();
        if (!faces.contains(pairs.getValue().twin.leftFace))
        {
            System.out.println("DAMN IT!!!!!");
                    // This is never reached
        }

    }

Also it does not seem to matter if I remove the twin’s face first or not. Also it can be assumed that the mesh is manifold at this point.

Half Edge:

public class HalfEdge {

public HalfEdge twin;
public HalfEdge next;
public Vertex head;
public Vertex tail;
public Face leftFace;

/** 
 * while perhaps wasting space, it may be convenient to
 * have a common edge object for each pair of half edges to 
 * store information about the error metric, optimal vertex
 * location on collapse, and the error 
 */
public Edge e;

/** @return the previous half edge (could just be stored) */
public HalfEdge prev() {
    HalfEdge prev = this;
    while ( prev.next != this ) prev = prev.next;        
    return prev;
}
 /**
 * Computes the valence by walking around the vertex at head.
 * @return valence of the vertex at the head of this half edge
 */
public int valence() {
    HalfEdge loop = this;
    int v = 0;
    do {
        v++;
        loop = loop.next.twin;
    } while ( loop != this );
    return v;
}

Face code:

public class Face {    
/** sure, why not keep a normal for flat shading? */
public Vector3d n = new Vector3d();

/** Plane equation */
Vector4d p = new Vector4d();

/** Quadratic function for the plane equation */
public Matrix4d K = new Matrix4d();

/** Some half edge on the face */
HalfEdge he;

/** 
 * Constructs a face from a half edge, and computes the flat normal
 * @param he
 */
public Face( HalfEdge he ) {
    this.he = he;
    HalfEdge loop = he;
    do {
        loop.leftFace = this;
        loop = loop.next;
    } while ( loop != he );
    recomputeNormal();
}

public Face(List<Vertex> vertexList, int[] faceVertices)
{

}

public void recomputeNormal() {
    Point3d p0 = he.head.p;
    Point3d p1 = he.next.head.p;
    Point3d p2 = he.next.next.head.p;
    Vector3d v1 = new Vector3d();
    Vector3d v2 = new Vector3d();
    v1.sub(p1,p0);
    v2.sub(p2,p1);
    n.cross( v1,v2 );

    // TODO: compute the plane and matrix K for the quadric error metric

}

}

Sorry about the last question, I was in a bit of a rush, and was hoping there was a simple solution. https://stackoverflow.com/questions/8031446/java-arraylist-removeo-returns-false-but-still-decrements-size-of-arraylist

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T17:03:14+00:00Added an answer on May 26, 2026 at 5:03 pm

    Quite a simple problem, but clouded by all your code:

    if (! heds.faces.remove(currentHE.twin.leftFace));
    {
        //...
    }
    

    It’s the semicolon at the end of the if-condition. That semicolon ends the statement, which is your if statement. It turns the “then” part of your if block into an empty statement (so nothing happens). Then you have a floating block after it that always happens.

    Your code executes like this:

    if (! heds.faces.remove(currentHE.twin.leftFace))
        ; //this empty statement never gets executed, but nothing to execute anyhow
    
    
    {
        //this will always print (since it's not guarded by the if)
        System.out.println("We have a twin problem");
    }
    

    In other words, heds.faces.remove() is indeed returning true; you just failed to report the result correctly. Remove the semi-colon and the output should start to make sense to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a coding problem for those that like this kind of thing. Let's see
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is the scenario: I'm writing an app that will watch for any changes
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's some of my production code (I had to force line breaks): task =
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.