你们能帮我用算法来做这些事情吗?我已经实现了前序、中序和后序,并且我得到了使用这些命令之一遍历树的提示。我正在使用 dotty 来标记(或“访问”)节点。
深度是从根到底部叶子的边数,所以每次移动时,我都会在深度上加+1?类似的东西?
不知道后代的算法。他们正在询问特定节点在其自身下的节点数。
顺便说一句,这些是普通的树。
我刚刚开始使用java和很少的LWJGL后使用c ++和OpenGL.我一直在关注这些教程http://ogldev.atspace.co.uk/并且在教程13周围我开始玩我的自我.在创建了一些金字塔和控件来移动后,我注意到从一个角度看物体它们看起来很正常,但看到其他物体后面的另一个角度物体正在前面渲染.我已经看过这个问题
并没有找到答案,所以现在我很困惑,决定建立一个stackoverflow帐户并提出一个问题.我会发布图片,但我没有足够的声誉所以这里是一个链接到他们(在一个zip文件中有3个)
http://www.mediafire.com/download/hucfisn0jytah7o/Game%20screenshots.zip
[编辑]
此外,我可能需要知道,我使用freeglut和glew(可能不是最好的选择,但我喜欢它)和Visual Studio 2012,Windows 8.1(只是有一台新的笔记本电脑,没有得到Windows 7安装光盘)
我有一个嵌套对象的示例数组:
let arr = [{id: 0, children: []},
{id: 1, children:[
{id: 2, children: []},
{id: 3, children: [
{id: 4, children: []}
]}
]}
];
Run Code Online (Sandbox Code Playgroud)
我需要计算每个对象的深度级别。在所有对象中我也有一个parentId 属性。
结果应该是:
let arr = [{id: 0, depth: 0, children: []},
{id: 1, depth: 0, children:[
{id: 2, depth: 1, children: []},
{id: 3, depth: 1, children: [
{id: 4, depth: 2, children: []}
]}
]}
];
Run Code Online (Sandbox Code Playgroud)
我也有一个平面结构中所有对象的数组。
解决方案?
自从我接触Java以来已经很长时间了,所以这看起来似乎是一个奇怪的问题.目前我在StackOverflow上找到了这个广度优先搜索代码,我在最后修改了它,但我会在这里发布原始代码.
public List<Node> getDirections(Node start, Node finish){
List<Node> directions = new LinkedList<Node>();
Queue<Node> q = new LinkedList<Node>();
Node current = start;
q.add(current);
while(!q.isEmpty()){
current = q.remove();
directions.add(current);
if (current.equals(finish)){
break;
}else{
for(Node node : current.getOutNodes()){
if(!q.contains(node)){
q.add(node);
}
}
}
}
if (!current.equals(finish)){
System.out.println("can't reach destination");
}
return directions;
}
Run Code Online (Sandbox Code Playgroud)
我知道其他深度优先搜索算法,但我也被告知可以轻松地将广度优先搜索转换为深度优先搜索,如果对此代码执行而不是2个完全不同的代码,我会更好地理解它.
如何将其更改为深度优先搜索?
我有一个应用程序,我创建自己的深度框架(使用Kinect SDK).问题是当检测到人的深度的FPS(然后颜色也是如此)显着减慢时.这是一部关于帧速度减慢的电影.我正在使用的代码:
using (DepthImageFrame DepthFrame = e.OpenDepthImageFrame())
{
depthFrame = DepthFrame;
pixels1 = GenerateColoredBytes(DepthFrame);
depthImage = BitmapSource.Create(
depthFrame.Width, depthFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels1,
depthFrame.Width * 4);
depth.Source = depthImage;
}
...
private byte[] GenerateColoredBytes(DepthImageFrame depthFrame2)
{
short[] rawDepthData = new short[depthFrame2.PixelDataLength];
depthFrame.CopyPixelDataTo(rawDepthData);
byte[] pixels = new byte[depthFrame2.Height * depthFrame2.Width * 4];
const int BlueIndex = 0;
const int GreenIndex = 1;
const int RedIndex = 2;
for (int depthIndex = 0, colorIndex = 0;
depthIndex < rawDepthData.Length …Run Code Online (Sandbox Code Playgroud) 我正在研究一个项目,我需要给一个小型人形机器人(Nao机器人)深度感知.我计划将Kinect连接到机器人的前额,并将其与机器人当前的操作和引导系统(默认系统OPEN NAO)集成,该系统在Linux上运行并通过wifi中继到机器人.
现在我正在摸索使用哪个软件.我看过Point Cloud Library,我看到它用于处理实际数据,OpenNI被定义为一个API框架,可以帮助应用程序访问自然交互设备,如Kinect,然后是官方的Kinect SDK.我只是不确定它们是如何组合在一起的.
我需要将哪些库/框架集成到机器人的操作系统中?
例如,在图形上编写一些算法时
def f(graph):
#graph is dictionary of pairs vertex_i:{set of edges (i,j)} for 1<=i,j<=n
def g(vertex):
for vertex1 in graph:
do sth
...
for (i,j) in graph[vertex1]:
...
g(j)#recursive call
...
return ...
return g(1)
Run Code Online (Sandbox Code Playgroud)
有限的递归深度有时非常烦人,因为如果必须避免递归,代码会变得更长,更复杂.有没有办法达到无限深度?也许您可以通过以下方法描述问题的一般解决方案
def nthNumber(n):
if n==1: return 1
else: return nthNumber(n-1)+1
Run Code Online (Sandbox Code Playgroud)
(我知道这很简单,请不要回答"你应该只写nthNumber(n):返回n" - 我对一般解决方案感兴趣).感谢帮助!
我用OpenGL它在屏幕上绘制一些内容.
这是初始化:
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, 10, -10);
glMatrixMode(GL_MODELVIEW);
Run Code Online (Sandbox Code Playgroud)
然后我使用这个绘制对象:
void draw(...)
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBegin(GL_QUADS); //Begining the cube's drawing
{
glTexCoord3f(tu1, tv1, 1); glVertex3f(offset, _y, _z);
glTexCoord3f(tu2, tv1, 1); glVertex3f(offset + w, _y, _z);
glTexCoord3f(tu2, tv2, 1); glVertex3f(offset + w, _y + h, _z);
glTexCoord3f(tu1, tv2, 1); glVertex3f(offset, _y + h, _z);
}
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
Run Code Online (Sandbox Code Playgroud)
但深度不受尊重(用很多_z值测试).它随着呼叫的顺序而变化,越近将是最后绘制的.
如果我先画出粉红色条:

如果我在奶油条后绘制粉红色条:

我已经为给定的校正立体对计算了视差图!我可以使用公式计算我的深度
z = (baseline * focal) / (disparity * p)
Run Code Online (Sandbox Code Playgroud)
让我们假设基线、焦距和像素常数 p 是已知的,并且我对两个图像使用了相同的相机。现在我的视差可能在 -32..128[pixel] 的范围内。当我使用上面的公式时,对于我的 0 视差值,我将得到无穷大/除以零。当我将视差值移动到 1..161 时,我选择了任意视差值的范围,这是一个问题,因为函数 1/disparity 将在 1..161 或 100..260 处给出完全不同的值间距这甚至不是线性的。所以我什至不会得到(线性)尺度的重建,因为尺度变化是非线性的。
我如何确定我的视差必须位于哪个区域才能使用上述公式进行度量重建?或者根本不可能用上述公式和校正后的图像以度量方式重建某些东西?如果是这样,为什么?
(我知道我可以重新投影到我的未校正图像并进行三角测量,但我特别想知道为什么或如果上面的公式不可能。感谢任何可以帮助我的人!)
computer-vision triangulation disparity-mapping depth 3d-reconstruction
我有一个数组,如下所示:
var times = ["mon","tue"];
Run Code Online (Sandbox Code Playgroud)
我将如何将其变为:
times = [["mon","tue"]];
Run Code Online (Sandbox Code Playgroud)
谢谢
定义一个函数sum_to_deepest(root),该函数返回以root为根的树中从根到最深叶的键的总和.如果有两个最深的叶子,则返回较大的总和; 如果根是None,则返回0.
在这个问题中,您会发现帮助定义一个辅助函数,它返回最深叶子的深度和沿叶子路径的总和.