Skip to content

Commit

Permalink
Add main for independent plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Aug 3, 2011
1 parent 6c1e0bc commit c0bf3fd
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 60 deletions.
38 changes: 38 additions & 0 deletions nbactions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>build-with-dependencies</actionName>
<basedir>.</basedir>
<reactor>also-make</reactor>
<goals>
<goal>install</goal>
</goals>
</action>
<action>
<actionName>run</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
</goals>
<properties>
<exec.workingdir>/media/projects_/module_bruit/data_computed/2011_07_25</exec.workingdir>
<exec.classpathScope>runtime</exec.classpathScope>
<exec.args>-Xms1024m -classpath %classpath org.noisemap.run.trigrid -ib bati_in_fence.gdms -is expline_source.gdms -o trilvl.gdms</exec.args>
<exec.executable>java</exec.executable>
</properties>
</action>
<action>
<actionName>debug</actionName>
<goals>
<goal>process-classes</goal>
<goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
</goals>
<properties>
<exec.workingdir>/media/projects_/module_bruit/data_computed/2011_07_25</exec.workingdir>
<exec.classpathScope>runtime</exec.classpathScope>
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Xms1024m -classpath %classpath org.noisemap.run.trigrid -ib bati_in_fence.gdms -is expline_source.gdms -o trilvl.gdms</exec.args>
<jpda.listen>true</jpda.listen>
<exec.executable>java</exec.executable>
</properties>
</action>
</actions>
11 changes: 5 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jdelaunay</groupId>
<artifactId>jdelaunay</artifactId>
<version>0.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jdelaunay</groupId>
<artifactId>jdelaunay</artifactId>
<version>0.5</version>
</dependency>
</dependencies>
<description>Translate light vehicle, heavy vehicle, public bus, tramway traffic into linear noise source. Then compute sound propagation and iso surface.</description>
<build>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/noisemap/core/BR_TriGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public ReadAccess evaluate(SQLDataSourceFactory dsf, ReadAccess[] tables,
// if not then append the distance attenuated sound level to the
// receiver
// Save the triangle geometry with the db_m value of the 3 vertices
;

int tableBuildings = 0;
int tableSources = 1;
long nbreceivers = 0;
Expand Down Expand Up @@ -612,7 +612,7 @@ public ReadAccess evaluate(SQLDataSourceFactory dsf, ReadAccess[] tables,
logger.info("Begin processing of cell " + cellI + ","
+ cellJ + " of the " + gridDim + "x" + gridDim
+ " grid..");
if (pm.isCancelled()) {
if (pm!=null && pm.isCancelled()) {
driver.writingFinished();
return driver.getTable("main");
}
Expand Down Expand Up @@ -773,7 +773,7 @@ public ReadAccess evaluate(SQLDataSourceFactory dsf, ReadAccess[] tables,
+ "x" + gridDim + " grid..");
// threadManager.executeBlocking(propaProcess);
while (!threadManager.isAvaibleQueueSlot()) {
if (pm.isCancelled()) {
if (pm!=null && pm.isCancelled()) {
driver.writingFinished();
return driver.getTable("main");
}
Expand All @@ -791,7 +791,7 @@ public ReadAccess evaluate(SQLDataSourceFactory dsf, ReadAccess[] tables,
// threadManager.getRemainingTasks()>0
Thread.sleep(100);
while (threadDataOut.getCellComputed() < nbcell && doMultiThreading) {
if (pm.isCancelled()) {
if (pm!=null && pm.isCancelled()) {
driver.writingFinished();
return driver.getTable("main");
}
Expand All @@ -802,7 +802,7 @@ public ReadAccess evaluate(SQLDataSourceFactory dsf, ReadAccess[] tables,
pmManager.stop();
logger.info("Wait for termination of writing to the driver..");
while (driverManager.isRunning()) {
if (pm.isCancelled()) {
if (pm!=null && pm.isCancelled()) {
driver.writingFinished();
return driver.getTable("main");
}
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/org/noisemap/core/ProgressionOrbisGisManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,20 @@ public void stop() {

@Override
public void run() {
while (enabled) {
monitor.progressTo((int) (getMainProgression() * 100));
if (monitor.isCancelled()) {
break;
}
try {
Thread.sleep(updateInterval);
} catch (InterruptedException e) {
break;
}
}
while (enabled) {
if(monitor!=null) {
monitor.progressTo((int) (getMainProgression() * 100));
if (monitor.isCancelled()) {
break;
}
}else{
System.out.println((getMainProgression() * 100)+" %");
}
try {
Thread.sleep(updateInterval);
} catch (InterruptedException e) {
break;
}
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/org/noisemap/core/PropagationProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ private void receiverSourcePropa(Coordinate srcCoord,

double ReflectedSrcReceiverDistance = receiverReflection
.getReceiverPos().distance(srcCoord);
if (ReflectedSrcReceiverDistance < data.maxSrcDist && PropagationProcess.wallPointTest(nearBuildingsWalls
.get(receiverReflection.getWallId()), srcCoord)) {
if (ReflectedSrcReceiverDistance < data.maxSrcDist ) {
boolean validReflection = false;
int reflectionOrderCounter = 0;
MirrorReceiverResult receiverReflectionCursor = receiverReflection;
Expand All @@ -369,7 +368,7 @@ private void receiverSourcePropa(Coordinate srcCoord,
linters.computeIntersection(seg.p0, seg.p1,
receiverReflection.getReceiverPos(),
destinationPt);
while (linters.hasIntersection()) // While there is a
while (linters.hasIntersection() && PropagationProcess.wallPointTest(seg, destinationPt)) // While there is a
// reflection point
// on another wall
{
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/noisemap/plugin/NoiseMapDeclaration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.noisemap.plugin;



import org.orbisgis.core.ui.pluginSystem.AbstractPlugIn;
import org.orbisgis.core.ui.pluginSystem.PlugInContext;
/**
*
* @author fortin
*/
public class NoiseMapDeclaration extends AbstractPlugIn {
NoiseMapExtension noiseExt;
@Override
public void initialize(PlugInContext context) throws Exception {
noiseExt=new NoiseMapExtension();
}

@Override
public boolean execute(PlugInContext context) throws Exception {
noiseExt.configure(context);
return true;
}

@Override
public boolean isEnabled() {
return true;
}

}
49 changes: 15 additions & 34 deletions src/main/java/org/noisemap/plugin/NoiseMapExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,26 @@
import org.gdms.sql.function.math.Power;
import org.orbisgis.core.ui.pluginSystem.Extension;
import org.orbisgis.core.ui.pluginSystem.PlugInContext;
import org.orbisgis.core.ui.pluginSystem.workbench.FeatureInstaller;

public class NoiseMapExtension extends Extension {

public void initialize(PlugInContext context) throws Exception {
context.getFeatureInstaller()
.addRegisterFunction(BR_EvalSource.class);
context.getFeatureInstaller().addRegisterFunction(
ST_SplitLineInPoints.class);
context.getFeatureInstaller().addRegisterFunction(Log10.class);
context.getFeatureInstaller().addRegisterFunction(Power.class);
context.getFeatureInstaller().addRegisterFunction(ST_SetNearestZ.class);
context.getFeatureInstaller().
addRegisterFunction(ST_SetNearestGeometryId.class);
context.getFeatureInstaller()
.addRegisterFunction(ST_SplitSegment.class);
context.getFeatureInstaller().addRegisterFunction(BR_TriGrid.class);
context.getFeatureInstaller().addRegisterFunction(
ST_TriangleContouring.class);
context.getFeatureInstaller().addRegisterFunction(
BR_SpectrumRepartition.class);
context.getFeatureInstaller().addRegisterFunction(
BTW_SpectrumRepartition.class);
context.getFeatureInstaller().addRegisterFunction(
BTW_EvalSource.class);
System.out.println("Noise mapping extension plugin loaded..");
}

@Override
public void configure(PlugInContext context) throws Exception {
this.initialize(context);
FeatureInstaller fi=context.getFeatureInstaller();
fi.addRegisterFunction(BR_EvalSource.class);
fi.addRegisterFunction(ST_SplitLineInPoints.class);
fi.addRegisterFunction(Log10.class);
fi.addRegisterFunction(Power.class);
fi.addRegisterFunction(ST_SetNearestZ.class);
fi.addRegisterFunction(ST_SetNearestGeometryId.class);
fi.addRegisterFunction(ST_SplitSegment.class);
fi.addRegisterFunction(BR_TriGrid.class);
fi.addRegisterFunction(ST_TriangleContouring.class);
fi.addRegisterFunction(BR_SpectrumRepartition.class);
fi.addRegisterFunction(BTW_SpectrumRepartition.class);
fi.addRegisterFunction(BTW_EvalSource.class);
System.out.println("Noise mapping extension plugin loaded..");
}

public boolean execute(PlugInContext context) throws Exception {
/* Place you code to execute here */
return true;
};

public boolean isEnabled() {
/* Place your condition here */
return true;
}
}
141 changes: 141 additions & 0 deletions src/main/java/org/noisemap/run/trigrid.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@

/***********************************
* ANR EvalPDU
* IFSTTAR 11_05_2011
* @author Nicolas FORTIN, Judicaël PICAUT
***********************************/


package org.noisemap.run;

import java.io.File;
import org.gdms.driver.DriverException;
import org.gdms.driver.ReadAccess;
import org.gdms.driver.gdms.GdmsDriver;
import java.util.Stack;
import org.gdms.data.SQLDataSourceFactory;
import org.gdms.data.values.Value;
import org.gdms.data.values.ValueFactory;
import org.gdms.sql.function.FunctionException;
import org.noisemap.core.BR_TriGrid;

/**
* Independant run of BR_TriGrid plugin
* Take two gdms file as input. The single output is another gdms file.
*/
public class trigrid {

private static void printUsage() {
System.out.println("Usage :");
System.out.println("java trigrid.jar [options] -ib bpath -is spath -o outpath");
System.out.println("Options :");
System.out.println("-bfield the_geom : buildings column name (polygons)");
System.out.println("-sfield the_geom : sources column nale (points or lines)");
System.out.println("-splfield db_m : sound lvl field name(string)");
System.out.println("-maxdist 170 : maximum propagation distance (double meter)");
System.out.println("-splitdepth 3 : subdivision level 4^n cells (int) [0-n]");
System.out.println("-rwidth 0.8 : roads width (double meter)");
System.out.println("-dense 5 : densification of receivers near roads (meter double)");
System.out.println("-marea 250 : maximum area of triangle (square meter)");
System.out.println("-rdepth 2 : sound reflection order [0-n] (int)");
System.out.println("-ddepth 1 : sound diffraction order [0-n] (int)");
System.out.println("-awalls 0.2 : alpha of walls [0-1[ (double)");
System.out.println("-ib builds.gdms : file name of buildings gdms file");
System.out.println("-is sources.gdms : file name of noise sources gdms file");
System.out.println("-o trilvl.gdms : output filename of gdms file");
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Parameters
String buildingsFilename="";
String sourcesFilename="";
String outputFilename="";
//Optionnal parameters
String bField="the_geom";
String sField="the_geom";
String splField="db_m";
double maxDist=170;
int splitDepth=3;
double roadsWidth=0.8;
double densification=5.;
double maxarea=250;
int reflectionDepth=2;
int diffractionDepth=1;
double wallAlpha=.2;


//Read parameters
Stack<String> sargs=new Stack<String>();
for(String arg : args) {
sargs.insertElementAt(arg, 0);
}
while(!sargs.empty()) {
String argument=sargs.pop();
System.out.println(argument+sargs);
if(argument.contentEquals("-bfield")) {
bField=sargs.pop();
}else if(argument.contentEquals("-sfield")) {
sField=sargs.pop();
}else if(argument.contentEquals("-splfield")) {
splField=sargs.pop();
}else if(argument.contentEquals("-maxdist")) {
maxDist=Double.valueOf(sargs.pop());
}else if(argument.contentEquals("-splitdepth")) {
splitDepth=Integer.valueOf(sargs.pop());
}else if(argument.contentEquals("-rwidth")) {
roadsWidth=Double.valueOf(sargs.pop());
}else if(argument.contentEquals("-dense")) {
densification=Double.valueOf(sargs.pop());
}else if(argument.contentEquals("-marea")) {
maxarea=Double.valueOf(sargs.pop());
}else if(argument.contentEquals("-rdepth")) {
reflectionDepth=Integer.valueOf(sargs.pop());
}else if(argument.contentEquals("-ddepth")) {
reflectionDepth=Integer.valueOf(sargs.pop());
}else if(argument.contentEquals("-awalls")) {
wallAlpha=Double.valueOf(sargs.pop());
}else if(argument.contentEquals("-ib")) {
buildingsFilename=sargs.pop();
}else if(argument.contentEquals("-is")) {
sourcesFilename=sargs.pop();
}else if(argument.contentEquals("-o")) {
outputFilename=sargs.pop();
}
}
if(buildingsFilename.isEmpty() || sourcesFilename.isEmpty() || outputFilename.isEmpty()) {
printUsage();
return;
}
//Load files
SQLDataSourceFactory factory=new SQLDataSourceFactory();
GdmsDriver buildings=new GdmsDriver();
GdmsDriver sources=new GdmsDriver();
ReadAccess[] tables={null,null};
try {
buildings.setFile(new File(buildingsFilename));
buildings.open();
tables[0]=buildings.getTable("main");
sources.setFile(new File(buildingsFilename));
sources.open();
tables[1]=sources.getTable("main");
} catch (DriverException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
return;
}
//Run propagation

BR_TriGrid propa=new BR_TriGrid();
Value[] propaArgs={ValueFactory.createValue(bField),ValueFactory.createValue(sField),ValueFactory.createValue(splField),ValueFactory.createValue(maxDist),ValueFactory.createValue(splitDepth),ValueFactory.createValue(roadsWidth),ValueFactory.createValue(densification),ValueFactory.createValue(maxarea),ValueFactory.createValue(reflectionDepth),ValueFactory.createValue(diffractionDepth),ValueFactory.createValue(wallAlpha)};
try {
ReadAccess data = propa.evaluate(factory, tables, propaArgs, null);
} catch (FunctionException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
return;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void testMergeSources() throws LayerDelaunayError {
System.out.println("Propagation initialisation in "+(System.currentTimeMillis()-startObstructionTest)+"ms");
long startSimulation=System.currentTimeMillis();
//Run test
//System.out.println(manager.getDelaunayGeoms());
System.out.println(manager.getDelaunayGeoms());
/////////////////////////////////////////////////////////////////////////
// Geometric dispersion test
propData.reflexionOrder=3;
Expand Down

0 comments on commit c0bf3fd

Please sign in to comment.