Commit 290d8c4e authored by Karthik Krishnan's avatar Karthik Krishnan
Browse files

ENH: Methods to initialize a contour widget from user defined geometry. Also...

ENH: Methods to initialize a contour widget from user defined geometry. Also set the interaction state appropriately.
parent 92df3501
......@@ -816,8 +816,7 @@ int TerrainPolylineEditor(int argc, char * argv[])
vtkPolyDataReader *terrainPathReader = vtkPolyDataReader::New();
terrainPathReader->SetFileName(argv[i+1]);
terrainPathReader->Update();
rep->BuildRepresentationFromUserSuppliedPolydata(
terrainPathReader->GetOutput() );
contourWidget->Initialize( terrainPathReader->GetOutput(), 0 );
terrainPathReader->Delete();
}
}
......
......@@ -32,7 +32,7 @@
#include <vtkstd/algorithm>
#include <vtkstd/iterator>
vtkCxxRevisionMacro(vtkContourRepresentation, "1.19");
vtkCxxRevisionMacro(vtkContourRepresentation, "1.20");
vtkCxxSetObjectMacro(vtkContourRepresentation, PointPlacer, vtkPointPlacer);
vtkCxxSetObjectMacro(vtkContourRepresentation, LineInterpolator, vtkContourLineInterpolator);
......@@ -1049,6 +1049,58 @@ void vtkContourRepresentation
displayPos[1] = pos[1];
}
//----------------------------------------------------------------------
void vtkContourRepresentation::Initialize( vtkPolyData * pd )
{
vtkPoints *points = pd->GetPoints();
vtkIdType nPoints = points->GetNumberOfPoints();
if (nPoints <= 0)
{
return; // Yeah right.. build from nothing !
}
// Clear all existing nodes.
for(unsigned int i=0;i<this->Internal->Nodes.size();i++)
{
for (unsigned int j=0;j<this->Internal->Nodes[i]->Points.size();j++)
{
delete this->Internal->Nodes[i]->Points[j];
}
this->Internal->Nodes[i]->Points.clear();
delete this->Internal->Nodes[i];
}
this->Internal->Nodes.clear();
vtkIdList *pointIds = pd->GetCell(0)->GetPointIds();
// Get the worldOrient from the point placer
double ref[3], displayPos[2], worldPos[3], worldOrient[9];
ref[0] = 0.0; ref[1] = 0.0; ref[2] = 0.0;
displayPos[0] = 0.0; displayPos[1] = 0.0;
this->PointPlacer->ComputeWorldPosition(this->Renderer,
displayPos, ref, worldPos, worldOrient );
// Add nodes
for ( vtkIdType i=0; i < nPoints; i++ )
{
double *p = points->GetPoint( i );
this->AddNodeAtWorldPosition( p, worldOrient );
}
if ( pointIds->GetNumberOfIds() > nPoints )
{
this->ClosedLoopOn();
}
// Update the contour representation from the nodes using the line interpolator
this->BuildRepresentation();
// Show the contour.
this->VisibilityOn();
}
//----------------------------------------------------------------------
void vtkContourRepresentation::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -87,6 +87,9 @@ public:
class VTK_WIDGETS_EXPORT vtkContourRepresentation : public vtkWidgetRepresentation
{
//BTX
friend class vtkContourWidget;
//ETX
public:
// Description:
// Standard VTK methods.
......@@ -320,17 +323,13 @@ public:
// Description:
// Get the points in this contour as a vtkPolyData.
//BTX
//BTX
virtual vtkPolyData * GetContourRepresentationAsPolyData() = 0;
//ETX
//ETX
protected:
vtkContourRepresentation();
~vtkContourRepresentation();
//BTX
friend class vtkContourWidget;
//ETX
// Selection tolerance for the handles
int PixelTolerance;
......@@ -384,7 +383,16 @@ protected:
mid[1] = (p1[1] + p2[1])/2;
mid[2] = (p1[2] + p2[2])/2;
}
// Description:
// Build a contour representation from externally supplied PolyData. This
// is very useful when you use an external program to compute a set of
// contour nodes, let's say based on image features. Subsequently, you want
// to build and display a contour that runs through those points.
// This method is protected and accessible only from
// vtkContourWidget::Initialize( vtkPolyData * )
virtual void Initialize( vtkPolyData * );
private:
vtkContourRepresentation(const vtkContourRepresentation&); //Not implemented
void operator=(const vtkContourRepresentation&); //Not implemented
......
......@@ -25,8 +25,9 @@
#include "vtkProperty2D.h"
#include "vtkEvent.h"
#include "vtkWidgetEvent.h"
#include "vtkPolyData.h"
vtkCxxRevisionMacro(vtkContourWidget, "1.17");
vtkCxxRevisionMacro(vtkContourWidget, "1.18");
vtkStandardNewMacro(vtkContourWidget);
//----------------------------------------------------------------------
......@@ -353,6 +354,20 @@ void vtkContourWidget::EndSelectAction(vtkAbstractWidget *w)
}
}
//----------------------------------------------------------------------
void vtkContourWidget::Initialize( vtkPolyData * pd, int state )
{
if (this->WidgetRep)
{
vtkContourRepresentation *rep =
reinterpret_cast<vtkContourRepresentation*>(this->WidgetRep);
rep->Initialize( pd );
this->WidgetState = (rep->GetClosedLoop() || state == 1 ) ?
vtkContourWidget::Manipulate : vtkContourWidget::Define;
}
}
//----------------------------------------------------------------------
void vtkContourWidget::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -109,6 +109,7 @@
#include "vtkAbstractWidget.h"
class vtkContourRepresentation;
class vtkPolyData;
class VTK_WIDGETS_EXPORT vtkContourWidget : public vtkAbstractWidget
{
......@@ -139,6 +140,15 @@ public:
// Create the default widget representation if one is not set.
void CreateDefaultRepresentation();
// Description:
// Initialize the contour widget from a user supplied set of points. The
// state of the widget decides if you are still defining the widget, or
// if you've finished defining (added the last point) are manipulating
// it. Note that if the polydata supplied is closed, the state will be
// set to manipulate.
// State: Define = 0, Manipulate = 1.
virtual void Initialize( vtkPolyData *, int state = 1 );
protected:
vtkContourWidget();
~vtkContourWidget();
......
......@@ -40,7 +40,7 @@
#include "vtkFocalPlanePointPlacer.h"
#include "vtkBezierContourLineInterpolator.h"
vtkCxxRevisionMacro(vtkOrientedGlyphContourRepresentation, "1.10");
vtkCxxRevisionMacro(vtkOrientedGlyphContourRepresentation, "1.11");
vtkStandardNewMacro(vtkOrientedGlyphContourRepresentation);
//----------------------------------------------------------------------
......@@ -607,58 +607,16 @@ void vtkOrientedGlyphContourRepresentation::BuildRepresentation()
}
#ifndef VTK_LEGACY_REMOVE
//----------------------------------------------------------------------
void vtkOrientedGlyphContourRepresentation
::BuildRepresentationFromUserSuppliedPolydata( vtkPolyData * pd )
{
vtkPoints *points = pd->GetPoints();
vtkIdType nPoints = points->GetNumberOfPoints();
if (nPoints <= 0)
{
return; // Yeah right.. build from nothing !
}
// Clear all existing nodes.
for(unsigned int i=0;i<this->Internal->Nodes.size();i++)
{
for (unsigned int j=0;j<this->Internal->Nodes[i]->Points.size();j++)
{
delete this->Internal->Nodes[i]->Points[j];
}
this->Internal->Nodes[i]->Points.clear();
delete this->Internal->Nodes[i];
}
this->Internal->Nodes.clear();
vtkIdList *pointIds = pd->GetCell(0)->GetPointIds();
// Get the worldOrient from the point placer
double ref[3], displayPos[2], worldPos[3], worldOrient[9];
ref[0] = 0.0; ref[1] = 0.0; ref[2] = 0.0;
displayPos[0] = 0.0; displayPos[1] = 0.0;
this->PointPlacer->ComputeWorldPosition(this->Renderer,
displayPos, ref, worldPos, worldOrient );
// Add nodes
for ( vtkIdType i=0; i < nPoints; i++ )
{
double *p = points->GetPoint( i );
this->AddNodeAtWorldPosition( p, worldOrient );
}
if ( pointIds->GetNumberOfIds() > nPoints )
{
this->ClosedLoopOn();
}
// Update the contour representation from the nodes using the line interpolator
this->BuildRepresentation();
// Show the contour.
this->VisibilityOn();
vtkWarningMacro( <<
"Deprecated. Please use vtkContourWidget::Initialize(vtkPolyData*) instead");
this->Initialize(pd);
}
#endif
//----------------------------------------------------------------------
void vtkOrientedGlyphContourRepresentation::GetActors(vtkPropCollection *pc)
......
......@@ -81,12 +81,12 @@ public:
virtual void WidgetInteraction(double eventPos[2]);
virtual int ComputeInteractionState(int X, int Y, int modified=0);
#ifndef VTK_LEGACY_REMOVE
// Description:
// Build a contour representation from externally supplied PolyData. This
// is very useful when you use an external program to compute a set of
// contour nodes, let's say based on image features. Subsequently, you want
// to build and display a contour that runs through those points.
// Build a contour representation from externally supplied PolyData.
// Deprecated : Use vtkContourWidget::Initialize( vtkPolyData * ).
virtual void BuildRepresentationFromUserSuppliedPolydata( vtkPolyData * );
#endif
// Description:
// Methods to make this class behave as a vtkProp.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment