Skip to content

Commit

Permalink
feat(AxesActor): add option to flip axes individually
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigobasilio2022 authored and finetjul committed Mar 21, 2024
1 parent 75a3019 commit 18cf0e4
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 91 deletions.
26 changes: 26 additions & 0 deletions Examples/Geometry/AxesActor/controlPanel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<table>
<tr>
<td>Center axis</td>
<td>
<input class="recenter" type="checkbox" checked />
</td>
</tr>
<tr>
<td>X axis inversion</td>
<td>
<input class="xAxisInvert" type="checkbox" />
</td>
</tr>
<tr>
<td>Y axis inversion</td>
<td>
<input class="yAxisInvert" type="checkbox" />
</td>
</tr>
<tr>
<td>Z axis inversion</td>
<td>
<input class="zAxisInvert" type="checkbox" />
</td>
</tr>
</table>
80 changes: 80 additions & 0 deletions Examples/Geometry/AxesActor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import '@kitware/vtk.js/favicon';

// Load the rendering pieces we want to use (for both WebGL and WebGPU)
import '@kitware/vtk.js/Rendering/Profiles/Geometry';

import macro from '@kitware/vtk.js/macros';
import vtkAxesActor from '@kitware/vtk.js/Rendering/Core/AxesActor';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';

import controlPanel from './controlPanel.html';

console.warn(
'Click on index.ts to open source code for this example --------->'
);

// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------

const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({
background: [0.2, 0.3, 0.4],
});
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();

const axesActor = vtkAxesActor.newInstance();
renderer.addActor(axesActor);

renderer.resetCamera();
renderWindow.render();

// ----------------------------------------------------------------------------
// UI control handling
// ----------------------------------------------------------------------------

fullScreenRenderer.addController(controlPanel);

function updateRendering() {
axesActor.update();
renderer.resetCameraClippingRange();
renderWindow.render();
}

document.querySelector('.recenter').addEventListener('change', (e) => {
const config = axesActor.getConfig();
config.recenter = !!e.target.checked;
axesActor.setConfig(config);
updateRendering();
});

document.querySelector('.xAxisInvert').addEventListener('change', (e) => {
const config = axesActor.getXConfig();
config.invert = !!e.target.checked;
axesActor.setXConfig(config);
updateRendering();
});

document.querySelector('.yAxisInvert').addEventListener('change', (e) => {
const config = axesActor.getYConfig();
config.invert = !!e.target.checked;
axesActor.setYConfig(config);
updateRendering();
});

document.querySelector('.zAxisInvert').addEventListener('change', (e) => {
const config = axesActor.getZConfig();
config.invert = !!e.target.checked;
axesActor.setZConfig(config);
updateRendering();
});

// -----------------------------------------------------------
// Make some variables global so that you can inspect and
// modify objects in your browser's developer console:
// -----------------------------------------------------------

global.setLoggerFunction = macro.setLoggerFunction;
global.axesActor = axesActor;
global.renderer = renderer;
global.renderWindow = renderWindow;
48 changes: 24 additions & 24 deletions Sources/Rendering/Core/AxesActor/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ export interface vtkAxesActor extends vtkActor {
/**
*
*/
getXAxisColor(): number[];
getXConfig(): object;

/**
*
*/
getXAxisColorByReference(): number[];
getYConfig(): object;

/**
*
*/
getYAxisColor(): number[];
getZConfig(): object;

/**
*
*/
getYAxisColorByReference(): number[];
getXAxisColor(): number[];

/**
*
*/
getZAxisColor(): number[];
getYAxisColor(): number[];

/**
*
*/
getZAxisColorByReference(): number[];
getZAxisColor(): number[];

/**
*
Expand All @@ -49,32 +49,38 @@ export interface vtkAxesActor extends vtkActor {
setConfig(config: object): boolean;

/**
* Set X axis color.
* @param {Number} r Defines the red component (between 0 and 1).
* @param {Number} g Defines the green component (between 0 and 1).
* @param {Number} b Defines the blue component (between 0 and 1).
*
* @param config
*/
setXAxisColor(r: number, g: number, b: number): boolean;
setXConfig(config: object): boolean;

/**
* Set X axis color.
* @param XAxisColor
*
* @param config
*/
setXAxisColorFrom(XAxisColor: number[]): boolean;
setYConfig(config: object): boolean;

/**
* Set Y axis color.
*
* @param config
*/
setZConfig(config: object): boolean;

/**
* Set X axis color.
* @param {Number} r Defines the red component (between 0 and 1).
* @param {Number} g Defines the green component (between 0 and 1).
* @param {Number} b Defines the blue component (between 0 and 1).
*/
setYAxisColor(r: number, g: number, b: number): boolean;
setXAxisColor(r: number, g: number, b: number): boolean;

/**
* Set Y axis color.
* @param YAxisColor
* @param {Number} r Defines the red component (between 0 and 1).
* @param {Number} g Defines the green component (between 0 and 1).
* @param {Number} b Defines the blue component (between 0 and 1).
*/
setYAxisColorFrom(YAxisColor: number[]): boolean;
setYAxisColor(r: number, g: number, b: number): boolean;

/**
* Set Z axis color.
Expand All @@ -84,12 +90,6 @@ export interface vtkAxesActor extends vtkActor {
*/
setZAxisColor(r: number, g: number, b: number): boolean;

/**
* Set E axis color.
* @param ZAxisColor
*/
setZAxisColorFrom(ZAxisColor: number[]): boolean;

/**
*
*/
Expand Down
Loading

0 comments on commit 18cf0e4

Please sign in to comment.