I am trying to add a second .vtp model to my render window, this model is supposed to be a second layer inside my main model. I have been using the same logic to add the new model but despite being able to retrieve the number of actors currently added (which equals to 2, I think that makes sense), the model is not showing. I even ““tried”” to force the new model to be added in the same position as the main model. Any ideas?
I already did something similar with an .STL file and it worked fine without much hassle.
Here’s the current code of my function (it’s supposed to be enabled by clicking on a button):
const loadVTPModel = (filePath) => {
console.log(Attempting to load VTP file from: ${filePath}
);
const reader = vtkXMLPolyDataReader.newInstance();
reader.setUrl(`${filePath}`).then(() => {
console.log('VTP file URL set successfully');
reader.loadData().then(() => {
const polydata = reader.getOutputData(0);
if (!polydata) {
console.error('No se pudieron cargar los datos del archivo VTP.');
return;
}
console.log('VTP data loaded successfully');
console.log('Polydata:', polydata);
const points = polydata.getPoints().getData();
console.log('Number of points in polydata:', points.length / 3); //
const mapper = vtkMapper.newInstance();
polydata.getPointData().setActiveScalars('FFR_Corrected');
mapper.setInputData(polydata);
const lookupTable = vtkColorTransferFunction.newInstance();
lookupTable.addRGBPoint(0.0, 0.0, 1.0, 0.0); // Green for new model
mapper.setLookupTable(lookupTable);
const actor = vtkActor.newInstance();
actor.setMapper(mapper);
actor.getProperty().setColor(0.0, 1.0, 0.0); // Green color
actor.getProperty().setOpacity(1.0); // Full opacity
const renderer = global.fullScreenRenderer.getRenderer();
renderer.addActor(actor);
console.log('Actor added to renderer');
const mainActor = renderer.getActors()[0];
if (mainActor) {
const mainActorPosition = mainActor.getPosition();
const mainActorOrientation = mainActor.getOrientation();
const mainActorBounds = mainActor.getBounds();
console.log('Main actor position:', mainActorPosition);
console.log('Main actor orientation:', mainActorOrientation);
console.log('Main actor bounds:', mainActorBounds);
actor.setPosition(mainActorPosition);
actor.setOrientation(mainActorOrientation);
} else {
console.warn('Main actor not found');
}
const bounds = actor.getBounds();
console.log('New actor bounds:', bounds);
renderer.resetCamera(bounds);
global.fullScreenRenderer.getRenderWindow().render();
console.log('Render window updated');
const actors = renderer.getActors();
console.log('Current actors in the renderer:', actors.length);
}).catch((error) => {
console.error('Error:', error);
});
}).catch((error) => {
console.error('Error:', error);
});
};