[vtk-developers] undo / redo for vtkContourWidget + expose SelectedNodesCursorShape

Will Schroeder will.schroeder at kitware.com
Wed Nov 25 13:46:51 EST 2009


IMHO Undo/redo is an application level feature. I do not think it
belongs in individual classes.

If you want to raise a discussion about general approaches for
undo/redo that is a different matter.

Will

On Wed, Nov 25, 2009 at 1:33 PM, Dean Inglis <dean.inglis at sympatico.ca> wrote:
> Hi all,
>
> I would like to add undo redo capability for vtkContourWidget.  The
> implementation would be to have vtkContourRepresentation's internals
> modified as follows:
> 1) add Copy methods to the vtkContourRepresentationNode:
>
>  void Copy( vtkContourRepresentationNode* node )
>  {
>    vtkstd::vector< vtkContourRepresentationPoint* > points = node->Points;
>    vtkstd::vector< vtkContourRepresentationPoint* >::iterator it1, it2;
>
>    memcpy( this->WorldPosition, node->WorldPosition, 3 * sizeof( double )
> );
>    memcpy( this->WorldOrientation, node->WorldOrientation, 9 * sizeof(
> double ) );
>    memcpy( this->NormalizedDisplayPosition,
> node->NormalizedDisplayPosition, 2 * sizeof( double ) );
>    this->Selected = node->Seleced;
>
>    this->Points.resize( points.size() );
>    for( it1 = points.begin(), it2 = this->Points.begin();
>         it1 != points.end() && it2 != this->Points.end();
>         it1++, it2++ )
>    {
>      ( *it2 ) = new vtkContourRepresentationPoint;
>      memcpy( ( *it2 )->WorldPosition, ( *it1 )->WorldPosition,
>        3 * sizeof( double ) );
>      memcpy( ( *it2 )->NormalizedDisplayPosition, ( *it1
> )->NormalizedDisplayPosition,
>        2 * sizeof( double ) );
>    }
>  }
>
> and the vtkContourRepresentationInternals:
>
>  void Copy( vtkContourRepresentationInternals* internal )
>  {
>    vtkstd::vector< vtkContourRepresentationNode* > nodes = internal->Nodes;
>    vtkstd::vector< vtkContourRepresentationNode* >::iterator it1, it2;
>
>    this->Nodes.resize( nodes.size() );
>    for( it1 = nodes.begin(), it2 = this->Nodes.begin();
>         it1 != nodes.end() && it2 != this->Nodes.end();
>         it1++, it2++ )
>    {
>      ( *it2 ) = new vtkContourRepresentationNode;
>      ( *it2 )->Copy( *it1 );
>    }
>  }
>
> and implement the following:
>
>  // Description:
>  // Records the current layout of nodes adding them to the node history
> list
>  // so that they can be undone/redone.
>  virtual void TakeSnapshot();
>
>  // Description:
>  // A history of changes to the layout of nodes is kept internally and
>  // externally by calling TakeSnapshot().
>  // These two methods are used to go back to earlier changes to the contour
>  // or return to more recent ones.
>  virtual void Undo();
>  virtual void Redo();
>
>  // Description:
>  // Methods to determine whether there is any history left to undo or redo.
>  virtual int CanUndo();
>  virtual int CanRedo();
>
> by maintaining protected members:
>
> //BTX
>  vtkstd::vector< vtkContourRepresentationInternals* >
> InternalHistory;
>  vtkstd::vector< vtkContourRepresentationInternals* >::iterator
> InternalHistoryIterator;
> //ETX
>
> Also, can the SelectedNodesCursorShape be exposed through the public API
> of vtkOrientedGlyphContourRepresentation as is done for SetCursorShape and
> SetActiveCursorShape ?
>
> Dean
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>



-- 
William J. Schroeder, PhD
Kitware, Inc.
28 Corporate Drive
Clifton Park, NY 12065
will.schroeder at kitware.com
http://www.kitware.com
(518) 881-4902



More information about the vtk-developers mailing list