[vtkusers] OK so does ANYONE use the vtkImageTracerWidget?
dean.inglis at camris.ca
dean.inglis at camris.ca
Tue Nov 6 13:06:47 EST 2007
okay, here is a bit more... to set up the
vtkcontourWidget to work with a vtkImageActor:
vtkOrientedGlyphContourRepresentation* contourRep= vtkOrientedGlyphContourRepresentation::New();
vtkContourWidget* contourWidget =vtkContourWidget::New();
vtkImageActorPointPlacer* placer=vtkImageActorPointPlacer:;New();
placer->SetImageActor( a_vtkImageActor );
contourRep->SetPointPlacer( placer );
contourWidget->SetInteractor(iren);
contourWidget->SetRepresentation(contourRep);
contourWidget->On();
and for completeness, heres the answer to the
homework which shows how to associate line topology
with points...
Dean
void ConvertPointSequenceToPolyData( vtkPoints* inPts,
const int& closed, vtkPolyData* outPoly )
{
if ( !inPts || !outPoly ) { return; }
int npts = inPts->GetNumberOfPoints();
if ( npts < 2 ) { return; }
double p0[3];
double p1[3];
inPts->GetPoint( 0, p0 );
inPts->GetPoint( npts - 1, p1 );
if ( p0[0] == p1[0] && p0[1] == p1[1] && p0[2] == p1[2] && closed ) { --npts; }
vtkPoints* temp = vtkPoints::New();
temp->SetNumberOfPoints( npts );
for ( int i = 0; i < npts; ++i )
{
temp->SetPoint( i, inPts->GetPoint( i ) );
}
vtkCellArray *cells = vtkCellArray::New();
cells->Allocate( cells->EstimateSize( npts + closed, 2 ) );
cells->InsertNextCell( npts + closed );
for ( int i = 0; i < npts; ++i )
{
cells->InsertCellPoint( i );
}
if ( closed )
{
cells->InsertCellPoint( 0 );
}
outPoly->SetPoints( temp );
temp->Delete();
outPoly->SetLines( cells );
cells->Delete();
> Yeah I was thinking about this. Thanks for the code. The only
> question I have about it is the function
> ConvertPointSequenceToPolyData -- which seems to be Left As An
> Exercise For The Reader.
>
> I've tried just using vtkPolyData::SetPoints to push points in, but
> I'm not sure that's the right thing to do. In fact, it really doesn't
> work, but I've just started debugging the code I'm using.
>
>
> > Another approach I have used to
> > reduce the number of handles is to
> > delete intermediate points between
> > points where a change in curvature occurs.
> > This works particularly well when the
> > handles/points are all coincident with
> > voxel or pixel coordinates. See code below.
> >
> > Dean
> >
> >
> >
> > //--------------------------------------------------------------------------
> > -
> > // assumes a piecwise linear polyline with points at discrete locations
> > //
> > int vtkGeometryUtilities::ReducePolyData2D( vtkPolyData* inPoly,
> > vtkPolyData* outPoly, const int& closed )
> > {
> > if ( !inPoly || !outPoly ){ return 0; }
> >
> > vtkPoints* inPts = inPoly->GetPoints();
> > if ( !inPts ){ return 0; }
> > int n = inPts->GetNumberOfPoints();
> > if ( n < 3 ) { return 0; }
> >
> > double p0[3];
> > inPts->GetPoint( 0, p0 );
> > double p1[3];
> > inPts->GetPoint( n - 1, p1 );
> > bool minusNth = ( p0[0] == p1[0] && p0[1] == p1[1] && p0[2] == p1[2] );
> > if ( minusNth && closed ) { --n; }
> >
> > struct frenet
> > {
> > double t[3]; // unit tangent vector
> > bool state; // state of kappa: zero or non-zero T/F
> > };
> >
> > frenet* f;
> > f = new frenet[n];
> > double tL;
> > // calculate the tangent vector by forward differences
> > for ( int i = 0; i < n; ++i )
> > {
> > inPts->GetPoint( i, p0 );
> > inPts->GetPoint( ( i + 1 ) % n, p1 );
> > tL = sqrt( vtkMath::Distance2BetweenPoints( p0, p1 ) );
> > if ( tL == 0.0 ){ tL = 1.0; }
> > for ( int j = 0 ; j < 3; ++j )
> > {
> > f[i].t[j] = (p1[j] - p0[j]) / tL;
> > }
> > }
> >
> > // calculate kappa from tangent vectors by forward differences
> > // mark those points that have very low curvature
> > double eps = 1.e-10;
> >
> > for ( int i = 0; i < n; ++i )
> > {
> > f[i].state = ( fabs( vtkMath::Dot( f[i].t, f[( i + 1 ) % n].t ) - 1.0 )
> > < eps );
> > }
> >
> > vtkPoints* tempPts = vtkPoints::New();
> >
> > // mark keepers
> > vtkIdTypeArray* ids = vtkIdTypeArray::New();
> >
> > // for now, insist on keeping the first point for closure
> > ids->InsertNextValue( 0 );
> >
> > for ( int i = 1; i < n; ++i )
> > {
> > bool pre = f[( i - 1 + n ) % n].state; // means fik != 1
> > bool cur = f[i].state; // means fik = 1
> > bool nex = f[( i + 1 ) % n].state;
> >
> > // possible vertex bend patterns for keep: pre cur nex
> > // 0 0 1
> > // 0 1 1
> > // 0 0 0
> > // 0 1 0
> >
> > // definite delete pattern
> > // 1 1 1
> >
> > bool keep = false;
> >
> > if ( pre && cur && nex ) { keep = false; }
> > else if ( !pre && !cur && nex ) { keep = true; }
> > else if ( !pre && cur && nex ) { keep = true; }
> > else if ( !pre && !cur && !nex ) { keep = true; }
> > else if ( !pre && cur && !nex ) { keep = true; }
> >
> > if ( keep ) // not a current sure thing but the preceding delete was
> > {
> > ids->InsertNextValue( i );
> > }
> > }
> >
> > for ( int i = 0; i < ids->GetNumberOfTuples(); ++i )
> > {
> > tempPts->InsertNextPoint( inPts->GetPoint( ids->GetValue( i ) ) );
> > }
> >
> > if ( closed )
> > {
> > tempPts->InsertNextPoint( inPts->GetPoint( ids->GetValue( 0 ) ) );
> > }
> >
> > ConvertPointSequenceToPolyData( tempPts, closed, outPoly );
> >
> > ids->Delete();
> > tempPts->Delete();
> > delete [] f;
> > return 1;
> > }
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> >
>
More information about the vtkusers
mailing list