[vtkusers] How to prevent merging points when clipping polydata
pahsieh at usgs.gov
pahsieh at usgs.gov
Fri Jun 16 19:56:08 EDT 2000
I am running into a problem using vtkClipPolyData because it
merges points for a situation in which I don't want the points
to be merged. I would appreciate it if someone would tell me
to how work around this problem.
This problem is illustrated by the attached sample program.
A polydata set contains 2 lines, defined as follows:
Line 1
------
Point index coordinates scalar value
0 (0, 0, 0) 0.0
1 (1, 1, 0) 0.1
2 (2, 2, 0) 0.2
3 (3, 3, 0) 0.3
4 (4, 4, 0) 0.4
Line 2
------
5 (4, 0, 0) 0.6
6 (3, 1, 0) 0.7
7 (2, 2, 0) 0.8
8 (1, 3, 0) 0.9
9 (0, 4, 0) 1.0
Note that the 2 lines intersect at a common point (2, 2, 0).
However because the lines have different scalar values,
the intersection point is represented by 2 points (indices 2
and 7) with different scalar values.
Without clipping, the 2 lines are rendered as expected, with
the proper colors. (This is illustrated by the left figure
generated by the sample code.)
However, suppose I want to clip the lines to keep only
those portions where the scalar values are between 0.25
and 0.95. This is done in 2 steps. First, I apply a
vtkClipPolyData filter with the clip value set at 0.95
(with "inside out" turned on). When this filter executes,
a part of Line 2 is removed. However, the intersection
point is also merged, so that point 7 of Line 2 now has
scalar value = 0.2 instead of the original 0.8. (This is
illustrated by the middle figure generated by the sample
program.)
In the second step, another vtkClipPolyData filter is
applied with the clip value set at 0.25 (with "inside out"
turned off). The intention is to remove a part of
Line 1. However, due to the point merging on the
previous step, the middle portion of Line 2 is also
removed. This is not the expected behavior.
How can I turn off point merging in vtkClipPolyData?
Many thanks.
Paul
// ==== Sample Code ====
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkScalars.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkClipPolyData.h"
void main()
{
int i;
float x[10][3]={{0,4,0}, {1,3,0}, {2,2,0}, {3,1,0}, {4,0,0},
{0,0,0}, {1,1,0} ,{2,2,0}, {3,3,0}, {4,4,0}};
float s[10] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.7, 0.8, 0.9, 1.0};
int pts[2][5]={{0,1,2,3,4}, {5,6,7,8,9}};
// Set up the rendering stuff
vtkRenderer *renderer = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(renderer);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// Create a polydata containing 2 lines
vtkPoints *points = vtkPoints::New();
vtkCellArray *lines = vtkCellArray::New();
vtkScalars *scalars = vtkScalars::New();
for (i=0; i<10; i++)
{
points->InsertNextPoint(x[i]);
scalars->InsertNextScalar(s[i]);
}
for (i=0; i<2; i++)
{
lines->InsertNextCell(5,pts[i]);
}
vtkPolyData *pd = vtkPolyData::New();
pd->SetPoints(points);
points->Delete();
pd->SetLines(lines);
lines->Delete();
pd->GetPointData()->SetScalars(scalars);
scalars->Delete();
// No clipping case (actor on left)
vtkPolyDataMapper *mapper0 = vtkPolyDataMapper::New();
mapper0->SetInput(pd);
vtkActor *actor0 = vtkActor::New();
actor0->SetMapper(mapper0);
renderer->AddActor(actor0);
// Clipping using value = 0.95 (inside out) (actor in middle)
vtkClipPolyData *clip1 = vtkClipPolyData::New();
clip1->SetInput(pd);
clip1->InsideOutOn();
clip1->SetValue(0.95);
vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New();
mapper1->SetInput(clip1->GetOutput());
vtkActor *actor1 = vtkActor::New();
actor1->SetMapper(mapper1);
actor1->AddPosition(5, 0, 0);
renderer->AddActor(actor1);
// Clip again using value = 0.25 (actor on right)
vtkClipPolyData *clip2 = vtkClipPolyData::New();
clip2->SetInput(clip1->GetOutput());
clip2->SetValue(0.25);
vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New();
mapper2->SetInput(clip2->GetOutput());
vtkActor *actor2 = vtkActor::New();
actor2->SetMapper(mapper2);
actor2->AddPosition(10, 0, 0);
renderer->AddActor(actor2);
renWin->Render();
iren->Start();
// Clean up
renderer->Delete();
renWin->Delete();
iren->Delete();
pd->Delete();
mapper0->Delete();
actor0->Delete();
clip1->Delete();
mapper1->Delete();
actor1->Delete();
clip2->Delete();
mapper2->Delete();
actor2->Delete();
}
More information about the vtkusers
mailing list