Skip to content

Commit f9ef2ee

Browse files
dakerfinetjul
authored andcommitted
fix(PLYReader): add support for duplicatePointsForFaceTexture
fixes #2877 fixes #3047
1 parent f6a5541 commit f9ef2ee

File tree

4 files changed

+291
-49
lines changed

4 files changed

+291
-49
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<table>
2+
<tr>
3+
<td colspan="2">
4+
<h3 style="margin: 5px 0">Options</h3>
5+
</td>
6+
</tr>
7+
<tr>
8+
<td>PLY file or w/ its texture file.</td>
9+
</tr>
10+
<tr>
11+
<td>
12+
<input type="file" class="file" multiple />
13+
</td>
14+
</tr>
15+
<tr>
16+
<td>Duplicate points for face texture</td>
17+
<td>
18+
<input
19+
type="checkbox"
20+
id="duplicate_points_for_face_texture"
21+
name="duplicate_points_for_face_texture"
22+
value="true"
23+
checked
24+
/>
25+
</td>
26+
</tr>
27+
</table>

Sources/IO/Geometry/PLYReader/example/index.js

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@ import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreen
88
import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
99
import vtkPLYReader from '@kitware/vtk.js/IO/Geometry/PLYReader';
1010
import vtkTexture from '@kitware/vtk.js/Rendering/Core/Texture';
11+
import vtkURLExtract from '@kitware/vtk.js/Common/Core/URLExtract';
12+
13+
import controlPanel from './controller.html';
1114

1215
// ----------------------------------------------------------------------------
13-
// Example code
16+
// Standard rendering code setup
1417
// ----------------------------------------------------------------------------
18+
const userParams = vtkURLExtract.extractURLParameters();
19+
const url = userParams.fileURL;
20+
const duplicatePointsForFaceTexture =
21+
userParams.duplicatePointsForFaceTexture || false;
22+
23+
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
24+
const renderer = fullScreenRenderer.getRenderer();
25+
const renderWindow = fullScreenRenderer.getRenderWindow();
1526

16-
let renderer = null;
17-
let renderWindow = null;
18-
const reader = vtkPLYReader.newInstance();
27+
// ----------------------------------------------------------------------------
28+
// Example code
29+
// ----------------------------------------------------------------------------
30+
const reader = vtkPLYReader.newInstance({
31+
duplicatePointsForFaceTexture,
32+
});
1933
const mapper = vtkMapper.newInstance({ scalarVisibility: false });
2034
const actor = vtkActor.newInstance();
2135

@@ -25,19 +39,13 @@ mapper.setInputConnection(reader.getOutputPort());
2539
// ----------------------------------------------------------------------------
2640

2741
function refresh() {
28-
if (renderer && renderWindow) {
29-
const resetCamera = renderer.resetCamera;
30-
const render = renderWindow.render;
31-
resetCamera();
32-
render();
33-
}
42+
const resetCamera = renderer.resetCamera;
43+
const render = renderWindow.render;
44+
resetCamera();
45+
render();
3446
}
3547

3648
function update() {
37-
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance();
38-
renderer = fullScreenRenderer.getRenderer();
39-
renderWindow = fullScreenRenderer.getRenderWindow();
40-
4149
renderer.addActor(actor);
4250

4351
actor.getMapper().setScalarVisibility(true);
@@ -51,13 +59,11 @@ function update() {
5159
// Use a file reader to load a local file
5260
// ----------------------------------------------------------------------------
5361

54-
const myContainer = document.querySelector('body');
55-
const fileContainer = document.createElement('div');
56-
fileContainer.innerHTML =
57-
'<div>Select a ply file or a ply file with its texture file.<br/><input type="file" class="file" multiple/></div>';
58-
myContainer.appendChild(fileContainer);
62+
fullScreenRenderer.addController(controlPanel);
5963

60-
const fileInput = fileContainer.querySelector('input');
64+
const fileInput = document.querySelector('input');
65+
const checkbox = document.querySelector('#duplicate_points_for_face_texture');
66+
checkbox.checked = duplicatePointsForFaceTexture;
6167

6268
function handlePlyFile(file) {
6369
const fileReader = new FileReader();
@@ -88,10 +94,8 @@ function handleFile(event) {
8894
const dataTransfer = event.dataTransfer;
8995
const files = event.target.files || dataTransfer.files;
9096
if (files.length === 1) {
91-
myContainer.removeChild(fileContainer);
9297
handlePlyFile(files[0]);
9398
} else if (files.length > 1) {
94-
myContainer.removeChild(fileContainer);
9599
Array.from(files).forEach((file) => {
96100
const name = file.name.toLowerCase();
97101
if (name.endsWith('.ply')) {
@@ -110,8 +114,17 @@ function handleFile(event) {
110114

111115
fileInput.addEventListener('change', handleFile);
112116

117+
checkbox.addEventListener('change', (e) => {
118+
const value = e.target.checked;
119+
console.log('duplicate points for face texture', value);
120+
window.location = `?duplicatePointsForFaceTexture=${value}`;
121+
refresh();
122+
});
123+
113124
// ----------------------------------------------------------------------------
114125
// Use the reader to download a file
115126
// ----------------------------------------------------------------------------
116127

117-
// reader.setUrl(`${__BASE_PATH__}/data/ply/mesh.ply`, { binary: true }).then(update);
128+
if (url) {
129+
reader.setUrl(url).then(update);
130+
}

Sources/IO/Geometry/PLYReader/index.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ interface IPLYReaderOptions {
1313
/**
1414
*
1515
*/
16-
export interface IPLYReaderInitialValues {}
16+
export interface IPLYReaderInitialValues {
17+
/**
18+
* Controls whether points are duplicated for face-texture mapping.
19+
*/
20+
duplicatePointsForFaceTexture?: boolean;
21+
22+
/**
23+
* The tolerance used to determine if two points are the same.
24+
*/
25+
faceTextureTolerance?: number;
26+
}
1727

1828
type vtkPLYReaderBase = vtkObject &
1929
Omit<
@@ -41,6 +51,16 @@ export interface vtkPLYReader extends vtkPLYReaderBase {
4151
| JSZipDataAccessHelper
4252
| LiteHttpDataAccessHelper;
4353

54+
/**
55+
* Controls whether points are duplicated for face-texture mapping.
56+
*/
57+
getDuplicatePointsForFaceTexture(): boolean;
58+
59+
/**
60+
* Get the tolerance used to determine if two points are the same.
61+
*/
62+
getFaceTextureTolerance(): number;
63+
4464
/**
4565
* Get the url of the object to load.
4666
*/

0 commit comments

Comments
 (0)