I'm new to java and java coding, so far I was only able to create a sphere which can be rotated and zoomed but my actual body is not a sphere, it is actually a body with its own specific shape. Another problem is like how to implement this contour plotting with colour mapping onto this body's surface. In my case I have a lot ports on the surface of my body which are pressure ports which yes obviously measures the pressure value at that particular port when the body is exposed to an external pressure and this pressure value should mapped with a colours on the surface of my body.
As I already explained, I started by creating small sphere's which represents the ports on the surface of my main sphere(represents my body)and successfully implemented a colour mappping on these small sphere's, so each small sphere will have a distinct colour based on my pressure values. But the issue is I was not able to move further on my project as in order to implement colour mapping on the whole surface of the body, some other way had to be sorted out(cause the above approach is restricted to the small sphere's only). Later found out something called Grid based mapping which includes Interpolation and all which I'm only still learning. That's all I have tried till now, so is there any way to display a specific body and on its surface colour mapping has to be done based on pressure values at the ports located at certain positions on the surface of the body.
package Phase_2.Step2.ColourOnSphereSurface;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.scene.*;
import javafx.scene.image.Image;
import javafx.scene.input.ScrollEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.MeshView;
import javafx.scene.shape.Sphere;
import javafx.scene.shape.TriangleMesh;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Transform;
import javafx.stage.Stage;
import java.util.Objects;
public class SphereSurfaceColors extends Application {
private static final float WIDTH = 1400;
private static final float HEIGHT = 800;
private double anchorX, anchorY;
private double anchorAngleX = 0;
private double anchorAngleY = 0;
private final DoubleProperty angleX = new SimpleDoubleProperty(0);
private final DoubleProperty angleY = new SimpleDoubleProperty(0);
@Override
public void start(Stage primaryStage) {
Sphere sp1= new Sphere(10);
PhongMaterial material = new PhongMaterial();
material.setDiffuseMap(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/resources/silvertexture.png"))));
sp1.setMaterial(material);
SmartGroup root = new SmartGroup();
root.getChildren().add(sp1);
Scene scene = new Scene(root, WIDTH, HEIGHT);
scene.setFill(Color.BLUE);
Camera cam1 = new PerspectiveCamera();
cam1.setNearClip(0.001);
root.translateXProperty().set(WIDTH / 2);
root.translateYProperty().set(HEIGHT / 2);
root.translateZProperty().set(-1450);
scene.setCamera(cam1);
initMouseControl(root, scene, primaryStage);
primaryStage.setScene(scene);
primaryStage.show();
}
private void initMouseControl(Group gp1, Scene sc1, Stage primaryStage) {
Rotate xRotate;
Rotate yRotate;
gp1.getTransforms().addAll(
xRotate = new Rotate(0, Rotate.X_AXIS),
yRotate = new Rotate(0, Rotate.Y_AXIS)
);
xRotate.angleProperty().bind(angleX);
yRotate.angleProperty().bind(angleY);
sc1.setOnMousePressed(event ->
{
anchorX = event.getSceneX();
anchorY = event.getSceneY();
anchorAngleX = angleX.get();
anchorAngleY = angleY.get();
});
sc1.setOnMouseDragged(event ->
{
angleX.set(anchorAngleX - (anchorY - event.getSceneY()));
angleY.set(anchorAngleY + anchorX - event.getSceneX());
});
primaryStage.addEventFilter(ScrollEvent.SCROLL, event -> {
double delta = event.getDeltaY()*0.2;
gp1.translateZProperty().set(gp1.getTranslateZ() - delta);
});
}
public static void main(String[] args) {
Application.launch(args);
}
class SmartGroup extends Group {
Rotate r;
Transform t = new Rotate();
void rotateByX(int ang) {
r = new Rotate(ang, Rotate.X_AXIS);
t = t.createConcatenation(r);
this.getTransforms().clear();
this.getTransforms().addAll(t);
}
void rotateByY(int ang) {
r = new Rotate(ang, Rotate.Y_AXIS);
t = t.createConcatenation(r);
this.getTransforms().clear();
this.getTransforms().addAll(t);
}
}
}
[This is what I'm trying to achieve with my body.](https://i.stack.imgur.com/Nl2Km.png)