<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi deras vtkusers,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>i would like to read a mesh file (points
coordinates and mesh caracteristics) and then draw it under a simple SDI MFC
</FONT></DIV>
<DIV><FONT face=Arial size=2>application.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>So my idea was the following :</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>read the mesh file, and use the vtk Mesh structure
to save data.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Mesh *m_pMaillage3D;</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>then here is the code of the function
which read the mesh file :</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>int CvtkMaillage::ReadMesh(char
*nom_fichier){<BR> FILE *ft;<BR> long i,nb_elt_cot;<BR> char
buffer[256];<BR> int dim_noe, dim_elt,nb_elt;<BR> long
fin;<BR> int nb_car_lu2=0;<BR> int n1,n2,n3,n4;<BR> vtkIdType Id,
nb_pts_cell;<BR> vtkIdType *IdList;<BR> vtkTetra* Element_Courant =
vtkTetra::New();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if((ft=fopen(nom_fichier,"r"))!=NULL)
{</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2> fgets(buffer,256,ft);<BR> sscanf(buffer,"%d %d %d
%d", &this->m_pMaillage3D->vertices, &dim_noe,
&this->m_pMaillage3D->faces, &dim_elt) ;<BR> nb_elt_cot =
this->m_pMaillage3D->faces;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> //Initialisation du tableau des
points<BR> this->m_pMaillage3D->vertex = new
Vector[this->m_pMaillage3D->vertices];<BR>
<BR> //Tableau de connectivité des
éléments<BR> this->m_pMaillage3D->aCellArray =
vtkCellArray::New();<BR> <BR>
<BR> for(i = 0 ; i<this->m_pMaillage3D->vertices ;
i++) {<BR>
fgets(buffer,256,ft);<BR>
traitement_texte_reel(buffer);<BR>
sscanf(buffer,"%lf %lf
%lf",&(this->m_pMaillage3D->vertex[i][0]),&(this->m_pMaillage3D->vertex[i][1]),&(this->m_pMaillage3D->vertex[i][2]));<BR>
} <BR>
<BR> Element_Courant->PointIds->Initialize();<BR> Element_Courant->PointIds->Allocate(4);<BR>
<BR> fin = - 1;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> for(i=0;i<nb_elt_cot;i++)
{<BR>
fgets(buffer,256,ft);<BR> sscanf(buffer,"%d %d %d
%d",&n1,&n2,&n3,&n4);<BR>
Element_Courant->PointIds->InsertId(0, n1);<BR>
Element_Courant->PointIds->InsertId(1, n2);<BR>
Element_Courant->PointIds->InsertId(2, n3);<BR>
Element_Courant->PointIds->InsertId(3,
n4);<BR> <BR> Id =
this->m_pMaillage3D->aCellArray->InsertNextCell(Element_Courant); <BR>
/*maillage3D.topologie.tab_typeelt[i]=1;*/<BR>
if(fin==-1 && n4==0) <BR> fin=i;<BR>
}<BR> <BR> if(fin!=-1)
{<BR>
nb_elt=fin;<BR>
this->m_pMaillage3D->faces=nb_elt_cot-fin;<BR>
this->m_pMaillage3D->face = new
Face[this->m_pMaillage3D->faces];<BR> for(i
= 0 ; i < this->m_pMaillage3D->faces; i++)
{<BR> this->m_pMaillage3D->aCellArray->GetCell(fin + i,
nb_pts_cell, IdList);<BR> this->m_pMaillage3D->face[i].a =
IdList[0];<BR> this->m_pMaillage3D->face[i].b =
IdList[1];<BR> this->m_pMaillage3D->face[i].c =
IdList[2];<BR> //free(maillage3D.topologie.tab_elt[fin+i]);<BR>
}<BR> <BR>
}<BR> else {<BR>
nb_elt=nb_elt_cot;<BR> }<BR> <BR>
fclose(ft);<BR> return 1;<BR> }<BR> return
0;<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>as you can see, i first save number of
vertices and number of faces. Then i first use </FONT> <FONT
face=Arial size=2>m_pMaillage3D->vertex to save points coordinates. Then i
use m_pMaillage3D->aCellArray to save elements connectivity of the mesh and
m_pMaillage3D->face to save face.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>When I saved this data, i build a vtkActor using a
vtk3DSImporter. I generate PolyData using vtk3DSImporter::GeneratePolyData. Then
i build the actor as usual in vtk.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>But now mesh cant be drawn although i call a
CView::OnPaint overroden method which call the vtkRenderer. Could you tell me if
the data structures and the general idea to save my mesh in VTK is good ? How
could I do better this method ?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>This project cant demonstrate my company that VTK
is a useful library :)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Thanks a lot,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Frederic</FONT></DIV></BODY></HTML>