[Insight-users] itk::Mesh and itk::QuadEdgeMesh converter
Gaëtan Lehmann
gaetan.lehmann at jouy.inra.fr
Fri Sep 9 12:44:21 EDT 2011
Le 9 sept. 11 à 18:12, Alexandre GOUAILLARD a écrit :
> hi,
>
> Yes, there is that weird type depency at runtime that is not easy as
> the poitn type is defined in the trait and you need both the mesh and
> the point to share this type. I remember now, sorry i couldn t help
> before.
>
> well, those vtk-itk bridges used to go into Insight Applications. I
> don t know where it should go now. maybe bill or luis can advise?
They should go in
Modules/Bridge/VtkGlue/
There is some code related to that in the wrapping directory also (it
should be moved in Modules/Bridge/VtkGlue/ too).
I'm not sure how well it works though.
Gaëtan
>
> alex.
>
>
> On Fri, Sep 9, 2011 at 11:01 PM, Gao, Yi <gaoyi.cn at gmail.com> wrote:
>> Hey Alex,
>>
>> I think it works now (maybe there is hidden problem in reserve
>> function but it seems not emerging in my case).
>>
>> The previous problem was that in (the mesh var below is a QE mesh)
>> mesh->SetPoint( p, QEMeshType::PointType( apoint ));
>>
>> the "apoint" is double[3]
>>
>> however, in my typedef of QEmesh, I did used:
>> typedef itk::QuadEdgeMesh< double, 3 > QEMeshType;
>>
>> But when it shows in the compiler error, it's
>> itk::QuadEdgeMeshPoint<float, 3u>.
>>
>> (in fact it's itk::QuadEdgeMeshPoint<float, 3u,
>> itk::GeometricalQuadEdge<long unsigned int, long unsigned int,
>> bool,bool, true> > )
>>
>> The solution I had was in the typedef for qemesh, I change it to:
>>
>> typedef itk::QuadEdgeMeshTraits<double, 3, double, double, double,
>> double > qetraits;
>> typedef itk::QuadEdgeMesh< vtkFloatingPointType, pointDimension,
>> qetraits > QEMeshType;
>>
>> This time it works!
>>
>> Do you think cleaning up the code and put it somewhere may help
>> others like me?
>>
>> Thanks for your help!
>>
>> Best,
>> yi
>>
>>
>>
>>
>> On Fri, Sep 9, 2011 at 10:52 AM, Alexandre GOUAILLARD
>> <agouaillard at gmail.com> wrote:
>>> yeah,
>>>
>>> the reserve function does not work well in QEMesh. It was reported
>>> by
>>> michel audette a couple of years back, but never addressed.
>>>
>>> I will give a try at your code over this week end.
>>>
>>> alex.
>>>
>>>
>>> On Fri, Sep 9, 2011 at 10:41 PM, Gao, Yi <gaoyi.cn at gmail.com> wrote:
>>>> Hi Alex and Arnaud,
>>>>
>>>> Here is the converter I used. It was the convert from vtkpolydata
>>>> to
>>>> itkMesh I got in 2006 (did I get this from you? Or download it
>>>> somewhere? Or I wrote it myself? I really forgot... ).
>>>>
>>>> I just change everything to QEmesh.
>>>>
>>>> Although I define qemesh <double, 3>, in the compilation error, i
>>>> get
>>>> its type as:
>>>> itk::QuadEdgeMeshPoint<float, 3u>. Then I can't use a double[3] to
>>>> init the point.
>>>>
>>>> (in fact it's itk::QuadEdgeMeshPoint<float, 3u,
>>>> itk::GeometricalQuadEdge<long unsigned int, long unsigned int,
>>>> bool,
>>>> bool, true> >::QuadEdgeMeshPoint(double [3])’)
>>>>
>>>> I could change everything I have to float, I will try that also.
>>>>
>>>>
>>>> Here is the converter function:
>>>>
>>>> typedef itk::QuadEdgeMesh< double, 3 > QEMeshType;
>>>>
>>>> QEMeshType::Pointer vtkPolyDataToITKQEMesh(
>>>> vtkSmartPointer<vtkPolyData> polyData)
>>>> {
>>>> /// Create a new mesh
>>>> QEMeshType::Pointer mesh = QEMeshType::New();
>>>>
>>>> /// Transfer the points from the vtkPolyData into the itk::Mesh
>>>> const unsigned int numberOfPoints = polyData-
>>>> >GetNumberOfPoints();
>>>>
>>>> vtkSmartPointer<vtkPoints> vtkpoints = polyData->GetPoints();
>>>>
>>>> mesh->GetPoints()->Reserve( numberOfPoints );
>>>>
>>>> {
>>>> double apoint[3];
>>>>
>>>> for(unsigned int p =0; p < numberOfPoints; p++)
>>>> {
>>>> vtkpoints->GetPoint( p, apoint );
>>>> mesh->SetPoint( p, QEMeshType::PointType( apoint ));
>>>> }
>>>> }
>>>>
>>>> /// Transfer the cells from the vtkPolyData into the itk::Mesh
>>>> vtkSmartPointer<vtkCellArray> triangleStrips = polyData-
>>>> >GetStrips();
>>>>
>>>>
>>>> vtkIdType* cellPoints;
>>>> vtkIdType numberOfCellPoints;
>>>>
>>>> /// First count the total number of triangles from all the
>>>> triangle strips.
>>>> unsigned int numberOfTriangles = 0;
>>>>
>>>> triangleStrips->InitTraversal();
>>>>
>>>> while( triangleStrips->GetNextCell( numberOfCellPoints,
>>>> cellPoints ) )
>>>> {
>>>> numberOfTriangles += numberOfCellPoints-2;
>>>> }
>>>>
>>>> vtkSmartPointer<vtkCellArray> polygons = polyData->GetPolys();
>>>>
>>>> polygons->InitTraversal();
>>>>
>>>> while( polygons->GetNextCell( numberOfCellPoints, cellPoints ) )
>>>> {
>>>> if( numberOfCellPoints == 3 )
>>>> {
>>>> numberOfTriangles ++;
>>>> }
>>>> }
>>>>
>>>>
>>>> /// Reserve memory in the itk::Mesh for all those triangles
>>>> mesh->GetCells()->Reserve( numberOfTriangles );
>>>>
>>>>
>>>> /// Copy the triangles from vtkPolyData into the itk::Mesh
>>>> typedef QEMeshType::CellType CellType;
>>>> typedef itk::TriangleCell< CellType > TriangleCellType;
>>>>
>>>> int cellId = 0;
>>>>
>>>> /// first copy the triangle strips
>>>> triangleStrips->InitTraversal();
>>>> while( triangleStrips->GetNextCell( numberOfCellPoints,
>>>> cellPoints ) )
>>>> {
>>>>
>>>> unsigned int numberOfTrianglesInStrip = numberOfCellPoints
>>>> - 2;
>>>>
>>>> unsigned long pointIds[3];
>>>> pointIds[0] = cellPoints[0];
>>>> pointIds[1] = cellPoints[1];
>>>> pointIds[2] = cellPoints[2];
>>>>
>>>> for( unsigned int t=0; t < numberOfTrianglesInStrip; t++ )
>>>> {
>>>> QEMeshType::CellAutoPointer c;
>>>> TriangleCellType * tcell = new TriangleCellType;
>>>> tcell->SetPointIds( pointIds );
>>>> c.TakeOwnership( tcell );
>>>> mesh->SetCell( cellId, c );
>>>> cellId++;
>>>> pointIds[0] = pointIds[1];
>>>> pointIds[1] = pointIds[2];
>>>> pointIds[2] = cellPoints[t+3];
>>>> }
>>>> }
>>>>
>>>> /// then copy the normal triangles
>>>> polygons->InitTraversal();
>>>> while( polygons->GetNextCell( numberOfCellPoints, cellPoints ) )
>>>> {
>>>> if( numberOfCellPoints !=3 ) // skip any non-triangle.
>>>> {
>>>> continue;
>>>> }
>>>> QEMeshType::CellAutoPointer c;
>>>> TriangleCellType * t = new TriangleCellType;
>>>> //t->SetPointIds( static_cast<unsigned long*>(cellPoints) );
>>>> t->SetPointIds( (unsigned long*)cellPoints );
>>>> c.TakeOwnership( t );
>>>> mesh->SetCell( cellId, c );
>>>> cellId++;
>>>> }
>>>>
>>>> return mesh;
>>>> }
>>>>
>>>> Thank you for any hint!
>>>>
>>>> Best,
>>>> yi
>>>>
>>>> On Fri, Sep 9, 2011 at 9:57 AM, Alexandre GOUAILLARD
>>>> <agouaillard at gmail.com> wrote:
>>>>> hum,
>>>>>
>>>>> what is you "converter" between polydata and itk:mesh?
>>>>> you shoudl be able to use the old vtkPolydatawriter templated
>>>>> over a QEMesh ...
>>>>>
>>>>> alex.
>>>>>
>>>>>
>>>>> On Fri, Sep 9, 2011 at 9:32 PM, Gao, Yi <gaoyi.cn at gmail.com>
>>>>> wrote:
>>>>>> Dear Alex,
>>>>>>
>>>>>> Thank you for the reply!
>>>>>>
>>>>>> I'm trying to use the smoothing filter Arnaud and you
>>>>>> contributed. The
>>>>>> triangles it gives are much better shaped than the vtk's
>>>>>> windowed sinc
>>>>>> filter!
>>>>>>
>>>>>> But my main pipeline is in VTK so in fact I want to convert from
>>>>>> vtkPolyData with QE mesh. Since I have converter between
>>>>>> vtkPolyData
>>>>>> <--> itk::Mesh, then the missing step is itk::Mesh <-->QE mesh.
>>>>>> That
>>>>>> is where the problem comes from. :)
>>>>>>
>>>>>> So I'll just get an itk::Mesh and feed it to the smoothing
>>>>>> filter for
>>>>>> QE mesh, I will try that out!
>>>>>>
>>>>>> Thanks again! :)
>>>>>>
>>>>>> Best,
>>>>>> yi
>>>>>>
>>>>>> On Fri, Sep 9, 2011 at 8:47 AM, Alexandre GOUAILLARD
>>>>>> <agouaillard at gmail.com> wrote:
>>>>>>> dear gao yi,
>>>>>>>
>>>>>>> an itk:QuadEdgeMesh is an itk:Mesh. You can pass the pointer
>>>>>>> to the
>>>>>>> itk:Pointset directly (sharing memory), then you can just make
>>>>>>> one
>>>>>>> loop on the cell container (and equivalent data) to feed your
>>>>>>> itk:Mesh
>>>>>>> with the cells. There is a little bit of magic to do as the
>>>>>>> cells
>>>>>>> types are a little bit different but nothing fancy. Namely, in a
>>>>>>> QEMesh cells are polygons and do not differentiate from
>>>>>>> triangles,
>>>>>>> quads or others. In your case, if you know it s triangular,
>>>>>>> then it s
>>>>>>> easier.
>>>>>>>
>>>>>>> Any reason you want to change it to itk:Mesh by the way?
>>>>>>> QEMesh API is
>>>>>>> supposedly 100% compatible with Mesh, so if there is a
>>>>>>> limitation,
>>>>>>> please let me know.
>>>>>>>
>>>>>>> What is your specific problem? If you re at miccai, we can
>>>>>>> take a look
>>>>>>> at it together, otherwise I can give a hand by e-mail.
>>>>>>>
>>>>>>> alex.
>>>>>>>
>>>>>>>
>>>>>>> On Fri, Sep 9, 2011 at 8:29 PM, Gao, Yi <gaoyi.cn at gmail.com>
>>>>>>> wrote:
>>>>>>>> Dear list,
>>>>>>>>
>>>>>>>> I'm trying to convert a triangular 2D mesh (all in memory,
>>>>>>>> not in
>>>>>>>> file) from itk::QuadEdgeMesh to itk::Mesh (or to VTK polydata).
>>>>>>>>
>>>>>>>> The itkVTKPolyDataReader and writer can do this... but I will
>>>>>>>> need to
>>>>>>>> write to file and then load, which does seem to be the optimal
>>>>>>>> solution. :)
>>>>>>>>
>>>>>>>> I googled but didn't find such a solution, could I get any
>>>>>>>> hint?
>>>>>>>>
>>>>>>>> Thank you in advance for the help!
>>>>>>>>
>>>>>>>> Best,
>>>>>>>> yi
>>>>>>>> _____________________________________
>>>>>>>> Powered by www.kitware.com
>>>>>>>>
>>>>>>>> Visit other Kitware open-source projects at
>>>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>>>
>>>>>>>> Kitware offers ITK Training Courses, for more information
>>>>>>>> visit:
>>>>>>>> http://www.kitware.com/products/protraining.html
>>>>>>>>
>>>>>>>> Please keep messages on-topic and check the ITK FAQ at:
>>>>>>>> http://www.itk.org/Wiki/ITK_FAQ
>>>>>>>>
>>>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>>>> http://www.itk.org/mailman/listinfo/insight-users
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
--
Gaëtan Lehmann
Biologie du Développement et de la Reproduction
INRA de Jouy-en-Josas (France)
tel: +33 1 34 65 29 66 fax: 01 34 65 29 09
http://mima2.jouy.inra.fr http://www.itk.org
http://www.bepo.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 203 bytes
Desc: Ceci est une signature ?lectronique PGP
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110909/fb030f63/attachment.pgp>
More information about the Insight-users
mailing list