Skip to content
Snippets Groups Projects
Commit 9baa770b authored by Harald Scheirich's avatar Harald Scheirich
Browse files

Fix crash in GeometryTransforExample

Fix missing material in the same example
Arrange objects so they are all visible
parent 372139a8
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,7 @@ main()
imstkNew<Scene> scene("GeometryTransforms");
auto sceneObj = apiutils::createAndAddVisualSceneObject(scene, iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj", "Dragon");
CHECK(sceneObj != nullptr) << "ERROR: Unable to create scene object";
......@@ -70,17 +71,17 @@ main()
planeVisualModel->setRenderMaterial(planeMaterial);
imstkNew<VisualObject> planeObj("Plane");
//planeObj->setVisualGeometry(planeGeom);
planeObj->setVisualGeometry(planeGeom);
planeObj->addVisualModel(planeVisualModel);
scene->addSceneObject(planeObj);
// Cube
imstkNew<Cube> cubeGeom;
cubeGeom->setWidth(20.0);
cubeGeom->setWidth(10.0);
cubeGeom->scale(0.5, Geometry::TransformType::ConcatenateToTransform);
cubeGeom->rotate(Vec3d(1.0, 1.0, 0.0), PI_4, Geometry::TransformType::ApplyToData);
cubeGeom->translate(Vec3d(0.0, 0.0, 10.0));
auto materialCube = std::make_shared<RenderMaterial>();
imstkNew<RenderMaterial> cubeMaterial;
cubeMaterial->setColor(Color::Red);
cubeMaterial->setDisplayMode(RenderMaterial::DisplayMode::WireframeSurface);
......@@ -96,9 +97,10 @@ main()
// Cylinder
imstkNew<Cylinder> cylinderGeom;
cylinderGeom->setRadius(4.0);
cylinderGeom->setLength(8.0);
cylinderGeom->setLength(12.0);
cylinderGeom->scale(0.4, Geometry::TransformType::ConcatenateToTransform);
cylinderGeom->rotate(Vec3d(1.0, 1.0, 0), PI_2, Geometry::TransformType::ApplyToData);
cylinderGeom->translate(Vec3d(0.0, 0.0, -10.0));
imstkNew<RenderMaterial> cylMaterial;
cylMaterial->setColor(Color::Red);
......@@ -106,7 +108,7 @@ main()
cylMaterial->setPointSize(6.0);
cylMaterial->setLineWidth(4.0);
imstkNew<VisualModel> cylVisualModel(cylinderGeom.get());
cylVisualModel->setRenderMaterial(materialCube);
cylVisualModel->setRenderMaterial(cylMaterial);
imstkNew<VisualObject> cylObj("Cylinder");
cylObj->addVisualModel(cylVisualModel);
......@@ -136,7 +138,7 @@ main()
connect<Event>(sceneManager, EventType::PostUpdate,
[&](Event*)
{
surfaceMesh->rotate(Vec3d(1.0, 0.0, 0.0), PI * scene->getElapsedTime(), Geometry::TransformType::ApplyToData);
// surfaceMesh->rotate(Vec3d(1.0, 0.0, 0.0), PI * scene->getElapsedTime(), Geometry::TransformType::ApplyToData);
});
// Add mouse and keyboard controls to the viewer
......
......@@ -34,16 +34,15 @@ VTKCylinderRenderDelegate::VTKCylinderRenderDelegate(std::shared_ptr<VisualModel
{
auto geometry = std::static_pointer_cast<Cylinder>(visualModel->getGeometry());
cylinderSource = vtkSmartPointer<vtkCylinderSource>();
cylinderSource->SetCenter(0.0, 0.0, 0.0);
cylinderSource->SetRadius(1.0);
cylinderSource->SetHeight(geometry->getLength());
cylinderSource->SetResolution(100);
m_cylinderSource->SetCenter(0.0, 0.0, 0.0);
m_cylinderSource->SetRadius(1.0);
m_cylinderSource->SetHeight(geometry->getLength());
m_cylinderSource->SetResolution(100);
// Setup mapper
{
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(cylinderSource->GetOutputPort());
mapper->SetInputConnection(m_cylinderSource->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->SetUserTransform(m_transform);
......@@ -62,8 +61,8 @@ VTKCylinderRenderDelegate::processEvents()
auto geometry = std::static_pointer_cast<Cylinder>(m_visualModel->getGeometry());
cylinderSource->SetRadius(geometry->getRadius());
cylinderSource->SetHeight(geometry->getLength());
m_cylinderSource->SetRadius(geometry->getRadius());
m_cylinderSource->SetHeight(geometry->getLength());
AffineTransform3d T = AffineTransform3d::Identity();
T.translate(geometry->getPosition(Geometry::DataType::PostTransform));
......
......@@ -49,8 +49,7 @@ public:
/// \brief Process the event queue
///
void processEvents() override;
protected:
vtkSmartPointer<vtkCylinderSource> cylinderSource;
vtkNew<vtkCylinderSource> m_cylinderSource;
};
} // imstk
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment