Commit c62f3584 authored by Krzysztof Nowinski's avatar Krzysztof Nowinski

Surface components module generalized to accept all types of irregular input...

Surface components module generalized to accept all types of irregular input fields and renamed to connected components
parent ddf35735
......@@ -102,7 +102,7 @@
<core package="pl.edu.icm.visnow.lib.basic.mappers.Isosurface"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.Isovolume"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.LineSlice"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.VolumeRenderer"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.PlanarSlice"/>
<core package="pl.edu.icm.visnow.lib.basic.mappers.RegularFieldSlice"/>
......
/* VisNow
Copyright (C) 2006-2013 University of Warsaw, ICM
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
University of Warsaw, Interdisciplinary Centre for Mathematical and
Computational Modelling, Pawinskiego 5a, 02-106 Warsaw, Poland.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package pl.edu.icm.visnow.lib.basic.filters.SurfaceComponents;
import pl.edu.icm.visnow.engine.core.Parameter;
import pl.edu.icm.visnow.engine.core.ParameterEgg;
import pl.edu.icm.visnow.engine.core.ParameterType;
import pl.edu.icm.visnow.engine.core.Parameters;
/**
*
* @author Krzysztof S. Nowinski
* Warsaw University, ICM
*/
public class Params extends Parameters
{
private Parameter<Integer> minComponentSize;
private Parameter<Integer> separateComponents;
private Parameter<Boolean> colorByComponents;
boolean minComponentSizeChanged = false;
@SuppressWarnings("unchecked")
private void initParameters()
{
minComponentSize = getParameter("minComponentSize");
separateComponents = getParameter("separateComponents");
colorByComponents = getParameter("colorByComponents");
colorByComponents.setValue(true);
minComponentSize.setValue(20);
separateComponents.setValue(20);
colorByComponents.setValue(true);
}
private static ParameterEgg[] eggs = new ParameterEgg[]{
new ParameterEgg<Integer>("minComponentSize", ParameterType.dependent),
new ParameterEgg<Integer>("separateComponents", ParameterType.dependent),
new ParameterEgg<Boolean>("colorByComponents", ParameterType.dependent),};
public Params()
{
super(eggs);
initParameters();
}
public int getMinComponentSize()
{
return minComponentSize.getValue();
}
public void setMinComponentSize(int minComponentSize)
{
this.minComponentSize.setValue(minComponentSize);
minComponentSizeChanged = true;
}
public int getSeparateComponents()
{
return separateComponents.getValue();
}
public void setSeparateComponents(int separateComponents)
{
this.separateComponents.setValue(separateComponents);
}
public boolean colorByComponents()
{
return colorByComponents.getValue();
}
public void setColorByComponents(boolean colorByComponents)
{
this.colorByComponents.setValue(colorByComponents);
}
public boolean isMinComponentSizeChanged()
{
boolean t = minComponentSizeChanged;
minComponentSizeChanged = false;
return t;
}
}
/* VisNow
Copyright (C) 2006-2013 University of Warsaw, ICM
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath 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
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
University of Warsaw, Interdisciplinary Centre for Mathematical and
Computational Modelling, Pawinskiego 5a, 02-106 Warsaw, Poland.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package pl.edu.icm.visnow.lib.basic.filters.SurfaceComponents;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import pl.edu.icm.jscic.IrregularField;
import pl.edu.icm.visnow.engine.core.InputEgg;
import pl.edu.icm.visnow.engine.core.OutputEgg;
import pl.edu.icm.visnow.gui.events.FloatValueModificationEvent;
import pl.edu.icm.visnow.gui.events.FloatValueModificationListener;
import pl.edu.icm.visnow.lib.templates.visualization.modules.OutFieldVisualizationModule;
import pl.edu.icm.visnow.lib.types.VNIrregularField;
import pl.edu.icm.visnow.lib.utils.SwingInstancer;
/**
* @author Krzysztof S. Nowinski (know@icm.edu.pl)
* Warsaw University, Interdisciplinary Centre
* for Mathematical and Computational Modelling
*/
public class SurfaceComponents extends OutFieldVisualizationModule
{
private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(SurfaceComponents.class);
/**
* Creates a new instance of SurfaceSmoother
*/
private static InputEgg[] inputEggs = null;
private static OutputEgg[] outputEggs = null;
public ProcessComponents processor = new ProcessComponents();
public GUI computeUI = null;
private Params params = new Params();
private IrregularField inField = null;
protected boolean fromGUI = false;
public SurfaceComponents()
{
parameters = params = new Params();
params.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent evt)
{
fromGUI = true;
startAction();
}
});
SwingInstancer.swingRunAndWait(new Runnable()
{
public void run()
{
computeUI = new GUI();
}
});
computeUI.setParams(params);
ui.addComputeGUI(computeUI);
setPanel(ui);
processor.addFloatValueModificationListener(
new FloatValueModificationListener()
{
public void floatValueChanged(FloatValueModificationEvent e)
{
setProgress(e.getVal());
}
});
processor.addChangeListener(computeUI.getNewCmpListener());
}
@Override
public void onActive()
{
if (!fromGUI) {
if (getInputFirstValue("inField") == null || ((VNIrregularField) getInputFirstValue("inField")).getField() == null)
return;
inField = ((VNIrregularField) getInputFirstValue("inField")).getField();
}
fromGUI = false;
if (processor.getInField() == null || inField != processor.getInField()) {
processor.setInField(inField, params);
}
outIrregularField = processor.split(params);
setOutputValue("outField", new VNIrregularField(outIrregularField));
outField = outIrregularField;
prepareOutputGeometry();
show();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module name="surface components" class="SurfaceComponents">
<inputs>
<input name="inField" type="pl.edu.icm.visnow.lib.types.VNField" modifiers="NECESSARY:TRIGGERING">
<acceptor>
<param name="IRREGULAR" value="true"/>
</acceptor>
</input>
</inputs>
<outputs>
<output name="outField" type="pl.edu.icm.visnow.lib.types.VNIrregularField">
<schema>
<param name="IRREGULAR" value="true"/>
</schema>
</output>
<geometryOutput/>
</outputs>
<parameters>
</parameters>
</module>
......@@ -34,7 +34,7 @@
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents;
package pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents;
import javax.media.j3d.PickInfo;
import pl.edu.icm.jscic.IrregularField;
......@@ -45,7 +45,7 @@ import pl.edu.icm.visnow.engine.core.ParameterChangeListener;
import pl.edu.icm.visnow.engine.core.Parameters;
import pl.edu.icm.visnow.engine.core.ProgressAgent;
import static pl.edu.icm.visnow.gui.widgets.RunButton.RunState.*;
import static pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents.SurfaceComponentsShared.*;
import static pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents.ConnectedComponentsShared.*;
import pl.edu.icm.visnow.lib.templates.visualization.modules.OutFieldVisualizationModule;
import pl.edu.icm.visnow.lib.types.VNIrregularField;
import pl.edu.icm.visnow.lib.utils.SwingInstancer;
......@@ -56,21 +56,21 @@ import pl.edu.icm.visnow.lib.utils.field.ExtractCellSets;
* Warsaw University, Interdisciplinary Centre
* for Mathematical and Computational Modelling
*/
public class SurfaceComponents extends OutFieldVisualizationModule
public class ConnectedComponents extends OutFieldVisualizationModule
{
public static InputEgg[] inputEggs = null;
public static OutputEgg[] outputEggs = null;
private ProcessComponents processor = new ProcessComponents();
private final ProcessComponents processor = new ProcessComponents();
private GUI computeUI = null;
private IrregularField inIrregularField = null;
private IrregularField midIrregularField = null;
private int lastMinComponentSize = 20, resetMinComponentSize = 20;
private int lastSeparateComponents = 20, resetSeparateComponents = 20;
private int lastMinComponentSize = 20, lastSeparateComponents = 20;
private final int resetMinComponentSize = 20, resetSeparateComponents = 20;
private int runQueue = 0;
public SurfaceComponents()
public ConnectedComponents()
{
parameters.addParameterChangelistener(new ParameterChangeListener()
{
......
......@@ -34,7 +34,7 @@
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents;
package pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents;
//import pl.edu.icm.visnow.lib.basic.filters.SurfaceComponents.*;
import pl.edu.icm.visnow.engine.core.ParameterName;
......@@ -46,7 +46,7 @@ import pl.edu.icm.visnow.gui.widgets.RunButton;
*/
public class SurfaceComponentsShared
public class ConnectedComponentsShared
{
//Minimal component sizes
static final ParameterName<Integer> MIN_COMPONENT_SIZE = new ParameterName("minComponentSize");
......
......@@ -36,7 +36,7 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
//</editor-fold>
package pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents;
package pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents;
import java.awt.Container;
import java.awt.Cursor;
......@@ -56,7 +56,7 @@ import javax.swing.table.TableColumn;
import pl.edu.icm.visnow.engine.core.ParameterProxy;
import pl.edu.icm.visnow.engine.core.Parameters;
import pl.edu.icm.visnow.gui.widgets.RunButton.RunState;
import static pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents.SurfaceComponentsShared.*;
import static pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents.ConnectedComponentsShared.*;
/**
*
......
......@@ -36,18 +36,17 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
//</editor-fold>
package pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents;
package pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents;
import org.apache.log4j.Logger;
import pl.edu.icm.jscic.CellArray;
import pl.edu.icm.jscic.CellSet;
import pl.edu.icm.jscic.IrregularField;
import pl.edu.icm.jscic.cells.Cell;
import pl.edu.icm.jscic.cells.CellType;
import pl.edu.icm.jscic.dataarrays.DataArray;
import pl.edu.icm.visnow.engine.core.Parameters;
import pl.edu.icm.visnow.engine.core.ProgressAgent;
import static pl.edu.icm.visnow.lib.basic.mappers.SurfaceComponents.SurfaceComponentsShared.*;
import static pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents.ConnectedComponentsShared.*;
import pl.edu.icm.visnow.lib.utils.numeric.HeapSort;
/**
......@@ -81,52 +80,28 @@ public class ProcessComponents
split(i);
}
private void addTriangleNeighbors(int[] pNeighb, int[] neighbInd, int i0, int i1, int i2)
private void addNeighbors(int[] pNeighb, int[] neighbInd, CellArray cellArray)
{
for (int j = neighbInd[i0]; j < neighbInd[i0 + 1]; j++) {
if (pNeighb[j] == i1)
break;
if (pNeighb[j] == -1) {
pNeighb[j] = i1;
break;
}
}
for (int j = neighbInd[i0]; j < neighbInd[i0 + 1]; j++) {
if (pNeighb[j] == i2)
break;
if (pNeighb[j] == -1) {
pNeighb[j] = i2;
break;
}
}
}
private void addQuadNeighbors(int[] pNeighb, int[] neighbInd, int i0, int i1, int i2, int i3)
{
for (int j = neighbInd[i0]; j < neighbInd[i0 + 1]; j++) {
if (pNeighb[j] == i1)
break;
if (pNeighb[j] == -1) {
pNeighb[j] = i1;
break;
}
}
for (int j = neighbInd[i0]; j < neighbInd[i0 + 1]; j++) {
if (pNeighb[j] == i2)
break;
if (pNeighb[j] == -1) {
pNeighb[j] = i2;
break;
}
}
for (int j = neighbInd[i0]; j < neighbInd[i0 + 1]; j++) {
if (pNeighb[j] == i3)
break;
if (pNeighb[j] == -1) {
pNeighb[j] = i3;
break;
if (cellArray == null && cellArray.getType().getNVertices() <= 1)
return;
int n = cellArray.getType().getNVertices();
int[] nodes = cellArray.getNodes();
for (int k = 0; k < nodes.length; k += n)
for (int i = k; i < k + n; i++) {
int i0 = nodes[i];
for (int j = k; j < k + n; j++)
if (i != j) {
int i1 = nodes[j];
for (int l = neighbInd[i0]; l < neighbInd[i0 + 1]; l++) {
if (pNeighb[l] == i1)
break;
if (pNeighb[l] == -1) {
pNeighb[l] = i1;
break;
}
}
}
}
}
}
private void split(int nSet)
......@@ -134,29 +109,19 @@ public class ProcessComponents
int[] neighb;
int[] neighbInd;
int n = 0, k0;
int[] tris = null;
int[] quads = null;
int[] pNeighb = null;
CellSet cs = inField.getCellSet(nSet);
neighbInd = new int[(int) inField.getNNodes() + 1];
for (int i = 0; i < neighbInd.length; i++)
neighbInd[i] = 0;
CellArray triangleArray = cs.getBoundaryCellArray(CellType.TRIANGLE);
if (triangleArray != null && triangleArray.getNCells() > 0) {
tris = triangleArray.getNodes();
for (int i = 0; i < tris.length; i++)
neighbInd[tris[i]] += 2;
n += tris.length;
}
CellArray quadArray = cs.getBoundaryCellArray(CellType.QUAD);
if (quadArray != null && quadArray.getNCells() > 0) {
quads = quadArray.getNodes();
for (int i = 0; i < quads.length; i++)
neighbInd[quads[i]] += 3;
n += 2 * quads.length;
}
for (CellArray cellArray : cs.getCellArrays())
if (cellArray != null && cellArray.getType().getNVertices() > 1) {
int k = cellArray.getType().getNVertices() - 1;
int[] nodes = cellArray.getNodes();
for (int i = 0; i < nodes.length; i++)
neighbInd[nodes[i]] += k;
}
int k = 0;
for (int i = 0; i < neighbInd.length; i++) {
......@@ -165,24 +130,14 @@ public class ProcessComponents
k = j;
}
pNeighb = new int[k];
int[] pNeighb = new int[k];
for (int i = 0; i < pNeighb.length; i++)
pNeighb[i] = -1;
if (tris != null)
for (int i = 0; i < tris.length; i += 3) {
// fireStatusChanged(i / (2.f * n));
addTriangleNeighbors(pNeighb, neighbInd, tris[i], tris[i + 1], tris[i + 2]);
addTriangleNeighbors(pNeighb, neighbInd, tris[i + 2], tris[i], tris[i + 1]);
addTriangleNeighbors(pNeighb, neighbInd, tris[i + 1], tris[i + 2], tris[i]);
}
if (quads != null)
for (int i = 0; i < quads.length; i += 4) {
// fireStatusChanged((2 * i + tris.length / 3) / (2.f * n));
addQuadNeighbors(pNeighb, neighbInd, quads[i], quads[i + 1], quads[i + 2], quads[i + 3]);
addQuadNeighbors(pNeighb, neighbInd, quads[i + 3], quads[i], quads[i + 1], quads[i + 2]);
addQuadNeighbors(pNeighb, neighbInd, quads[i + 2], quads[i + 3], quads[i], quads[i + 1]);
addQuadNeighbors(pNeighb, neighbInd, quads[i + 1], quads[i + 2], quads[i + 3], quads[i]);
for (CellArray cellArray : cs.getCellArrays())
if (cellArray != null && cellArray.getType().getNVertices() > 1) {
addNeighbors(pNeighb, neighbInd, cellArray);
}
k = 0;
......@@ -242,7 +197,6 @@ public class ProcessComponents
for (int i = 0; i < nNodes; i++)
cellSetComponentSizes[nSet][2 * components[i]] += 1;
HeapSort.sort(cellSetComponentSizes[nSet], 2, false);
// fireStateChanged();
}
public IrregularField buildOutput(Parameters p)
......@@ -259,7 +213,6 @@ public class ProcessComponents
maxComponentIndices[i] = 0;
orderingLoop:
for (int nSeparate = 0; nSeparate < nSeparateComponents; nSeparate++) {
// fireStatusChanged(.5f + .5f * (nSeparate + 1.f) / nSeparateComponents);
progressAgent.increase();
int maxComponentIndex = -1;
int maxComponentSize = p.get(MIN_COMPONENT_SIZE);
......@@ -275,6 +228,29 @@ public class ProcessComponents
maxComponentIndices[maxComponentIndex] += 1;
CellSet inCS = inField.getCellSet(maxComponentIndex);
CellSet outCS = new CellSet("component_" + nSeparate);
if (inCS.getCellArray(CellType.SEGMENT) != null) {
inCellArray = inCS.getCellArray(CellType.SEGMENT);
inCells = inCellArray.getNodes();
inOrientations = inCellArray.getOrientations();
int nCells = 0;
for (int i = 0; i < inCells.length; i += 2)
if (cellSetComponents[maxComponentIndex][inCells[i]] == maxComponentMark)
nCells += 1;
if (nCells == 0)
continue;
int[] outCells = new int[2 * nCells];
byte[] outOrientations = new byte[nCells];
for (int i = 0, k = 0; i < inCells.length / 2; i++)
if (cellSetComponents[maxComponentIndex][inCells[2 * i]] == maxComponentMark) {
for (int j = 0; j < 2; j++)
outCells[2 * k + j] = inCells[2 * i + j];
outOrientations[k] = inOrientations[i];
k += 1;
}
CellArray outCellArray = new CellArray(CellType.SEGMENT, outCells, outOrientations, null);
outCS.setCellArray(outCellArray);
outCS.setBoundaryCellArray(outCellArray);
}
if (inCS.getBoundaryCellArray(CellType.TRIANGLE) != null) {
inCellArray = inCS.getBoundaryCellArray(CellType.TRIANGLE);
inCells = inCellArray.getNodes();
......@@ -321,7 +297,9 @@ public class ProcessComponents
outCS.setCellArray(outCellArray);
outCS.setBoundaryCellArray(outCellArray);
}
if (inCS.getBoundaryCellArray(CellType.QUAD) != null || inCS.getBoundaryCellArray(CellType.TRIANGLE) != null) {
if (inCS.getBoundaryCellArray(CellType.QUAD) != null ||
inCS.getBoundaryCellArray(CellType.TRIANGLE) != null ||
inCS.getBoundaryCellArray(CellType.SEGMENT) != null) {
outCS.generateDisplayData(outField.getCurrentCoords());
logger.debug("adding" + outCS);
outField.addCellSet(outCS);
......
<?xml version="1.0" encoding="UTF-8"?>
<module name="surface components" class="SurfaceComponents">
<module name="connected components" class="ConnectedComponents">
<inputs>
<input name="inField" type="pl.edu.icm.visnow.lib.types.VNIrregularField" modifiers="NECESSARY:TRIGGERING">
<acceptor>
<param name="CELLS_2D" value="true"/>
</acceptor>
</input>
</inputs>
......@@ -17,5 +14,5 @@
</outputs>
<parameters>
</parameters>
<description value="breaks a triangulated surface into connested components and outputs them as separate cell sets"/>
<description value="splits an irregular field into connested components and outputs them as separate cell sets"/>
</module>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment