Skip to content

Commit

Permalink
update for version 0.9.1.3 / force field updates / Shp file importer
Browse files Browse the repository at this point in the history
  • Loading branch information
Satoru Sugihara committed Oct 21, 2014
1 parent 8669387 commit 6ae25bd
Show file tree
Hide file tree
Showing 51 changed files with 8,787 additions and 328 deletions.
63 changes: 63 additions & 0 deletions I2DMapField.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/

package igeo;

/**
2D vector filed defined by a map
@author Satoru Sugihara
*/

public class I2DMapField extends I2DField{

public I2DMapField(IMap map, IVec corner, double width, double height){
super(new I2DMapFieldGeo(map,corner,width,height));
}

public I2DMapField(IMap map, double left, double bottom, double right, double top){
super(new I2DMapFieldGeo(map,new IVec(left,bottom,0),right-left, top-bottom));
}

public I2DMapField(String imageFile, IVec corner, double width, double height){
super(new I2DMapFieldGeo(new IImageMap(imageFile),corner,width,height));
}

public I2DMapField(String imageFile, double left, double bottom, double right, double top){
super(new I2DMapFieldGeo(new IImageMap(imageFile),
new IVec(left,bottom,0), right-left, top-bottom));
}

public I2DMapField noDecay(){ super.noDecay(); return this; }
public I2DMapField linearDecay(double threshold){ super.linearDecay(threshold); return this; }
public I2DMapField linear(double threshold){ super.linear(threshold); return this; }
public I2DMapField gaussianDecay(double threshold){ super.gaussianDecay(threshold); return this; }
public I2DMapField gaussian(double threshold){ super.gaussian(threshold); return this; }
public I2DMapField gauss(double threshold){ super.gauss(threshold); return this; }
public I2DMapField constantIntensity(boolean b){ super.constantIntensity(b); return this; }

/** if bidirectional is on, field force vector is flipped when velocity of particle is going opposite */
public I2DMapField bidirectional(boolean b){ super.bidirectional(b); return this; }

public I2DMapField threshold(double t){ super.threshold(t); return this; }
public I2DMapField intensity(double i){ super.intensity(i); return this; }
}
237 changes: 237 additions & 0 deletions I2DMapFieldGeo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/

package igeo;

/**
2D vector filed defined by a IMap
@author Satoru Sugihara
*/

public class I2DMapFieldGeo extends IFieldGeo implements I2DFieldI{

public IMap map;
public IDoubleMap dmap; // cast from map
public IVec corner;
public double width,height;
public int mapWidth, mapHeight;

public int interpolationRange = 5;

public I2DMapFieldGeo(IMap m, IVec cnr, double wid, double hei){
map = m;
corner = cnr;
width = wid;
height = hei;
//linearDecay(0);

if(map instanceof IDoubleMap){
dmap = (IDoubleMap)map;
mapWidth = dmap.getWidth();
mapHeight = dmap.getHeight();

if(dmap instanceof IImageMap){
dmap.flipV(); // upside down
}

}
else{
mapWidth = IMap.defaultDensityWidth;
mapHeight = IMap.defaultDensityHeight;
}
}

public double udif(int uidx, int vidx){
if(dmap!=null){
return dmap.map[uidx+1][vidx] - dmap.map[uidx][vidx];
}
return map.get( (double)(uidx+1)/mapWidth, (double)vidx/mapHeight ) -
map.get( (double)uidx/mapWidth, (double)vidx/mapHeight );
}

public double vdif(int uidx, int vidx){
if(dmap!=null){
return dmap.map[uidx+1][vidx] - dmap.map[uidx][vidx];
}
return map.get( (double)(uidx+1)/mapWidth, (double)vidx/mapHeight ) -
map.get( (double)uidx/mapWidth, (double)vidx/mapHeight );
}

public IVec2 dif(int uidx, int vidx){

if(uidx<0) uidx=0; else if(uidx>=mapWidth-1) uidx=mapWidth-2;
if(vidx<0) vidx=0; else if(vidx>=mapHeight-1) vidx=mapHeight-2;

// interpolation of 4 cells
double udif1=0, udif2=0, vdif1=0, vdif2=0;
if(dmap!=null){
udif1 = dmap.map[uidx+1][vidx] - dmap.map[uidx][vidx];
udif2 = dmap.map[uidx+1][vidx+1] - dmap.map[uidx][vidx+1];
vdif1 = dmap.map[uidx][vidx+1] - dmap.map[uidx][vidx];
vdif2 = dmap.map[uidx+1][vidx+1] - dmap.map[uidx+1][vidx];
}
else{
udif1 = map.get( (double)(uidx+1)/mapWidth, (double)vidx/mapHeight ) -
map.get( (double)uidx/mapWidth, (double)vidx/mapHeight );
udif2 = map.get( (double)(uidx+1)/mapWidth, (double)(vidx+1)/mapHeight ) -
map.get( (double)uidx/mapWidth, (double)(vidx+1)/mapHeight );
vdif1 = map.get( (double)(uidx)/mapWidth, (double)(vidx+1)/mapHeight ) -
map.get( (double)uidx/mapWidth, (double)(vidx)/mapHeight );
vdif2 = map.get( (double)(uidx+1)/mapWidth, (double)(vidx+1)/mapHeight ) -
map.get( (double)(uidx+1)/mapWidth, (double)(vidx)/mapHeight );
}

return new IVec2((udif1+udif2)/2, (vdif1+vdif2)/2);
}


IVec2 interpolateDif(int uidx, int vidx){

double weight=0;
double u=0;
double v=0;
IVec2 vec = new IVec2();
for(int i=uidx-interpolationRange; i<uidx+interpolationRange; i++){
for(int j=vidx-interpolationRange; j<vidx+interpolationRange; j++){
vec.add(dif(i,j));
weight += 1 - Math.abs(i-uidx)/(interpolationRange+1);
}
}
vec.div(weight);
return vec;
}


/** get original field value out of surface parameter uv */
public IVec2I get(IVecI pos, double u, double v){
/*
int uidx1 = (int)(u*mapWidth);
int vidx1 = (int)(v*mapHeight);
if(uidx1<0) uidx1=0; else if(uidx1>=mapWidth){ uidx1=mapWidth-1; }
if(vidx1<0) vidx1=0; else if(vidx1>=mapHeight){ vidx1=mapHeight-1; }
*/
int uidx2 = (int)(u*mapWidth-0.5);
int vidx2 = (int)(v*mapHeight-0.5);
if(uidx2<0) uidx2=0; else if(uidx2>=mapWidth-1){ uidx2=mapWidth-2; }
if(vidx2<0) vidx2=0; else if(vidx2>=mapHeight-1){ vidx2=mapHeight-2; }

//double udif = udif(uidx2, vidx1);
//double vdif = vdif(uidx1, vidx2);

return interpolateDif(uidx2,vidx2);

//return dif( uidx2, vidx2);

/*
double udif=0, vdif=0;
if(dmap!=null){
udif = dmap.map[uidx2+1][vidx1] - dmap.map[uidx2][vidx1];
vdif = dmap.map[uidx1][vidx2+1] - dmap.map[uidx1][vidx2];
}
else{
udif =
map.get( (double)(uidx2+1)/mapWidth, (double)vidx1/mapHeight ) -
map.get( (double)uidx2/mapWidth, (double)vidx1/mapHeight );
vdif =
map.get((double)uidx1/mapWidth, (double)(vidx2+1)/mapHeight) -
map.get((double)uidx1/mapWidth, (double)vidx2/mapHeight);
}
*/
//return new IVec2(udif, vdif);
}

/** get original field value out of surface parameter uv */
public IVec2I get(IVecI pos, IVecI vel, double u, double v){
return get(pos,u,v);
}

/** get 3D vector field value */
public IVec2I get(IVecI v){ return get(v,(IVecI)null); }

/** get 3D vector field value */
public IVec2I get(IVecI pos, IVecI vel){

double u = (pos.x()-corner.x)/width;
double v = (pos.y()-corner.y)/height;

if(u<0 || u>1 || v<0 || v>1){
return new IVec2(0,0); // no decay
}

double r = intensity;

/*
if(decay == Decay.Linear){
double dist = surface.pt(uv).to2d().dist(pos.to2d());
if(dist >= threshold &&
(uv.x<=0||uv.y<=0||uv.x>=1.0||uv.y>=1.0)) return new IVec2(); // zero
if(threshold>0) r *= (threshold-dist)/threshold;
}
else if(decay == Decay.Gaussian){
double dist = surface.pt(uv).to2d().dist(pos.to2d());
if(threshold>0) r *= Math.exp(-2*dist*dist/(threshold*threshold));
}
*/

IVec2I vec = get(pos, vel, u, v);

/*
if(bidirectional && vec.get().dot(vel.to2d()) < 0){ r=-r; }
if(constantIntensity){
double len = vec.len();
if(len<IConfig.tolerance){ return vec.zero(); }
return vec.len(r);
}
*/

return vec.mul(r);

}

/*
public I2DSurfaceFieldGeo constantIntensity(boolean b){ super.constantIntensity(b); return this; }
public I2DSurfaceFieldGeo bidirectional(boolean b){ super.bidirectional(b); return this; }
public I2DSurfaceFieldGeo noDecay(){ super.noDecay(); return this; }
public I2DSurfaceFieldGeo linearDecay(double threshold){
super.linearDecay(threshold); return this;
}
public I2DSurfaceFieldGeo linear(double threshold){
super.linear(threshold); return this;
}
public I2DSurfaceFieldGeo gaussianDecay(double threshold){
super.gaussianDecay(threshold); return this;
}
public I2DSurfaceFieldGeo gaussian(double threshold){
super.gaussian(threshold); return this;
}
public I2DSurfaceFieldGeo gauss(double threshold){ super.gauss(threshold); return this; }
public I2DSurfaceFieldGeo threshold(double t){ super.threshold(t); return this; }
*/

public I2DMapFieldGeo intensity(double i){ super.intensity(i); return this; }

public void del(){
}
}
39 changes: 39 additions & 0 deletions IArithmeticVal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/

package igeo;

/**
Abstract Scalar (1D) Value Interface
@author Satoru Sugihara
*/

public interface IArithmeticVal<T,S> extends IVal{
public T add(T val);
public T sub(T val);
public T mul(S val);
public T div(S val);
public T zero();
public T dup();
public T cp(); // alias of dup
public T set(T val);
}
5 changes: 5 additions & 0 deletions IColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ public static IColor hsb(float h, float s, float b, float a){

/** returns array of 4 float in the order of RGBA */
public float[] rgba(){ return rgba; }

/** returns array of 4 float in the order of RGBA with alpha overwritten */
public float[] rgba(float alpha){ return new float[]{ rgba[0], rgba[1], rgba[2], alpha}; }



/** returns one 32 bit integer in the order of ARGB */
public int argb(){
Expand Down
13 changes: 10 additions & 3 deletions IConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@
public static boolean updateMeshNormal=false;

/** remove duplicated vertices and edges under the tolerance = IConfig.tolerance automatically when a mesh is created in new IMesh(IFace[] faces) */
public static boolean removeDuplicatesAtMeshCreation=true;
public static boolean removeDuplicatesAtMeshCreation=true;

/** Enable vertex colors instead of mesh object color */
//public static boolean enableVertexColor=false; //true;

/** Enable face colors instead of mesh object color */
//public static boolean enableFaceColor=false; //true;


/*****************************
Expand Down Expand Up @@ -427,8 +433,9 @@ Speed of zooming in keyboard (arrow keys in default) 3D navigation in axonometri
/*************************************************************************************
* AI Export
************************************************************************************/
public static double defaultAIExportScale = 0.01;

public static double defaultAIExportScale = 0.00001; //0.01;
public static double defaultAIExportPixelScale = 0.1; //0.01;


/*************************************************************************************
* Text Object Property
Expand Down
Loading

0 comments on commit 6ae25bd

Please sign in to comment.