import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import javax.media.j3d.Alpha;
import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Texture;
import javax.media.j3d.TextureAttributes;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Point3d;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class TextureImage extends Applet {
private java.net.URL texImage = null;
private SimpleUniverse u = null;
public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();
// Create the transform group node and initialize it to the
// identity. Enable the TRANSFORM_WRITE capability so that
// our behavior code can modify it at runtime. Add it to the
// root of the subgraph.
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objTrans);
// Create appearance object for textured cube
Appearance app = new Appearance();
Texture tex = new TextureLoader(texImage, this).getTexture();
app.setTexture(tex);
TextureAttributes texAttr = new TextureAttributes();
texAttr.setTextureMode(TextureAttributes.MODULATE);
app.setTextureAttributes(texAttr);
// Create textured cube and add it to the scene graph.
Box textureCube = new Box(0.4f, 0.4f, 0.4f,
Box.GENERATE_TEXTURE_COORDS, app);
objTrans.addChild(textureCube);
// Create a new Behavior object that will perform the desired
// operation on the specified transform object and add it into
// the scene graph.
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
4000, 0, 0, 0, 0, 0);
RotationInterpolator rotator = new RotationInterpolator(rotationAlpha,
objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
100.0);
rotator.setSchedulingBounds(bounds);
objTrans.addChild(rotator);
// Have Java 3D perform optimizations on this scene graph.
objRoot.compile();
return objRoot;
}
public TextureImage() {
}
public TextureImage(java.net.URL url) {
texImage = url;
}
public void init() {
if (texImage == null) {
// the path to the image for an applet
try {
texImage = new java.net.URL(getCodeBase().toString()
+ "/stone.jpg");
} catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
}
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse
.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add("Center", c);
// Create a simple scene and attach it to the virtual universe
BranchGroup scene = createSceneGraph();
u = new SimpleUniverse(c);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public void destroy() {
u.cleanup();
}
//
// The following allows TextureImage to be run as an application
// as well as an applet
//
public static void main(String[] args) {
java.net.URL url = null;
if (args.length > 0) {
try {
url = new java.net.URL("file:" + args[0]);
} catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
} else {
// the path to the image for an application
try {
url = new java.net.URL("file:stone.jpg");
} catch (java.net.MalformedURLException ex) {
System.out.println(ex.getMessage());
System.exit(1);
}
}
new MainFrame(new TextureImage(url), 256, 256);
}
}
分享到:
相关推荐
We present a simple image-based method of generating novel visual appearance in which a new image is synthesized by stitching together small patches of existing images. We call this process image ...
think of texture mapping as “the application of a texture image to a primitive,” and while it certainly is that – there is more math going on than most folks think. If you have ever written your ...
rotating cube with a texture
image processing texture analysisimage processing texture analysisimage processing texture analysisimage processing texture analysis
this is a opencv project to add background and texture for the image
在Xcode4.5上调试通过,利用OpenGL ES2.0实现cubemap texture.
Image retargeting aims at adapting a given image to fit the size of arbitrary displays without severe visual distortions.
Image Texture Analysis Foundations Models and Algorithms,2019年新书,介绍图像纹理分析的基本模型和算法
The image structure elements’ histogram (SEH) is computed by SED, and HSV color space is used (it has been quantized to 72 bins). SEH integrates the advantages of both statistical and structural ...
-enhance apply a digital filter to enhance a noisy image -equalize perform histogram equalization to an image -evaluate operator value evaluate an arithmetic, relational, or logical expression -...
color and texture information for the segmentation of color images. The algorithm uses maximum likelihood classication combined with a certainty based fusion criterion. The algorithm was validated ...
[ And it uses a dynamic link, there is no obligation to disclose the source. ] [Source code is included in the package. If necessary, it may be used to modify. ] Supported resolutions: Android: ...
You could place a wood texture on a cube to make the cube look like it is actually made of wood. The Texture sample project adds a banana peel texture to the cylinder created in tutorial 4. This ...
distribution, we first estimate the principal orientations of the texture image and then use them to align LBP histograms. The aligned histograms are then in turn used to measure the dissimilarity ...
使用fbo来实现render to texture演示
纹理图像处理领域的著作,Wiley出版社出版.
While texture synthesis on surfaces has received much attention in computer graphics, the ideal solution ...preprocessed texture sample can be used to synthesize a texture map on any number of meshes.
This introductory textbook presents the modern signal processing concepts used in computer vision and image analysis in a systematic and mathematically coherent way. For the first time in a textbook ...
A cartoon-plus-texture image decomposition model for blind deconvolution
QML中Image控件升级版,利用预解释和预读取,提升图片加载速度