Skip to content

Commit

Permalink
Added the steric meshes to deforming, the javascript console is requi…
Browse files Browse the repository at this point in the history
…red for using the feature.
  • Loading branch information
m smith committed Feb 6, 2019
1 parent aff6f69 commit 97f05ff
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 24 deletions.
4 changes: 4 additions & 0 deletions src/main/java/deformablemesh/SegmentationController.java
Expand Up @@ -61,6 +61,10 @@ public void setPressure(double d) {
model.setPressure(d);
}

public void setStericNeighborWeight(double d){
model.setStericNeighborWeight(d);
}

public void setCortexThickness(double d) {
model.setCortexThickness(d);
}
Expand Down
38 changes: 30 additions & 8 deletions src/main/java/deformablemesh/SegmentationModel.java
@@ -1,13 +1,6 @@
package deformablemesh;

import deformablemesh.externalenergies.ExternalEnergy;
import deformablemesh.externalenergies.GradientEnergy;
import deformablemesh.externalenergies.ImageEnergyType;
import deformablemesh.externalenergies.IntensityEnergy;
import deformablemesh.externalenergies.PerpendicularGradientEnergy;
import deformablemesh.externalenergies.PerpendicularIntensityEnergy;
import deformablemesh.externalenergies.PressureForce;
import deformablemesh.externalenergies.TriangleAreaDistributor;
import deformablemesh.externalenergies.*;
import deformablemesh.geometry.BinaryMomentsOfInertia;
import deformablemesh.geometry.Box3D;
import deformablemesh.geometry.DeformableMesh3D;
Expand Down Expand Up @@ -61,6 +54,8 @@ public class SegmentationModel {
double ALPHA = 1.0;
double BETA = 0.0;
double pressure = 0.0;
double stericNeighborWeight;

private double cortex_thickness = 0.3;

boolean reshape = true;
Expand Down Expand Up @@ -351,6 +346,13 @@ public double getPressure() {
return pressure;
}

public void setStericNeighborWeight(double d){
stericNeighborWeight = d;
}

public double getStericNeighborWeight(){
return stericNeighborWeight;
}
public void saveMeshes(final File f) throws IOException {
lastSavedFile = null;
MeshWriter.saveMeshes(f, tracker);
Expand Down Expand Up @@ -528,13 +530,33 @@ public void externalEnergies(){

if(normalize!=0){
selectedMesh.addExternalEnergy(new TriangleAreaDistributor(stack, selectedMesh, normalize));
}

if(stericNeighborWeight!=0){
List<ExternalEnergy> segs = generateStericEnergies();
for(ExternalEnergy eg: segs){
selectedMesh.addExternalEnergy(eg);
}
}

snakeBox.addRingEnergy(stack.CURRENT, selectedMesh);

}

private List<ExternalEnergy> generateStericEnergies() {
List<Track> tracks = tracker.getAllMeshTracks();
DeformableMesh3D sel = getSelectedMesh(stack.CURRENT);
List<ExternalEnergy> es = new ArrayList<>(tracks.size());
for(Track track: tracks){
if(!track.containsMesh(sel) && track.containsKey(stack.CURRENT) ){

es.add(new StericMesh(track.getMesh(stack.CURRENT), stericNeighborWeight));

}
}
return es;
}

public double getCurveWeight() {

return snakeBox.getCurveWeight();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/deformablemesh/externalenergies/StericMesh.java
Expand Up @@ -4,9 +4,10 @@
import deformablemesh.geometry.InterceptingMesh3D;

public class StericMesh implements ExternalEnergy{
//final InterceptingMesh3D mesh;
InterceptingMesh3D mesh;
final DeformableMesh3D deformableMesh;
final double weight;
boolean staticShape = true;
public StericMesh(DeformableMesh3D a, double weight){
//mesh = new InterceptingMesh3D(a);
deformableMesh = a;
Expand All @@ -15,7 +16,9 @@ public StericMesh(DeformableMesh3D a, double weight){

@Override
public void updateForces(double[] positions, double[] fx, double[] fy, double[] fz) {
InterceptingMesh3D mesh = new InterceptingMesh3D(deformableMesh);
if(!staticShape || mesh==null) {
mesh = new InterceptingMesh3D(deformableMesh);
}
double[] pt = new double[3];
double[] center = mesh.getCenter();
for(int i = 0; i<fx.length; i++){
Expand Down
68 changes: 54 additions & 14 deletions src/main/java/deformablemesh/simulations/TwoDrops.java
Expand Up @@ -16,29 +16,29 @@
public class TwoDrops {
DeformableMesh3D a;
DeformableMesh3D b;
double gravityMagnitude = 0.0;
double surfaceFactor = 0.0;
double volumeConservation = 1.0;
double gravityMagnitude = 0.00001;
double surfaceFactor = 0.0002;
double volumeConservation = 0.01;
double steric = 0.0;
double sticky = 1.0;
double sticky = 0.01;
List<StickyVertex> links = new ArrayList<>();
public TwoDrops(){
Sphere sA = new Sphere(new double[]{-0.1, 0, 0.5}, 0.1);
a = new NewtonMesh3D(RayCastMesh.rayCastMesh(sA, sA.getCenter(), 2));
//a = RayCastMesh.rayCastMesh(sA, sA.getCenter(), 2);
a.GAMMA = 500;
//a = new NewtonMesh3D(RayCastMesh.rayCastMesh(sA, sA.getCenter(), 2));
a = RayCastMesh.rayCastMesh(sA, sA.getCenter(), 2);
a.GAMMA = 1;
a.ALPHA = 0.01;
a.BETA = 0.0;
a.reshape();
a.setShowSurface(true);
a.setColor(Color.RED);
Sphere sB = new Sphere(new double[]{0.1, 0, 0.5}, 0.1);
b = new NewtonMesh3D(RayCastMesh.rayCastMesh(sB, sB.getCenter(), 2));
//b = RayCastMesh.rayCastMesh(sB, sB.getCenter(), 2);
//b = new NewtonMesh3D(RayCastMesh.rayCastMesh(sB, sB.getCenter(), 2));
b = RayCastMesh.rayCastMesh(sB, sB.getCenter(), 2);

b.ALPHA = 0.1;
b.BETA = 0.0;
b.GAMMA = 500;
b.ALPHA = 0.01;
b.BETA = 0.001;
b.GAMMA = 1;
b.reshape();
b.setColor(Color.BLUE);
b.setShowSurface(true);
Expand Down Expand Up @@ -100,10 +100,43 @@ public double getEnergy(double[] pos) {
b.addExternalEnergy(new StericMesh(a, steric));
}

if(sticky != 0) {
stickVertexes(a, b);

}

Set<Integer> stuckA = new HashSet<>();
Set<Integer> stuckB = new HashSet<>();
double cutoff = 0.0001;
public void stickyCell(DeformableMesh3D sticky, DeformableMesh3D neighbor){
int nA = sticky.positions.length/3;
int nB = neighbor.positions.length/3;



for(int i = 0; i<nA; i++){
if(stuckA.contains(i)) continue;
for(int j = 0; j<nB; j++){
if(stuckB.contains(j)) continue;

double[] a = sticky.getCoordinates(i);
double[] b = neighbor.getCoordinates(j);

double dx = b[0] - a[0];
double dy = b[1] - a[1];
double dz = b[2] - a[2];

if(dx*dx + dy*dy + dz*dz < cutoff){
stuckA.add(i);
stuckB.add(j);
sticky.addExternalEnergy(new StickyVertex(i, neighbor.nodes.get(j), this.sticky));
neighbor.addExternalEnergy(new StickyVertex(j, sticky.nodes.get(i), this.sticky));
}

}
}


}

public void stickVertexes(DeformableMesh3D a, DeformableMesh3D b){

Set<Node3D> possibleA = new HashSet<>();
Expand Down Expand Up @@ -198,6 +231,13 @@ public void createDisplay(){
public void step(){
a.update();
b.update();
if(sticky!=0){
int before = stuckA.size();
stickyCell(a,b);
if(stuckA.size() > before){
System.out.println("stuck!");
}
}
}
public static void main(String[] args){
TwoDrops sim = new TwoDrops();
Expand Down

0 comments on commit 97f05ff

Please sign in to comment.