Commit b1327491 authored by Casey Goodlett's avatar Casey Goodlett Committed by Code Review

Merge topic 'poly_line_source' into master

eab3e389 Tests for vtkPolyLine{Widget,Source,Representation}
e52e1b40 Added base class for representations of curves
9ac195f1 Added vtkPolyLineRepresentation and vtkPolyLineWidget
e0f018c1 Added vtkPolyLineSource
parents d58e1b0c eab3e389
......@@ -19,6 +19,7 @@ set(Module_SRCS
vtkPlaneSource.cxx
vtkPlatonicSolidSource.cxx
vtkPointSource.cxx
vtkPolyLineSource.cxx
vtkProgrammableDataObjectSource.cxx
vtkProgrammableSource.cxx
vtkRectangularButtonSource.cxx
......
......@@ -15,6 +15,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestPlaneSource.cxx,NO_VALID
TestPlatonicSolidSource.cxx,NO_VALID
TestPointSource.cxx,NO_VALID
TestPolyLineSource.cxx,NO_VALID
TestRectangularButtonSource.cxx,NO_VALID
TestRegularPolygonSource.cxx,NO_VALID
TestSphereSource.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestPolyLineSource.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include <cstdio>
#include <vtkPolyLineSource.h>
#include <vtkSmartPointer.h>
int TestPolyLineSource(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
{
vtkSmartPointer<vtkPolyLineSource> source = vtkSmartPointer<vtkPolyLineSource>::New();
// Basic tests
int expectedNumberOfPoints = 4;
source->SetNumberOfPoints( 4 );
int actualNumberOfPoints = source->GetNumberOfPoints();
if (expectedNumberOfPoints != actualNumberOfPoints)
{
std::cerr << "Expected NumberOfPoints setting to be " << expectedNumberOfPoints << ", got "
<< actualNumberOfPoints << std::endl;
return EXIT_FAILURE;
}
int expectedClosed = 1;
source->SetClosed( expectedClosed );
int actualClosed = source->GetClosed();
if (expectedClosed != actualClosed)
{
std::cerr << "Expected Closed setting to be " << expectedClosed << ", got "
<< actualClosed << std::endl;
return EXIT_FAILURE;
}
// Test setting individual points
double pts[4][3] = {
{ 1.0, 2.0, 3.0 },
{ 4.0, 5.0, 6.0 },
{ 7.0, 8.0, 9.0 },
{ 10.0, 11.0, 12.0 }
};
for ( int i = 0; i < 4; ++i )
{
source->SetPoint( i, pts[i][0], pts[i][1], pts[i][2] );
}
// Test getting the points
vtkPoints* testPoints = source->GetPoints();
if ( testPoints->GetNumberOfPoints() != 4 )
{
std::cerr << "Expected 4 points in vtkPoints returned from GetPoints() method, but got "
<< testPoints->GetNumberOfPoints() << " instead." << std::endl;
return EXIT_FAILURE;
}
// Test the point values
vtkPoints* outputPoints = source->GetPoints();
for ( int i = 0; i < 4; ++i )
{
double pt[3];
outputPoints->GetPoint(i, pt);
if ( pt[0] != pts[i][0] || pt[1] != pts[i][1] || pt[2] != pts[i][2] )
{
std::cerr << "Point disagreement in point " << i << std::endl;
std::cerr << "Expected point: " << pts[i][0] << ", " << pts[i][1] << ", " << pts[i][2] << std::endl;
std::cerr << "Actual point: " << pt[0] << ", " << pt[1] << ", " << pt[2] << std::endl;
return EXIT_FAILURE;
}
}
// Test setting the points from a vtkPoints object
double newPts[3][3] = {
{ 13.0, 14.0, 15.0 },
{ 16.0, 17.0, 18.0 },
{ 19.0, 20.0, 21.0 }
};
vtkSmartPointer<vtkPoints> newPoints = vtkSmartPointer<vtkPoints>::New();
newPoints->SetNumberOfPoints( 3 );
for ( int i = 0; i < 3; ++i )
{
newPoints->SetPoint( i, newPts[i] );
}
source->SetPoints( newPoints );
actualNumberOfPoints = source->GetNumberOfPoints();
if ( source->GetNumberOfPoints() != 3)
{
std::cerr << "Expected 3 points, got " << source->GetNumberOfPoints() << std::endl;
return EXIT_FAILURE;
}
outputPoints = source->GetPoints();
for ( int i = 0; i < 3; ++i )
{
double pt[3];
outputPoints->GetPoint(i, pt);
if ( pt[0] != newPts[i][0] || pt[1] != newPts[i][1] || pt[2] != newPts[i][2] )
{
std::cerr << "Point disagreement in point " << i << std::endl;
std::cerr << "Expected point: " << newPts[i][0] << ", " << newPts[i][1] << ", " << newPts[i][2] << std::endl;
std::cerr << "Actual point: " << pt[0] << ", " << pt[1] << ", " << pt[2] << std::endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPolyLineSource.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPolyLineSource.h"
#include "vtkCellArray.h"
#include "vtkIdList.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPolyLineSource);
//----------------------------------------------------------------------------
vtkPolyLineSource::vtkPolyLineSource()
{
this->Points = NULL;
this->Closed = 0;
this->SetNumberOfInputPorts(0);
}
//----------------------------------------------------------------------------
vtkPolyLineSource::~vtkPolyLineSource()
{
this->Points->Delete();
}
//----------------------------------------------------------------------------
void vtkPolyLineSource::SetNumberOfPoints(vtkIdType numPoints)
{
if (!this->Points)
{
vtkPoints* pts = vtkPoints::New(VTK_DOUBLE);
this->SetPoints(pts);
this->Points = pts;
pts->Delete();
}
if (numPoints != this->GetNumberOfPoints())
{
this->Points->SetNumberOfPoints(numPoints);
this->Modified();
}
}
//----------------------------------------------------------------------------
vtkIdType vtkPolyLineSource::GetNumberOfPoints()
{
return this->Points->GetNumberOfPoints();
}
//----------------------------------------------------------------------------
void vtkPolyLineSource::SetPoint(vtkIdType id, double x, double y, double z)
{
if (!this->Points)
{
return;
}
if (id >= this->Points->GetNumberOfPoints())
{
vtkErrorMacro(<< "point id " << id << " is larger than the number of points");
return;
}
this->Points->SetPoint(id, x, y, z);
this->Modified();
}
//----------------------------------------------------------------------------
void vtkPolyLineSource::SetPoints(vtkPoints* points)
{
if ( points != this->Points )
{
if ( this->Points != NULL )
{
this->Points->Delete();
}
this->Points = points;
if ( this->Points != NULL )
{
this->Points->Register(this);
}
this->Modified();
}
}
//----------------------------------------------------------------------------
int vtkPolyLineSource::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
// get the info object
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the ouptut
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkIdType numPoints = this->GetNumberOfPoints();
vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
pointIds->SetNumberOfIds(this->Closed ? numPoints + 1 : numPoints);
for (vtkIdType i = 0; i < numPoints; ++i)
{
pointIds->SetId(i, i);
}
if (this->Closed)
{
pointIds->SetId(numPoints, 0);
}
vtkSmartPointer<vtkCellArray> polyLine = vtkSmartPointer<vtkCellArray>::New();
polyLine->InsertNextCell(pointIds.GetPointer());
output->SetPoints(this->Points);
output->SetLines(polyLine);
return 1;
}
//----------------------------------------------------------------------------
void vtkPolyLineSource::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Points: " << this->Points << "\n";
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPolyLineSource.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPolyLineSource - create a poly line from a list of input points
// .SECTION Description
// vtkPolyLineSource is a source object that creates a poly line from
// user-specified points. The output is a vtkPolyLine.
#ifndef vtkPolyLineSource_h
#define vtkPolyLineSource_h
#include "vtkFiltersSourcesModule.h" // For export macro
#include "vtkPolyDataAlgorithm.h"
class vtkPoints;
class VTKFILTERSSOURCES_EXPORT vtkPolyLineSource : public vtkPolyDataAlgorithm
{
public:
static vtkPolyLineSource* New();
vtkTypeMacro(vtkPolyLineSource, vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Set the number of points in the poly line.
void SetNumberOfPoints(vtkIdType numPoints);
vtkIdType GetNumberOfPoints();
// Description:
// Set a point location.
void SetPoint(vtkIdType id, double x, double y, double z);
// Description:
// Get the points.
void SetPoints(vtkPoints* points);
vtkGetObjectMacro(Points, vtkPoints);
// Description:
// Set whether to close the poly line by connecting the last and first points.
vtkSetMacro(Closed, int);
vtkGetMacro(Closed, int);
vtkBooleanMacro(Closed, int);
protected:
vtkPolyLineSource();
~vtkPolyLineSource();
int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector *);
vtkPoints* Points;
int Closed;
private:
vtkPolyLineSource(const vtkPolyLineSource&); // Not implemented.
void operator=(const vtkPolyLineSource&); // Not implemented.
};
#endif
......@@ -42,6 +42,7 @@ set(Module_SRCS
vtkContourLineInterpolator.cxx
vtkContourRepresentation.cxx
vtkContourWidget.cxx
vtkCurveRepresentation.cxx
vtkDijkstraImageContourLineInterpolator.cxx
vtkDistanceRepresentation2D.cxx
vtkDistanceRepresentation3D.cxx
......@@ -85,6 +86,8 @@ set(Module_SRCS
vtkPolyDataContourLineInterpolator.cxx
vtkPolyDataPointPlacer.cxx
vtkPolyDataSourceWidget.cxx
vtkPolyLineRepresentation.cxx
vtkPolyLineWidget.cxx
vtkPolygonalHandleRepresentation3D.cxx
vtkPolygonalSurfaceContourLineInterpolator.cxx
vtkPolygonalSurfacePointPlacer.cxx
......@@ -142,6 +145,7 @@ set_source_files_properties(
vtkContinuousValueWidgetRepresentation
vtkContourLineInterpolator
vtkContourRepresentation
vtkCurveRepresentation
vtkFocalPlaneContourRepresentation
vtkDistanceRepresentation
vtkHandleRepresentation
......
......@@ -72,8 +72,11 @@ vtk_add_test_cxx(${vtk-module}CxxTests no_valid_tests
vtkHoverWidgetTest1.cxx
vtkLineRepresentationTest1.cxx
vtkLineWidget2Test1.cxx
vtkPolyLineRepresentationTest1.cxx
vtkPolyLineWidgetTest1.cxx
vtkSeedRepresentationTest1.cxx
vtkSeedWidgetTest1.cxx
vtkSplineRepresentationTest1.cxx
vtkSplineWidget2Test1.cxx
vtkTextRepresentationTest1.cxx
vtkTextWidgetTest1.cxx
......
#include "vtkPolyLineRepresentation.h"
#include <cstdlib>
#include <iostream>
#include "WidgetTestingMacros.h"
#include <vtkPointHandleRepresentation3D.h>
#include <vtkPlaneSource.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkDoubleArray.h>
int vtkPolyLineRepresentationTest1(int , char * [] )
{
vtkSmartPointer< vtkPolyLineRepresentation > node1 = vtkSmartPointer< vtkPolyLineRepresentation >::New();
EXERCISE_BASIC_REPRESENTATION_METHODS(vtkPolyLineRepresentation, node1);
vtkSmartPointer<vtkPlaneSource> planeSource = vtkSmartPointer<vtkPlaneSource>::New();
node1->SetPlaneSource(planeSource);
TEST_SET_GET_BOOLEAN(node1, ProjectToPlane);
// clamped 0-3
TEST_SET_GET_INT_RANGE(node1, ProjectionNormal, 1, 2);
node1->SetProjectionNormalToXAxes();
node1->SetProjectionNormalToYAxes();
node1->SetProjectionNormalToZAxes();
node1->SetProjectionNormalToOblique();
TEST_SET_GET_DOUBLE_RANGE(node1, ProjectionPosition, -10.0, 10.0);
vtkSmartPointer<vtkPolyData> pd = vtkSmartPointer<vtkPolyData>::New();
node1->GetPolyData(pd);
if (pd == NULL)
{
std::cout << "Polydata is null" << std::endl;
}
vtkSmartPointer<vtkProperty> prop = node1->GetHandleProperty();
if (prop == NULL)
{
std::cout << "Handle Property is NULL." << std::endl;
}
prop = node1->GetSelectedHandleProperty();
if (prop == NULL)
{
std::cout << "Selected Handle Property is NULL." << std::endl;
}
prop = node1->GetLineProperty();
if (prop == NULL)
{
std::cout << "Line Property is NULL." << std::endl;
}
prop = node1->GetSelectedLineProperty();
if (prop == NULL)
{
std::cout << "Selected Line Property is NULL." << std::endl;
}
node1->SetNumberOfHandles(10);
int numHandles = node1->GetNumberOfHandles();
if (numHandles != 10)
{
std::cerr << "Error in Setting number of Handles to 10, got " << numHandles << std::endl;
return EXIT_FAILURE;
}
node1->SetNumberOfHandles(-1);
numHandles = node1->GetNumberOfHandles();
std::cout << "After setting num handles to -1, got back " << numHandles << std::endl;
node1->SetNumberOfHandles(0);
numHandles = node1->GetNumberOfHandles();
std::cout << "After setting num handles to 0, got back " << numHandles << std::endl;
numHandles = 5;
node1->SetNumberOfHandles(numHandles);
double x, y, z;
x = y = z = 0.0;
double xyz[3] = {0.0, 0.0, 0.0};
double* hpos;
double hpos2[3];
for (int h = 0; h < numHandles; h++)
{
node1->SetHandlePosition(h, x, y, z);
hpos = node1->GetHandlePosition(h);
if (!hpos)
{
std::cerr << "Null handle position back for handle " << h << std::endl;
return EXIT_FAILURE;
}
else if (hpos[0] != x ||
hpos[1] != y ||
hpos[2] != z)
{
std::cerr << "Failure in SetHandlePosition(" << h << "," << x << "," << y << "," << z << "), got " << hpos[0] << ", " << hpos[1] << ", " << hpos[2] << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Handle " << h << " position = " << hpos[0] << ", " << hpos[1] << ", " << hpos[2] << std::endl;
}
node1->GetHandlePosition(h, hpos2);
if (hpos2[0] != x ||
hpos2[1] != y ||
hpos2[2] != z)
{
std::cerr << "Failure in SetHandlePosition(" << h << "," << x << "," << y << "," << z << "), got " << hpos2[0] << ", " << hpos2[1] << ", " << hpos2[2] << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Handle " << h << " position = " << hpos2[0] << ", " << hpos2[1] << ", " << hpos2[2] << std::endl;
}
node1->SetHandlePosition(h, xyz);
hpos = node1->GetHandlePosition(h);
if (!hpos)
{
std::cerr << "Null handle position back for handle " << h << std::endl;
return EXIT_FAILURE;
}
else if (hpos[0] != xyz[0] ||
hpos[1] != xyz[1] ||
hpos[2] != xyz[2])
{
std::cerr << "Failure in SetHandlePosition(" << h << ", xyz), expected " << xyz[0] << ", " << xyz[1] << ", " << xyz[2] << ", got " << hpos[0] << ", " << hpos[1] << ", " << hpos[2] << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Handle " << h << " position = " << hpos[0] << ", " << hpos[1] << ", " << hpos[2] << std::endl;
}
node1->GetHandlePosition(h, hpos2);
if (hpos2[0] != xyz[0] ||
hpos2[1] != xyz[1] ||
hpos2[2] != xyz[2])
{
std::cerr << "Failure in SetHandlePosition(" << h << ",xyz), , expected " << xyz[0] << ", " << xyz[1] << ", " << xyz[2] << ", got " << hpos2[0] << ", " << hpos2[1] << ", " << hpos2[2] << std::endl;
return EXIT_FAILURE;
}
else
{
std::cout << "Handle " << h << " position xyz = " << hpos2[0] << ", " << hpos2[1] << ", " << hpos2[2] << std::endl;
}
x -= 1.0;
y += 1.0;
z += 2.5;
xyz[0] += 1.0;
xyz[1] -= 1.0;
xyz[2] += 3.9;
}
vtkSmartPointer<vtkDoubleArray> da = node1->GetHandlePositions();
if (da == NULL)
{
std::cerr << "HandlePositions array is null!" << std::endl;
return EXIT_FAILURE;
}
else
{
for (vtkIdType i = 0; i < da->GetNumberOfTuples(); i++)
{
double val[3];
da->GetTupleValue(i, val);
std::cout << i << " = " << val[0] << ", " << val[1] << ", " << val[2] << std::endl;
}
}
TEST_SET_GET_BOOLEAN(node1, Closed);
std::cout << "Closed = " << node1->IsClosed() << std::endl;
std::cout << "Summed Length = " << node1->GetSummedLength();
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->SetNumberOfPoints(2);
points->SetPoint(0, 3.0, 6.8, -9.9);
points->SetPoint(1, -3.0, -6.8, 9.9);
node1->InitializeHandles(points);
da = node1->GetHandlePositions();
if (da == NULL)
{
std::cerr << "HandlePositions array is null after initing with vtkPoints!" << std::endl;
return EXIT_FAILURE;
}
else
{
for (vtkIdType i = 0; i < da->GetNumberOfTuples(); i++)
{
double val[3];
da->GetTupleValue(i, val);
std::cout << i << " = " << val[0] << ", " << val[1] << ", " << val[2] << std::endl;
}
}
node1->SetLineColor(1.0, 0.5, 0.3);
return EXIT_SUCCESS;
}
#include "vtkPolyLineWidget.h"
#include "vtkPolyLineRepresentation.h"
#include <cstdlib>
#include <iostream>
#include "WidgetTestingMacros.h"
int vtkPolyLineWidgetTest1(int , char * [] )
{
vtkSmartPointer< vtkPolyLineWidget > node1 = vtkSmartPointer< vtkPolyLineWidget >::New();
EXERCISE_BASIC_ABSTRACT_METHODS ( node1 );
vtkSmartPointer<vtkPolyLineRepresentation> rep1 = vtkSmartPointer<vtkPolyLineRepresentation>::New();
node1->SetRepresentation(rep1);
EXERCISE_BASIC_INTERACTOR_OBSERVER_METHODS( node1 );
return EXIT_SUCCESS;
}
......@@ -45,7 +45,7 @@ int vtkSplineRepresentationTest1(int , char * [] )
vtkSmartPointer<vtkProperty> prop = node1->GetHandleProperty();
if (prop == NULL)
{
std::cout << "Hanlde Property is NULL." << std::endl;
std::cout << "Handle Property is NULL." << std::endl;
}
prop = node1->GetSelectedHandleProperty();
if (prop == NULL)
......@@ -79,9 +79,11 @@ int vtkSplineRepresentationTest1(int , char * [] )
std::cout << "After setting num handles to 0, got back " << numHandles << std::endl;
// 0 is invalid
TEST_SET_GET_INT_RANGE(node1, Resolution, 2, 100);
TEST_SET_GET_INT_RANGE(node1, Resolution, 10, 100);
vtkSmartPointer<vtkParametricSpline> pspline = vtkSmartPointer<vtkParametricSpline>::New();
pspline->SetPoints(node1->GetParametricSpline()->GetPoints());
node1->SetParametricSpline(pspline);
vtkSmartPointer<vtkParametricSpline> pspline2 = node1->GetParametricSpline();
if (pspline2 != pspline)
......@@ -97,7 +99,7 @@ int vtkSplineRepresentationTest1(int , char * [] )
double xyz[3] = {0.0, 0.0, 0.0};
double* hpos;
double hpos2[3];
for (int h = -1; h <= numHandles; h++)
for (int h = 0; h < numHandles; h++)
{
node1->SetHandlePosition(h, x, y, z);
hpos = node1->GetHandlePosition(h);
......@@ -210,7 +212,6 @@ int vtkSplineRepresentationTest1(int , char * [] )
}
}
node1->SetLineColor(1.0, 0.5, 0.3);
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkCurveRepresentation
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkCurveRepresentation - vtkWidgetRepresentation
// base class for a widget that represents an curve that connects control
// points.
// .SECTION Description
// Base class for widgets used to define curves from points, such as
// vtkPolyLineRepresentation and vtkSplineRepresentation. This class
// uses handles, the number of which can be changed, to represent the
// points that define the curve. The handles can be picked can be
// picked on the curve itself to translate or rotate it in the scene.
#ifndef vtkCurveRepresentation_h
#define vtkCurveRepresentation_h