[vtkusers] this code does not work
david michell
davidmichell at rediffmail.com
Wed May 19 04:22:23 EDT 2004
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040519/7cd3ce08/attachment.htm>
-------------- next part --------------
hi everyone,
I am working on vtkSurfaceReconstructionFilter.
I have a file of unstructured points and Iam trying to builda surface out of it.
Soemthing is wrong, its taking a looooong time to render and in the end it crashes.
I have put the code below.
Please help me.
Thank you,
David Michell
#define VTK_USE_ANSI_STDLIB
#include "vtkUnstructuredGrid.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkIdType.h"
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkDoubleArray.h"
#include "vtkProperty.h"
#include "vtkButterflySubdivisionFilter.h"
#include "vtkReverseSense.h"
#include "vtkSurfaceReconstructionFilter.h"
#include "vtkContourFilter.h"
#include "stdio.h"
void main()
{
vtkRenderer *ren=vtkRenderer::New();
vtkRenderWindow *win=vtkRenderWindow::New();
win->AddRenderer(ren);
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
win->SetInteractor(iren);
iren->Initialize();
FILE *fp;
fp=fopen("data.set","r");
int npts=25;
double *data=new double[npts*3];
int i,counter;
double temp;
for (i=0;i<npts;i++)
{
fscanf(fp,"%lf",&temp);
data[i*3]=temp;//works if i do temp/100000000.0;
fscanf(fp,"%lf",&temp);
data[i*3+1]=temp;
fscanf(fp,"%lf",&temp);
data[i*3+2]=temp;
fscanf(fp,"%lf",&temp);
}
vtkIdType *m_saCellArray=new vtkIdType[npts];
for (counter=0;counter<npts;counter++)
{
m_saCellArray[counter]=counter;
}
vtkCellArray *m_spCells=vtkCellArray::New();
m_spCells->Allocate(m_spCells->EstimateSize(npts,1));
m_spCells->InsertNextCell(npts);
m_spCells->ReplaceCell(0,npts,m_saCellArray);
vtkDoubleArray *m_spPointSet=vtkDoubleArray::New();
m_spPointSet->SetNumberOfComponents(3);
m_spPointSet->SetNumberOfTuples(npts);
m_spPointSet->SetArray(data,npts*3,1);
m_spPointSet->Modified();
vtkPoints *m_spPoints=vtkPoints::New();
m_spPoints->Allocate(npts*3);
m_spPoints->SetData(m_spPointSet);
vtkUnstructuredGrid *m_spData=vtkUnstructuredGrid::New();
m_spData->Allocate(npts*3);
m_spData->SetPoints(m_spPoints);
int *cell_type=new int[npts];
memset(cell_type,1,sizeof(int)*npts);
m_spData->SetCells(cell_type,m_spCells);
m_spData->Modified();
m_spData->Update();
vtkSurfaceReconstructionFilter *reconst=vtkSurfaceReconstructionFilter::New();
reconst->SetInput(m_spData);
vtkContourFilter *filter=vtkContourFilter::New();
filter->SetInput((vtkDataSet*)reconst->GetOutput());
filter->SetValue(0,0.0);
vtkButterflySubdivisionFilter *butr=vtkButterflySubdivisionFilter::New();
butr->SetInput(filter->GetOutput());
butr->SetNumberOfSubdivisions(3);
vtkReverseSense *rev=vtkReverseSense::New();
rev->SetInput(butr->GetOutput());
rev->ReverseCellsOn();
rev->ReverseNormalsOn();
vtkPolyDataMapper *mapper=vtkPolyDataMapper::New();
mapper->SetInput(rev->GetOutput());
vtkActor *surface=vtkActor::New();
surface->SetMapper(mapper);
ren->AddActor(surface);
iren->Start();
}
/* these data must be put in a file called data.set
150000000.000000 1.000000 0.350000 1.500000
150000000.000000 1.500000 0.350000 1.000000
150000000.000000 1.500000 0.350000 1.500000
150000000.000000 2.000000 0.350000 1.500000
150000000.000000 7.000000 0.350000 1.500000
150000000.000000 8.000000 0.350000 1.500000
150000000.000000 1.000000 0.400000 1.000000
150000000.000000 1.500000 0.400000 0.500000
150000000.000000 1.500000 0.400000 1.000000
150000000.000000 1.500000 0.400000 1.000000
150000000.000000 1.500000 0.400000 1.000000
150000000.000000 1.500000 0.400000 1.000000
150000000.000000 1.500000 0.400000 1.500000
150000000.000000 2.000000 0.400000 1.000000
150000000.000000 7.000000 0.400000 1.500000
150000000.000000 0.500000 0.450000 1.000000
150000000.000000 0.500000 0.450000 1.000000
150000000.000000 1.500000 0.450000 0.500000
150000000.000000 1.500000 0.450000 1.000000
150000000.000000 1.500000 0.450000 1.000000
200000000.000000 1.500000 0.350000 1.000000
200000000.000000 2.000000 0.350000 0.500000
200000000.000000 7.000000 0.350000 1.500000
200000000.000000 8.000000 0.350000 1.500000
200000000.000000 1.000000 0.400000 1.000000
*/
More information about the vtkusers
mailing list