Skip to content
Snippets Groups Projects
Commit ced88cca authored by Andrew Wilson's avatar Andrew Wilson :elephant:
Browse files

BUG: Plane fix, width should not use base transform scaling

parent 5e7eddbc
No related branches found
No related tags found
No related merge requests found
......@@ -58,18 +58,18 @@ Plane::setNormal(const double x, const double y, const double z)
double
Plane::getWidth()
{
const Vec3d s = Vec3d(
m_transform.block<3, 1>(0, 0).squaredNorm(),
m_transform.block<3, 1>(0, 1).squaredNorm(),
m_transform.block<3, 1>(0, 2).squaredNorm());
double t = s.cwiseAbs().maxCoeff();
return std::sqrt(t);
return m_width;
}
void
Plane::setWidth(const double w)
{
setScaling(Vec3d(w, w, w));
if (m_width == w || m_width <= 0.0)
{
return;
}
m_width = w;
this->postModified();
}
void
......
......@@ -38,7 +38,7 @@ public:
///
Plane(const Vec3d& pos = Vec3d(0.0, 0.0, 0.0), const Vec3d& normal = Vec3d(0.0, 1.0, 0.0),
const std::string& name = std::string("defaultPlane")) :
AnalyticalGeometry(name)
AnalyticalGeometry(name), m_width(1.0)
{
setPosition(pos);
setNormal(normal.normalized());
......@@ -98,5 +98,6 @@ protected:
protected:
Vec3d m_normal;
mutable Vec3d m_normalPostTransform;
double m_width;
};
} // imstk
......@@ -33,15 +33,6 @@ namespace imstk
VTKPlaneRenderDelegate::VTKPlaneRenderDelegate(std::shared_ptr<VisualModel> visualModel) : VTKPolyDataRenderDelegate(visualModel),
m_planeSource(vtkSmartPointer<vtkPlaneSource>::New())
{
auto geometry = std::dynamic_pointer_cast<Plane>(m_visualModel->getGeometry());
m_planeSource = vtkSmartPointer<vtkPlaneSource>::New();
m_planeSource->SetCenter(0.0, 0.0, 0.0);
m_planeSource->SetNormal(geometry->getNormal(Geometry::DataType::PreTransform).data());
const Mat4d& transform = geometry->getTransform().transpose();
m_transform->SetMatrix(transform.data());
// Setup mapper
{
vtkNew<vtkPolyDataMapper> mapper;
......@@ -55,6 +46,9 @@ VTKPlaneRenderDelegate::VTKPlaneRenderDelegate(std::shared_ptr<VisualModel> visu
update();
updateRenderProperties();
// Call to update to initialize
processEvents();
}
void
......@@ -65,13 +59,14 @@ VTKPlaneRenderDelegate::processEvents()
// Events aren't used for primitives, always update
auto geometry = std::dynamic_pointer_cast<Plane>(m_visualModel->getGeometry());
m_planeSource->SetCenter(0.0, 0.0, 0.0);
m_planeSource->SetNormal(geometry->getNormal(Geometry::DataType::PreTransform).data());
m_planeSource->Modified();
AffineTransform3d T = AffineTransform3d::Identity();
T.translate(geometry->getPosition(Geometry::DataType::PostTransform));
T.rotate(geometry->getOrientation(Geometry::DataType::PostTransform));
T.scale(geometry->getScaling().maxCoeff());
T.scale(geometry->getWidth());
T.matrix().transposeInPlace();
m_transform->SetMatrix(T.data());
}
......
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