@Test public void singleFace() throws IOException { ElementType vertexType = new ElementType( "vertex", new Property("x", DataType.DOUBLE), new Property("y", DataType.DOUBLE), new Property("z", DataType.DOUBLE), new Property("nx", DataType.DOUBLE), new Property("ny", DataType.DOUBLE), new Property("nz", DataType.DOUBLE)); Element vertex0 = new Element(vertexType); vertex0.setDouble("x", 0); vertex0.setDouble("y", 0); vertex0.setDouble("z", 0); Element vertex1 = new Element(vertexType); vertex1.setDouble("x", 1); vertex1.setDouble("y", 0); vertex1.setDouble("z", 0); Element vertex2 = new Element(vertexType); vertex2.setDouble("x", 1); vertex2.setDouble("y", 1); vertex2.setDouble("z", 0); Element expected0 = new Element(vertexType); expected0.setDouble("x", 0); expected0.setDouble("y", 0); expected0.setDouble("z", 0); expected0.setDouble("nx", 0); expected0.setDouble("ny", 0); expected0.setDouble("nz", 1); Element expected1 = new Element(vertexType); expected1.setDouble("x", 1); expected1.setDouble("y", 0); expected1.setDouble("z", 0); expected1.setDouble("nx", 0); expected1.setDouble("ny", 0); expected1.setDouble("nz", 1); Element expected2 = new Element(vertexType); expected2.setDouble("x", 1); expected2.setDouble("y", 1); expected2.setDouble("z", 0); expected2.setDouble("nx", 0); expected2.setDouble("ny", 0); expected2.setDouble("nz", 1); ElementType faceType = new ElementType( "face", new ListProperty(DataType.UCHAR, "vertex_index", DataType.INT)); Element face0 = new Element(faceType); face0.setIntList("vertex_index", new int[]{0, 1, 2}); ElementReader vertexReaderMock = mock(ElementReader.class); when(vertexReaderMock.getElementType()).thenReturn(vertexType); when(vertexReaderMock.readElement()). thenReturn(vertex0). thenReturn(vertex1). thenReturn(vertex2). thenReturn(null); BufferedElementReader vertexReader = new BufferedElementReader(vertexReaderMock); ElementReader faceReader = mock(ElementReader.class); when(faceReader.getElementType()).thenReturn(faceType); when(faceReader.readElement()). thenReturn(face0). thenReturn(null); NormalGenerator target = new NormalGenerator(); target.generateNormals(vertexReader, faceReader); vertexReader.reset(); assertEquals(expected0, vertexReader.readElement()); assertEquals(expected1, vertexReader.readElement()); assertEquals(expected2, vertexReader.readElement()); }
public void generateNormals(final RandomElementReader vertexReader, final ElementReader faceReader) throws IOException { if (vertexReader == null) { throw new NullPointerException("vertexReader must not be null."); } if (faceReader == null) { throw new NullPointerException("faceReader must not be null."); } if (!vertexReader.getElementType().getName().equals("vertex")) { throw new IllegalArgumentException( "vertexReader does not read vertices."); } boolean foundX = false; boolean foundY = false; boolean foundZ = false; for (Property p : vertexReader.getElementType().getProperties()) { foundX |= p.getName().equals("x") && !(p instanceof ListProperty); foundY |= p.getName().equals("y") && !(p instanceof ListProperty); foundZ |= p.getName().equals("z") && !(p instanceof ListProperty); } if (!foundX || !foundY || !foundZ) { throw new IllegalArgumentException("Vertex type does not include" + " the three non-list properties x y and z."); } if (!faceReader.getElementType().getName().equals("face")) { throw new IllegalArgumentException( "faceReader does not read faces."); } boolean foundVertexIndex = false; for (Property p : faceReader.getElementType().getProperties()) { foundVertexIndex |= p.getName().equals("vertex_index") && (p instanceof ListProperty); } if (!foundVertexIndex) { throw new IllegalArgumentException( "Face type does not include a list property named " + "vertex_index."); } for (Element face = faceReader.readElement(); face != null; face = faceReader.readElement()) { accumulateNormals(vertexReader, face); } for (Element vertex = vertexReader.readElement(); vertex != null; vertex = vertexReader.readElement()) { normalize(vertex); } }
NormalGenerator { public void generateNormals(final RandomElementReader vertexReader, final ElementReader faceReader) throws IOException { if (vertexReader == null) { throw new NullPointerException("vertexReader must not be null."); } if (faceReader == null) { throw new NullPointerException("faceReader must not be null."); } if (!vertexReader.getElementType().getName().equals("vertex")) { throw new IllegalArgumentException( "vertexReader does not read vertices."); } boolean foundX = false; boolean foundY = false; boolean foundZ = false; for (Property p : vertexReader.getElementType().getProperties()) { foundX |= p.getName().equals("x") && !(p instanceof ListProperty); foundY |= p.getName().equals("y") && !(p instanceof ListProperty); foundZ |= p.getName().equals("z") && !(p instanceof ListProperty); } if (!foundX || !foundY || !foundZ) { throw new IllegalArgumentException("Vertex type does not include" + " the three non-list properties x y and z."); } if (!faceReader.getElementType().getName().equals("face")) { throw new IllegalArgumentException( "faceReader does not read faces."); } boolean foundVertexIndex = false; for (Property p : faceReader.getElementType().getProperties()) { foundVertexIndex |= p.getName().equals("vertex_index") && (p instanceof ListProperty); } if (!foundVertexIndex) { throw new IllegalArgumentException( "Face type does not include a list property named " + "vertex_index."); } for (Element face = faceReader.readElement(); face != null; face = faceReader.readElement()) { accumulateNormals(vertexReader, face); } for (Element vertex = vertexReader.readElement(); vertex != null; vertex = vertexReader.readElement()) { normalize(vertex); } } }
NormalGenerator { public void generateNormals(final RandomElementReader vertexReader, final ElementReader faceReader) throws IOException { if (vertexReader == null) { throw new NullPointerException("vertexReader must not be null."); } if (faceReader == null) { throw new NullPointerException("faceReader must not be null."); } if (!vertexReader.getElementType().getName().equals("vertex")) { throw new IllegalArgumentException( "vertexReader does not read vertices."); } boolean foundX = false; boolean foundY = false; boolean foundZ = false; for (Property p : vertexReader.getElementType().getProperties()) { foundX |= p.getName().equals("x") && !(p instanceof ListProperty); foundY |= p.getName().equals("y") && !(p instanceof ListProperty); foundZ |= p.getName().equals("z") && !(p instanceof ListProperty); } if (!foundX || !foundY || !foundZ) { throw new IllegalArgumentException("Vertex type does not include" + " the three non-list properties x y and z."); } if (!faceReader.getElementType().getName().equals("face")) { throw new IllegalArgumentException( "faceReader does not read faces."); } boolean foundVertexIndex = false; for (Property p : faceReader.getElementType().getProperties()) { foundVertexIndex |= p.getName().equals("vertex_index") && (p instanceof ListProperty); } if (!foundVertexIndex) { throw new IllegalArgumentException( "Face type does not include a list property named " + "vertex_index."); } for (Element face = faceReader.readElement(); face != null; face = faceReader.readElement()) { accumulateNormals(vertexReader, face); } for (Element vertex = vertexReader.readElement(); vertex != null; vertex = vertexReader.readElement()) { normalize(vertex); } }  }
NormalGenerator { public void generateNormals(final RandomElementReader vertexReader, final ElementReader faceReader) throws IOException { if (vertexReader == null) { throw new NullPointerException("vertexReader must not be null."); } if (faceReader == null) { throw new NullPointerException("faceReader must not be null."); } if (!vertexReader.getElementType().getName().equals("vertex")) { throw new IllegalArgumentException( "vertexReader does not read vertices."); } boolean foundX = false; boolean foundY = false; boolean foundZ = false; for (Property p : vertexReader.getElementType().getProperties()) { foundX |= p.getName().equals("x") && !(p instanceof ListProperty); foundY |= p.getName().equals("y") && !(p instanceof ListProperty); foundZ |= p.getName().equals("z") && !(p instanceof ListProperty); } if (!foundX || !foundY || !foundZ) { throw new IllegalArgumentException("Vertex type does not include" + " the three non-list properties x y and z."); } if (!faceReader.getElementType().getName().equals("face")) { throw new IllegalArgumentException( "faceReader does not read faces."); } boolean foundVertexIndex = false; for (Property p : faceReader.getElementType().getProperties()) { foundVertexIndex |= p.getName().equals("vertex_index") && (p instanceof ListProperty); } if (!foundVertexIndex) { throw new IllegalArgumentException( "Face type does not include a list property named " + "vertex_index."); } for (Element face = faceReader.readElement(); face != null; face = faceReader.readElement()) { accumulateNormals(vertexReader, face); } for (Element vertex = vertexReader.readElement(); vertex != null; vertex = vertexReader.readElement()) { normalize(vertex); } }  boolean isCounterClockwise(); void setCounterClockwise(final boolean counterClockwise); void generateNormals(final RandomElementReader vertexReader,
            final ElementReader faceReader); }
NormalGenerator { public void generateNormals(final RandomElementReader vertexReader, final ElementReader faceReader) throws IOException { if (vertexReader == null) { throw new NullPointerException("vertexReader must not be null."); } if (faceReader == null) { throw new NullPointerException("faceReader must not be null."); } if (!vertexReader.getElementType().getName().equals("vertex")) { throw new IllegalArgumentException( "vertexReader does not read vertices."); } boolean foundX = false; boolean foundY = false; boolean foundZ = false; for (Property p : vertexReader.getElementType().getProperties()) { foundX |= p.getName().equals("x") && !(p instanceof ListProperty); foundY |= p.getName().equals("y") && !(p instanceof ListProperty); foundZ |= p.getName().equals("z") && !(p instanceof ListProperty); } if (!foundX || !foundY || !foundZ) { throw new IllegalArgumentException("Vertex type does not include" + " the three non-list properties x y and z."); } if (!faceReader.getElementType().getName().equals("face")) { throw new IllegalArgumentException( "faceReader does not read faces."); } boolean foundVertexIndex = false; for (Property p : faceReader.getElementType().getProperties()) { foundVertexIndex |= p.getName().equals("vertex_index") && (p instanceof ListProperty); } if (!foundVertexIndex) { throw new IllegalArgumentException( "Face type does not include a list property named " + "vertex_index."); } for (Element face = faceReader.readElement(); face != null; face = faceReader.readElement()) { accumulateNormals(vertexReader, face); } for (Element vertex = vertexReader.readElement(); vertex != null; vertex = vertexReader.readElement()) { normalize(vertex); } }  boolean isCounterClockwise(); void setCounterClockwise(final boolean counterClockwise); void generateNormals(final RandomElementReader vertexReader,
            final ElementReader faceReader);  }