GeometryArray ge=(GeometryArray)shape.getGeometry(); double[] cc1=new double[3]; ge.getCoordinate(0, cc1); System.out.println(cc1[0]+" "+cc1[1]+" "+cc1[2]); ge.getCoordinate(1, cc1); System.out.println(cc1[0]+" "+cc1[1]+" "+cc1[2]);
new PointArray(nAll, GeometryArray.COORDINATES | GeometryArray.COLOR_3); ta.setValidVertexCount(nValid); ta.setCoordinates(0, coords); ta.setColors(0, colors); ta.setCapability(GeometryArray.ALLOW_COLOR_WRITE); ta.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE); ta.setCapability(GeometryArray.ALLOW_COUNT_WRITE); ta.setCapability(GeometryArray.ALLOW_COUNT_READ); ta.setCapability(Geometry.ALLOW_INTERSECT);
protected void addVerticesToGeometryArray(final Point3f[] v) { changed = true; mesh.addAll(Arrays.asList(v)); // check maximum vertex count final GeometryArray ga = (GeometryArray) getGeometry(); final int max = ga.getVertexCount(); final int idx = ga.getValidVertexCount(); if (idx + v.length > max) { // enlarge arrays setGeometry(createGeometry()); return; } ga.setValidVertexCount(idx + v.length); ga.setCoordinates(idx, v); // update colors final Color3f[] colors = new Color3f[v.length]; Arrays.fill(colors, this.color); ga.setColors(idx, colors); recalculateNormals(ga); }
public void setColor(final Color3f color) { this.color = color != null ? color : DEFAULT_COLOR; final GeometryArray ga = (GeometryArray) getGeometry(); if (ga == null) return; final int N = ga.getVertexCount(); final Color3f colors[] = new Color3f[N]; for (int i = 0; i < N; i++) { colors[i] = this.color; } ga.setColors(0, colors); changed = true; }
@Override protected void writeConstructorParams( DataOutput out ) throws IOException { vertexCount = ((GeometryArray)node).getVertexCount(); vertexFormat = ((GeometryArray)node).getVertexFormat(); texCoordSetCount = ((GeometryArray)node).getTexCoordSetCount(); texCoordSetMap = new int[ ((GeometryArray)node).getTexCoordSetMapLength() ]; ((GeometryArray)node).getTexCoordSetMap( texCoordSetMap ); out.writeInt(vertexCount); out.writeInt(vertexFormat); out.writeInt( texCoordSetCount ); out.writeInt( texCoordSetMap.length ); for(int i=0; i<texCoordSetMap.length; i++) out.writeInt( texCoordSetMap[i] ); super.writeConstructorParams( out ); }
out.writeInt( ((GeometryArray)node).getInitialVertexIndex() ); if ( !(node instanceof GeometryStripArray) ) out.writeInt( ((GeometryArray)node).getValidVertexCount() ); FloatBuffer x = (FloatBuffer)((GeometryArray)node).getInterleavedVertexBuffer().getBuffer(); float[] f = new float[x.limit()]; x.position( 0 ); x.get( f ); writeFloatArray( out, f ); } else writeFloatArray( out, ((GeometryArray)node).getInterleavedVertices() ); } else { boolean byRef = (vertexFormat & GeometryArray.BY_REFERENCE) != 0; out.writeInt( ((GeometryArray)node).getInitialVertexIndex() ); if ( !(node instanceof GeometryStripArray) ) out.writeInt( ((GeometryArray)node).getValidVertexCount() ); out.writeInt( ((GeometryArray)node).getInitialColorIndex() ); J3DBuffer buf = ((GeometryArray)node).getColorRefBuffer(); switch( BufferWrapper.getBufferType( buf ) ) { case BufferWrapper.TYPE_BYTE: { } else if ( ((GeometryArray)node).getColorRef4f()!=null ) { out.writeInt( FORMAT_4F ); Color4f[] colors = ((GeometryArray)node).getColorRef4f(); float[] data = new float[ colors.length*4 ]; for (int i = 0 ; i < colors.length ; i++) {
((GeometryArray)node).setInitialVertexIndex( in.readInt() ); if ( !(node instanceof GeometryStripArray) ) ((GeometryArray)node).setValidVertexCount( in.readInt() ); FloatBuffer f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(floats); ((GeometryArray)node).setInterleavedVertexBuffer(new J3DBuffer(f)); } else ((GeometryArray)node).setInterleavedVertices( readFloatArray( in ) ); } else { boolean byRef = (vertexFormat & GeometryArray.BY_REFERENCE) != 0; ((GeometryArray)node).setInitialVertexIndex( in.readInt() ); if ( !(node instanceof GeometryStripArray) ) ((GeometryArray)node).setValidVertexCount( in.readInt() ); if ( byRef ) { if ( !(node instanceof IndexedGeometryArray) ) { ((GeometryArray)node).setInitialColorIndex( in.readInt() ); ByteBuffer b = ByteBuffer.allocateDirect(bytes.length); b.put(bytes); ((GeometryArray) node).setColorRefBuffer(new J3DBuffer(b)); FloatBuffer f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put( floats ); ((GeometryArray)node).setColorRefBuffer(new J3DBuffer(f)); ((GeometryArray)node).setColorRef4f( colors );
FloatBuffer f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(d); ga.setInterleavedVertexBuffer(new J3DBuffer(f)); } else ga.setInterleavedVertices(d); } else if (nio) { FloatBuffer f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(vecmathToFloat(coordinates)); ga.setCoordRefBuffer(new J3DBuffer(f)); f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(vecmathToFloat(colors3)); ga.setColorRefBuffer(new J3DBuffer(f)); } else if (colors4 != null) { b = ByteBuffer.allocateDirect(colors4.length * 4 * 4); f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(vecmathToFloat(colors4)); ga.setColorRefBuffer(new J3DBuffer(f)); f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(vecmathToFloat(normals)); ga.setNormalRefBuffer(new J3DBuffer(f)); f = b.order(ByteOrder.nativeOrder()).asFloatBuffer(); f.put(vecmathToFloat(texCoordSets[i])); ga.setTexCoordRefBuffer(i, new J3DBuffer(f)); ga.setCoordRefFloat(vecmathToFloat(coordinates)); if (colors3 != null) ga.setColorRefFloat(vecmathToFloat(colors3));
numTris += totalVerts - currPrimCnt * 2; obj.setCoordinates(0, newpts); if ((flags & Primitive.GENERATE_NORMALS) != 0) obj.setNormals(0, newnormals); if ((flags & Primitive.GENERATE_TEXTURE_COORDS) != 0) obj.setTextureCoordinates(0, 0, newtcoords);
primitiveCoordinates = new Point3d[primitiveVertexIndices.length]; int[] indices = getPrimitiveCoordinateIndices(); int vformat = geom.getVertexFormat(); int val; primitiveCoordinates[i] = new Point3d(); geom.getCoordinate(indices[i], primitiveCoordinates[i]); double[] doubleData = geom.getCoordRefDouble(); float[] floatData = geom.getCoordRefFloat(); if (floatData == null) { Point3f[] p3fData = geom.getCoordRef3f(); if (p3fData == null) { Point3d[] p3dData = geom.getCoordRef3d(); for (int i = 0; i < indices.length; i++) { primitiveCoordinates[i] = new Point3d(p3dData[indices[i]].x, p3dData[indices[i]].y, p3dData[indices[i]].z); float[] floatData = geom.getInterleavedVertices(); int offset = getInterleavedVertexOffset(geom); int stride = offset + 3; // for the vertices .
final boolean intersect(int geomIndex, boolean firstpick) { int offset; GeometryArray geom = geometryArrays[geomIndex]; int numPts = geom.getVertexCount(); double[] doubleData = null; float[] floatData = null; Point3d[] p3dData = null; Point3f[] p3fData = null; int vformat = geom.getVertexFormat(); int stride; boolean retFlag = false; geom.getCoordinates (0, doubleData); doubleData = geom.getCoordRefDouble(); floatData = geom.getCoordRefFloat(); if (floatData == null) { p3fData = geom.getCoordRef3f(); if (p3fData == null) { p3dData = geom.getCoordRef3d(); floatData = geom.getInterleavedVertices(); offset += 3; if ((vformat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2) { offset += 2 * geom.getTexCoordSetCount(); offset += 3 * geom.getTexCoordSetCount();
c3f[i] = v.color3 ; ga.setColors(0, c3f) ; c4f[i] = v.color4 ; ga.setColors(0, c4f) ; ga.setNormals(0, v3f) ; c3f[i] = v.color3 ; ga.setColors(0, c3f) ; c4f[i] = v.color4 ; ga.setColors(0, c4f) ; ga.setCoordinates(0, p3f) ;
primitiveCoordinates = new Point3d[primitiveVertexIndices.length]; int[] indices = getPrimitiveCoordinateIndices(); int vformat = geom.getVertexFormat(); int val; primitiveCoordinates[i] = new Point3d(); geom.getCoordinate(indices[i], primitiveCoordinates[i]); double[] doubleData = geom.getCoordRefDouble(); float[] floatData = geom.getCoordRefFloat(); if (floatData == null) { throw new UnsupportedOperationException("Deprecated : BY_REF - c3f and c3d"); float[] floatData = geom.getInterleavedVertices(); int offset = getInterleavedVertexOffset(geom); int stride = offset + 3; // for the vertices .
public void recalculateNormals(final GeometryArray ga) { if (ga == null) return; if ((ga.getVertexFormat() & GeometryArray.NORMALS) == 0) return; changed = true; final GeometryInfo gi = new GeometryInfo(ga); final NormalGenerator ng = new NormalGenerator(); ng.generateNormals(gi); final GeometryArray tmp = gi.getGeometryArray(); final int v = ga.getValidVertexCount(); final float[] normals = new float[3 * v]; tmp.getNormals(0, normals); ga.setNormals(0, normals); }
public void loadSurfaceColorsFromImage(ImagePlus imp) { final GeometryArray ga = (GeometryArray) getGeometry(); if (ga == null) return; if (imp.getType() != ImagePlus.COLOR_RGB) { imp = new Duplicator().run(imp); new StackConverter(imp).convertToRGB(); } final InterpolatedImage ii = new InterpolatedImage(imp); final int N = ga.getValidVertexCount(); final Color3f[] colors = new Color3f[N]; final Calibration cal = imp.getCalibration(); final double pw = cal.pixelWidth; final double ph = cal.pixelHeight; final double pd = cal.pixelDepth; final Point3f coord = new Point3f(); for (int i = 0; i < N; i++) { ga.getCoordinate(i, coord); final int v = (int) Math.round(ii.interpol.get(coord.x / pw, coord.y / ph, coord.z / pd)); colors[i] = new Color3f(((v & 0xff0000) >> 16) / 255f, ((v & 0xff00) >> 8) / 255f, (v & 0xff) / 255f); } ga.setColors(0, colors); changed = true; }
primitiveNormals = new Vector3f[primitiveVertexIndices.length]; int[] indices = getPrimitiveNormalIndices(); int vformat = geom.getVertexFormat(); int val; for (int i = 0; i < indices.length; i++) { primitiveNormals[i] = new Vector3f(); geom.getNormal(indices[i], primitiveNormals[i]); float[] floatNormals = geom.getNormalRefFloat(); if (floatNormals != null) { for (int i = 0; i < indices.length; i++) { Vector3f[] normal3f = geom.getNormalRef3f(); for (int i = 0; i < indices.length; i++) { primitiveNormals[i] = new Vector3f(normal3f[indices[i]].x,normal3f[indices[i]].y,normal3f[indices[i]].z); float[] floatData = geom.getInterleavedVertices(); int offset = getInterleavedColorOffset(geom); int stride = getInterleavedStride(geom);
for (j=0;j < islandCounts.length;j++) { GeometryArray ga = triangData.get(j); vertOffset = ga.getVertexCount(); ga.getCoordinate(i, p1); ga.getNormal(i, n1); ga.getCoordinate(i+1, p2); ga.getCoordinate(i+2, p3);
int vformat = geom.getVertexFormat(); if ((vformat & GeometryArray.BY_REFERENCE) == 0) { for (int i = 0; i < indices.length; i++) { primitiveTexCoords[i] = new TexCoord3f(); geom.getTextureCoordinate(index, indices[i], primitiveTexCoords2DTmp); primitiveTexCoords[i].set( primitiveTexCoords2DTmp.x, if ((vformat & GeometryArray.INTERLEAVED) == 0) { int val; float[] floatTexCoords = geom.getTexCoordRefFloat(index); if (floatTexCoords != null) { if ((vformat & GeometryArray.TEXTURE_COORDINATE_2) == GeometryArray.TEXTURE_COORDINATE_2) { TexCoord2f[] texCoord2f = geom.getTexCoordRef2f(index); if (texCoord2f != null) { for (int i = 0; i < indices.length; i++) { TexCoord3f[] texCoord3f = geom.getTexCoordRef3f(index); for (int i = 0; i < indices.length; i++) { primitiveTexCoords[i] = new TexCoord3f(texCoord3f[indices[i]].x, float[] floatData = geom.getInterleavedVertices(); int stride = getInterleavedStride(geom); int offset;
final GeometryArray geometryArray = gi.getGeometryArray(); { geometryArray.setCapability(GeometryArray.ALLOW_COLOR_READ); geometryArray.setCapability(GeometryArray.ALLOW_COLOR_WRITE); }
public void setTransparentColor(final List<Color4f> color) { this.color = null; final GeometryArray ga = (GeometryArray) getGeometry(); if (ga == null) return; final int N = ga.getValidVertexCount(); if (color.size() != N) throw new IllegalArgumentException("list of size " + N + " expected"); final Color4f[] colors = new Color4f[N]; color.toArray(colors); ga.setColors(0, colors); changed = true; }