Commit 1a965eb9 authored by Will Schroeder's avatar Will Schroeder

All working before SMP conversion

parent 46009b9b
......@@ -25,6 +25,8 @@ set(Module_SRCS
vtkExecutionTimer.cxx
vtkFeatureEdges.cxx
vtkFieldDataToAttributeDataFilter.cxx
vtkFlyingEdges2D.cxx
vtkFlyingEdges3D.cxx
vtkGlyph2D.cxx
vtkGlyph3D.cxx
vtkHedgeHog.cxx
......
......@@ -16,6 +16,8 @@ vtk_add_test_python(
QuadricDecimation.py
StreamPolyData.py
TestElevationFilter.py
TestFlyingEdges2D.py
TestFlyingEdges3D.py
TestGridSynchronizedTemplates3D.py
TestMarchingSquares.py
TestRectilinearSynchronizedTemplates.py
......
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.SetMultiSamples(0)
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Create image manually for testing purposes
xSze = 5
ySze = 12
xSze = 4000
ySze = 6000
isoValue = 750
maxValue = 100
imageData = vtk.vtkImageData()
imageData.SetDimensions(xSze,ySze,1)
scalars = vtk.vtkUnsignedCharArray()
scalars.SetNumberOfTuples(xSze*ySze)
for i in range (0,xSze*ySze):
scalars.SetValue(i,0)
scalars.SetValue(9,maxValue)
scalars.SetValue(17,maxValue)
scalars.SetValue(18,maxValue)
scalars.SetValue(36,maxValue)
scalars.SetValue(42,maxValue)
scalars.SetValue(1000000,maxValue)
imageData.GetPointData().SetScalars(scalars)
# pipeline
reader = vtk.vtkStructuredPointsReader()
reader.SetFileName("C:\D\gitVTK\Bugs\FlyingEdges\StructuredPoints-Test.vtk")
reader2 = vtk.vtkPNGReader()
reader2.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/fullhead15.png")
iso = vtk.vtkFlyingEdges2D()
iso.SetInputData(imageData)
#iso.SetInputConnection(reader2.GetOutputPort())
iso.SetValue(0, isoValue)
#iso.GenerateValues(12,500,1150)
iso2 = vtk.vtkSynchronizedTemplates2D()
iso2.SetInputData(imageData)
#iso2.SetInputConnection(reader2.GetOutputPort())
iso2.SetValue(0, isoValue)
#iso2.GenerateValues(12,500,1150)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInputConnection(iso.GetOutputPort())
#isoMapper.SetInputConnection(iso2.GetOutputPort())
isoMapper.ScalarVisibilityOff()
isoActor = vtk.vtkActor()
isoActor.SetMapper(isoMapper)
isoActor.GetProperty().SetColor(1,1,1)
outline = vtk.vtkOutlineFilter()
outline.SetInputData(imageData)
#outline.SetInputConnection(reader2.GetOutputPort())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineProp = outlineActor.GetProperty()
#eval $outlineProp SetColor 0 0 0
# Time the execution of the filter
timer = vtk.vtkExecutionTimer()
timer.SetFilter(iso)
iso.Update()
FEwallClock = timer.GetElapsedWallClockTime()
FEcpuClock = timer.GetElapsedCPUTime()
print ("FE:", FEwallClock, FEcpuClock)
timer2 = vtk.vtkExecutionTimer()
timer2.SetFilter(iso2)
iso2.Update()
wallClock = timer2.GetElapsedWallClockTime()
cpuClock = timer2.GetElapsedCPUTime()
print ("ST:", wallClock, cpuClock)
if FEwallClock > 0:
print ("Speedup:", (wallClock/FEwallClock))
#write output
writer = vtk.vtkPolyDataWriter()
writer.SetInputConnection(iso.GetOutputPort())
writer.SetFileName("C:\D\gitVTK\Bugs\FlyingEdges\FE-output.vtk")
#if xSze*ySze <= 100:
writer.Write()
# Add the actors to the renderer, set the background and size
#
ren1.AddActor(outlineActor)
ren1.AddActor(isoActor)
ren1.SetBackground(0,0,0)
renWin.SetSize(400,400)
ren1.ResetCamera()
iren.Initialize()
iren.Start()
# prevent the tk window from showing up then start the event loop
# --- end of script --
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.SetMultiSamples(0)
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Create image manually for testing purposes
xSze = 6
ySze = 5
zSze = 8
#xSze = 150
#ySze = 175
#zSze = 750
isoValue = 200
maxValue = 250
imageData = vtk.vtkImageData()
imageData.SetDimensions(xSze,ySze,zSze)
scalars = vtk.vtkIntArray()
scalars.SetNumberOfTuples(xSze*ySze*zSze)
for i in range (0,xSze*ySze*zSze):
# scalars.SetValue(i,i)
scalars.SetValue(i,0)
scalars.SetValue(222,maxValue)
imageData.GetPointData().SetScalars(scalars)
# pipeline
reader = vtk.vtkImageReader()
reader.SetDataByteOrderToLittleEndian()
reader.SetDataExtent(0,63,0,63,1,93)
reader.SetDataSpacing(3.2,3.2,1.5)
reader.SetFilePrefix("" + str(VTK_DATA_ROOT) + "/Data/headsq/quarter")
reader.SetDataMask(0x7fff)
# another source
sphere = vtk.vtkSphere()
sphere.SetCenter( 0.0,0.0,0.0)
sphere.SetRadius(0.25)
# iso-surface to create geometry
sample = vtk.vtkSampleFunction()
sample.SetImplicitFunction(sphere)
sample.SetModelBounds(-0.5,0.5, -0.5,0.5, -0.5,0.5)
sample.SetSampleDimensions(200,200,200)
iso = vtk.vtkFlyingEdges3D()
#iso.SetInputData(imageData)
#iso.SetInputConnection(reader.GetOutputPort())
iso.SetInputConnection(sample.GetOutputPort())
#iso.SetValue(0, isoValue)
#iso.SetValue(0, 750)
#iso.SetValue(0, 0.0)
#iso.GenerateValues(12,500,1150)
iso.GenerateValues(3,-.11,.11)
iso.ComputeNormalsOn()
iso.ComputeGradientsOff()
iso2 = vtk.vtkSynchronizedTemplates3D()
#iso2.SetInputData(imageData)
#iso2.SetInputConnection(reader.GetOutputPort())
iso2.SetInputConnection(sample.GetOutputPort())
#iso2.SetValue(0, isoValue)
#iso2.SetValue(0, 750)
#iso2.SetValue(0, 0.0)
#iso2.GenerateValues(12,500,1150)
iso2.GenerateValues(3,-.11,.11)
isoMapper = vtk.vtkPolyDataMapper()
isoMapper.SetInputConnection(iso.GetOutputPort())
#isoMapper.SetInputConnection(iso2.GetOutputPort())
isoMapper.ScalarVisibilityOff()
isoActor = vtk.vtkActor()
isoActor.SetMapper(isoMapper)
isoActor.GetProperty().SetColor(1,1,1)
isoActor.GetProperty().SetOpacity(0.5)
outline = vtk.vtkOutlineFilter()
#outline.SetInputData(imageData)
#outline.SetInputConnection(reader.GetOutputPort())
outline.SetInputConnection(sample.GetOutputPort())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInputConnection(outline.GetOutputPort())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineProp = outlineActor.GetProperty()
#eval $outlineProp SetColor 0 0 0
# Time the execution of the filter
timer = vtk.vtkExecutionTimer()
timer.SetFilter(iso)
iso.Update()
FEwallClock = timer.GetElapsedWallClockTime()
FEcpuClock = timer.GetElapsedCPUTime()
print ("FE:", FEwallClock, FEcpuClock)
timer2 = vtk.vtkExecutionTimer()
timer2.SetFilter(iso2)
iso2.Update()
wallClock = timer2.GetElapsedWallClockTime()
cpuClock = timer2.GetElapsedCPUTime()
print ("ST:", wallClock, cpuClock)
if FEwallClock > 0:
print ("Speedup:", (wallClock/FEwallClock))
#write output
writer = vtk.vtkPolyDataWriter()
writer.SetInputConnection(iso.GetOutputPort())
writer.SetFileName("C:\D\gitVTK\Bugs\FlyingEdges\FE-output.vtk")
#if xSze*ySze <= 100:
#writer.Write()
# Add the actors to the renderer, set the background and size
#
ren1.AddActor(outlineActor)
ren1.AddActor(isoActor)
ren1.SetBackground(0,0,0)
renWin.SetSize(400,400)
ren1.ResetCamera()
iren.Initialize()
iren.Start()
# prevent the tk window from showing up then start the event loop
# --- end of script --
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFlyingEdges2D.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 vtkFlyingEdges2D - generate isoline(s) from a structured points set
// .SECTION Description
// vtkFlyingEdges2D is a serial, reference implementation of the 2D version
// of the flying edges algorithm. It is designed to be highly scalable (i.e.,
// parallelizable) for large data. It implements certain performance
// optimizations including computational trimming to rapidly eliminate
// processing of data regions, packed bit representation of case table
// values, single edge intersection, elimination of point merging, and
// elimination of any reallocs (due to dynamic data insertion). Note that
// computational trimming is a method to reduce total computational cost in
// which partial computational results can be used to eliminate future
// computations.
//
// This is a three-pass algorithm. The first pass processes all x-edges and
// builds x-edge case values (which, when the two x-edges defining a pixel
// are combined, are equivalent to vertex-based case table except edge-based
// approaches are separable to parallel computing). Next x-pixel rows are
// processed to gather information from y-edges (basically to count the
// number of edge intersections and lines generated). Finally in the
// third pass output primitives are generated into pre-allocated arrays. This
// implementation uses pixel cell axes (a x-y dyad located at the pixel
// origin) to ensure that each edge is intersected at most one time.
// .SECTION Caveats
// This filter is specialized to 2D images. This implementation can produce
// degenerate line segments (i.e., zero-length line segments).
// .SECTION See Also
// vtkContourFilter vtkFlyingEdges3D vtkSynchronizedTemplates2D
// vtkMarchingSquares
#ifndef __vtkFlyingEdges2D_h
#define __vtkFlyingEdges2D_h
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkPolyDataAlgorithm.h"
#include "vtkContourValues.h" // Needed for direct access to ContourValues
class vtkImageData;
class VTKFILTERSCORE_EXPORT vtkFlyingEdges2D : public vtkPolyDataAlgorithm
{
public:
static vtkFlyingEdges2D *New();
vtkTypeMacro(vtkFlyingEdges2D,vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Because we delegate to vtkContourValues.
unsigned long int GetMTime();
// Description:
// Set a particular contour value at contour number i. The index i ranges
// between 0<=i<NumberOfContours.
void SetValue(int i, double value)
{this->ContourValues->SetValue(i,value);}
// Description:
// Get the ith contour value.
double GetValue(int i)
{return this->ContourValues->GetValue(i);}
// Description:
// Get a pointer to an array of contour values. There will be
// GetNumberOfContours() values in the list.
double *GetValues()
{return this->ContourValues->GetValues();}
// Description:
// Fill a supplied list with contour values. There will be
// GetNumberOfContours() values in the list. Make sure you allocate
// enough memory to hold the list.
void GetValues(double *contourValues)
{this->ContourValues->GetValues(contourValues);}
// Description:
// Set the number of contours to place into the list. You only really
// need to use this method to reduce list size. The method SetValue()
// will automatically increase list size as needed.
void SetNumberOfContours(int number)
{this->ContourValues->SetNumberOfContours(number);}
// Description:
// Get the number of contours in the list of contour values.
int GetNumberOfContours()
{return this->ContourValues->GetNumberOfContours();}
// Description:
// Generate numContours equally spaced contour values between specified
// range. Contour values will include min/max range values.
void GenerateValues(int numContours, double range[2])
{this->ContourValues->GenerateValues(numContours, range);}
// Description:
// Generate numContours equally spaced contour values between specified
// range. Contour values will include min/max range values.
void GenerateValues(int numContours, double rangeStart, double rangeEnd)
{this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);}
// Description:
// Option to set the point scalars of the output. The scalars will be the
// iso value of course. By default this flag is on.
vtkSetMacro(ComputeScalars,int);
vtkGetMacro(ComputeScalars,int);
vtkBooleanMacro(ComputeScalars,int);
// Description:
// Set/get which component of the scalar array to contour on; defaults to 0.
vtkSetMacro(ArrayComponent, int);
vtkGetMacro(ArrayComponent, int);
protected:
vtkFlyingEdges2D();
~vtkFlyingEdges2D();
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
virtual int FillInputPortInformation(int port, vtkInformation *info);
vtkContourValues *ContourValues;
int ComputeScalars;
int ArrayComponent;
private:
vtkFlyingEdges2D(const vtkFlyingEdges2D&); // Not implemented.
void operator=(const vtkFlyingEdges2D&); // Not implemented.
};
#endif
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkFlyingEdges3D.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 vtkFlyingEdges3D - generate isosurface from 3D image data (volume)
// .SECTION Description
// vtkFlyingEdges3D is a serial, reference implementation of the 3D version
// of the flying edges algorithm. It is designed to be highly scalable (i.e.,
// parallelizable) for large data. It implements certain performance
// optimizations including computational trimming to rapidly eliminate
// processing of data regions, packed bit representation of case table
// values, single edge intersection, elimination of point merging, and
// elimination of any reallocs (due to dynamic data insertion). Note that
// computational trimming is a method to reduce total computational cost in
// which partial computational results can be used to eliminate future
// computations.
//
// This is a three-pass algorithm. The first pass processes all x-edges and
// builds x-edge case values (which, when the four x-edges defining a voxel
// are combined, are equivalent to vertex-based case table except edge-based
// approaches are separable to parallel computing). Next x-voxel rows are
// processed to gather information from yz-edges (basically to count the
// number of edge intersections and triangles generated). Finally in the
// third pass output primitives are generated into pre-allocated arrays. This
// implementation uses voxel cell axes (a x-y-z triad located at the voxel
// origin) to ensure that each edge is intersected at most one time. Note
// that this implementation also reuses the VTK Marching Cubes case table,
// although the vertex-based MC table is transformed into an edge-based
// table.
// .SECTION Caveats
// This filter is specialized to 3D volumes. This implementation can produce
// degenerate triangles (i.e., zero-area triangles).
// .SECTION See Also
// vtkContourFilter vtkFlyingEdges2D vtkSynchronizedTemplates3D
// vtkMarchingCubes vtkSMPFlyingEdges3D
#ifndef __vtkFlyingEdges3D_h
#define __vtkFlyingEdges3D_h
#include "vtkFiltersCoreModule.h" // For export macro
#include "vtkPolyDataAlgorithm.h"
#include "vtkContourValues.h" // Passes calls through
class vtkImageData;
class VTKFILTERSCORE_EXPORT vtkFlyingEdges3D : public vtkPolyDataAlgorithm
{
public:
static vtkFlyingEdges3D *New();
vtkTypeMacro(vtkFlyingEdges3D,vtkPolyDataAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Because we delegate to vtkContourValues.
unsigned long int GetMTime();
// Description:
// Set/Get the computation of normals. Normal computation is fairly
// expensive in both time and storage. If the output data will be processed
// by filters that modify topology or geometry, it may be wise to turn
// Normals and Gradients off.
vtkSetMacro(ComputeNormals,int);
vtkGetMacro(ComputeNormals,int);
vtkBooleanMacro(ComputeNormals,int);
// Description:
// Set/Get the computation of gradients. Gradient computation is fairly
// expensive in both time and storage. Note that if ComputeNormals is on,
// gradients will have to be calculated, but will not be stored in the
// output dataset. If the output data will be processed by filters that
// modify topology or geometry, it may be wise to turn Normals and
// Gradients off.
vtkSetMacro(ComputeGradients,int);
vtkGetMacro(ComputeGradients,int);
vtkBooleanMacro(ComputeGradients,int);
// Description:
// Set/Get the computation of scalars.
vtkSetMacro(ComputeScalars,int);
vtkGetMacro(ComputeScalars,int);
vtkBooleanMacro(ComputeScalars,int);
// Description:
// Set a particular contour value at contour number i. The index i ranges
// between 0<=i<NumberOfContours.
void SetValue(int i, double value) {this->ContourValues->SetValue(i,value);}
// Description:
// Get the ith contour value.
double GetValue(int i) {return this->ContourValues->GetValue(i);}
// Description:
// Get a pointer to an array of contour values. There will be
// GetNumberOfContours() values in the list.
double *GetValues() {return this->ContourValues->GetValues();}
// Description:
// Fill a supplied list with contour values. There will be
// GetNumberOfContours() values in the list. Make sure you allocate
// enough memory to hold the list.
void GetValues(double *contourValues) {
this->ContourValues->GetValues(contourValues);}
// Description:
// Set the number of contours to place into the list. You only really
// need to use this method to reduce list size. The method SetValue()
// will automatically increase list size as needed.
void SetNumberOfContours(int number) {
this->ContourValues->SetNumberOfContours(number);}
// Description:
// Get the number of contours in the list of contour values.
int GetNumberOfContours() {
return this->ContourValues->GetNumberOfContours();}
// Description:
// Generate numContours equally spaced contour values between specified
// range. Contour values will include min/max range values.
void GenerateValues(int numContours, double range[2]) {
this->ContourValues->GenerateValues(numContours, range);}
// Description:
// Generate numContours equally spaced contour values between specified
// range. Contour values will include min/max range values.
void GenerateValues(int numContours, double rangeStart, double rangeEnd)
{this->ContourValues->GenerateValues(numContours, rangeStart, rangeEnd);}
// Description:
// Set/get which component of the scalar array to contour on; defaults to 0.
vtkSetMacro(ArrayComponent, int);
vtkGetMacro(ArrayComponent, int);
protected:
vtkFlyingEdges3D();
~vtkFlyingEdges3D();
int ComputeNormals;
int ComputeGradients;
int ComputeScalars;
int ArrayComponent;
vtkContourValues *ContourValues;
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
virtual int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
virtual int FillInputPortInformation(int port, vtkInformation *info);
private:
vtkFlyingEdges3D(const vtkFlyingEdges3D&); // Not implemented.
void operator=(const vtkFlyingEdges3D&); // Not implemented.
};
#endif
Markdown is supported
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