bug in ifs2heds?[SOLVED]

Have jReality programming problems or questions? Post them here.
Post Reply
benjamin.kutschan
Posts: 48
Joined: Mon 16. May 2011, 16:29

bug in ifs2heds?[SOLVED]

Post by benjamin.kutschan » Thu 26. May 2011, 12:24

The code below is from ConverterJR2Heds, line 149, (rev? 1152). i iterates over the faces. but suddenly it's used as an index over the edges. It appears, that here every edge adjacent to the i-th face(indices[2 for face]) is given the color of some i-th edge(colors[1 for edge]). The i-th edge could be anywhere in relation to the i-th face...

Code: Select all

for (int i = 0; i < numF; i++){
			int[] f = indices[2][i];
			if (f.length < 3) continue;
			for (int j = 0; j < f.length; j++){
				int s = f[j];
				int t = f[(j + 1) % f.length];
//...
				vertexEdgeMap.put(s, t, e);
				if (coords[1] != null) eAdapters.set(Position.class, e, coords[1][i]);
				if (colors[1] != null) eAdapters.set(Color.class, e, colors[1][i]);
Last edited by benjamin.kutschan on Mon 6. Jun 2011, 21:04, edited 1 time in total.

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: bug in ifs2heds?

Post by sechel » Tue 31. May 2011, 16:27

You are right, there is definitely something fishy going on in the edge color code. I could not figure out whats wrong exactly. Could you post source code that unveils the problems of this section? That would be nice.
Stefan

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: bug in ifs2heds?

Post by sechel » Tue 31. May 2011, 16:36

Actually the code from line 149 looks quite OK to me. The edges coming from face boundaries ought to have the same color as the face they are attached to. What looks peculiar to me is the next section where the extra edges, that do not have a supporting face get their colors. This seems to be wrong. Anyway can you invesigate this some more and post an example that fails when using the converter?
Thank you
Stefan

benjamin.kutschan
Posts: 48
Joined: Mon 16. May 2011, 16:29

Re: bug in ifs2heds?

Post by benjamin.kutschan » Wed 1. Jun 2011, 11:02

The actual problem starts in line 165, where the edge belonging to face i is not assigned the color of face i but the color of edge i.

current code:

Code: Select all

if (coords[1] != null) eAdapters.set(Position.class, e, coords[1][i]);
maybe right code:

Code: Select all

if (coords[1] != null) eAdapters.set(Position.class, e, coords[2][i]);
This is because coords[2] are face attributes , coords[1] are edge attributes and coords[0] point attributes I believe.

Code: Select all

/// some facts:
		int numV = 0;
		if (coords[0] != null) numV = coords[0].length;
		int numE = 0;
		if (indices[1] != null) numE = indices[1].length;
		int numF = 0;
		if (indices[2] != null) numF = indices[2].length;
The same applies to lines 166-171

An example that failed for me was creating a closed IndexedFaceSet, converting it to Heds, then setting the color value of an edge, and finally converting it a few times back and forth. This would eventually result in many other edges also being colored.

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: bug in ifs2heds?

Post by sechel » Mon 6. Jun 2011, 17:35

This code is a little away from the design of the IndexedFaceSet. In the IndexedFaceSet edges are independently defined. There is no such an implication that for any triangle there are three edges each of them shared by another triangle. Instead the IndexedFaceSetFactory has a method that crates the edges from the given face data. My suggestion here is to delete the "// edges (from faces)" property setting code alltogether and only write colors that are specified by the IndexedFaceSet. The opposite converter creates edges coming from faces anyway.
Stefan

Post Reply