My aim is to display points in a 3D space/chart/graph. In python, it seems to be possible : https://plot.ly/python/3d-scatter-plots/
But in Scala, I didn't find this object/class/trait :
The Web site speaks only about surfaces : https://plot.ly/scala/
The Plotly's documentation doesn't contain Scatter3d but only Scatter, which doesn't seem to support 3D : https://asidatascience.github.io/scala-plotly-client/latest/api/#co.theasi.plotly.Scatter
The ThreeDPlot class seems impossible to display points in 3D without drawing surfaces : https://asidatascience.github.io/scala-plotly-client/latest/api/#co.theasi.plotly.ThreeDPlot, and the set of Z-coordinates is strange (e.g. Iterable[Iterable[Double]] instead of something easier, e.g. Iterable[Double])
The GitHub page's presentation use 3D points but display the only in a 2D space, by using only the X and Y coordinates : https://github.com/ASIDataScience/scala-plotly-client
Unfortunately the latest version does not support 3D scatter plots yet.
However I've forked the project and added basic support for 3D scatter plots.
Here is an example that can be run directly from the sbt console:
val (x,y,z) = (Vector(1.0, 3.0, 3.0),Vector(2.0, 5.0, 1.0),Vector(5.0, 7.0, -1.0))
val p = ThreeDPlot().withScatter3D(x,y,z,ScatterOptions().copy(mode = Seq(ScatterMode.Marker)));
draw(p, "hello-plotly");
I've also opened a pull request so that the commit gets reviewed and possibly merged also.
You may use matplotlib (most especially mplot3d)
Taking in consideration that matplotlib does not support natively Scala, you need to convert your scala data to matplotlib format before display and/or use this module which is:
The missing MatPlotLib for Scala + Spark
Regards
Related
I'm trying to figure out a good way to programmatically generate contours describing a 2D surface, from a 3D STEP model. Application is generating NC code for a laser-cutting program from a 3D model.
Note: it's easy enough to do this in a wide variety of CAD systems. I am writing software that needs to do it automatically.
For example, this (a STEP model):
Needs to become this (a vector file, like an SVG or a DXF):
Perhaps the most obvious way of tackling the problem is to parse the STEP model and run some kind of algorithm to detect planes and select the largest as the cut surface, then generate the contour. Not a simple task!
I've also considered using a pre-existing SDK to render the model using an orthographic camera, capture a high-res image, and then operating on it to generate the appropriate contours. This method would work, but it will be CPU-heavy, and its accuracy will be limited to the pixel resolution of the rendered image - not ideal.
This is perhaps a long shot, but does anyone have thoughts about this? Cheers!
I would use a CAD library to load the STEP file (not a CAD API), look for the planar face with the higher number of edge curves in the face loop and transpose them on the XY plane. Afterward, finding 2D geometry min/max for centering etc. would be pretty easy.
Depending on the programming language you are using I would search for "CAD control" or "CAD component" on Google combining it with "STEP import".
Being used to Matlab and its great capabilities of drawing vector graphics, I am looking for something similar in OpenCV. OpenCV drawing functions seem to raster the lines or points at pixel level. Currently, I am dumping the data into text, copy-paste to Matlab and doing all the plots. I also thought about using Matlab engine to pass it the parameters and running plots, but it seems to be too much mess for simple debug operation.
I want to be able to do the following:
Zoom in, out of the image
Draw a line/point which is re-rastered each time I do zoom, like in Matlab.
Currently, I found image watch plugin to take care of zooming, but it does not help with the second part.
Any idea?
OpenCV has a lot of capabilities to process an image but only minimal ones for displaying the result. It has nothing that can display vector graphics like Matlab. When I need to see polygons on image (or just polygons) I am dumping them to file and using third party viewer (usually Giv viewer).
I'd like to stack the images from this map: http://earthquake.usgs.gov/regional/nca/soiltype/map/ from linear projection into a leaflet map. The source tiles are in known but nonstandard zoom levels, and leaflet maps want mercator mercator XYZ tiles. In principle, I know how to do this - I have functions for changing XY coordinates into lat-lng coordinates in the two maps, and I just need to map pixels for the target map in terms of pixels in the source map.
This is unfortunately nontrivial, as the source pixels are spread across hundreds of different image files, and I am trying to put them into hundreds more images. Is there a software package that makes this a little bit more straightforward? If there is no library for dealing with this kind of data, it seems like there really should be...
Postgis has the RT_ST_Transform method, which under the hood uses GdalWarp. So, you have at least these two options. If you use Postgis, you will need to actually register/import the images into Postgis, using raster2pgsql and then call RT_ST_Transform on each one and then dump them out again -- which could be scripted to some extent using plpgsql (Postgres's scripting language). There is something of a learning curve involved with using Postgis raster, which may be worthwhile if you plan to do any other image processing analysis. You could also write a shell script (or similar) to automate gdalwarp if you don't wish to go the Postgis route.
For a less formal method than gdalwarp (an excellent program), you can check out the Leaflet plugin Leaflet.imageTransform, that can transform and image on the fly in the browser.
I have a 3D datastructure in C code that I want to visualize as boxes and points in 3D space. So I have a bunch of coordinates, some for points and some for boxes and I want to plot these in 3D to visualize the data structure. Anyone have experience doing anything similar to this? I started trying to use paraview. My plan being to generate a paraview statefile (xml-type file) and then just open it with paraview. The problem is those state files are massive and complex. To try and figure out the xml structure I was creating Boxes and Point sources in paraview and then looking at the state files it generated. It looks awful.
I just want to be able to say display a box with these coordinates and a point with these coordinates in a minimalistic way. Anyone have any ideas? Doesn't have to be in C or paraview necessarily as I can output the coordinates and input in whatever to generate the final product. Python + Matlab would work just as well if it works.
So I figured out a nice compromise. I started with the git code as described here:
http://www.shocksolution.com/microfluidics-and-biotechnology/visualization/python-vtk-paraview/
It's only one python file. The gist is the code there lets you give x,y,z positions and radius for points and outputs an XML file that is in VTK format. So to do the particles I just hand it the x,y,z positions and then a constant for the radius for all particles. Then I just make a spherical glyph on the datasets.
For the boxes I use the exact same code. For each box I still output x,y,z coordinates where the x,y,z values are the coordinates of the center of the box. Then for the "radius" parameter I use the edge length of the cube. This works because again in paraview I just glyph the datapoints for the boxes. I use the box glyph, and scale by scalar where the scalar is the radius. If you don't orient the box glyphs and set the scalar factor to 1 you get the desired result. Here's a simple example with everything uniform:
So I just output the coordinates in my C datastructure to CSV files and then in python pull in the files and use the code at the link and open the result with paraview. Here's how I used the code at the link:
from vtktools import VTK_XML_Serial_Unstructured
import sys
if len(sys.argv) > 2:
treeFile = sys.argv[1]
bodyFile = sys.argv[2]
else:
print 'No input files'
exit(4)
x = []
y = []
z = []
r = []
f = open(treeFile, 'r')
for line in f:
v = line.split(',')
x.append(float(v[0].strip()))
y.append(float(v[1].strip()))
z.append(float(v[2].strip()))
r.append(float(v[3].strip()))
f.close()
temp = treeFile.split('/')
if (len(temp) == 1):
temp = temp[0]
else:
temp = temp[-1]
tree_writer = VTK_XML_Serial_Unstructured()
tree_writer.snapshot(temp.split('.',1)[0] + '.vtu', x, y, z, [], [], [], [], [], [], r)
tree_writer.writePVD("octree.pvd")
x = []
y = []
z = []
r = []
f = open(bodyFile, 'r')
for line in f:
v = line.split(',')
x.append(float(v[0].strip()))
y.append(float(v[1].strip()))
z.append(float(v[2].strip()))
r.append(float(v[3].strip()))
f.close()
temp = bodyFile.split('/')
if (len(temp) == 1):
temp = temp[0]
else:
temp = temp[-1]
body_writer = VTK_XML_Serial_Unstructured()
body_writer.snapshot(temp.split('.',1)[0] + '.vtu', x, y, z, [], [], [], [], [], [], r)
body_writer.writePVD("distribution.pvd")
Since your data doesn't seem to be complex... Why don't you export it to a CSV file?
You'll be able to open it from ParaView, MATLAB, etc... Besides, it is a really straightforward implementation.
I would choose this if your data is not going to get more complex than that.
Happy coding!
If your algorithm is pure C and it's producing static or canned animated data you may like to export to an XML format or proprietary format that will open up many options.
Collada is an XML format designed for representing 3D objects in a software agnostic fashion and certainly worth a peek. You can then open in in a multitude of applications to view it, even Max and Maya which means no coding required to view it. There are also engines available that will read these exports natively.
As for other specific ways to visualize it this could be a totally open ended answer so depending on how many items you're trying to visualize and how much interatction you need here are a few suggestions but I know this is just the tip of the iceberg.
Matlab seems very good at plotting mathematical graphics but my rather dated memory of it was it was very slow and cumbersome to manipulate.
If it's simple gouraud shaded textured stuff and you want full control just go for a native OpenGL program as there's nothing too scary in there these days. It also means you get to keep you C code. Downside is it does take longer, especially if you need to handle camera controls or 'pixel quality' matters. I.e. if you're looking for shadowing, animation, shader effects, etc... please read on...
If it requires some user interaction, a stand alone app, more sophisticated rendering and the dataset isn't vast or you can compile it as C# (i.e. no pointers used) you may like to take a look at Unity. It simplifies 3D rendering for you by an order of magnitude and you just need to write C# to generate the mesh/particles you want to render and chuck some simple camera controls in (or import your collada file). The tricky bit is if you're new to it it'll take a day or two to get familiar with generating their meshes for your purpose.
Alternatively you could code it up in WebGL via HTML5 or better yet use someone else's WebGL system to do it for you!
There are a few items out there worth a peek if you opt for this route. My favourite is PlayCanvas and I believe it'll take your collada files too if you just need to generate them.
There's also SceneJS.org which is more raw and not personally tried that yet but mentioning it should that appeal too.
Is there a way to create a heat map in google earth, so areas with higher values (of some specified parameter, such as population) appear as hotspots?
This seems possible.
For instance, take a look at those few links :
Disclaimer : I've tried none of those
HeatMapAPI.com
And an example
But I'm not sure how you'd do it ; seems related to .NET and a dll in some way... so might not be as nice as it seems...
Density Mapping in Google Maps with HeatMapAPI
Heat Maps for Google Maps - (a.k.a GeoIQ mashup)
Using Google Maps to Produce Heat Maps
You've got a couple of links in those articles too ; some might be interesting too.
My colleague developed an open source java program that will generate 3D heat maps (KML) files for Google Earth from simply formatted XML data files. It may be of use. The entire project code is up at https://github.com/Noblis/OSAT You can ignore the bulk of what's there, and focus on GUIMain and the supporting files. There's sample files and documentation. I'd call it about a 0.5 version - it works, we used it in our studies, but there's some rough edges. It was done for transportation accessibility studies, but you can change the parameters you're graphing to anything you want, run from command line, whatever.
You can use the vertical axis to either view the same parameter as is used for the color OR use it to map an entirely different variable.
Here's two screen shots so you can see what it does:
tool interface:
example 3D output:
You can create polygons in a KML file and set the color of them. You can also make the polygons 3D, with height perhaps representing temperature.
There is also http://www.openheatmap.com, which offers free heatmaps on top of OpenStreetMap from a CSV upload.
Try free API heat maps. A really interesting implementation : http://en.tixik.com/tools/heatmaps
HeatmapTool.com can take a CSV file of coordinates and intensity values to generate heat map tiles for Google Maps.