Skip to content

Commit

Permalink
The texturedplanedataobject now extends the deforming mesh data objec…
Browse files Browse the repository at this point in the history
…t, and can be a drop in replacement.
  • Loading branch information
m smith committed Feb 7, 2020
1 parent a1458f1 commit 335a1ce
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 113 deletions.
1 change: 0 additions & 1 deletion src/main/java/deformablemesh/SegmentationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import lightgraph.Graph;
import snakeprogram3d.display3d.DataObject;

import javax.swing.JLabel;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/deformablemesh/gui/ControlFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public ControlFrame( SegmentationController model){
}
public void showFrame(){
frame = new JFrame("Deformable Mesh Control Panel");
frame.setIconImage(GuiTools.getIcon());
JPanel contentPanel = new JPanel();
contentPanel.setLayout(new BorderLayout());
tabbedPane = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.WRAP_TAB_LAYOUT);
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/deformablemesh/gui/GuiTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,19 @@ public static Image getIcon(){
icon = new BufferedImage(64, 64, BufferedImage.TYPE_4BYTE_ABGR);

Graphics2D g = (Graphics2D)icon.getGraphics();
g.setPaint(Color.GRAY);
//g.fillRect(0, 0, 64, 64);

g.setPaint(Color.BLACK);
g.fillRoundRect(3, 3, 58, 58, 16, 16);
Color transparentWhite = new Color(255, 255, 255, 0);
g.setPaint(
new GradientPaint(48, 16, Color.WHITE, 32, 32, transparentWhite)
);
g.fillOval(-64, 0, 128, 128);

g.setPaint(
new GradientPaint(16, 48, Color.WHITE, 32, 32, transparentWhite)
);
g.fillOval(0, -64, 128, 128);

g.setColor(Color.LIGHT_GRAY);
g.setStroke(new BasicStroke(3));
g.drawLine(32, 3, 32, 32);
g.drawLine(32, 32, 3, 61);
g.drawLine(32, 32, 58, 32);

g.setColor(Color.WHITE);
g.fillOval(26, 24, 22, 22);




Expand Down
103 changes: 3 additions & 100 deletions src/main/java/deformablemesh/meshview/TexturedPlaneDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import java.util.Arrays;
import java.util.List;

public class TexturedPlaneDataObject implements DataObject {
IndexedTriangleArray surfaces;
Shape3D surface_object;
BranchGroup branch_group;
public class TexturedPlaneDataObject extends DeformableMeshDataObject {
private boolean showSurface = false;
private Color volumeColor = Color.WHITE;
Appearance texturedAppearance;
Expand All @@ -33,30 +30,12 @@ public class TexturedPlaneDataObject implements DataObject {
float min = 0;
float max = 1;
public TexturedPlaneDataObject(DeformableMesh3D mesh, MeshImageStack stack){
double[] positions = mesh.positions;

super(mesh.nodes, mesh.connections, mesh.triangles, mesh.positions, mesh.connection_index, mesh.triangle_index);
offsets = new double[]{ stack.offsets[0], stack.offsets[1], stack.offsets[2]};

surfaces = new IndexedTriangleArray(mesh.nodes.size(), GeometryArray.COORDINATES|GeometryArray.NORMALS, 3*mesh.triangles.size());
surfaces.setCoordinates(0, positions);
surfaces.setCoordinateIndices(0, mesh.triangle_index);
surfaces.setNormals(0, generateNormals(mesh.positions, mesh.triangle_index));
surfaces.setNormalIndices(0, mesh.triangle_index);

surfaces.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
surfaces.setCapability(GeometryArray.ALLOW_NORMAL_WRITE);

surface_object = new Shape3D(surfaces);
surface_object.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

setTextureData(stack);

surface_object.setAppearance(createTexturedSurface());


branch_group = new BranchGroup();
branch_group.setCapability(BranchGroup.ALLOW_DETACH);
branch_group.addChild(surface_object);
branch_group.removeChild(mesh_object);
}

public void setTextureData(MeshImageStack stack){
Expand Down Expand Up @@ -94,10 +73,6 @@ public void setTextureData(MeshImageStack stack){

}





private Appearance hiddenSurface() {
Appearance a = new Appearance();
a.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.SCREEN_DOOR, 1f));
Expand Down Expand Up @@ -159,78 +134,6 @@ public void updateVolume(){

}


float[] generateNormals(double[] positions, int[] triangleIndexes){
float[] normals = new float[positions.length];
int t = triangleIndexes.length/3;

for(int i = 0; i<t; i++){
int dex = i*3;
int a = triangleIndexes[dex];
int b = triangleIndexes[dex+1];
int c = triangleIndexes[dex+2];
double ax = positions[3*a];
double ay = positions[3*a + 1];
double az = positions[3*a + 2];
double bx = positions[3*b];
double by = positions[3*b + 1];
double bz = positions[3*b + 2];
double cx = positions[3*c];
double cy = positions[3*c + 1];
double cz = positions[3*c + 2];

double rbx = bx -ax;
double rby = by - ay;
double rbz = bz - az;
double rcx = cx -ax;
double rcy = cy -ay;
double rcz = cz - az;

double nx = rby*rcz - rbz*rcy;
double ny = rbz*rcx - rbx*rcz;
double nz = rbx*rcy - rby*rcx;

double mag = Math.sqrt(nx*nx + ny*ny + nz*nz);
if(mag>0){
nx = nx/mag;
ny = ny/mag;
nz = nz/mag;
}
normals[3*a] += nx;
normals[3*a + 1] += ny;
normals[3*a + 2] += nz;

normals[3*b] += nx;
normals[3*b + 1] += ny;
normals[3*b + 2] += nz;

normals[3*c] += nx;
normals[3*c + 1] += ny;
normals[3*c + 2] += nz;



}

for(int i = 0; i<normals.length/3; i++){
double nx = normals[i*3];
double ny = normals[i*3+1];
double nz = normals[i+3+2];

double mag = Math.sqrt(nx*nx + ny*ny + nz*nz);
if(mag==0){
continue;
}
normals[i*3]/=mag;
normals[i*3+1] /= mag;
normals[i*3 + 2] /= mag;


}

return normals;
}

@Override
public BranchGroup getBranchGroup() {
return branch_group;
Expand Down

0 comments on commit 335a1ce

Please sign in to comment.