[From nobody Thu Jan 29 12:05:14 2009
Message-ID: &lt;49819E07.2060302@doc.ic.ac.uk&gt;
Date: Thu, 29 Jan 2009 12:16:07 +0000
From: Fabian Wanner &lt;fpw05@doc.ic.ac.uk&gt;
User-Agent: Thunderbird 2.0.0.16 (X11/20080724)
MIME-Version: 1.0
To: nourmestiri@yahoo.fr
Subject: Re: [vtkusers] Conversion from VRML into VTK format
References: &lt;786021.66055.qm@web28210.mail.ukl.yahoo.com&gt;
In-Reply-To: &lt;786021.66055.qm@web28210.mail.ukl.yahoo.com&gt;
Content-Type: multipart/alternative;
	boundary=&quot;------------080807000101020102030607&quot;

This is a multi-part message in MIME format.
--------------080807000101020102030607
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hey,

I don't have my code on me right now, but I am sure that I am not using 
a GeometryFilter at all.

Instead I am going directly from the vtkDataSet to the vtkPolyData.

It should look similar to this.

vtkPolyData *polyData = vtkPolyData::SafeDownCast(pDataset);

I changed parts in your code, which I think are wrong (written in red).

1. If you set the Header you also have to write it. This has to be done 
before inserting the line *vtkFile &lt;&lt; &quot;DATASET POLYDATA\n&quot;;

2. You problably also want to write the points, so I added that line.

vtkVRMLImporter *imp = vtkVRMLImporter::New();
imp-&gt;SetFileName(Fichier);
imp-&gt;Read();
imp-&gt;Update();
vtkDataSet *pDataset;
vtkActorCollection *actors = imp-&gt;GetRenderer()-&gt;GetActors();
actors-&gt;InitTraversal();
pDataset = actors-&gt;GetNextActor()-&gt;GetMapper()-&gt;GetInput();
 
vtkPolyData *polyData = vtkPolyData::SafeDownCast(pDataset);
polyData-&gt;Update();
 
vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
strcat(vrmlFileName,&quot;.vtk&quot;);
writer-&gt;SetFileName(vrmlFileName);
writer-&gt;SetFileTypeToASCII();
 
ostream *vtkFile = writer-&gt;OpenVTKFile();
writer-&gt;SetHeader(&quot;vtkFile&quot;);
writer-&gt;WriteHeader(vtkFile);
*vtkFile &lt;&lt; &quot;DATASET POLYDATA\n&quot;;
writer-&gt;WritePoints(vtkFile, polyData-&gt;GetPoints());
writer-&gt;WriteCells(vtkFile, polyData-&gt;GetPolys(), &quot;POLYGONS&quot;);
writer-&gt;CloseVTKFile(vtkFile);

Hope this works now
Fabian


Nour Mestiri wrote:
&gt; Hey Fabian,
&gt; Thank you one more time for your helpful answer.
&gt; I did what you told me, but i always have problems. I post you my new 
&gt; code and please try to tell me what is wrong on it.
&gt; Can you also telle me how to use the &quot;SafeDownCast&quot; method for the 
&gt; &quot;GeometryFilter&quot;?
&gt;  
&gt; vtkVRMLImporter *imp = vtkVRMLImporter::New();
&gt; imp-&gt;SetFileName(Fichier);
&gt; imp-&gt;Read();
&gt; imp-&gt;Update();
&gt; vtkDataSet *pDataset;
&gt; vtkActorCollection *actors = imp-&gt;GetRenderer()-&gt;GetActors();
&gt; actors-&gt;InitTraversal();
&gt; pDataset = actors-&gt;GetNextActor()-&gt;GetMapper()-&gt;GetInput();
&gt;  
&gt; vtkGeometryFilter *geometryFilter = vtkGeometryFilter::New();
&gt; geometryFilter-&gt;SetInput(pDataset);
&gt;    
&gt; vtkPolyData *polyData = vtkPolyData::New();
&gt; polyData = geometryFilter-&gt;GetOutput();
&gt; polyData-&gt;Update();
&gt;  
&gt; vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
&gt; strcat(vrmlFileName,&quot;.vtk&quot;);
&gt; writer-&gt;SetFileName(vrmlFileName);
&gt; writer-&gt;SetFileTypeToASCII();
&gt;  
&gt; ostream *vtkFile = writer-&gt;OpenVTKFile();
&gt; *vtkFile &lt;&lt; &quot;DATASET POLYDATA\n&quot;;
&gt; writer-&gt;SetHeader(&quot;vtkFile&quot;);
&gt; writer-&gt;WriteCells(vtkFile, polyData-&gt;GetPolys(), &quot;POLYGONS&quot;);
&gt; writer-&gt;CloseVTKFile(vtkFile);
&gt;  
&gt; Thank you sooo much
&gt;
&gt; --- En date de : *Jeu 22.1.09, Fabian Wanner /&lt;fpw05@doc.ic.ac.uk&gt;/* a 
&gt; écrit :
&gt;
&gt;     De: Fabian Wanner &lt;fpw05@doc.ic.ac.uk&gt;
&gt;     Objet: Re: [vtkusers] Conversion from VRML into VTK format
&gt;     À: nourmestiri@yahoo.fr
&gt;     Cc: &quot;vtk&quot; &lt;vtkusers@vtk.org&gt;
&gt;     Date: Jeudi 22 Janvier 2009, 20h50
&gt;
&gt;     Hello Nour,
&gt;
&gt;     the main part of your code is exactly the same as mine, but there are a few
&gt;     differences.
&gt;
&gt;     1. I had problems with the vtkGeometryFilter, so instead of doing that I used
&gt;     the static SafeDownCast method of the vtkPolyData and passed in the vtkDataSet.
&gt;
&gt;     2. You are writing the PointData, which is only the texture information. If you
&gt;     want to write the actual coordinates, you should do something like this:
&gt;     writer-&gt;WritePoints(vtkFile, polyData1-&gt;GetPoints());
&gt;
&gt;     For writing the polygon or line information use something similar to this:
&gt;     writer-&gt;WriteCells(vtkFile, polyData1-&gt;GetPolys(), &quot;POLYGONS&quot;);
&gt;     The label has to be the one mentioned on this website
&gt;     http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html
&gt;     &lt;http://www.cacr.caltech.edu/%7Eslombey/asci/vtk/vtk_formats.simple.html&gt;
&gt;     under DataSet Format -&gt; Polygonal Data
&gt;
&gt;     3. Unfortunately the line &quot;DATASET POLYDATA&quot; is not written by the
&gt;     vtkPolyDataWriter. After writing the header you should add the line (this took
&gt;     me a long time to find out):
&gt;     *vtkFile &lt;&lt; &quot;DATASET POLYDATA\n&quot;;
&gt;     This is necessary for the vtkReader to understand what type of data can be
&gt;     found in the file.
&gt;
&gt;     I didn't test anything I mentioned here, but this is how it works for me,
&gt;     so I hope it does for you as well. Please let me know if there are any problems.
&gt;     Fabian
&gt;
&gt;
&gt;     Nour Mestiri wrote:
&gt;     &gt; Hi all vtk users,
&gt;     &gt; I have a VRML file and i want  to convert it into VTK files. I found a
&gt;     code but i have some problems with it :
&gt;     &gt;  vtkVRMLImporter *imp1 = vtkVRMLImporter::New();
&gt;     &gt; imp1-&gt;SetFileName(&quot;C:/vrmlFile&quot;);
&gt;     &gt; imp1-&gt;Read();
&gt;     &gt; imp1-&gt;Update();
&gt;     &gt;  vtkDataSet *pDataset1;
&gt;     &gt; vtkActorCollection *actors1 = imp1-&gt;GetRenderer()-&gt;GetActors();
&gt;     &gt; actors1-&gt;InitTraversal();
&gt;     &gt; pDataset1 = actors1-&gt;GetNextActor()-&gt;GetMapper()-&gt;GetInput();
&gt;     &gt;    vtkGeometryFilter *geometryFilter1 = vtkGeometryFilter::New();
&gt;     &gt; geometryFilter1-&gt;SetInput(pDataset1);
&gt;     &gt;    vtkPolyData *polyData1 = vtkPolyData::New();
&gt;     &gt; polyData1 = geometryFilter1-&gt;GetOutput();
&gt;     &gt; polyData1-&gt;Update();
&gt;     &gt;  vtkDataSetWriter *writer1 = vtkDataSetWriter::New();
&gt;     &gt; writer1-&gt;SetInput(polyData1);
&gt;     &gt; writer1-&gt;SetFileName(OutputFile);
&gt;     &gt; writer1-&gt;SetFileTypeToASCII();
&gt;     &gt;    ostream *vtkFile1 = writer1-&gt;OpenVTKFile();
&gt;     &gt; writer1-&gt;WriteHeader(vtkFile);
&gt;     &gt; writer1-&gt;WritePointData(vtkFile, pDataset1);
&gt;     &gt; writer1-&gt;CloseVTKFile(vtkFile);
&gt;     &gt;  Can you tell me if that code makes the conversion from VRML to VTK
&gt;     format?
&gt;     &gt; If yes, can you specify me the extensions to add for
&gt;     &quot;OutputFile&quot; and &quot;vtkFile&quot;?
&gt;     &gt;  Thank you sooooo much for your help.
&gt;     &gt; 
&gt;     &gt; 
&gt;     &gt; ------------------------------------------------------------------------
&gt;     &gt; 
&gt;     &gt; _______________________________________________
&gt;     &gt; This is the private VTK discussion list.
&gt;     &gt; Please keep messages on-topic. Check the FAQ at:
&gt;     http://www.vtk.org/Wiki/VTK_FAQ
&gt;     &gt; Follow this link to subscribe/unsubscribe:
&gt;     &gt; http://www.vtk.org/mailman/listinfo/vtkusers
&gt;     &gt;   
&gt;
&gt;               
&gt;
&gt;


--------------080807000101020102030607
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;meta content=&quot;text/html;charset=UTF-8&quot; http-equiv=&quot;Content-Type&quot;&gt;
  &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body bgcolor=&quot;#ffffff&quot; text=&quot;#000000&quot;&gt;
Hey,&lt;br&gt;
&lt;br&gt;
I don't have my code on me right now, but I am sure that I am not using
a GeometryFilter at all.&lt;br&gt;
&lt;br&gt;
Instead I am going directly from the vtkDataSet to the vtkPolyData.&lt;br&gt;
&lt;br&gt;
It should look similar to this.&lt;br&gt;
&lt;br&gt;
vtkPolyData *polyData = vtkPolyData::SafeDownCast(pDataset);&lt;br&gt;
&lt;br&gt;
I changed parts in your code, which I think are wrong (written in red).&lt;br&gt;
&lt;br&gt;
1. If you set the Header you also have to write it. This has to be done
before inserting the line *vtkFile &amp;lt;&amp;lt; &quot;DATASET POLYDATA\n&quot;;&lt;br&gt;
&lt;br&gt;
2. You problably also want to write the points, so I added that line.&lt;br&gt;
&lt;br&gt;
&lt;div&gt;vtkVRMLImporter *imp = vtkVRMLImporter::New();&lt;br&gt;
imp-&amp;gt;SetFileName(Fichier);&lt;br&gt;
imp-&amp;gt;Read();&lt;br&gt;
imp-&amp;gt;Update();&lt;br&gt;
&lt;/div&gt;
&lt;div&gt;vtkDataSet *pDataset;&lt;br&gt;
vtkActorCollection *actors = imp-&amp;gt;GetRenderer()-&amp;gt;GetActors();&lt;br&gt;
actors-&amp;gt;InitTraversal();&lt;br&gt;
pDataset = actors-&amp;gt;GetNextActor()-&amp;gt;GetMapper()-&amp;gt;GetInput();&lt;br&gt;
 &lt;br&gt;
&lt;font color=&quot;#ff0000&quot;&gt;vtkPolyData *polyData =
vtkPolyData::SafeDownCast(pDataset);&lt;/font&gt;&lt;br&gt;
polyData-&amp;gt;Update();&lt;br&gt;
 &lt;br&gt;
vtkPolyDataWriter *writer = vtkPolyDataWriter::New();&lt;br&gt;
strcat(vrmlFileName,&quot;.vtk&quot;);&lt;br&gt;
writer-&amp;gt;SetFileName(vrmlFileName);&lt;br&gt;
writer-&amp;gt;SetFileTypeToASCII();&lt;br&gt;
 &lt;br&gt;
ostream *vtkFile = writer-&amp;gt;OpenVTKFile();&lt;br&gt;
&lt;font color=&quot;#ff0000&quot;&gt;writer-&amp;gt;SetHeader(&quot;vtkFile&quot;);&lt;br&gt;
&lt;/font&gt;&lt;font color=&quot;#ff0000&quot;&gt;writer-&amp;gt;WriteHeader(vtkFile);&lt;/font&gt;&lt;br&gt;
*vtkFile &amp;lt;&amp;lt; &quot;DATASET POLYDATA\n&quot;;&lt;font color=&quot;#ff0000&quot;&gt;&lt;br&gt;
writer-&amp;gt;WritePoints(vtkFile, polyData-&amp;gt;GetPoints());&lt;br&gt;
&lt;/font&gt;writer-&amp;gt;WriteCells(vtkFile, polyData-&amp;gt;GetPolys(),
&quot;POLYGONS&quot;);&lt;br&gt;
writer-&amp;gt;CloseVTKFile(vtkFile);&lt;br&gt;
&lt;br&gt;
Hope this works now&lt;br&gt;
Fabian&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
Nour Mestiri wrote:
&lt;blockquote cite=&quot;mid:786021.66055.qm@web28210.mail.ukl.yahoo.com&quot;
 type=&quot;cite&quot;&gt;
  &lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;
    &lt;tbody&gt;
      &lt;tr&gt;
        &lt;td
 style=&quot;font-family: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-size: inherit; line-height: inherit; font-size-adjust: inherit; font-stretch: inherit;&quot;
 valign=&quot;top&quot;&gt;
        &lt;div&gt;Hey Fabian,&lt;/div&gt;
        &lt;div&gt;Thank you one more time for your helpful answer.&lt;/div&gt;
        &lt;div&gt;I did what you told me, but i always have problems. I post
you my new code and please try to tell me what is wrong on it.&lt;/div&gt;
        &lt;div&gt;Can you also telle me how to use the &quot;SafeDownCast&quot; method
for the &quot;GeometryFilter&quot;?&lt;/div&gt;
        &lt;div&gt; &lt;/div&gt;
        &lt;div&gt;vtkVRMLImporter *imp = vtkVRMLImporter::New();&lt;br&gt;
imp-&amp;gt;SetFileName(Fichier);&lt;br&gt;
imp-&amp;gt;Read();&lt;br&gt;
imp-&amp;gt;Update();&lt;br&gt;
        &lt;/div&gt;
        &lt;div&gt;vtkDataSet *pDataset;&lt;br&gt;
vtkActorCollection *actors = imp-&amp;gt;GetRenderer()-&amp;gt;GetActors();&lt;br&gt;
actors-&amp;gt;InitTraversal();&lt;br&gt;
pDataset = actors-&amp;gt;GetNextActor()-&amp;gt;GetMapper()-&amp;gt;GetInput();&lt;br&gt;
 &lt;br&gt;
vtkGeometryFilter *geometryFilter = vtkGeometryFilter::New();&lt;br&gt;
geometryFilter-&amp;gt;SetInput(pDataset);&lt;br&gt;
    &lt;br&gt;
vtkPolyData *polyData = vtkPolyData::New();&lt;br&gt;
polyData = geometryFilter-&amp;gt;GetOutput();&lt;br&gt;
polyData-&amp;gt;Update();&lt;br&gt;
 &lt;br&gt;
vtkPolyDataWriter *writer = vtkPolyDataWriter::New();&lt;br&gt;
strcat(vrmlFileName,&quot;.vtk&quot;);&lt;br&gt;
writer-&amp;gt;SetFileName(vrmlFileName);&lt;br&gt;
writer-&amp;gt;SetFileTypeToASCII();&lt;br&gt;
 &lt;br&gt;
ostream *vtkFile = writer-&amp;gt;OpenVTKFile();&lt;br&gt;
*vtkFile &amp;lt;&amp;lt; &quot;DATASET POLYDATA\n&quot;;&lt;br&gt;
writer-&amp;gt;SetHeader(&quot;vtkFile&quot;);&lt;br&gt;
writer-&amp;gt;WriteCells(vtkFile, polyData-&amp;gt;GetPolys(), &quot;POLYGONS&quot;);&lt;br&gt;
writer-&amp;gt;CloseVTKFile(vtkFile);&lt;/div&gt;
        &lt;div&gt; &lt;/div&gt;
        &lt;div&gt;Thank you sooo much&lt;br&gt;
        &lt;br&gt;
--- En date de : &lt;b&gt;Jeu 22.1.09, Fabian Wanner &lt;i&gt;&lt;a class=&quot;moz-txt-link-rfc2396E&quot; href=&quot;mailto:fpw05@doc.ic.ac.uk&quot;&gt;&amp;lt;fpw05@doc.ic.ac.uk&amp;gt;&lt;/a&gt;&lt;/i&gt;&lt;/b&gt;
a écrit :&lt;br&gt;
        &lt;/div&gt;
        &lt;blockquote
 style=&quot;border-left: 2px solid rgb(16, 16, 255); padding-left: 5px; margin-left: 5px;&quot;&gt;De:
Fabian Wanner &lt;a class=&quot;moz-txt-link-rfc2396E&quot; href=&quot;mailto:fpw05@doc.ic.ac.uk&quot;&gt;&amp;lt;fpw05@doc.ic.ac.uk&amp;gt;&lt;/a&gt;&lt;br&gt;
Objet: Re: [vtkusers] Conversion from VRML into VTK format&lt;br&gt;
À: &lt;a class=&quot;moz-txt-link-abbreviated&quot; href=&quot;mailto:nourmestiri@yahoo.fr&quot;&gt;nourmestiri@yahoo.fr&lt;/a&gt;&lt;br&gt;
Cc: &quot;vtk&quot; &lt;a class=&quot;moz-txt-link-rfc2396E&quot; href=&quot;mailto:vtkusers@vtk.org&quot;&gt;&amp;lt;vtkusers@vtk.org&amp;gt;&lt;/a&gt;&lt;br&gt;
Date: Jeudi 22 Janvier 2009, 20h50&lt;br&gt;
          &lt;br&gt;
          &lt;pre&gt;Hello Nour,

the main part of your code is exactly the same as mine, but there are a few
differences.

1. I had problems with the vtkGeometryFilter, so instead of doing that I used
the static SafeDownCast method of the vtkPolyData and passed in the vtkDataSet.

2. You are writing the PointData, which is only the texture information. If you
want to write the actual coordinates, you should do something like this:
writer-&amp;gt;WritePoints(vtkFile, polyData1-&amp;gt;GetPoints());

For writing the polygon or line information use something similar to this:
writer-&amp;gt;WriteCells(vtkFile, polyData1-&amp;gt;GetPolys(), &quot;POLYGONS&quot;);
The label has to be the one mentioned on this website
&lt;a class=&quot;moz-txt-link-freetext&quot; href=&quot;http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html&quot;&gt;http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html&lt;/a&gt;
&lt;a class=&quot;moz-txt-link-rfc2396E&quot; href=&quot;http://www.cacr.caltech.edu/%7Eslombey/asci/vtk/vtk_formats.simple.html&quot;&gt;&amp;lt;http://www.cacr.caltech.edu/%7Eslombey/asci/vtk/vtk_formats.simple.html&amp;gt;&lt;/a&gt;
under DataSet Format -&amp;gt; Polygonal Data

3. Unfortunately the line &quot;DATASET POLYDATA&quot; is not written by the
vtkPolyDataWriter. After writing the header you should add the line (this took
me a long time to find out):
*vtkFile &amp;lt;&amp;lt; &quot;DATASET POLYDATA\n&quot;;
This is necessary for the vtkReader to understand what type of data can be
found in the file.

I didn't test anything I mentioned here, but this is how it works for me,
so I hope it does for you as well. Please let me know if there are any problems.
Fabian


Nour Mestiri wrote:
&amp;gt; Hi all vtk users,
&amp;gt; I have a VRML file and i want  to convert it into VTK files. I found a
code but i have some problems with it :
&amp;gt;  vtkVRMLImporter *imp1 = vtkVRMLImporter::New();
&amp;gt; imp1-&amp;gt;SetFileName(&quot;C:/vrmlFile&quot;);
&amp;gt; imp1-&amp;gt;Read();
&amp;gt; imp1-&amp;gt;Update();
&amp;gt;  vtkDataSet *pDataset1;
&amp;gt; vtkActorCollection *actors1 = imp1-&amp;gt;GetRenderer()-&amp;gt;GetActors();
&amp;gt; actors1-&amp;gt;InitTraversal();
&amp;gt; pDataset1 = actors1-&amp;gt;GetNextActor()-&amp;gt;GetMapper()-&amp;gt;GetInput();
&amp;gt;    vtkGeometryFilter *geometryFilter1 = vtkGeometryFilter::New();
&amp;gt; geometryFilter1-&amp;gt;SetInput(pDataset1);
&amp;gt;    vtkPolyData *polyData1 = vtkPolyData::New();
&amp;gt; polyData1 = geometryFilter1-&amp;gt;GetOutput();
&amp;gt; polyData1-&amp;gt;Update();
&amp;gt;  vtkDataSetWriter *writer1 = vtkDataSetWriter::New();
&amp;gt; writer1-&amp;gt;SetInput(polyData1);
&amp;gt; writer1-&amp;gt;SetFileName(OutputFile);
&amp;gt; writer1-&amp;gt;SetFileTypeToASCII();
&amp;gt;    ostream *vtkFile1 = writer1-&amp;gt;OpenVTKFile();
&amp;gt; writer1-&amp;gt;WriteHeader(vtkFile);
&amp;gt; writer1-&amp;gt;WritePointData(vtkFile, pDataset1);
&amp;gt; writer1-&amp;gt;CloseVTKFile(vtkFile);
&amp;gt;  Can you tell me if that code makes the conversion from VRML to VTK
format?
&amp;gt; If yes, can you specify me the extensions to add for
&quot;OutputFile&quot; and &quot;vtkFile&quot;?
&amp;gt;  Thank you sooooo much for your help.
&amp;gt; 
&amp;gt; 
&amp;gt; ------------------------------------------------------------------------
&amp;gt; 
&amp;gt; _______________________________________________
&amp;gt; This is the private VTK discussion list.
&amp;gt; Please keep messages on-topic. Check the FAQ at:
&lt;a class=&quot;moz-txt-link-freetext&quot; href=&quot;http://www.vtk.org/Wiki/VTK_FAQ&quot;&gt;http://www.vtk.org/Wiki/VTK_FAQ&lt;/a&gt;
&amp;gt; Follow this link to subscribe/unsubscribe:
&amp;gt; &lt;a class=&quot;moz-txt-link-freetext&quot; href=&quot;http://www.vtk.org/mailman/listinfo/vtkusers&quot;&gt;http://www.vtk.org/mailman/listinfo/vtkusers&lt;/a&gt;
&amp;gt;   

          &lt;/pre&gt;
        &lt;/blockquote&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;br&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;/body&gt;
&lt;/html&gt;

--------------080807000101020102030607--

]
