[vtkusers] reading triangles data
Nick Ton
nton at photon.com
Tue Oct 21 13:25:31 EDT 2003
Hi Patrick,
I am doing something similar to you. I had a previous email pertaining to
reading Trixels (Triangular Pixel).
I finally was able to render the Trixels but as it turns out it's not
exactly what I expected. So I think that
the ECR (earth-centered rotating) coordinate system that I am using is
screwing up my rendering. Anyway,
here is some code that will help you along. It's written in C++.
<--------------------code start
-------------------------------------------------------------------->
// open file stream to read in trixels from file.
ifstream ifs;
ifstreams.open("c:\\temp\\mytrixel.txt");
// create two very important data objects
// 1) setup a triangle grid
vtkUnstructuredGrid * aTriangleGrid = vtkUnstructuredGrid::New();
// Must allocate memory for reading triangle data
aTriangleGrid->Allocate(1000,1);
// 2) vtkPoints * trianglePoints = vtkPoints::New();
// Must allocate memory for reading triangle vertices 3 vertices for 1
triangle
trianglePoints->SetNumberof Points(3*1000);
int id = 0;
// read in triangles
while(id < 3*1000)
{
ifs >> v01 >> v02 >> v03; // vertex 0
ifs >> v11 >> v12 >> v13; // vertex 1
ifs >> v21 >> v22 >> v23; // vertex 2
// create unique id's for each points
int pid1 = id;
int pid2 = id + 1;
int pid3 = id + 2;
// insert the points into the vtkPoints object
trianglePoints->InsertPoint(pid1,v01,v02,v03);
trianglePoints->InsertPoint(pid2,v11,v12,v13);
trianglePoints->InsertPoint(pid3,v21,v22,v23);
// use the point id to create triangles
aTriangle = vtkTriangle::New();
// the first number represents the vertex, the second number is the id
aTriangle->GetPointIds()->SetId(0,pid1);
aTriangle->GetPointIds()->SetId(0,pid2);
aTriangle->GetPointIds()->SetId(0,pid3);
// insert the triangle into the grid data object
aTriangleGrid->InsertNextCell(aTriangle->GetCellType(),
aTriangle->GetPointIds());
// delete the triangle to reclaim memory
aTriangle->Delete();
id = id + 3;
}
aTriangleGrid->SetPoints(trianglePoints);
// need to create a mapper to pass data to the actor
vtkDataSetMapper * aTriangleMapper = vtkDataSetMapper::New();
aTriangleMapper->SetInput(aTriangleGrid);
// create an actor
vtkActor * aTriangleActor = new vtkActor::New();
aTriangleActor->SetMapper(aTriangleMapper);
// set color property since I didn't create scalar data to be used as color
map
aTriangleActor->GetProperty()->SetDiffuseColor(0.3,1,0.5);
Hope this helps.
Nick
-----Original Message-----
From: Patrick Schuska [mailto:schuska at dbi.udel.edu]
Sent: Tuesday, October 21, 2003 11:23 AM
To: vtkusers at vtk.org
Subject: [vtkusers] reading triangles data
Hi.
I am trying to read triangles data (I took the file from amira) with vtk.
But it doesn`t work. There comes allways the same error message.
I think I did something with the header wrong.
It looks like this..
# vtk DataFile Version 3.0
Triangle Data
BINARY
DATASET POLYDATA
TRIANGLES 3790
...data...
can anybody help me??
Thanks, Patrick.
error message:
ERROR: In C:\martink\vtk42\VTK\IO\vtkPolyDataReader.cxx, line 305
vtkPolyDataReader (0x064B5200): Unrecognized keyword: triangles
my vtk file.
package require vtk
package require vtkinteraction
# Create the standard renderer, render window
# and interactor
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
# Create the reader for the data
vtkPolyDataReader reader
#vtkDataReader reader
reader SetFileName "D:/amira/ear2bsurf.vtk"
vtkOutlineFilter outlineData
outlineData SetInput [reader GetOutput]
vtkPolyDataMapper mapOutline
mapOutline SetInput [outlineData GetOutput]
vtkActor outline
outline SetMapper mapOutline
[outline GetProperty] SetColor 0 0 0
ren1 AddActor outline
ren1 SetBackground 1 1 1
renWin SetSize 600 600
renWin Render
proc TkCheckAbort {} {
set foo [renWin GetEventPending]
if {$foo != 0} {renWin SetAbortRender 1}
}
renWin AddObserver AbortCheckEvent {TkCheckAbort}
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20031021/857ed7ef/attachment.htm>
More information about the vtkusers
mailing list