[vtk-developers] undo / redo for vtkContourWidget + expose SelectedNodesCursorShape
Dean Inglis
dean.inglis at sympatico.ca
Wed Nov 25 13:33:44 EST 2009
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
More information about the vtk-developers
mailing list