@Override public TextureTile getTextureTile( TextureTileRequest request ) { return getTextureTile( request.getMinX(), request.getMinY(), request.getMaxX(), request.getMaxY() ); }
/** * @param candidate * @return true if this request covers the total area of the given 'candiate'. */ public boolean isFullfilled( TextureTile candidate ) { return ( this.minX - candidate.getMinX() ) >= ( -EPS ) && ( this.minY - candidate.getMinY() ) >= ( -EPS ) && ( this.maxX - candidate.getMaxX() ) <= ( EPS ) && ( this.maxY - candidate.getMaxY() ) <= ( EPS ) && ( this.unitsPerPixel - candidate.getMetersPerPixel() ) >= ( -EPS ); }
@Override public TextureTile getTextureTile( TextureTileRequest request ) { return getTextureTile( request.getMinX(), request.getMinY(), request.getMaxX(), request.getMaxY() ); }
/** * @param request */ private TextureTile getMatchingTileWithout( TextureTileRequest request ) { TextureTile tile = null; for ( TextureTile candidate : cachedTiles ) { if ( request.isFullfilled( candidate ) ) { tile = candidate; cachedTiles.remove( candidate ); cachedTiles.add( candidate ); break; } } if ( tile == null ) { tile = getMatchingProvider( request.getUnitsPerPixel() ).getTextureTile( request ); if ( tile != null && tile.enableCaching() ) { addToCache( tile ); } } return tile; }
/** * @param request * to copy the values from. */ public TextureTileRequest( TextureRequest request ) { this( request.getMinX(), request.getMinY(), request.getMaxX(), request.getMaxY(), request.getUnitsPerPixel() ); }
/** * * @param that * @return true if two request share a border. */ public boolean shareCorner( TextureTileRequest that ) { return this.shareCornerNE( that ) || this.shareCornerNW( that ) || this.shareCornerSE( that ) || this.shareCornerSW( that ); }
/** * Enable the given fragment texture. * * @param fragmentTexture * @param gl * context to which the given textures are bound. */ public void enable( FragmentTexture fragmentTexture, GL gl ) { if ( fragmentTexture.cachingEnabled() ) { FragmentTexture inCache = get( fragmentTexture.getId() ); if ( inCache == null ) { this.put( fragmentTexture.getId(), fragmentTexture ); } } if ( !fragmentTexture.isEnabled() ) { fragmentTexture.enable( gl ); } }
private TextureTileProvider getMatchingProvider( double unitsPerPixel ) { TextureTileProvider provider = providers[0]; for ( int i = 0; i < providers.length; i++ ) { // double provRes = providers[i].getNativeResolution(); if ( !providers[i].hasTextureForResolution( unitsPerPixel ) ) { break; } provider = providers[i]; } LOG.debug( "Using povider with native resolution: " + provider.getNativeResolution() ); return provider; }
public Pair<TextureTileRequest, File> get( TextureTileRequest req ) { Pair<TextureTileRequest, File> result = null; File f = super.get( req ); if ( f == null ) { for ( TextureTileRequest key : keySet() ) { if ( key != null && req.isFullfilled( key, 0.003 ) ) { f = super.get( key ); result = new Pair<TextureTileRequest, File>( key, f ); break; } } } else { result = new Pair<TextureTileRequest, File>( req, f ); } // if ( result != null ) { // System.out.println( "******************Found a cachefile******************" ); // } return result; }
/** * Generate the texture coordinates for the current fragment and the current texture. The texture coordinates will * be put into the given direct buffer. * * @param directTexCoordBuffer * @param translationVector */ public void generateTextureCoordinates( PooledByteBuffer directTexCoordBuffer, double[] translationVector ) { this.texCoords = directTexCoordBuffer; this.texCoordsBuffer = generateTexCoordsBuffer( translationVector ); }
/** * @return the id of the fragment */ public Integer getId() { return hashCode(); } }
/** * Returns the resolution of the texture (world units per pixel). * * @return the resolution of the texture */ public double getTextureResolution() { return texture.getMetersPerPixel(); }
/** * @return true if caching was enabled for this texture. */ public boolean cachingEnabled() { return this.texture.enableCaching(); }
private void addTileProvider( AbstractRaster raster, List<TextureTileProvider> tileProviders ) { TextureTileProvider ttProv = new RasterAPITextureTileProvider( raster ); tileProviders.add( ttProv ); } }
private void addToCache( TextureTile tile ) { // tile will not be null if ( cachedTiles.size() == maxCached ) { TextureTile cacheDrop = cachedTiles.iterator().next(); if ( cacheDrop != null ) { cachedTiles.remove( cacheDrop ); cacheDrop.dispose(); } } cachedTiles.add( tile ); }
@Override public boolean equals( Object o ) { if ( !( o instanceof TextureRequest ) ) { return false; } TextureRequest that = (TextureRequest) o; return this.fragment.getId() == that.fragment.getId() && ( getUnitsPerPixel() - that.getUnitsPerPixel() ) < 0.001f; }
private void setColor( GL gl, TextureTileRequest request ) { if ( request.getUnitsPerPixel() <= 0.1 ) { gl.glColor4f( 1.0f, 0.0f, 0.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 0.2 ) { gl.glColor4f( 1.0f, 0.5f, 0.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 0.4 ) { gl.glColor4f( 1.0f, 1.0f, 0.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 0.8 ) { gl.glColor4f( 0.5f, 1.0f, 0.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 1.6 ) { gl.glColor4f( 0.0f, 1.0f, 0.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 3.2 ) { gl.glColor4f( 0.0f, 1.0f, 0.5f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 6.4 ) { gl.glColor4f( 0.0f, 1.0f, 1.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 12.8 ) { gl.glColor4f( 0.0f, 0.5f, 1.0f, 0.2f ); } else if ( request.getUnitsPerPixel() <= 25.6 ) { gl.glColor4f( 0.0f, 0.0f, 1.0f, 0.2f ); } else { gl.glColor4f( 0.0f, 0.0f, 0.9f, 0.2f ); } }
@Override public boolean equals( Object other ) { if ( other != null && other instanceof FragmentTexture ) { final FragmentTexture that = (FragmentTexture) other; return this.fragment.getId() == that.fragment.getId() && this.texture.equals( that.texture ); } return false; }
/** * @param request */ private TextureTile getMatchingTileWithLogging( TextureTileRequest request ) { TextureTile tile = null; // System.out.println( "Cached tiles: " + cachedTiles.size() ); LOG.debug( "testing: " + request.toString() ); for ( TextureTile candidate : cachedTiles ) { LOG.debug( "against: " + candidate ); if ( request.isFullfilled( candidate ) ) { LOG.debug( "-- a match " ); tile = candidate; // System.out.println( "using from cache tile: " + tile.hashCode() ); cachedTiles.remove( candidate ); cachedTiles.add( candidate ); break; } } if ( tile == null ) { LOG.debug( "-- no match " ); tile = getMatchingProvider( request.getUnitsPerPixel() ).getTextureTile( request ); if ( tile != null && tile.enableCaching() ) { addToCache( tile ); } } return tile; }
/** * @param fragment * needed to generate the texture coordinates * @param texture * @param translationVector * @param buffer */ public FragmentTexture( RenderMeshFragment fragment, TextureTile texture, double[] translationVector, PooledByteBuffer buffer ) { this( fragment, texture ); this.texCoords = buffer; // buffer.getBuffer().order( ByteOrder.nativeOrder() ); this.texCoordsBuffer = generateTexCoordsBuffer( translationVector ); // this.xOffset = xOffset; // this.yOffset = yOffset; }