[vtkusers] Inverse visualisation of points clouds
Evgeniy Lalovski
elalovski at hotmail.com
Thu Jun 2 06:00:53 EDT 2005
Hi all,
I'm trying to make a surface from a txt file containing the coordinates of
the contour exterior of slices of MRI scan(black contour on white
background).I put the points in PolyData and then use
SurfaceReconstructionFilter and ContourFilter.But what I get is not that I
expect.I get a surface of the background of the images not with the contours
and it has some holes in it althought the slices are ok.How can I invert the
surface and get it for my contours.
here is a part of my txt file: //coordinates of the black pixels I want to
visualize
498 263 0 //for the first slice etc.
499 263 0
500 263 0
501 263 0
502 263 0
507 263 0
508 263 0
.............
and here's the code that i use
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include <stdio.h>
#include "vtkSurfaceReconstructionFilter.h"
#include "vtkContourFilter.h"
#include "vtkSmoothPolyDataFilter.h"
#include "vtkReverseSense.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
int main( int argc, char *argv[] )
{
FILE *donnees = fopen("points.txt","r");
vtkPolyData *data = vtkPolyData::New();
vtkPoints *points = vtkPoints::New();
int iCounter = 0;
while (!feof(donnees))
{
fprintf(stdout,"reading points: %i\r", iCounter);
float x, y, z;
fscanf(donnees,"%f %f %f\n", &x, &y, &z);
points->InsertPoint(iCounter++, x, y, z);
}
data->SetPoints(points);
fclose(donnees);
fprintf(stdout,"\n\n");
// Construire la surface et cree une isosurface
vtkSurfaceReconstructionFilter *surf =
vtkSurfaceReconstructionFilter::New();
surf->SetInput(data);
vtkContourFilter *cf = vtkContourFilter::New();
cf->SetInput((vtkDataSet*)surf->GetOutput());
cf->SetValue(0, 0.0);
#ifdef _SMOOTHING_
vtkSmoothPolyDataFilter *smoother = vtkSmoothPolyDataFilter::New();
smoother->SetInput(cf->GetOutput());
smoother->SetNumberOfIterations(50);
vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
normals->SetInput(smoother->GetOutput());
normals->FlipNormalsOn();
vtkPolyDataMapper *map = vtkPolyDataMapper::New();
map->SetInput(normals->GetOutput());
#else
vtkReverseSense *reverse = vtkReverseSense::New();
reverse->SetInput(cf->GetOutput());
reverse->ReverseCellsOn();
reverse->ReverseNormalsOn();
vtkPolyDataMapper *map = vtkPolyDataMapper::New();
map->SetInput(reverse->GetOutput());
#endif
map->ScalarVisibilityOff();
vtkActor *surfaceActor = vtkActor::New();
surfaceActor->SetMapper(map);
surfaceActor->GetProperty()->SetDiffuseColor(1.0000, 0.3882, 0.2784);
surfaceActor->GetProperty()->SetSpecularColor(1, 1, 1);
surfaceActor->GetProperty()->SetSpecular(.4);
surfaceActor->GetProperty()->SetSpecularPower(50);
vtkCamera *camera = vtkCamera::New();
camera->SetPosition(1,1,1);
camera->SetFocalPoint(0,0,0);
vtkRenderer *renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renderer->AddActor(surfaceActor);
renderer->SetActiveCamera(camera);
renderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
renderer->GetActiveCamera()->SetPosition(1, 0, 0);
renderer->GetActiveCamera()->SetViewUp(0, 0, 1);
renderer->ResetCamera();
renderer->GetActiveCamera()->Azimuth(20);
renderer->GetActiveCamera()->Elevation(30);
renderer->GetActiveCamera()->Dolly(1.2);
renderer->ResetCameraClippingRange();
renderer->SetBackground(1,1,1);
renWin->SetSize(300,300);
renWin->Render();
iren->Start();
points->Delete();
data->Delete();
surf->Delete();
cf->Delete();
#ifdef _SMOOTHING_
smoother->Delete();
normals->Delete();
#else
reverse->Delete();
#endif
map->Delete();
surfaceActor->Delete();
camera->Delete();
renderer->Delete();
renWin->Delete();
iren->Delete();
return 0;
}
Any suggestions are welcome.
Evgeni
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
More information about the vtkusers
mailing list