[vtkusers] splines
Dean Inglis
dean.inglis at camris.ca
Mon Sep 12 10:11:11 EDT 2005
sorry, I missed that.
Maybe it's because you call Reset()
without setting the number of points.
if(spline_points) spline_points->Reset(); float t = 0.0;
for(int i=0; i<numberOfOutputPoints;i++)
{
t = ( (float)numberOfInputPoints - 1.0 ) / (
(float)numberOfOutputPoints - 1.0 ) * (float)i;
spline_points->SetPoint(i, splineX->Evaluate(t),
splineY->Evaluate(t), splineZ->Evaluate(t));
float* pt = spline_points->GetPoint(i);
If you do
points->Initialize();
or
points->Reset();
you must then do
points->SetNumberOfPoints( npoints ); // pre-allocate memory
before calling
points->SetPoint(i,x,y,z); // when memmory is pre-allocated (faster)
if you do not set the number of points, you can do
points->InsertNextPoint(x,y,z); //allocate memory as required (slower)
Dean
Hi,
Thanks for your reply. But your are wrong: I set:
t = ( (float)numberOfInputPoints - 1.0 ) / ( (float)numberOfOutputPoints -
1.0 ) * (float)i;
spline_points->SetPoint(i, splineX->Evaluate(t),
splineY->Evaluate(t), splineZ->Evaluate(t));
Is it not correct? Any other idea?
Isabelle
dean.inglis at camris.ca a écrit :
you didn't define any points:
//Generate the polyline for the spline.
spline_points = vtkPoints::New();
spline_points->SetNumberOfPoints( static_cast(numberOfOutputPoints) );
you need to also do:
spline_points->SetPoint(i,somethingX,somethingY,somethingZ);
or,
double somethingXYZ[3];
spline_points->SetPoint(i,somethingXYZ);
Dean
>
Hi,
I am really confused about interpolating my glyph points with a spline.
I look a lot of examples on this and I thought having understood, but
actually, only my glyph are drawn.
I put a TRACE instruction to see what is computed after calling
spline-.Evaluate(): i got crazy values except for the first one: not so
amazing that nothing is drawn!
Here is what I did:
splineX = vtkCardinalSpline::New();
splineY = vtkCardinalSpline::New();
splineZ = vtkCardinalSpline::New();
numberOfOutputPoints = 20; //Number of points on the spline
//Generate the polyline for the spline.
spline_points = vtkPoints::New();
spline_points->SetNumberOfPoints(
static_cast<vtkIdType>(numberOfOutputPoints) );
//Create the polyline.
spline_lines = vtkCellArray::New();
spline_lines->InsertNextCell(numberOfOutputPoints);
for(int i=0; i<numberOfOutputPoints;i++)
spline_lines->InsertCellPoint(i);//add points one at a time
spline_polyData = vtkPolyData::New();
spline_polyData->SetPoints(spline_points);
spline_points->Delete();
spline_polyData->SetLines(spline_lines);
spline_lines->Delete();
//Add thickness to the resulting line.
tubes = vtkTubeFilter::New();
tubes->SetInput(spline_polyData);
tubes->SetRadius(0.075);
tubes->SetNumberOfSides(6);
vtkPolyDataMapper* spline_mapper = vtkPolyDataMapper::New();
spline_mapper->SetInput(tubes->GetOutput());
tubes->Delete();
splines = vtkActor::New();
splines->SetMapper(spline_mapper);
spline_mapper->Delete();
splines->GetProperty()->SetColor(1.0, 0.0, 1.0);
And after each click:
case vtkCommand::LeftButtonPressEvent:
{
vtkRenderWindowInteractor *interactor =
reinterpret_cast<vtkRenderWindowInteractor *>(caller);
int x = interactor->GetEventPosition()[0];
int y = interactor->GetEventPosition()[1];
// Convert display point to world point
double world_point[4];
m_Renderer->SetDisplayPoint( x, y, 0 );
m_Renderer->DisplayToWorld();
m_Renderer->GetWorldPoint( world_point );
// Store the point with no range checking or memory allocation.
points->SetPoint( nodeId, world_point[0], world_point[1],
world_point[2] );
// Create a vertex for each node. This type of cell has a single
point.
vtkIdType topology[1];
topology[0] = nodeId;
vertices->InsertNextCell( 1, topology );
//create new points
numberOfInputPoints = points->GetNumberOfPoints();
if ( numberOfInputPoints >= 2 )
{
if(numberOfInputPoints==2)
{
m_Renderer->AddActor( splines );
splines->Delete();
}
splineX->RemoveAllPoints();
splineY->RemoveAllPoints();
splineZ->RemoveAllPoints();
for ( int i = 0 ; i < numberOfInputPoints; i++)
{
//add coordinates points to the splines.
float* point = points->GetPoint(i);
splineX->AddPoint( i, point[0] );
splineY->AddPoint( i, point[1] );
splineZ->AddPoint( i, point[2] );
}
if(spline_points) spline_points->Reset();
float t = 0.0;
for(int i=0; i<numberOfOutputPoints;i++)
{
t = ( (float)numberOfInputPoints - 1.0 ) / (
(float)numberOfOutputPoints - 1.0 ) * (float)i;
spline_points->SetPoint(i, splineX->Evaluate(t),
splineY->Evaluate(t), splineZ->Evaluate(t));
float* pt = spline_points->GetPoint(i);
TRACE("spline points:%f %f %f\n", pt[0], pt[1], pt[2]);
}
spline_polyData->Modified();
}
nodeId++;
m_glyphActor->VisibilityOn();
splines->VisibilityOn();
this->Render();
}
break;
- Does someone see what is wrong? Insofar as my glyph are correcly drawn, I
assume that my input points are correct. So what's wrong?
Please help me,
Isabelle
_______________________________________________
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
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez le ici !
More information about the vtkusers
mailing list