Skip to content
Snippets Groups Projects
Commit 460db167 authored by Will Schroeder's avatar Will Schroeder
Browse files

New filter visualizes point connectivity

parent 7f1e5bbf
No related branches found
No related tags found
No related merge requests found
......@@ -48,6 +48,7 @@ set(Module_SRCS
vtkOBBDicer.cxx
vtkOBBTree.cxx
vtkPassThrough.cxx
vtkPointConnectivityFilter.cxx
vtkPolyDataStreamer.cxx
vtkPolyDataToReebGraphFilter.cxx
vtkProbePolyhedron.cxx
......
c14dc77f28ca8e1a70a801f8b0bf8083
......@@ -9,6 +9,7 @@ vtk_add_test_python(
TestDiscreteMarchingCubes.py
TestGraphLayoutFilter.py
TestMultiBlockStreamer.py
TestPointConnectivityFilter.py
TestRectilinearGridToTetrahedra.py
TestSplineFilter.py
WarpToImage.py
......
#!/usr/bin/env python
import math
import vtk
import vtk.test.Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
npts = 1000
# Create a pipeline with variable point connectivity
math = vtk.vtkMath()
points = vtk.vtkPoints()
i = 0
while i < npts:
points.InsertPoint(i,math.Random(0,1),math.Random(0,1),0.0)
i = i + 1
profile = vtk.vtkPolyData()
profile.SetPoints(points)
# triangulate them
#
del1 = vtk.vtkDelaunay2D()
del1.SetInputData(profile)
del1.BoundingTriangulationOff()
del1.SetTolerance(0.001)
del1.SetAlpha(0.0)
conn = vtk.vtkPointConnectivityFilter()
conn.SetInputConnection(del1.GetOutputPort())
conn.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(conn.GetOutputPort())
mapper.SetScalarModeToUsePointFieldData()
mapper.SelectColorArray("Point Connectivity Count")
mapper.SetScalarRange(conn.GetOutput().GetPointData().GetArray("Point Connectivity Count").GetRange())
print ("Point connectivity range: ", mapper.GetScalarRange())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(1,1,1)
# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
ren1.AddActor(actor)
camera = vtk.vtkCamera()
camera.SetFocalPoint(0,0,0)
camera.SetPosition(0,0,1)
ren1.SetActiveCamera(camera)
ren1.SetBackground(0, 0, 0)
renWin.SetSize(250,250)
# render and interact with data
iRen = vtk.vtkRenderWindowInteractor()
iRen.SetRenderWindow(renWin);
ren1.ResetCamera()
renWin.Render()
iRen.Initialize()
#iRen.Start()
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointConnectivityFilter.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 "vtkPointConnectivityFilter.h"
#include "vtkIdList.h"
#include "vtkUnsignedIntArray.h"
#include "vtkCellData.h"
#include "vtkPointData.h"
#include "vtkDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkSMPTools.h"
#include "vtkSMPThreadLocalObject.h"
#include "vtkNew.h"
#include "vtkSmartPointer.h"
vtkStandardNewMacro(vtkPointConnectivityFilter);
//----------------------------------------------------------------------------
vtkPointConnectivityFilter::vtkPointConnectivityFilter()
{
}
//----------------------------------------------------------------------------
vtkPointConnectivityFilter::~vtkPointConnectivityFilter()
{
}
//----------------------------------------------------------------------------
namespace {
// This class is general purpose for all dataset types.
struct UpdateConnectivityCount
{
vtkDataSet *Input;
unsigned int *ConnCount;
vtkSMPThreadLocalObject<vtkIdList> CellIds;
UpdateConnectivityCount(vtkDataSet *input, unsigned int *connPtr) :
Input(input), ConnCount(connPtr)
{
}
void Initialize()
{
vtkIdList*& cellIds = this->CellIds.Local();
cellIds->Allocate(128); //allocate some memory
}
void operator() (vtkIdType ptId, vtkIdType endPtId)
{
vtkIdList*& cellIds = this->CellIds.Local();
for ( ; ptId < endPtId; ++ptId )
{
this->Input->GetPointCells(ptId, cellIds);
this->ConnCount[ptId] = cellIds->GetNumberOfIds();
}
}
void Reduce()
{
}
};
} // end anon namespace
//----------------------------------------------------------------------------
// This is the generic non-optimized method
int vtkPointConnectivityFilter::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkSmartPointer<vtkDataSet> input = vtkDataSet::GetData(inputVector[0]);
vtkDataSet *output = vtkDataSet::GetData(outputVector);
// First, copy the input to the output as a starting point
output->CopyStructure( input );
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->PassData(input->GetCellData());
// Check input
vtkIdType numPts;
if ( input == NULL || (numPts=input->GetNumberOfPoints()) < 1 )
{
return 1;
}
// Create integral array and populate it
vtkNew<vtkUnsignedIntArray> connCount;
connCount->SetNumberOfTuples(numPts);
connCount->SetName("Point Connectivity Count");
unsigned int *connPtr = static_cast<unsigned int*>(connCount->GetVoidPointer(0));
// Loop over all points, retrieving connectivity count
// The first GetPointCells() primes the pump (builds internal structures, etc.)
vtkNew<vtkIdList> cellIds;
input->GetPointCells(0, cellIds.GetPointer());
UpdateConnectivityCount updateCount(input,connPtr);
vtkSMPTools::For(0,numPts, updateCount);
// Pass array to the output
output->GetPointData()->AddArray(connCount.GetPointer());
return 1;
}
//----------------------------------------------------------------------------
void vtkPointConnectivityFilter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkPointConnectivityFilter.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 vtkPointConnectivityFilter - output a scalar field indicating point connectivity
// .SECTION Description
// vtkPointConnectivityFilter is a filter the produces a point scalar field
// that characerizes the connectivity of the point. What is meant by
// connectivity is the number of cells that use each point. The output
// scalar array is represented by a 16-bit integral value. A value of zero
// means that no cells use a particular point.
#ifndef vtkPointConnectivityFilter_h
#define vtkPointConnectivityFilter_h
#include "vtkFiltersGeneralModule.h" // For export macro
#include "vtkDataSetAlgorithm.h"
class VTKFILTERSGENERAL_EXPORT vtkPointConnectivityFilter : public vtkDataSetAlgorithm
{
public:
// Description:
// Standard methods for instantiation, obtaining type information and
// printing.
static vtkPointConnectivityFilter *New();
vtkTypeMacro(vtkPointConnectivityFilter,vtkDataSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
protected:
vtkPointConnectivityFilter();
~vtkPointConnectivityFilter();
int RequestData(vtkInformation *,
vtkInformationVector **,
vtkInformationVector *);
private:
vtkPointConnectivityFilter(const vtkPointConnectivityFilter&) VTK_DELETE_FUNCTION;
void operator=(const vtkPointConnectivityFilter&) VTK_DELETE_FUNCTION;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment