Package com.sun.j3d.utils.image

Examples of com.sun.j3d.utils.image.TextureLoader


      DocumentKarto mydocK = KartoLoader.loadDocumentKarto(Variables.textureCalibreeURL);
      initTextureCalibree(mydocK);

      break;
      case DialogVisu3DkartoMNT.TEX_FICHIER:
        earth = new TextureLoader(new java.net.URL(Variables.textureURL), this).getTexture();
      break;
      case DialogVisu3DkartoMNT.NO_TEX:
      default:
      earth = new TextureLoader(new java.net.URL("file:/nofile"), this).getTexture();
      }
    }
    catch (Exception e)
    {
      //System.out.println("Land texture init error: "+e.getMessage());
View Full Code Here


      Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS |
                      Sphere.GENERATE_NORMALS_INWARD |
                      Sphere.GENERATE_TEXTURE_COORDS, 20);
      /* BackGround appearance */
      Appearance backgroundApp = sphere.getAppearance();
      TextureLoader texture = new TextureLoader(backGroundUrl, this);
      if (texture != null)
        backgroundApp.setTexture(texture.getTexture());
      /* BackGround to the scene */
      backGroundGeoBranch.addChild(sphere);
      backGround.setGeometry(backGroundGeoBranch);
      graphRoot.addChild(backGround);
    }
 
View Full Code Here

   */
  private void initTextureCalibree(DocumentKarto docK){
    try{
      if ((docK==null)||(docK.getCarteFileName()==null)){
        //System.err.println("Erreur : Probl�me lors de l'initialisation de la texture calibr�e");
        earth = new TextureLoader(new java.net.URL("file:/nofile"), this).getTexture();
        return;
      }      else if (!docK.isCalibrated()){   
        earth = new TextureLoader(new java.net.URL("file:"+((docK.getCarteFileName().charAt(0)=='/')?"":"/")+docK.getCarteFileName()), this).getTexture();
        return;
      }

      // rectangle englobant la texture dont les positions sont calibr�es
      Rectangle2 rect=MathUtil.getEnglobingRect(docK.getProjection(),0,0,
                            docK.getLignesDeNiveaux().getXMax()-1,docK.getLignesDeNiveaux().getYMax()-1);
   
      System.out.println("RectangleTexture : "+rect);
      System.out.println("RectangleMNT : "+landMNT.getX1()+" "+landMNT.getY1()+" "+landMNT.getX2()+" "+landMNT.getY2());
   
      MediaTracker monTracker = new MediaTracker(this);
      Image img=Toolkit.getDefaultToolkit().getImage(docK.getCarteFileName());
      monTracker.addImage(img,0);   
      try
        monTracker.waitForID(0);
      }catch(InterruptedException e) {
        System.out.println("Exception : " + e.toString());
      }

      Image imageTexture;
     
      // rectangle � s�lectionner dans la texture
      double rx=Math.max(landMNT.getX1(),rect.x1);
      double ry=Math.max(landMNT.getY1(),rect.y1);
      double rw=Math.min(landMNT.getX2(),rect.x2)-rx;
      double rh=Math.min(landMNT.getY2(),rect.y2)-ry;
   
      //System.out.println("RectangleTexture1' : "+rx+" "+ry+" "+rw+" "+rh);
      //System.out.println("Taille image : "+img.getWidth(this)+"x"+img.getHeight(this));
   
      // on transforme les coordonn�es sur la carte en pixel dans l'image
   
      int x=(int)((rx-rect.x1)*img.getWidth(this)/(rect.x2-rect.x1));
      int y=(int)((ry-rect.y1)*img.getHeight(this)/(rect.y2-rect.y1));
      int w=(int)(rw*img.getWidth(this)/(rect.x2-rect.x1));
      int h=(int)(rh*img.getHeight(this)/(rect.y2-rect.y1));
     
      System.out.println("RectangleTexture2 : "+x+" "+y+" "+w+" "+h);
 
 
      if ((w>0) && (h>0)){
        // pixels contenant les donn�es de la texture
        int[] pixels = new int[(int)(w * h)];
        PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
        try {
          pg.grabPixels();
        } catch (InterruptedException e) {
          System.err.println("interrupted waiting for pixels!");
          return;
        }
        if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
          System.err.println("image fetch aborted or errored");
          return;
        }
       
        // si le MNT se trouve dans la texture, c'est bon
        if ((landMNT.getX1()>rect.x1)&&(landMNT.getY1()>rect.y1)&&(landMNT.getX2()<rect.x2)&&(landMNT.getY2()<rect.y2)){
          imageTexture = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, pixels, 0, w));
     
        }else{
          // calcul de la taille de la texture calibr�e finale
          int tailleW=(int)((landMNT.getX2()-landMNT.getX1())*w/rw);
          int tailleH=(int)((landMNT.getY2()-landMNT.getY1())*h/rh);
          int[] pixelsTex = new int[tailleW*tailleH];
         
          // dialog bouche-trou
          BoucheTrouDialog bchTrou=new BoucheTrouDialog();
     
          // tant qu'on n'a pas une r�ponse, on attend
          while (!bchTrou.isGood());
         
          // si l'utilisateur a choisi la couleur
          if (bchTrou.choiceIsColor()){
            // on remplit le tableau de la couleur
            Arrays.fill(pixelsTex,bchTrou.getCouleurBC().getRGB());
          }else{
            // sinon l'utilisateur a choisi la texture
            // on r�cup�re la texture d�finie par l'utilisateur
            Image imgBT=Toolkit.getDefaultToolkit().getImage(bchTrou.getNomFichier());
            monTracker.addImage(imgBT,1);   
            try
              monTracker.waitForID(1);
            }catch(InterruptedException e) {
              System.out.println("Exception : " + e.toString());
            }

            // on transforme l'image en un tableau
            int[] pixelsBT=new int[imgBT.getWidth(this)*imgBT.getHeight(this)];
     
            //System.out.println("W : "+imgBT.getWidth(this)+" H : "+imgBT.getHeight(this)+" L : "+pixelsBT.length);

            pg = new PixelGrabber(imgBT, 0, 0, imgBT.getWidth(this), imgBT.getHeight(this), pixelsBT, 0, imgBT.getWidth(this));
            try {
              pg.grabPixels();
            } catch (InterruptedException e) {
              System.err.println("interrupted waiting for pixels!");
              return;
            }
            if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              return;
            }
   
            // on remplit notre tableau de texture avec la texture r�cup�r�e
            // que l'on r�p�te au bord
            for(int i=0;i<tailleW;i++){
              for (int j=0;j<tailleH;j++){       
                pixelsTex[i+tailleW*j]=pixelsBT[(i%imgBT.getWidth(this))+imgBT.getWidth(this)*(j%imgBT.getHeight(this))];
              }
            }
          } // else du if (bchTrou.choiceIsColor())
          // on r�cup�re la m�moire
          bchTrou.dispose();
     
          // indice o� l'on doit commencer � remplir la texture
          int debX=(int)((Math.max(rect.x1,landMNT.getX1())-landMNT.getX1())*w/rw);
          int debY=(int)((Math.max(rect.y1,landMNT.getY1())-landMNT.getY1())*h/rh);
           
          // remplissage
          for(int i=0;i<w;i++){
            for (int j=0;j<h;j++){
              pixelsTex[(debX+i) + (debY+j)*tailleW]=pixels[i+w*j]
            }
          }
          // on cr�e l'image � partir du tableau
          imageTexture = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(tailleW, tailleH, pixelsTex, 0, tailleW));
           
        } // else de if ((landMNT.getX1()>rect.x1)&&(landMNT.getY1()>rect.y1)&&(landMNT.getX2()<rect.x2)&&(landMNT.getY2()<rect.y2)){
      }else{
        // else du if ((w>0) && (h>0)){
        imageTexture = createImage(16,16);
      }
      // taille de la texture finale calibr�e
      // (le TextureLoader ne fonctionne pas si les textures qu'on lui donne
      //  sont trop grandes ou bien si elles ne sont pas assez carr�)
      int newWidth=512;
      int newHeight=512;
 
      // retaillage de l'image � la nouvelle taille
      BufferedImage resizedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_RGB);
      Graphics2D graphics2D = resizedImage.createGraphics();
      graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
      graphics2D.drawImage(imageTexture, 0, 0, newWidth, newHeight, null);
 
//System.out.println("Visu3DKartoMNT : resize image taille "+imageTexture.getHeight(null)+"x"+imageTexture.getWidth(null)+" sur taille : "+resizedImage.getHeight()+"x"+resizedImage.getWidth());
      // on affiche l'image et on demande a l'utilisateur s'il veut sauver
      Object[] options2 = {ResourceManager.get("OkKey"),ResourceManager.get("save")};
      int value = JOptionPane.showOptionDialog(this, "", ResourceManager.get("TextureMNT"),
      JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
      new ImageIcon(resizedImage),options2,options2[0]);

      if (value==JOptionPane.NO_OPTION) {
        enregistreImage(resizedImage);
      }
    //GFE??  imageTexture=img_ico;
      // on charge la texture
      earth = new TextureLoader(resizedImage).getTexture();

    } catch (Exception e){
      //System.out.println("Land texture init error: "+e.getMessage());
      e.printStackTrace();
      JOptionPane.showMessageDialog(null,ResourceManager.get("errorTexMNT"),ResourceManager.get("error"),JOptionPane.WARNING_MESSAGE);     
View Full Code Here

      DocumentKarto mydocK = KartoLoader.loadDocumentKarto(Variables.textureCalibreeURL);
      initTextureCalibree(mydocK);

      break;
      case DialogVisu3DKartoMNT.TEX_FICHIER:
        earth = new TextureLoader(new java.net.URL(Variables.textureURL), this).getTexture();
      break;
      case DialogVisu3DKartoMNT.NO_TEX:
      default:
      earth = new TextureLoader(new java.net.URL("file:/nofile"), this).getTexture();
      }
    }
    catch (Exception e)
    {
      //System.out.println("Land texture init error: "+e.getMessage());
View Full Code Here

      Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS |
                      Sphere.GENERATE_NORMALS_INWARD |
                      Sphere.GENERATE_TEXTURE_COORDS, 20);
      /* BackGround appearance */
      Appearance backgroundApp = sphere.getAppearance();
      TextureLoader texture = new TextureLoader(backGroundUrl, this);
      if (texture != null)
        backgroundApp.setTexture(texture.getTexture());
      /* BackGround to the scene */
      backGroundGeoBranch.addChild(sphere);
      backGround.setGeometry(backGroundGeoBranch);
      graphRoot.addChild(backGround);
    }
 
View Full Code Here

  //the SimpleUniverse.
  public void createSceneGraph(SimpleUniverse su)
  {

    //Load the image for the texture.
    TextureLoader textureLoad = new TextureLoader("./eas/miscellaneous/java3D/myTexture.jpg",null);

    //Generate a (scaled) image of the texture. Height and width must be
    //powers of 2.
    ImageComponent2D textureIm = textureLoad.getScaledImage(64,128);

    //Generate the texture.
    Texture2D aTexture = new Texture2D(Texture2D.BASE_LEVEL,Texture2D.RGB,
                                            textureIm.getWidth(),
                                            textureIm.getHeight());
View Full Code Here


    //The bounding region for the background sound.
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    //Load the background image.
    TextureLoader textureLoad = new TextureLoader("./eas/miscellaneous/java3D/darkclouds.jpg",null);
    //Define the loaded image as the background for the scene.
    Background bgImage = new Background(textureLoad.getImage());
    bgImage.setApplicationBounds(bounds);
    theScene.addChild(bgImage);

    //Add the background sound (rain) to the scene.
    theScene.addChild(soundBG);
View Full Code Here


    //The bounding region for the background.
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),Double.MAX_VALUE);
    //Load the background image.
    TextureLoader textureLoad = new TextureLoader("./eas/miscellaneous/java3D/darkclouds.jpg",null);
    //Define the image as the background and add it to the scene.
    Background bgImage = new Background(textureLoad.getImage());
    bgImage.setApplicationBounds(bounds);
    theScene.addChild(bgImage);


    theScene.compile();
View Full Code Here

                if ((attribute == texture) && (_appearance != null)) {
                    URL textureURL = texture.asURL();

                    if ((_viewScreen != null) && (textureURL != null)) {
                        TextureLoader loader;
                        loader = new TextureLoader(textureURL, _viewScreen
                                .getCanvas());

                        Texture loadedTexture = loader.getTexture();

                        if (loadedTexture != null) {
                            _appearance.setTexture(loadedTexture);
                        }
                    }
View Full Code Here

        URL textureURL = texture.asURL();
        TextureAttributes attributes = null;

        if (textureURL != null) {
            TextureLoader loader;
            loader = new TextureLoader(textureURL, _viewScreen.getCanvas());

            Texture loadedTexture = loader.getTexture();

            if (loadedTexture != null) {
                attributes = new TextureAttributes();
                attributes.setTextureMode(TextureAttributes.MODULATE);
                _appearance.setTextureAttributes(attributes);
View Full Code Here

TOP

Related Classes of com.sun.j3d.utils.image.TextureLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.