reading or open STL file on processing - processing

I am using processing for Serial Communication and want to read/open the STL file in it, I have STL file in my Harddisk.
Can you please guide me on How do I do fixed it?

I read and practically test this link from github, it is really very useful and best thing is that it is working.
So in your case
Just make a directory with any name
Put Below Coding and actual image file in same folder
I edited it according to your file name so just copy/paste this code followed by all above instruction
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;
TriangleMesh mesh;
ToxiclibsSupport gfx;
void setup() {
size(600,600,P3D);
mesh=(TriangleMesh)new STLReader().loadBinary(sketchPath("check.stl"),STLReader.TRIANGLEMESH);
//mesh=(TriangleMesh)new STLReader().loadBinary(sketchPath("mesh-flipped.stl"),STLReader.TRIANGLEMESH).flipYAxis();
gfx=new ToxiclibsSupport(this);
}
void draw() {
background(51);
lights();
translate(width/2,height/2,0);
rotateX(mouseY*0.01);
rotateY(mouseX*0.01);
gfx.origin(new Vec3D(),200);
noStroke();
gfx.mesh(mesh,false,10);
}

Related

How to remove window elements of a processing sketch?

I'm wondering if it's possible to do something in processing java (or native java idk much about it though) where you can get rid of the windows gui elements of the window (I'm using windows 7). I want it to be able to look like when you boot up a program like eclipse or visual studio and it has like a rectangle in the middle of the screen, but you can't x out of the program or minimize it, etc. is that possible even or would I have to use another java library? Thanks.
Yes, you can. I had no idea, but you totally can! There's some class juggling involved, though, but it's all fairly simple.
Here's a code snippet for you to try and tinker with the principle:
import java.awt.Frame;
import processing.awt.PSurfaceAWT;
import processing.awt.PSurfaceAWT.SmoothCanvas;
void setup() {
size(200, 200);
}
PSurface initSurface() {
PSurface pSurface = super.initSurface();
PSurfaceAWT awtSurface = (PSurfaceAWT) surface;
SmoothCanvas smoothCanvas = (SmoothCanvas) awtSurface.getNative();
Frame frame = smoothCanvas.getFrame();
frame.setUndecorated(true);
return pSurface;
}
void draw() {
background(0);
ellipse(mouseX, mouseY, 20, 20);
}
Have fun!

JavaFX Export Scene as PDF/SVG

I have currently developed an ultimately open source application to analyse some data in a table view and visualise the resulting data in some additional plots. A problematic thing with this is, that the generated plots could potentially be useful for end users for e.g. a presentation, further downstream informative discussion and so on. This is why I started working on an export function using ImageWriter
//adding a context menu item to the chart
final MenuItem saveAsPng = new MenuItem("Save as png");
saveAsPng.setOnAction(new EventHandler<ActionEvent>() {
#Override public void handle(ActionEvent event) {
int scale = 6; //6x resolution should be enough, users should downscale if required
final Bounds bounds = bc.getLayoutBounds();
final SnapshotParameters spa = new SnapshotParameters();
spa.setTransform(javafx.scene.transform.Transform.scale(scale, scale));
ImageWriter imageWriter = new ImageWriter();
try {
imageWriter.saveImage(stage, bc.snapshot(spa, null));
} catch (ImageException e) {
e.printStackTrace();
}
}
});
This successfully creates a PNG file with sufficient size, but my ideal solution would be to export in vector-based format, e.g. PDF/SVG. For Swing applications, I knew how to achieve this, but for JFX I couldn't really find a proper solution for that matter. I already investigated several potential ideas, e.g. using a printer dialogue and then exporting as a PDF via virtual printer, but that does result in a bitmap inside the PDF, too.
Any ideas on this?

JavaFX display scene background image

I’m developing a JavaFX application on Eclipse Kepler using the built-in FX library from Java SDK1.7.0_45. I want to display a background image in a scene. Following the tutorial provided in the Java documentation, following code should work:
public class Main extends Application {
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage primaryStage) {
GridPane grid = new GridPane();
Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
scene.getStylesheets().add(Main.class.getResource("Login.css").toExternalForm());
primaryStage.show();
}
}
My CSV file looks like this:
.root {
-fx-background-image: url("background.jpg");
}
But I just get a blank screen instead. I have 3 files in the src/application folder: background.jpg, Main.java and Login.css.
I have tried adding a backslash, putting the image into a separate folder, providing an absolute path, providing several types of images, using ../application/background.jpg, changing the code to file:background.jpg, providing the URL directly into the code and dismissing the CSS file, using an imageview instead, ..... but nothing works.
I've taken a look at several other stackoverflow links, all seemed to fail:
JavaFX How to set scene background image (renders a blank screen)
Setting background image by javafx code (not css) exception)
Cannot load image in JavaFX
and many more.
The strange thing is, when I supply an image from a server as a hyperlink, everything works fine. Supplying the path to a local file never works though. What am I doing wrong? Can somebody show me how to display a local image? Is this a bug?
This worked fine for me with a .png, the only noticeable difference I had as opposed to you, was that I split up the .css file, and my background.png into a sub-package of the main one. Example:
my directory structure looks as follows:
sotestproject ----|
|
|---package sotestProject ---SOTestProject.java
|
|
|
|
package sotestProject.style
|
|---Login.css
|
|---background.png
using this breakdown, the following files with code successfully produced a background with an image:
SoTestProject.java:
package sotestproject;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
/**
*
* #author William
*/
public class SOTestProject extends Application {
#Override
public void start(Stage primaryStage) {
GridPane grid = new GridPane();
Scene scene = new Scene(grid, 300, 275);
primaryStage.setScene(scene);
scene.getStylesheets().add(SOTestProject.class.getResource("style/Login.css").toExternalForm());
primaryStage.show();
}
/**
* The main() method is ignored in correctly deployed JavaFX application.
* main() serves only as fallback in case the application can not be
* launched through deployment artifacts, e.g., in IDEs with limited FX
* support. NetBeans ignores main().
*
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Login.css:
.root {
-fx-background-image: url("background.png");
}
And then obviously my background.png is in the same directory as the .css file. The main 'change' in code is to note that with the scene.getStyleSheet() I used a reference to style/ instead of just the resource.
I hope this helps!
One thing to note: I'm compiling against the 32-bit jdk 7.0_45. That shouldn't make any difference, but there it is.
Partly thanks to the answer from WillBD, I decided to ditch Eclipse Kepler and start all over in Netbeans. I used the exact same code I provided in my question and now everything works just fine. I guess this is a bug between JavaFX and Eclipse Kepler.
Image file must be in the 'bin/application' directory and add your css definitions to the 'src/application/filename.css'
I've had the same problem in NetBeans and tried basically everything. Eventually, I discovered that the file extension "jpg" was written in capital letters in this "project hierarchy box" on the left side of NetBeans.
I changed that part of my code to all capital letters and tadaaa everything worked just fine.

Key Input using GtkD

I'm a beginner of both gtk and GtkD.
Now, I'm trying to get input from keyboard with reference to this .
But, It seems that three years have made some changes in Toolkits.
I wrote code below. However, I got strange values of ev in callback function.
I could not see any prospect of resolution with going alone.
So, could you show me where to modify?
I appreciate you in advance, and also your patient with my poor English.
I'm using gtkD-2.1.1 and gtk+3.2.3.
this is the full code:
import std.stdio;
import gtkc.gdktypes;
import gtk.MainWindow;
import gtk.Widget;
import gdk.Event;
import gtk.Main;
class Window : MainWindow{
immutable width = 200;
immutable height = 200;
this(){
super("input test");
setDefaultSize(width,height);
setEvents(EventMask.KEY_PRESS_MASK); // Actually I don't know how this works
auto callback_func = cast(bool delegate(Event,Widget))&get_key; // I doubt this cast
this.addOnKeyPress(callback_func);
showAll();
}
bool get_key(GdkEventKey* ev, Widget widget){
writefln("sender %s", widget);
writefln("type %x",ev.type);
writefln("window* %x",ev.window);
writefln("send_event %x",ev.sendEvent);
writefln("time %x",ev.time);
writefln("state %x",ev.state);
writefln("keyval %x",ev.keyval);
writefln("length %x",ev.length);
writefln("gchar* %x",ev.string);
writefln("hardware_keycode %x",ev.hardwareKeycode);
writefln("group %x",ev.group);
writefln("is_modifier %x\n",ev.bitfield0);
return true;
}
}
void main(string[] args){
Main.init(args);
auto win = new Window();
Main.run();
}
Yes, that cast is wrong. I guess that Signature with GdkEventKey* is outdated. Change your get_key to take an Event and you should get proper results:
...
auto call = &get_key;
...
bool get_key(Event e, Widget widget){
GdkEventKey* ev = e.key();
...
I have never done anything with GtkD, and this is just the result of some glances over the docs. So, it's probably not best practice, but it should get you back on the road.

What is the difference between MainWindows show() and showAll() method in GtkD?

Here is my test:
import gtk.Main;
import gtk.MainWindow;
import gtk.Label;
void main(string[] args)
{
Main.init(args);
auto window = new MainWindow("My Window");
window.add(new Label("Label1"));
window.show();
Main.run();
}
When I replace Main.show() with Main.showAll() it works as expected, however I can't find any documentation for either function here: http://api.gtkd.org/src/gtk/MainWindow.html What is the difference between these two methods and where can I find documentation?
These links from official GTK+ documentation should help: gtk_widget_show, gtk_widget_show_all. In short, show shows only the widget it is called on, and show_all, being applied to a container, shows all widgets in this container recursively.
GtkD has very poor and nearly impossible to use API docs, though this seems to be a problem not of GtkD but of D tools. The methods you are referring to are defined on GtkWidget class, but unfortunately the page about gtk.Widget is empty (mostly).

Resources