[vtkusers] reading triangles data

Nick Ton nton at photon.com
Wed Oct 22 15:22:21 EDT 2003


Hi Patrick,
 
I created my own triangle (aka Trixel) data file format which is very
simple.
Three set of triplet representing the vertices of a triangle like this
0.0  0.0  0.0    1.0 1.0 1.0     0.5 0.5 0.0. The spaces are exaggerated for
clarity. But it doesn't really matter since C++ input stream will ignore
spaces
when you are directing the stream into a double or a float data type. In
this case,
a triple represents x,y,z coordinate for one vertex point. 
 
After watching the slew of emails regarding "reading triangles", I think I
was using
VTK API somewhat differently from everyone else. I created my own triangle
reader
application, and thus my own triangle data format.  I hope I didn't confuse
you. Essentially,
my point is that you can easily develop your own triangle reader to read
your data.
I have had very little success trying to format my data into the VTK
Unstructured Grid format
so that I can use the VTK Reader API.
 
Nick
-----Original Message-----
From: Patrick Schuska [mailto:schuska at dbi.udel.edu]
Sent: Wednesday, October 22, 2003 3:07 PM
To: 'Nick Ton'
Subject: AW: [vtkusers] reading triangles data


Hi Nick.
I think I have more problems with the file header. There is always the error
message..
. Generic Warning: In C:\martink\vtk42\VTK\IO\vtkDataReader.cxx, line 833
Error reading ascii data!
 
Can you send me one of your files, so that I can see how your file header
looks like...
 
 thanks..  :o)
 
Patrick
-----Ursprüngliche Nachricht-----
Von: Nick Ton [mailto:nton at photon.com] 
Gesendet: Dienstag, 21. Oktober 2003 13:26
An: 'Patrick Schuska'; vtkusers at vtk.org
Betreff: RE: [vtkusers] reading triangles data
 
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/20031022/225a0d31/attachment.htm>


More information about the vtkusers mailing list