Revision 91 1.10/trunk/libraries/lib3DMap/src/org/gvsig/gvsig3d/map3d/MapContext3D.java
MapContext3D.java | ||
---|---|---|
10 | 10 |
import java.awt.image.RenderedImage; |
11 | 11 |
import java.io.File; |
12 | 12 |
import java.io.IOException; |
13 |
import java.util.ArrayList; |
|
13 | 14 |
import java.util.Hashtable; |
14 | 15 |
import java.util.Vector; |
15 | 16 |
|
... | ... | |
18 | 19 |
import org.apache.log4j.Logger; |
19 | 20 |
import org.cresques.cts.IProjection; |
20 | 21 |
import org.gvsig.cacheservice.TileNum; |
22 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
|
21 | 23 |
import org.gvsig.gvsig3d.cacheservices.FLayerCacheService; |
22 | 24 |
import org.gvsig.gvsig3d.cacheservices.OSGCacheService; |
23 | 25 |
import org.gvsig.gvsig3d.cacheservices.VectorCacheService; |
... | ... | |
799 | 801 |
hlayer.setEnabled(layer.isVisible()); |
800 | 802 |
hlayer.setExtent(extent); |
801 | 803 |
hlayer.setVerticalExaggeration(props3D.getVerticalEx()); |
804 |
_logger.warn("computed optimum level = "+computeOptimumLevel(layer,20)); |
|
805 |
//hlayer.setMaxResolution(computeOptimumLevel(layer,20)-1); |
|
802 | 806 |
hlayer.setDataDriver(_terrainDataManager); |
803 | 807 |
try { |
804 | 808 |
_terrainLayerManager.addLayer(hlayer); |
... | ... | |
834 | 838 |
} |
835 | 839 |
} |
836 | 840 |
|
841 |
public int computeOptimumLevel(FLayer layer, int maxLevel) { |
|
842 |
int level = maxLevel; |
|
843 |
if(!(layer instanceof FLyrRasterSE)) |
|
844 |
return level; |
|
845 |
|
|
846 |
|
|
847 |
Rectangle2D ext = null; |
|
848 |
try { |
|
849 |
ext = layer.getFullExtent(); |
|
850 |
} catch (ReadDriverException e1) { |
|
851 |
NotificationManager.addError("Error al obtener el extent", e1); |
|
852 |
} |
|
853 |
|
|
854 |
ArrayList attr = ((FLyrRasterSE)layer).getAttributes(); |
|
855 |
int width = 0, height = 0; |
|
856 |
for (int i=0; i<attr.size(); i++) { |
|
857 |
Object[] a = (Object []) attr.get(i); |
|
858 |
if (a[0].toString().equals("Width")) |
|
859 |
width = ((Integer)a[1]).intValue(); |
|
860 |
if (a[0].toString().equals("Height")) |
|
861 |
height = ((Integer)a[1]).intValue(); |
|
862 |
} |
|
863 |
|
|
864 |
if( ext != null && |
|
865 |
width != 0 && |
|
866 |
height != 0){ |
|
867 |
|
|
868 |
Extent destinationExtents = _terrain.getExtent(); |
|
869 |
double destination_xRange = destinationExtents.xMax()-destinationExtents.xMin(); |
|
870 |
double destination_yRange = destinationExtents.yMax()-destinationExtents.yMin(); |
|
871 |
double AR = destination_xRange / destination_yRange; |
|
872 |
int C1 = 1; |
|
873 |
int R1 = 1; |
|
874 |
|
|
875 |
boolean swapAxis = AR<1.0; |
|
876 |
if (swapAxis) AR = 1.0/AR; |
|
877 |
|
|
878 |
double lower_AR = Math.floor(AR); |
|
879 |
double upper_AR = Math.ceil(AR); |
|
880 |
|
|
881 |
if (AR<Math.sqrt(lower_AR*upper_AR)) |
|
882 |
{ |
|
883 |
C1 = (int)(lower_AR); |
|
884 |
R1 = 1; |
|
885 |
} |
|
886 |
else |
|
887 |
{ |
|
888 |
C1 = (int)(upper_AR); |
|
889 |
R1 = 1; |
|
890 |
} |
|
891 |
|
|
892 |
if (swapAxis) |
|
893 |
{ |
|
894 |
//std::swap(C1,R1); |
|
895 |
int t = C1; |
|
896 |
C1 = R1; |
|
897 |
R1 = t; |
|
898 |
} |
|
899 |
|
|
900 |
|
|
901 |
double source_xRange = ext.getMaxX() - ext.getMinX(); |
|
902 |
double source_yRange = ext.getMaxY() - ext.getMinY(); |
|
903 |
|
|
904 |
float sourceResolutionX = ((float)source_xRange)/(float)width; |
|
905 |
float sourceResolutionY = ((float)source_yRange)/(float)height; |
|
906 |
|
|
907 |
// log(osg::NOTICE,"Source %s resX %f resY %f",source->getFileName().c_str(), sourceResolutionX, sourceResolutionX); |
|
908 |
|
|
909 |
double tileSize = 32.0; |
|
910 |
|
|
911 |
int k_cols = (int)( Math.ceil( 1.0 + Math.log( destination_xRange / (C1 * sourceResolutionX * tileSize ) ) / Math.log(2.0) ) ); |
|
912 |
int k_rows = (int)( Math.ceil( 1.0 + Math.log( destination_yRange / (R1 * sourceResolutionY * tileSize ) ) / Math.log(2.0) ) ); |
|
913 |
level = Math.max(k_cols, k_rows); |
|
914 |
level = Math.min(level, maxLevel); |
|
915 |
level = Math.max(level, 0); |
|
916 |
} |
|
917 |
return level; |
|
918 |
} |
|
919 |
|
|
837 | 920 |
private void CreateOSGLayer(FLayer layer, Layer3DProps props3D) { |
838 | 921 |
if (_terrain == null || _viewProjection == null) |
839 | 922 |
return; |
Also available in: Unified diff