[vtk-developers] Should vtkClipPolyData keep the normals?

Berk Geveci berk.geveci at kitware.com
Wed Sep 10 16:54:41 EDT 2008


I know what the problem is. vtkClipPolyData does copy the normals. The
reason you are seeing artifacts is due to the fact that
vtkClipPolyData merges coincident points. This produces the effect you
are seeing where there are sharp angles. You can fix this problem by
subclassing vtkPointLocator, making sure that this subclass does not
merge points and pass it to vtkClipPolyData::SetLocator(). So this
class would have something like:

int vtkMyPointLocator::InsertUniquePoint(const double x[3], vtkIdType &id)
{
id = this->InsertNextPoint(x);
return 1;
}

You code would have

vtkMyPointLocator* lc = vtkPointLocator::New();
clipper->SetLocator(lc);
	
-berk


On Wed, Sep 10, 2008 at 9:47 AM, Mathieu Coursolle
<mcoursolle at rogue-research.com> wrote:
> Hi,
> Here is a more detailed description of the issue:
> I loaded 42400-IDGH.stl from the VTKData folder using vtkSTLReader.
> I then use the following code to compute the normals, as none are read:
> vtkSmartPointer<vtkPolyDataNormals> normalsFilter =
> vtkSmartPointer<vtkPolyDataNormals>::New();
> normalsFilter->SetInput(myPolyData);
> normalsFilter->SetFeatureAngle(60.0);
> normalsFilter->Update();
> myPolyData = normalsFilter->GetOutput();
> Then, if I display this polydata, the result looks just fine (see
> attachment). However, if I apply the vtkClipPolyData filter
> using an implicit function that includes the entire polydata, the normals
> are lost:
> vtkSmartPointer<vtkClipPolyData> clipper =
> vtkSmartPointer<vtkClipPolyData>::New();
> clipper->SetInput(myPolyData);
> clipper->SetClipFunction(aBox);
> clipper->SetGenerateClippedOutput(0);
> clipper->SetInsideOut(1);
> clipper->Update();
> myPolyData = clipper->GetOutput();
> Would it be easy to change the filter to add an option to keep the normals,
> and to compute the missing ones?
> Sure I can call the normals filter after the clip filter, but some of my
> data have specific normals I need to keep, and
> calling a normals filter after the clipping modifies them. Since I have no
> knowledge on how those normals were created,
> I need to keep them for the untouched cells.
> See attachment on the effect of the clipping process.
> Thanks!
> Mathieu
> On 9-Sep-08, at 4:44 PM, Berk Geveci wrote:
>
> Something is fishy there. The line you added is copying the point data
> onto itself.
>
>  vtkPointData *inPD=input->GetPointData(), *outPD = output->GetPointData();
>  ....
>  output->GetPointData()->PassData(outPD);
>
> That PassData() should not do anything at best and may corrupt the
> output data at worst. Can you post a small example demonstrating the
> issue?
>
> -berk
>
>
> 2008/9/9 Mathieu Coursolle <mcoursolle at rogue-research.com>:
>
> Hi VTK developers,
>
> I am using vtkClipPolyData to clip a vtkPolyData with an implicit function
>
> (vtkBox).
>
> The origin vtkPolyData has specific normals I want to keep for the resulting
>
> polydata.
>
> Unfortunately, the normals are not the same in the output polydata.
>
> I looked at the code, and I have a question regarding the creation of the
>
> output polydata:
>
> For the Clipped Output, the PassData() method and the Squeeze() method are
>
> called one
>
> the points, lines, polys, strips are set. This is not true for the standard
>
> output. Is there a reason?
>
> Shouldn't the code be:
>
>  if (newVerts->GetNumberOfCells())
>
>    {
>
>    output->SetVerts(newVerts);
>
>    }
>
>  newVerts->Delete();
>
>  if (newLines->GetNumberOfCells())
>
>    {
>
>    output->SetLines(newLines);
>
>    }
>
>  newLines->Delete();
>
>  if (newPolys->GetNumberOfCells())
>
>    {
>
>    output->SetPolys(newPolys);
>
>    }
>
>  newPolys->Delete();
>
>
>
>  output->GetPointData()->PassData(outPD);      <<<<<<<<<< ADDED CODE
>
> <<<<<<<<<<<<
>
>  output->Squeeze();                            <<<<<<<<<< ADDED CODE
>
> <<<<<<<<<<<<
>
>  if ( this->GenerateClippedOutput )
>
>    {
>
>    this->GetClippedOutput()->SetPoints(newPoints);
>
>    if (clippedVerts->GetNumberOfCells())
>
>      {
>
>      this->GetClippedOutput()->SetVerts(clippedVerts);
>
>      }
>
>    clippedVerts->Delete();
>
>    if (clippedLines->GetNumberOfCells())
>
>      {
>
>      this->GetClippedOutput()->SetLines(clippedLines);
>
>      }
>
>    clippedLines->Delete();
>
>    if (clippedPolys->GetNumberOfCells())
>
>      {
>
>      this->GetClippedOutput()->SetPolys(clippedPolys);
>
>      }
>
>    clippedPolys->Delete();
>
>
>
>    this->GetClippedOutput()->GetPointData()->PassData(outPD);
>
>    this->GetClippedOutput()->Squeeze();
>
>    }
>
> It seems to work alright with that fix, but I am not too sure of what it is
>
> doing...
>
> Thanks!
>
> Mathieu
>
> _______________________________________________
>
> vtk-developers mailing list
>
> vtk-developers at vtk.org
>
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>
>
>
>



More information about the vtk-developers mailing list