[vtkusers] Visual Problem in 3D rendering (polygon)

polys_poly at hotmail.com polys_poly at hotmail.com
Sat Feb 9 09:32:13 EST 2008


Hello.

I create a polygon in 3D space by reading the 2D coordinates from a file and when I render it 
i get the following image which is correct. The z coordinate is always 0

http://img164.imageshack.us/img164/8985/polygon1ge2.jpg

But when i try to rotate the image it becomes a bit messy

http://img91.imageshack.us/img91/7253/polygon2yn4.jpg

I don't know why this happens and I was hoping if you could help me. 

Here is my code for the function that creates and renders the polygon  (at the beginning 
it's the code that reads the file and gets the coordinates line by line)
void CreateVtkPolygon::Polygon() {

ifstream inFile;

ifstream inFile2;

int numLines = 0;

int countId = 0;

int countLines = 1;

char buffer[14];

char * pEnd;

double x;

double y;


inFile.open("IM_00104_1.out");

if (!inFile) {

cout << "Unable to open file";

exit(1); // terminate with error

}

while (inFile.getline(buffer, 14)) {

numLines++;

}


polygonPoints ->SetNumberOfPoints(numLines-1);

polygon->GetPointIds()->SetNumberOfIds(numLines-1);


inFile.close();

inFile2.open("IM_00104_1.out");

if (!inFile2) {

cout << "Unable to open file";

exit(1); // terminate with error

} 


while(countLines <= numLines-1) { 

inFile2.getline(buffer, 14);

x = strtod (buffer, &pEnd);

y = strtod (pEnd,NULL); 

polygonPoints ->InsertPoint(countId, x, y, 0); 

polygon->GetPointIds()->SetId(countId, countId);

countId++;

countLines++;

} 

polygonGrid->Allocate(1,1);

polygonGrid->InsertNextCell(polygon->GetCellType(), polygon->GetPointIds());

polygonGrid->SetPoints(polygonPoints);

polygonMapper->SetInput(polygonGrid);


polygonActor->SetMapper(polygonMapper);

polygonActor->GetProperty()->SetDiffuseColor(1,1,1);

ren->SetBackground(0,0,0);

renWin->AddRenderer(ren);

iren->SetRenderWindow(renWin);

iren->SetInteractorStyle(interactorStyle3D);


ren->AddActor(polygonActor);

ren->ResetCamera(); 

ren->ResetCameraClippingRange();


renWin->Render();

iren->Initialize();

iren->Start();

}

Thanx, Polys
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080209/2be84a1e/attachment.htm>


More information about the vtkusers mailing list