Commit 14e03599 authored by Krzysztof Nowinski's avatar Krzysztof Nowinski

Merge ConnectedComponentsUpdate into TextGlyph_formatting

parents 1f468729 71806e24
......@@ -38,6 +38,7 @@
//</editor-fold>
package pl.edu.icm.visnow.lib.basic.mappers.ConnectedComponents;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import pl.edu.icm.jscic.CellArray;
import pl.edu.icm.jscic.CellSet;
......@@ -205,9 +206,6 @@ public class ProcessComponents
outField = inField.cloneShallow();
outField.removeComponents();
outField.getCellSets().clear();
CellArray inCellArray = null;
byte[] inOrientations = null;
int[] inCells = null;
int[] maxComponentIndices = new int[cellSetComponentSizes.length]; //maxComponentIndices[i] is the index of largest component not yet assigned to output
for (int i = 0; i < maxComponentIndices.length; i++)
maxComponentIndices[i] = 0;
......@@ -227,83 +225,39 @@ public class ProcessComponents
int maxComponentMark = cellSetComponentSizes[maxComponentIndex][2 * maxComponentIndices[maxComponentIndex] + 1];
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();
inOrientations = inCellArray.getOrientations();
int nCells = 0;
for (int i = 0; i < inCells.length; i += 3)
if (cellSetComponents[maxComponentIndex][inCells[i]] == maxComponentMark)
nCells += 1;
if (nCells == 0)
String prefix = inField.getNCellSets() > 1 ? inCS.getName() + "_" : "";
CellSet outCS = new CellSet(prefix + "cmp_" + nSeparate);
for (DataArray inComponent : inCS.getComponents())
outCS.addComponent(inComponent.cloneShallow());
for (CellArray inCellArray : inCS.getCellArrays()) {
if (inCellArray == null || inCellArray.getNCells() < 1)
continue;
int[] outCells = new int[3 * nCells];
byte[] outOrientations = new byte[nCells];
for (int i = 0, k = 0; i < inCells.length / 3; i++)
if (cellSetComponents[maxComponentIndex][inCells[3 * i]] == maxComponentMark) {
for (int j = 0; j < 3; j++)
outCells[3 * k + j] = inCells[3 * i + j];
outOrientations[k] = inOrientations[i];
k += 1;
}
CellArray outCellArray = new CellArray(CellType.TRIANGLE, outCells, outOrientations, null);
outCS.setCellArray(outCellArray);
outCS.setBoundaryCellArray(outCellArray);
}
if (inCS.getBoundaryCellArray(CellType.QUAD) != null) {
inCellArray = inCS.getBoundaryCellArray(CellType.QUAD);
inCells = inCellArray.getNodes();
inOrientations = inCellArray.getOrientations();
int inNCells = inCellArray.getNCells();
int nCellNodes = inCellArray.getNCellNodes();
int[] inNodes = inCellArray.getNodes();
int[] inIndices = inCellArray.getDataIndices();
byte[] inOrientations = inCellArray.getOrientations();
int nCells = 0;
for (int i = 0; i < inCells.length; i += 3)
if (cellSetComponents[maxComponentIndex][inCells[i]] == maxComponentMark)
for (int i = 0; i < inNodes.length; i += nCellNodes)
if (cellSetComponents[maxComponentIndex][inNodes[i]] == maxComponentMark)
nCells += 1;
if (nCells == 0)
continue;
int[] outCells = new int[4 * nCells];
int[] outNodes = new int[nCellNodes * nCells];
int[] outIndices = inIndices == null ? null : new int[nCells];
byte[] outOrientations = new byte[nCells];
for (int i = 0, k = 0; i < inCells.length / 4; i++)
if (cellSetComponents[maxComponentIndex][inCells[4 * i]] == maxComponentMark) {
for (int j = 0; j < 4; j++)
outCells[4 * k + j] = inCells[4 * i + j];
for (int i = 0, k = 0; i < inNCells; i ++)
if (cellSetComponents[maxComponentIndex][inNodes[nCellNodes * i]] == maxComponentMark) {
System.arraycopy(inNodes, nCellNodes * i, outNodes, nCellNodes * k, nCellNodes);
outOrientations[k] = inOrientations[i];
if (inIndices != null)
outIndices[k] = inIndices[i];
k += 1;
}
CellArray outCellArray = new CellArray(CellType.QUAD, outCells, outOrientations, null);
outCS.setCellArray(outCellArray);
outCS.setBoundaryCellArray(outCellArray);
}
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);
outCS.setCellArray(new CellArray(inCellArray.getType(), outNodes, outOrientations, outIndices));
}
outCS.generateDisplayData(outField.getCurrentCoords());
outField.addCellSet(outCS);
}
int[] componentNumber = new int[(int) inField.getNNodes()];
......
......@@ -95,28 +95,32 @@ public class ExtractCellSets
out.addComponent(DataArray.create(outTD, da.getVectorLength(), da.getName(), da.getUnit(), da.getUserData()));
}
for (CellSet s : in.getCellSets())
if (s.isSelected()) {
CellSet outS = new CellSet(s.getName());
for (CellArray a : s.getCellArrays())
if (a != null) {
int[] nodes = a.getNodes();
for (CellSet inCS : in.getCellSets())
if (inCS.isSelected()) {
CellSet outCS = new CellSet(inCS.getName());
for (DataArray inComponent : inCS.getComponents())
outCS.addComponent(inComponent.cloneShallow());
for (CellArray inCellArray : inCS.getCellArrays())
if (inCellArray != null) {
int[] nodes = inCellArray.getNodes();
int[] outNodes = new int[nodes.length];
for (int i = 0; i < nodes.length; i++)
outNodes[i] = vptinds[nodes[i]];
CellArray outA = new CellArray(a.getType(), outNodes, a.getOrientations(), a.getDataIndices());
outS.setCellArray(outA);
outCS.setCellArray(new CellArray(inCellArray.getType(), outNodes,
inCellArray.getOrientations(),
inCellArray.getDataIndices()));
}
for (CellArray a : s.getBoundaryCellArrays())
if (a != null) {
int[] nodes = a.getNodes();
for (CellArray inCellArray : inCS.getBoundaryCellArrays())
if (inCellArray != null) {
int[] nodes = inCellArray.getNodes();
int[] outNodes = new int[nodes.length];
for (int i = 0; i < nodes.length; i++)
outNodes[i] = vptinds[nodes[i]];
CellArray outA = new CellArray(a.getType(), outNodes, a.getOrientations(), a.getDataIndices());
outS.setBoundaryCellArray(outA);
outCS.setBoundaryCellArray(new CellArray(inCellArray.getType(), outNodes,
inCellArray.getOrientations(),
inCellArray.getDataIndices()));
}
out.addCellSet(outS);
out.addCellSet(outCS);
}
return out;
}
......
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