[vtkusers] surface reconstruction and contour filter

marisa aurelio asiram00 at hotmail.com
Thu Feb 6 05:51:02 EST 2003


Hi vtk users,

There is a file in TCL on vtk CD about surface reconstruction and contour 
filter, and I want to translate it to C++. But there are some things that I 
don't know how to translate.
Below, there's my code in c++. Can anyone help me and try to answer my 
questions in the code ???
If, in the code, there is something wrong, please tell me.
I really need your help. This is for my course, for my final year project.

Thanks.
Marisa

-------

#include "vtkFloatArray.h"
#include "vtkPoints.h"
#include "vtkProgrammableSource.h"
#include "vtkSurfaceReconstructionFilter.h"
#include "vtkContourFilter.h"
#include "vtkReverseSense.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageData.h"

//# Read some points. Use a programmable filter to read them.
//#

void readPoints(void *) {

	//-------> How do I put this in C++?
	//??????????????set output [pointSource GetPolyDataOutput]

	vtkPoints *points = vtkPoints::New();

	//-------> How do I put this in C++?
	//??????????????output SetPoints points

   FILE *ficheiro;
   char firstToken;
   float x, y, z;

   ficheiro = fopen("C:/Documents and Settings/hcarvalho/Ambiente de 
trabalho/works/ReconstruçãoBin/cactus.3337.pts","r");
   while( !feof(ficheiro) ) {
		fscanf(ficheiro,"%c ", &firstToken);
	    if(firstToken == 'p') {
			fscanf(ficheiro, "%f %f %f", &x, &y, &z);
			points->InsertNextPoint(x, y, z);
		}
   }
   points->Delete();
}

int main(int argc, char *argv[])
{
    vtkProgrammableSource *pointSource = vtkProgrammableSource::New();
    pointSource->SetExecuteMethod(readPoints, NULL);

    vtkPolyData *polyData = vtkPolyData::New();

    //------> What is missing here ???
    //------> I must 'link' polyData with the points that come from de 
function,
    //so I can do GetNumberOfPoints(), right ????

    int nPts = polyData->GetNumberOfPoints(); // A nPts = 3337 points

    //------> where do I get the 'bounds' ???

    polyData->GetBounds(bounds);
    polyData->Modified();

    vtkSurfaceReconstructionFilter *surf = 
vtkSurfaceReconstructionFilter::New();

    surf->SetInput( polyData );
    //surf->Update();

    nPts = ((vtkDataSet * )surf->GetOutput())->GetNumberOfPoints();
    // B nPts = 75760 points
    ((vtkDataSet * )surf->GetOutput())->GetBounds(bounds);

    // Contour at 0 to extract the surface.
    vtkContourFilter * cf = vtkContourFilter::New();
	cf->SetInput( surf->GetOutput() );
	cf->SetValue(0,0.0);
    cf->Update();

    nPts = cf->GetOutput()->GetNumberOfPoints();
    // C nPts = 0 points
    cf->GetOutput()->GetBounds(bounds);

    vtkReverseSense * rev = vtkReverseSense::New();
    rev->SetInput(cf->GetOutput());
    rev->ReverseCellsOn();
    rev->ReverseNormalsOn();
    rev->Update();

    polyData->Initialize();
    polyData->DeepCopy(rev->GetOutput());

    vtkPolyDataMapper *map = vtkPolyDataMapper::New();
    map->SetInput(rev->GetOutput());
    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(0.4);
    (surfaceActor->GetProperty())->SetSpecularPower(50);

    //# Create the RenderWindow, Renderer and both Actors
    //#
    vtkRenderer *ren1 = vtkRenderer::New();

    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(ren1);

    //# Add the actors to the renderer, set the background and size
    //#
    ren1->AddActor(surfaceActor);
    ren1->SetBackground(1, 1, 1);
    renWin->SetSize(400, 400);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);
    iren->Initialize();
    iren->Start();

    return 0;
}




_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963




More information about the vtkusers mailing list