Fw: [vtkusers] Closing 3d surfaces...
Luca Antiga
lucantiga at hotmail.com
Fri May 3 09:51:53 EDT 2002
Hi everyone,
please take a look to the following code: it should solve your problems.
PS: maybe the style is not perfect and the code is not extremely efficient,
but there's no limit to improvement :-) Watch out for memory leaks!
void FindBoundaryIds(vtkPolyData* model, vtkCollection* boundaries)
{
model->BuildLinks();
model->Update();
vtkIdList* boundaryIds = vtkIdList::New();
vtkIdList* cellEdgeNeighbors = vtkIdList::New();
vtkTriangle* triangle;
int i, j;
for (i=0; i<model->GetNumberOfCells(); i++)
{
triangle = (vtkTriangle*)model->GetCell(i);
for (j=0; j<3; j++)
{
cellEdgeNeighbors->Initialize();
model->GetCellEdgeNeighbors(i,triangle->GetEdge(j)->GetPointIds()->GetId(0),triangle->GetEdge(j)->GetPointIds()->GetId(1),cellEdgeNeighbors);
if (cellEdgeNeighbors->GetNumberOfIds()==0)
{
boundaryIds->InsertUniqueId(triangle->GetEdge(j)->GetPointIds()->GetId(0));
boundaryIds->InsertUniqueId(triangle->GetEdge(j)->GetPointIds()->GetId(1));
}
}
}
bool foundAny = false, foundNeighbor = false, done = false;
int currentId = -1;
vtkIdList* boundary = vtkIdList::New();
while (!done)
{
foundAny = false;
foundNeighbor = false;
for (i=0; i<boundaryIds->GetNumberOfIds(); i++)
{
if (boundaryIds->GetId(i)!=-1)
{
foundAny = true;
if (currentId==-1)
{
foundNeighbor = true;
currentId = boundaryIds->GetId(i);
boundary->InsertNextId(currentId);
boundaryIds->SetId(i,-1);
break;
}
else
{
if (model->IsEdge(currentId,boundaryIds->GetId(i)))
{
foundNeighbor = true;
currentId = boundaryIds->GetId(i);
boundary->InsertNextId(currentId);
boundaryIds->SetId(i,-1);
break;
}
}
}
}
if (((!foundNeighbor)&&(foundAny))||(!foundAny))
{
vtkIdList* boundaryToCollection = vtkIdList::New();
boundaryToCollection->DeepCopy(boundary);
boundaries->AddItem(boundaryToCollection);
currentId = -1;
boundary->Initialize();
}
if (!foundAny)
done = true;
}
}
Hope this helps.
Luca
---
Luca Antiga, Eng.D.
Bioengineering Department, Mario Negri Institute
Clinical Research Center for Rare Diseases "Aldo e Cele Dacco'",
Villa Camozzi, Ranica (BG), Italy
>From: "alexandre gouaillard" <alexandre.gouaillard at insa-lyon.fr>
>To: <vtkusers at public.kitware.com>, "Michal Chlebiej"
><mchlebie at ajax.umcs.lublin.pl>
>CC: <bdelhay at ge-serveur.insa-lyon.fr>
>Subject: Fw: [vtkusers] Closing 3d surfaces...
>Date: Mon, 1 May 2000 17:57:29 +0200
>
>
>
> > dear michal and dear all,
> >
> > We are curently working on a similar problem.
> > We have found a quite easy solution for one hole, but it doesn't work
>when
> > you have multiple holes.
> > Please find along the corresponding code, implemented as a VTK class
> > (VtkCloseMesh).
> > vtkCloseMesh.* are the main files
> > vtkCloseMeshTCL_INIT.cxx is for TCL wrapping
> > and the .dsp files are for compiling with MSVC++
> >
> > Here is the method under "heavy" :-) investigation right now which
>should
> > lead to the multiple holes' closing:
> >
> > * find edge through VtkFeatureEdge class,
> > * separate holes (method is still to find , we are thinking about using
>the
> > vtkConnectivityFilter somehow, but it would mean we are first able to
>join
> > all the points corresponding to one specific edge)
> > * apply the allready existing method (implemented in our vtkCloseMesh)
>to
> > close each hole one by one.
> >
> > If someone allready implemented a working solution to this problem, or
>if
> > someone go any idea about another vtk class that could be used in a
>smart
> > way here, please contact either Bertrand Delhay
> > (bdelhay at ge-serveur.insa-lyon.fr) who is responsible for this point in
>the
> > team, or myself.
> >
> > regards,
> >
> > alex. gouaillard, for the "WaveMesh" graduation project's team
> >
> >
> > ----- Original Message -----
> > From: "Michal Chlebiej" <mchlebie at ajax.umcs.lublin.pl>
> > To: <vtkusers at public.kitware.com>
> > Sent: Tuesday, April 30, 2002 11:40 AM
> > Subject: [vtkusers] Closing 3d surfaces...
> >
> >
> > > Hi all
> > >
> > > I've generated surface with MC algorithm. The I've preformed some
>cutting
> > > (clippolydata with plane) operations so I've created a polydata with
> > > holes. In vtk it's possible to extract edges but is it possible to
> > > triangulate them???
> > >
> > > I have to close the edges to affirm if some points are situated
> > > inside/outside the surface...
> > >
> > > please help
> > >
> > > regards
> > >
> > > Meow
> > >
> > >
> > > _______________________________________________
> > > This is the private VTK discussion list.
> > > Please keep messages on-topic. Check the FAQ at:
> > <http://public.kitware.com/cgi-bin/vtkfaq>
> > > Follow this link to subscribe/unsubscribe:
> > > http://public.kitware.com/mailman/listinfo/vtkusers
> >
><< vtkCloseMesh.h >>
><< vtkCloseMesh.cxx >>
><< vtkCloseMeshTCL_INIT.cxx >>
><< vtkClosemeshTCL.dsp >>
><< vtkCloseMesh.dsp >>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
More information about the vtkusers
mailing list