I am using the following code to generate a surface normal map from a depth image:
for x in range(depth.shape[0]):
for y in range(depth.shape[1]):
try:
dzdx=(depth[x+1,y,0]-depth[x-1,y,0])/2
dzdy=(depth[x,y+1,0]-depth[x,y+1,0])/2
except:
dzdx=0
dzdy=0
sub=np.asarray([-dzdx,-dzdy,1])
normals[x,y,:]=sub/np.linalg.norm(sub)
any thoughts as to what is going on?
You have a bug in the line:
dzdy=(depth[x,y+1,0]-depth[x,y+1,0])/2
it should be
dzdy=(depth[x,y+1,0]-depth[x,y-1,0])/2
Related
I'm trying to let the LED keep blinking while waiting in the "wait_msg()" function. can I achieve this by uasycncio, _thread, or modification on the main loop in the module? And how?
Many thanks.
Try the following:
client.check_msg()
led.toggle()
time.sleep(0.1)
I have some .nc data that I use xarray to analyze. I wanted to overlay a shapefile on the plot and came across hv.plot which seems to have the interactive component I have been needing. However, when I tried to plot, it does not seem to work. Then I found the following thread: Why doesn't holoviews show histogram in Spyder? but could not get Maxime's answer to work and Sander's only partly works, however I have trouble "connecting to the local host" consistently. Does anyone have a solution?
ds_path = 'Z:/MODIS-LAADS-DAAC/'
ds_file = 'anom_2016_v1.nc'
ds_anom = xr.open_dataset(ds_path+ds_file)
x = ds_anom.Rrs_667.isel(time=0)
# create holoviews plot
hv_map = x.hvplot()
# display graph in browser
# a bokeh server is automatically started
bokeh_server = pn.Row(hv_map).show(port=12345)
# stop the bokeh server (when needed)
bokeh_server.stop()
However, I get this 95% of the time ERR_CONNECTION_REFUSED but occasionally get it to work and look like this (however I don't know why!!!) sample ocean data plot
IN SUMMARY:
What I want to do:
https://tutorial.xarray.dev/scipy-tutorial/04_plotting_and_visualization.html#interactive-bokeh-plots-using-hvplot
, https://hvplot.holoviz.org/user_guide/Geographic_Data.html#declaring-an-output-projection
What I have tried:
https://discourse.holoviz.org/t/whats-the-most-efficient-way-to-overlay-a-shapefile-onto-a-hvplot-xarray-plot/397, Why doesn't holoviews show histogram in Spyder?
What I get: ERR_CONNECTION_REFUSED but occasionally (don't know why) sample ocean data plot
I'm trying to use TracedPath to make a curve in manim (CE v0.10), which I then want to manipulate (move around, rotate, etc.). The problem is, the tracing continues once I start moving the curve and I don't want it to. Does anyone know how to turn the tracing off? Any help would be greatly appreciated (this is the last issue I need to solve to finish my video). Here is some sample code:
class TracedPathProblem(Scene):
def construct(self):
dot = Dot(color=RED)
trace = TracedPath(dot.get_center,stroke_color=RED)
self.add(dot,trace)
self.play(dot.animate.shift(RIGHT),run_time=2)
path = trace.copy()
self.play(path.animate.shift(2*UP+RIGHT)) #do not want tracing here
self.wait()
Issue solved. Benjamin Hackl gave me a solution: path = trace.copy().clear_updaters()
In the path tracer example in the SDK I want to add an OBJ file to trace, so I went over to the loadGeometry() function, and right after the last parallelogram creation, I added this code block
OptiXMesh mesh;
mesh.context = context;
loadMesh(mesh_file, mesh);
gis.push_back(mesh.geom_instance);
//setMaterial(gis.back(), diffuse, "diffuse_color", white);
note that gis is a GeometryInstance vector.
When I run it, the display window opens, and immediately closes and I get the following exceptions:
Exception thrown at 0x00007FFA2856A388 in optixPathTracer.exe: Microsoft C++ exception: optix::TypeMismatch at memory location 0x0000000E29EFF030.
Exception thrown at 0x00007FFA2856A388 in optixPathTracer.exe: Microsoft C++ exception: optix::Exception at memory location 0x0000000E29EFF5C0.
If I comment out the modified code block, it works fine.
How can I load an OBJ file to the tracer? Do I need to add something in the shaders / RT_PROGRAMs side?
Thank in advance!
P.S. I know that the loadMesh() function takes care of the material, but since the program doesn't work, I tried to set a material just like it's shown for all the other GeometryInstances, as demonstrated in the code block above.
About intersect function:
In the path tracer example the scene is made of parallelograms. In the parallelogram.cu file the intersect function is called by the OptiX pipeline to detect if a ray intersects a parallelogram (4 points shape). In OptixPathTracer.cpp, in the createParallelogram method, the intersection program is set to be the function in parallelogram.cu file.
When you load a mesh, it is (most commonly) made of triangles, so the intersect function that is being used is not appropriate to the geometry of the mesh (and I guess that explains the TypeMismatch error, but the message is not very clear and you did not post a complete example that allows to reproduce the error).
How to fix:
If you look at the ray casting example, in OptixRaycastingContext.cu there's an intersect function that's made for triangles. You should most probably copy that triangle intersection function to your cu file (don't forget to rename it: there's already an intercept function there that is used for parallelograms), then when you create the Geometry object for your mesh, call setIntersectionProgram with the triangle intersection function as parameter.
The other way:
You can also start working on the mesh viewer example and change the raytracing code (cu files) to do path tracing. It is a good exercice to understand how OptiX works.
I am rather new to OpenGL and trying to learn a little WebGl. I came across a tutorial that, while great, appears to be a bit dated. I implemented my own version of this example in a Plunkr. I left out the square on purpose, however, once I have everything wired I do not see the triangle. I found a warning in the console...
WARNING: Attribute 0 is disabled. This has signficant performance penalty
And there is another SO question that seems to be similar but looking through the diff I can't get it to work and I can't get what he is saying to click. Here is my drawing code for reference...
drawScene() {
this.gl.viewport(0, 0, this.gl.viewportWidth, this.gl.viewportHeight);
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
mat4.perspective(45, this.gl.viewportWidth / this.gl.viewportHeight, 0.1, 100.0, this.pMatrix);
mat4.identity(this.mvMatrix);
mat4.translate(this.mvMatrix, this.mvMatrix, [-1.5, 0.0, -7.0]);
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, this.triangleVertexPositionBuffer);
this.gl.vertexAttribPointer(this.shaderProgram.vertexPositionAttribute, this.triangleVertexPositionBuffer.itemSize, this.gl.FLOAT, false, 0, 0);
this.setMatrixUniforms();
this.gl.drawArrays(this.gl.TRIANGLES, 0, this.triangleVertexPositionBuffer.numItems);
}
Does anyone have experiance here that can help guide a newbie?
So going back through this link helped a lot. One thing to consider is it doesn't talk about the glUtils js file they import so yeah that is needed. It seems that what the warning message is referring to is the need in newer versions to be explicit about params for the shader. Here is an example plnkr you will notice this is different...
// NEEDED to prevent warning
this.vertexPositionAttribute = this.gl.getAttribLocation(this.shaderProgram, "aVertexPosition");
this.gl.enableVertexAttribArray(this.vertexPositionAttribute);
When I set my shader attributes this way I avoid the warning!