-
-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: retyping macros and OutlineFilter
- Loading branch information
Showing
11 changed files
with
2,507 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default class ClassHierarchy extends Array { | ||
push(...args: string[]): number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default class ClassHierarchy extends Array { | ||
push(...args: string[]) { | ||
// no perf issue since args.length should be small | ||
const newArgs = args.filter((arg) => !this.includes(arg)); | ||
return super.push(...newArgs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import macro, { | ||
AlgoModel, | ||
IndexableAPI, | ||
IndexableModel, | ||
} from 'vtk.js/Sources/macros'; | ||
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; | ||
import { vtkObject, vtkOutputPort } from 'vtk.js/Sources/interfaces'; | ||
import { default as PublicAPI } from '.'; | ||
|
||
const { vtkErrorMacro } = macro; | ||
|
||
// prettier-ignore | ||
export const BOUNDS_MAP = [ | ||
0, 2, 4, // pt 0 | ||
1, 2, 4, // pt 1 | ||
0, 3, 4, // pt 2 | ||
1, 3, 4, // pt 3 | ||
0, 2, 5, // pt 4 | ||
1, 2, 5, // pt 5 | ||
0, 3, 5, // pt 6 | ||
1, 3, 5, // pt 7 | ||
]; | ||
|
||
// prettier-ignore | ||
export const LINE_ARRAY = [ | ||
2, 0, 1, | ||
2, 2, 3, | ||
2, 4, 5, | ||
2, 6, 7, | ||
2, 0, 2, | ||
2, 1, 3, | ||
2, 4, 6, | ||
2, 5, 7, | ||
2, 0, 4, | ||
2, 1, 5, | ||
2, 2, 6, | ||
2, 3, 7, | ||
]; | ||
|
||
interface Model extends AlgoModel {} | ||
|
||
export type vtkOutlineFilterModel = Model; | ||
|
||
// ---------------------------------------------------------------------------- | ||
// vtkOutlineFilter methods | ||
// ---------------------------------------------------------------------------- | ||
|
||
function vtkOutlineFilter(publicAPI: PublicAPI, model: Model) { | ||
// Set our className | ||
model.classHierarchy.push('vtkOutlineFilter'); | ||
|
||
publicAPI.requestData = (inData, outData) => { | ||
// implement requestData | ||
const input = inData[0]; | ||
|
||
if (!input) { | ||
vtkErrorMacro('Invalid or missing input'); | ||
return; | ||
} | ||
|
||
const bounds = input.getBounds(); | ||
const output = vtkPolyData.newInstance(); | ||
|
||
output | ||
.getPoints() | ||
.setData(Float32Array.from(BOUNDS_MAP.map((idx) => bounds[idx])), 3); | ||
output.getLines().setData(Uint16Array.from(LINE_ARRAY)); | ||
|
||
outData[0] = output; | ||
}; | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Object factory | ||
// ---------------------------------------------------------------------------- | ||
|
||
const DEFAULT_VALUES = {}; | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
export function extend( | ||
publicAPI: IndexableAPI<PublicAPI>, | ||
model: IndexableModel<Model>, | ||
initialValues = {} | ||
) { | ||
Object.assign(model, DEFAULT_VALUES, initialValues); | ||
|
||
// Make this a VTK object | ||
macro.obj(publicAPI, model); | ||
|
||
// Also make it an algorithm with one input and one output | ||
macro.algo(publicAPI, model, 1, 1); | ||
|
||
// Object specific methods | ||
vtkOutlineFilter(publicAPI, model); | ||
} | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
export const newInstance = macro.newInstance(extend, 'vtkOutlineFilter'); | ||
|
||
// ---------------------------------------------------------------------------- | ||
|
||
export default { newInstance, extend, BOUNDS_MAP, LINE_ARRAY }; |
Oops, something went wrong.