[vtkusers] Again: How to scale widget representations based on scale interactions with a different widget?

kent williams nkwmailinglists at gmail.com
Wed Jun 17 15:37:50 EDT 2009


Once I realized how to solve this by subclassing this is what I came
up with.  It would be easy to fold back into
vtkPolygonalHandleRepresentation3D, or conceivably get pushed up into
the superclass.

After I'd implemented THIS I had to deal with also propogating the
scaling to a vtkActor showing a sphere as well.
What I then realized, is that if the vtkHandleWidget instances and the
vtkActor all use the same instance of the Sphere source, I could just
scale the one instance of vtkSphereSource, and all widgets would scale
together.

-------------------------------------------------------------------------------------------------------------------------------------------------------
#include <vtkPolygonalHandleRepresentation3D.h>

class BTPolygonalHandleRepresentation3D : public
vtkPolygonalHandleRepresentation3D
{
public:
  static BTPolygonalHandleRepresentation3D *New();

  vtkTypeRevisionMacro(BTPolygonalHandleRepresentation3D,vtkPolygonalHandleRepresentation3D);
  virtual void WidgetInteraction(double eventPos[2]);
  double GetScale() { return this->m_Scale; }
  void SetScale(double newScale);
protected:
  BTPolygonalHandleRepresentation3D() : m_Scale(1.0)
  {
  }
private:
  BTPolygonalHandleRepresentation3D(const
BTPolygonalHandleRepresentation3D&);  //Not implemented
  void operator=(const BTPolygonalHandleRepresentation3D&);  //Not implemented
  double m_Scale;
};

vtkCxxRevisionMacro(BTPolygonalHandleRepresentation3D, "$Revision: 1.10 $");
vtkStandardNewMacro(BTPolygonalHandleRepresentation3D);

void
BTPolygonalHandleRepresentation3D::
WidgetInteraction(double eventPos[2])
{
  this->Superclass::WidgetInteraction(eventPos);
  if(this->InteractionState == vtkHandleRepresentation::Scaling)
    {
    this->m_Scale = this->HandleTransformMatrix->GetElement(0,0);
    this->InvokeEvent(vtkWidgetEvent::Scale,0);
    }
}

void
BTPolygonalHandleRepresentation3D::
SetScale(double newScale)
{
  this->HandleTransformMatrix->SetElement(0, 0, newScale);
  this->HandleTransformMatrix->SetElement(1, 1, newScale);
  this->HandleTransformMatrix->SetElement(2, 2, newScale);
}



More information about the vtkusers mailing list