Skip to content

Commit

Permalink
Merge pull request #27 from CASL/coremap_fill
Browse files Browse the repository at this point in the history
fix(InpHelper): use minmax to fill interior of coreshape with 1
  • Loading branch information
aronhelser authored May 15, 2018
2 parents d2d2a25 + 2ad47ce commit a268de8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/utils/ImageGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransfe
import ColorManager from './ColorManager';
import ImageReady from './ImageReady';
import ModelHelper from './ModelHelper';
import InpHelper from './InpHelper';

let idFor3D = 1;

Expand Down Expand Up @@ -298,27 +299,7 @@ function updateLayoutImage(
if (item.coreShape) {
// display an indication of the core shape on editor coremaps.
ctx.beginPath();
const minmax = [];
minmax[-1] = [width, -1];
for (let j = 0; j < width; j++) {
const halfJ = j < width / 2 ? j : width - j - 1;
let minI = width;
let maxI = -1;
for (let i = 0; i < width; i++) {
if (item.coreShape[j * width + i]) {
minI = Math.min(minI, i);
maxI = Math.max(maxI, i + 1);
}
}
minmax[halfJ] = minmax[halfJ]
? [Math.min(minI, minmax[halfJ][0]), Math.max(maxI, minmax[halfJ][1])]
: [minI, maxI];
}
for (let j = 1; j < width / 2; j++) {
// the previous row, away from the middle, sets a bound.
minmax[j][0] = Math.min(minmax[j - 1][0], minmax[j][0]);
minmax[j][1] = Math.max(minmax[j - 1][1], minmax[j][1]);
}
const minmax = InpHelper.getCoreShapeMinMax(item.coreShape, width);
// console.log(...minmax);
for (let j = 0; j <= width; j++) {
const halfJ = j < width / 2 ? j : width - j - 1;
Expand Down
37 changes: 37 additions & 0 deletions src/utils/InpHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,31 @@ function stripCoreZeros(textMap, coreMap, pad = '') {
return lines.join(`\n${pad}`);
}

function getCoreShapeMinMax(coreShape, width) {
const minmax = [];
minmax[-1] = [width, -1];
for (let j = 0; j < width; j++) {
const halfJ = j < width / 2 ? j : width - j - 1;
let minI = width;
let maxI = -1;
for (let i = 0; i < width; i++) {
if (+coreShape[j * width + i]) {
minI = Math.min(minI, i);
maxI = Math.max(maxI, i + 1);
}
}
minmax[halfJ] = minmax[halfJ]
? [Math.min(minI, minmax[halfJ][0]), Math.max(maxI, minmax[halfJ][1])]
: [minI, maxI];
}
for (let j = 1; j < width / 2; j++) {
// the previous row, away from the middle, sets a bound.
minmax[j][0] = Math.min(minmax[j - 1][0], minmax[j][0]);
minmax[j][1] = Math.max(minmax[j - 1][1], minmax[j][1]);
}
return minmax;
}

function getCoreShape(coremaps, inShapeMap = null) {
let coreShapeMap = inShapeMap;
// build a core_shape array.
Expand All @@ -205,6 +230,17 @@ function getCoreShape(coremaps, inShapeMap = null) {
}
});
if (coreShapeMap) {
// fill in interior locations with 1 for sparse maps.
const width = Math.sqrt(coreShapeMap.length);
const minmax = getCoreShapeMinMax(coreShapeMap, width);
for (let j = 0; j < width; j++) {
const halfJ = j < width / 2 ? j : width - j - 1;
for (let i = 0; i < width; i++) {
if (i >= minmax[halfJ][0] && i < minmax[halfJ][1]) {
coreShapeMap[j * width + i] = 1;
}
}
}
return {
type: 'coremaps',
symmetry: 'none',
Expand Down Expand Up @@ -352,6 +388,7 @@ function writeToInp(state, GROUP_TYPES) {

export default {
getCoreShape,
getCoreShapeMinMax,
getNumPins,
getTextMap,
getFullMap,
Expand Down

0 comments on commit a268de8

Please sign in to comment.