gpt4 book ai didi

java - Worldwind SurfaceImage 深度/批量拣选

转载 作者:行者123 更新时间:2023-11-30 02:44:06 25 4
gpt4 key购买 nike

我正在使用 WorldWind 并尝试在同一层中“挑选”多个表面图像,但不明白为什么它不起作用。

我的印象是这样称呼:

this.getWwd().getSceneController().setDeepPickEnabled(true);

将使我能够在同一层中选择多个可渲染对象。这似乎适用于 SurfaceImage 之外的所有其他情况。我还注意到,如果我将加载的 SurfaceImage 强制放入不同的层,它会按预期工作。

这是我用来测试的代码:

public class SurfaceImageViewer extends ApplicationTemplate
{
public static class AppFrame extends ApplicationTemplate.AppFrame
{
private JFileChooser fileChooser = new JFileChooser();
private JSlider opacitySlider;
private SurfaceImageLayer layer;
private JLabel statusLabel = new JLabel("status: ready");

public AppFrame()
{
super(true, true, false);

this.getWwd().getSceneController().setDeepPickEnabled(true);

try
{
this.layer = new SurfaceImageLayer();
this.layer.setOpacity(1);
this.layer.setPickEnabled(true);
this.layer.setName("Surface Images");

insertBeforeCompass(this.getWwd(), layer);

this.getControlPanel().add(makeControlPanel(), BorderLayout.SOUTH);
}
catch (Exception e)
{
e.printStackTrace();
}

this.getWwd().addSelectListener(new SelectListener() {

@Override
public void selected(SelectEvent event) {
PickedObjectList pol = AppFrame.this.getWwd().getObjectsAtCurrentPosition();

if(event.isLeftClick()){
System.out.println("POL SIZE "+pol.size());
}

}
});


}

Action openElevationsAction = new AbstractAction("Open Elevation File...")
{
public void actionPerformed(ActionEvent e)
{
int status = fileChooser.showOpenDialog(AppFrame.this);
if (status != JFileChooser.APPROVE_OPTION)
return;

final File imageFile = fileChooser.getSelectedFile();
if (imageFile == null)
return;

Thread t = new Thread(new Runnable()
{
public void run()
{
try
{
CompoundElevationModel cem
= (CompoundElevationModel) getWwd().getModel().getGlobe().getElevationModel();
LocalElevationModel em = new LocalElevationModel();
em.addElevations(imageFile.getPath());
cem.addElevationModel(em);
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
};

Action openImageAction = new AbstractAction("Open Image File...")
{
public void actionPerformed(ActionEvent actionEvent)
{
int status = fileChooser.showOpenDialog(AppFrame.this);
if (status != JFileChooser.APPROVE_OPTION)
return;

final File imageFile = fileChooser.getSelectedFile();
if (imageFile == null)
return;

Thread t = new Thread(new Runnable()
{
public void run()
{
try
{
statusLabel.setText("status: Loading image");
// TODO: proper threading
layer.addImage(imageFile.getAbsolutePath());

getWwd().redraw();
statusLabel.setText("status: ready");
}
catch (IOException e)
{
e.printStackTrace();
}
}
});
t.setPriority(Thread.MIN_PRIORITY);
t.start();
}
};

private JPanel makeControlPanel()
{
JPanel controlPanel = new JPanel(new GridLayout(0, 1, 5, 5));
JButton openImageButton = new JButton(openImageAction);
controlPanel.add(openImageButton);

this.opacitySlider = new JSlider();
this.opacitySlider.setMaximum(100);
this.opacitySlider.setValue((int) (layer.getOpacity() * 100));
this.opacitySlider.setEnabled(true);
this.opacitySlider.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent e)
{
int value = opacitySlider.getValue();
layer.setOpacity(value / 100d);
getWwd().redraw();
}
});
JPanel opacityPanel = new JPanel(new BorderLayout(5, 5));
opacityPanel.setBorder(new EmptyBorder(0, 10, 0, 0));
opacityPanel.add(new JLabel("Opacity"), BorderLayout.WEST);
opacityPanel.add(this.opacitySlider, BorderLayout.CENTER);

controlPanel.add(opacityPanel);

JButton openElevationsButton = new JButton(openElevationsAction);
controlPanel.add(openElevationsButton);

controlPanel.add(statusLabel);
controlPanel.setBorder(new EmptyBorder(15, 15, 15, 15));

return controlPanel;
}
}

public static void main(String[] args)
{
ApplicationTemplate.start("World Wind Surface Images", SurfaceImageViewer.AppFrame.class);
}
}

这些是 2 个相互层叠的 geotiff,我一直用它们来测试这一点。当我左键单击两个 geotiff 时,我希望 SelectListener 上的 println 打印出“3”。 (我已将 geotiff 上传到可用的 zip here )

您将看到这些的区域位于旧金山,请参见屏幕截图:

enter image description here

最佳答案

更新:

我们发现批量拣选的示例是面向 AbstractSurfaceObject 实例的,这在本例中并不适用。对于 SurfaceImage 实例的处理,setAlwaysOnTop 的属性应配置为 false,这似乎让选择事件处理光标下的所有元素。

<小时/>

通读 DeepPicking 的示例,实际上有两件事需要完成。

  1. setDeepPickEnabled(true);//这就完成了。
  2. 禁用对所需元素的批量选取

https://github.com/nasa/World-Wind-Java/blob/master/WorldWind/src/gov/nasa/worldwindx/examples/DeepPicking.java

In order to enable deep picking, any batch picking for the desired elements must be disabled and theSceneController's deep picking property must be enabled. See {@link gov.nasa.worldwind.SceneController#setDeepPickEnabled(boolean)

我花了一点时间才理解第二个,但它似乎与 AbstractSurfaceObject 类相关。

<小时/>
  • 我假设您在图层上绘制的内容是 AbstractSurfaceObject 的子类

我相信在这种情况下,我会继承 SurfaceImageLayer ,并重写 addRenderable 方法。我会检查可渲染对象是否是 AbstractSurfaceObject 的实例,并在将其转发到父类(super class)之前禁用对其进行批量选取。

This code may not be the best long-term solution, but it may provide quick results to determine if this is the underlying issue.

import gov.nasa.worldwind.layers.SurfaceImageLayer;
import gov.nasa.worldwind.render.AbstractSurfaceObject;
import gov.nasa.worldwind.render.Renderable;

/**
* Very Rough extension of SurfaceImageLayer which disables batch picking on all AbstractSurfaceobjects.
* @author http://stackoverflow.com/users/5407189/jeremiah
* @since Nov 26, 2016
*
*/
public class MySurfaceImageLayer extends SurfaceImageLayer {


@Override
public void addRenderable(Renderable renderable) {
if (renderable instanceof AbstractSurfaceObject) {
((AbstractSurfaceObject)renderable).setEnableBatchPicking(false);
}
super.addRenderable(renderable);
}

@Override
public void addRenderables(Iterable<? extends Renderable> renderables) {
for (Renderable r : renderables) {
addRenderable(r);
}
}
}
<小时/>

如果您想要直接选择图像,则似乎不支持开箱即用。您需要执行一些操作才能从 SurfaceImageLayer 获取 SurfaceImage 引用,以便对 doPick 上的 RenderableLayer 可见。这可能会带来一系列需要注意的新问题。

  • 顺便说一句,如果您要渲染图标,那么您所需要做的就是设置 IconRenderer.setAllowBatchPicking(false)

我希望这至少有一些帮助。
祝你好运。

关于java - Worldwind SurfaceImage 深度/批量拣选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40751700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com