[vtkusers] No contours in contour plot

david michell davidmichell at rediffmail.com
Fri Jul 30 05:47:27 EDT 2004


An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040730/0a55752d/attachment.htm>
-------------- next part --------------
Hi everyone,
I have attached a code that Iam working on to produce contours.
Somehow Iam not able to get any contours.
Please help me.
Thank you,
david michell


#define VTK_USE_ANSI_STDLIB 

#include "vtk/vtkPolyDataMapper.h"

#include "vtk/vtkActor.h"

#include "vtk/vtkRenderer.h"

#include "vtk/vtkRenderWindow.h"

#include "vtk/vtkRenderWindowInteractor.h"

#include "vtk/vtkPoints.h"

#include "vtk/vtkFloatArray.h"

#include "vtk/vtkPointData.h"

#include "vtk/vtkDelaunay2D.h"

#include "vtk/vtkPolyData.h"

#include "vtk/vtkButterflySubdivisionFilter.h"

#include "vtk/vtkMarchingContourFilter.h"

#include "stdio.h"

int main(int argc,char* argv[])

{

vtkRenderer *ren=vtkRenderer::New();

vtkRenderWindow *win=vtkRenderWindow::New();

win->AddRenderer(ren);

vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();

win->SetInteractor(iren);

iren->Initialize();

 

 

vtkPoints *points=vtkPoints::New();



vtkFloatArray *scalar=vtkFloatArray::New();


int i,counter;

float temp;

double *data;


int npts=100;


points->SetNumberOfPoints(npts);

scalar->SetNumberOfTuples(npts);

data=new double[npts*3];

double y=0.01;

for (i=0;i<npts;i++)

{

data[i*3]=rand()*i;

data[i*3+1]=rand()*i;

data[i*3+2]=0.0;//z=0 because 2D

points->InsertPoint(i,data[i*3],data[i*3+1],data[i*3+2]);

float temp=1.0;

scalar->InsertValue(i,temp);

}

vtkPolyData *m_spData=vtkPolyData::New();

m_spData->Allocate(npts*3);

m_spData->SetPoints(points);

m_spData->GetPointData()->SetScalars(scalar);

m_spData->Modified();

m_spData->Update();

 

vtkDelaunay2D *del=vtkDelaunay2D::New();

del->SetInput(m_spData);

del->SetTolerance(0.00001f);

del->Update();

//to get smooth curved contours

vtkButterflySubdivisionFilter *butr=vtkButterflySubdivisionFilter::New();

butr->SetInput(del->GetOutput());

butr->SetNumberOfSubdivisions(2);

butr->Update();


vtkMarchingContourFilter *contour2D=vtkMarchingContourFilter::New();

contour2D->SetInput(butr->GetOutput()); 

contour2D->SetValue(0,1.0);

contour2D->Update();


vtkPolyDataMapper *mapper=vtkPolyDataMapper::New();

mapper->SetInput(contour2D->GetOutput());


vtkActor *surface=vtkActor::New();

surface->SetMapper(mapper); 

ren->AddActor(surface);

 

iren->Start();

 

points->Delete();

scalar->Delete();

m_spData->Delete();

del->Delete();

butr->Delete();

contour2D->Delete();

mapper->Delete();

surface->Delete();

delete[] data;

ren->Delete();

win->Delete();

iren->Delete();

return 1;

}



More information about the vtkusers mailing list