use of maspack.util.Rectangle in project artisynth_core by artisynth.
the class DicomTextureContent method getTextureCoordinates.
/**
* Texture coordinates for a given plane ({@link #COL_ROW_PLANE},
* {@link #ROW_SLICE_PLANE}, or {@link #COL_SLICE_PLANE}), starting with the
* bottom-left corner and working around clockwise.
*
* @return texture coordinates
*/
public Point2d[] getTextureCoordinates(int plane) {
Point2d[] out = new Point2d[4];
Rectangle rect = rects[plane];
int w = textureWidth - 1;
int h = textureHeight - 1;
double tx1 = (double) rect.x() / w;
double tx2 = ((double) rect.x() + rect.width() - 1) / w;
double ty1 = (double) rect.y() / h;
double ty2 = ((double) rect.y() + rect.height() - 1) / h;
out[0] = new Point2d(tx1, ty1);
out[1] = new Point2d(tx1, ty2);
out[2] = new Point2d(tx2, ty2);
out[3] = new Point2d(tx2, ty1);
return out;
}
use of maspack.util.Rectangle in project artisynth_core by artisynth.
the class DicomTextureContent method updateBounds.
protected void updateBounds(Rectangle[] rects) {
textureWidth = 0;
textureHeight = 0;
for (Rectangle r : rects) {
int x = r.x() + r.width();
if (x > textureWidth) {
textureWidth = x;
}
int y = r.y() + r.height();
if (y > textureHeight) {
textureHeight = y;
}
}
textureWidth = get2Fold(textureWidth);
textureHeight = get2Fold(textureHeight);
}
use of maspack.util.Rectangle in project artisynth_core by artisynth.
the class TextImageStore method markDirty.
/**
* Mark a region of the backing image as "dirty" (i.e. modified)
*/
public void markDirty(Rectangle rect) {
if (dirty == null) {
dirty = rect;
return;
}
int x = Math.min(dirty.x(), rect.x());
int y = Math.min(dirty.y(), rect.y());
int w = Math.max(Math.max(dirty.width(), rect.width()), Math.max(rect.x() + rect.width() - dirty.x(), dirty.x() + dirty.width() - rect.x()));
int h = Math.max(Math.max(dirty.height(), rect.height()), Math.max(rect.y() + rect.height() - dirty.y(), dirty.y() + dirty.height() - rect.y()));
dirty = new Rectangle(x, y, w, h);
}
use of maspack.util.Rectangle in project artisynth_core by artisynth.
the class TextureContentImage method setImage.
protected void setImage(BufferedImage image, boolean powerOfTwo) {
if (image == null) {
this.image = null;
this.dirty = null;
} else {
this.image = convert(image, powerOfTwo);
this.dirty = new Rectangle(0, 0, image.getWidth(), image.getHeight());
}
}
use of maspack.util.Rectangle in project artisynth_core by artisynth.
the class GLSharedResources method maybeUpdateTexture.
private boolean maybeUpdateTexture(GL gl, GLTexture texture, TextureContent content) {
boolean update = false;
Rectangle dirty = content.getDirty();
if (dirty != null) {
ContentFormat format = content.getFormat();
int glFormat = 0;
int glType = 0;
int[] swizzle = null;
switch(format) {
case GRAYSCALE_ALPHA_BYTE_2:
if (gl.isGL3()) {
glFormat = GL3.GL_RG;
swizzle = GLTextureLoader.SWIZZLE_GRAY_ALPHA;
} else if (gl.isGL2()) {
glFormat = GL2.GL_LUMINANCE_ALPHA;
}
glType = GL.GL_UNSIGNED_BYTE;
break;
case GRAYSCALE_ALPHA_SHORT_2:
if (gl.isGL3()) {
glFormat = GL3.GL_RG;
swizzle = GLTextureLoader.SWIZZLE_GRAY_ALPHA;
} else if (gl.isGL2()) {
glFormat = GL2.GL_LUMINANCE_ALPHA;
}
glType = GL.GL_UNSIGNED_SHORT;
break;
case GRAYSCALE_BYTE:
if (gl.isGL3()) {
glFormat = GL3.GL_RED;
swizzle = GLTextureLoader.SWIZZLE_GRAY;
} else if (gl.isGL2()) {
glFormat = GL2.GL_LUMINANCE;
}
glType = GL.GL_BYTE;
break;
case GRAYSCALE_UBYTE:
if (gl.isGL3()) {
glFormat = GL3.GL_RED;
swizzle = GLTextureLoader.SWIZZLE_GRAY;
} else if (gl.isGL2()) {
glFormat = GL2.GL_LUMINANCE;
}
glType = GL.GL_UNSIGNED_BYTE;
break;
case GRAYSCALE_SHORT:
if (gl.isGL3()) {
glFormat = GL3.GL_RED;
swizzle = GLTextureLoader.SWIZZLE_GRAY;
} else if (gl.isGL2()) {
glFormat = GL2.GL_LUMINANCE;
}
glType = GL.GL_SHORT;
break;
case GRAYSCALE_USHORT:
if (gl.isGL3()) {
glFormat = GL3.GL_RED;
swizzle = GLTextureLoader.SWIZZLE_GRAY;
} else if (gl.isGL2()) {
glFormat = GL2.GL_LUMINANCE;
}
glType = GL.GL_UNSIGNED_SHORT;
break;
case RGBA_BYTE_4:
glFormat = GL.GL_RGBA;
glType = GL.GL_UNSIGNED_BYTE;
if (gl.isGL3()) {
swizzle = GLTextureLoader.SWIZZLE_RGBA;
}
break;
case RGBA_INTEGER:
glFormat = GL2GL3.GL_RGBA_INTEGER;
glType = GL2GL3.GL_UNSIGNED_INT_8_8_8_8;
if (gl.isGL3()) {
swizzle = GLTextureLoader.SWIZZLE_RGBA;
}
break;
case RGB_BYTE_3:
glFormat = GL.GL_RGB;
glType = GL.GL_UNSIGNED_BYTE;
if (gl.isGL3()) {
swizzle = GLTextureLoader.SWIZZLE_RGBA;
}
break;
default:
break;
}
update = true;
int psize = content.getPixelSize();
int width = dirty.width();
int height = dirty.height();
if (texture.getFormat() != glFormat || texture.getType() != glType) {
// re-create entire texture
width = content.getWidth();
height = content.getHeight();
ByteBuffer buff = BufferUtilities.newNativeByteBuffer(width * height * psize);
content.getData(buff);
buff.flip();
texture.fill(gl, width, height, psize, glFormat, glType, swizzle, buff);
buff = BufferUtilities.freeDirectBuffer(buff);
} else {
ByteBuffer buff = BufferUtilities.newNativeByteBuffer(width * height * psize);
content.getData(dirty, buff);
buff.flip();
texture.fill(gl, dirty.x(), dirty.y(), width, height, psize, glFormat, glType, buff);
buff = BufferUtilities.freeDirectBuffer(buff);
}
content.markClean();
}
return update;
}
Aggregations