[vtk-developers] Should vtkClipPolyData keep the normals?
Karthik Krishnan
karthik.krishnan at kitware.com
Thu Sep 11 12:27:20 EDT 2008
On Thu, Sep 11, 2008 at 11:49 AM, Mathieu Coursolle
<mcoursolle at rogue-research.com> wrote:
> Hi,
>
> Thanks a lot, it works just as expected!
>
> It brings some other questions though. I overloaded vtkPointLocator and
> created
> a vtkNoMergePointLocator with the suggested changes.
>
> I did not add that class to VTK, but to my project. However, vtkDebugLeaks
> complains
> it does not know the class, and so that object leaks.
That should not matter as far as vtkDebugLeaks is concerned. I think
something else is going on.
--
karthik
>
> 1) Is there a way to give knowledge of my new class to vtkDebugLeaks?
> 2) Should just a class find its way into VTK?
>
> Thanks!
>
> Mathieu
>
> On 10-Sep-08, at 4:54 PM, Berk Geveci wrote:
>
>> 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
>>>
>>>
>>>
>>>
>>>
>>
>
> _______________________________________________
> 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