[vtkusers] Only flat shading with VRML data
Mika Fischer
mika.fischer at zoopnet.de
Fri Jul 6 10:45:40 EDT 2012
OK, as far as I can understand it I need to have duplicate vertices at
the seams of the texture, because otherwise I cannot have gaps in the
texture image.
So I'd like to get the smooth shading working even if there are
duplicate vertices.
Can someone explain why this is difficult? In my naivete I would have
assumed that setting the normals at both the duplicate vertices to the
same value would give the same results? Is it only that finding the
neighboring polygons is more difficult?
Best,
Mika
On Fri, Jul 6, 2012 at 4:12 PM, Mika Fischer <mika.fischer at zoopnet.de> wrote:
> Seems so, unfortunately it also seems I need it to get reasonable
> surface normals. Or does anyone know of another way to fix the
> polygons that doesn't break the texture?
>
> BTW. I think the seam across the middle of the face is there because
> the texture bmp contains two 45 degree views of the face. I think what
> might happen is that the vertices get merged in such a way that the
> seam polygons have texture coodinates on both views of the face, thus
> incorporating all the background between the two faces as well...
>
> Best,
> Mika
>
> On Fri, Jul 6, 2012 at 3:59 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>> OK, so the culprit is clean polydata.
>>
>>
>> On Fri, Jul 6, 2012 at 9:56 AM, Mika Fischer <mika.fischer at zoopnet.de>
>> wrote:
>>>
>>> If I leave out the normals filter, I get flat shading *and* broken
>>> textures.
>>>
>>> So:
>>> vtkPolyDataMapper: flat shading, good texture
>>> vtkPolyDataNormals -> vtkPolyDataMapper: flat shading, good texture
>>> vtkCleanPolyData -> vtkPolyDataMapper: flat shading, broken texture
>>> vtkCleanPolyData -> vtkPolyDataNormals -> vtkPolyDataMapper: smooth
>>> shading, broken texture
>>>
>>> Best,
>>> Mika
>>>
>>> On Fri, Jul 6, 2012 at 3:50 PM, Bill Lorensen <bill.lorensen at gmail.com>
>>> wrote:
>>> > Leave out the normals filter. Let's see you is messing with the texture
>>> > coordinates.
>>> >
>>> >
>>> > On Fri, Jul 6, 2012 at 9:38 AM, Mika Fischer <mika.fischer at zoopnet.de>
>>> > wrote:
>>> >>
>>> >> Unfortnuately, that yields exactly the same results...
>>> >>
>>> >> On Fri, Jul 6, 2012 at 3:33 PM, Bill Lorensen <bill.lorensen at gmail.com>
>>> >> wrote:
>>> >> > on the normals filter try
>>> >> > ->SplittingOff();
>>> >> >
>>> >> > On Fri, Jul 6, 2012 at 9:22 AM, Mika Fischer
>>> >> > <mika.fischer at zoopnet.de>
>>> >> > wrote:
>>> >> >>
>>> >> >> Ok, unfortunately now I get a problem when mapping the texture on
>>> >> >> the
>>> >> >> surface. There are strage "seams" in some places:
>>> >> >> http://zoopnet.de/vrml2.png
>>> >> >>
>>> >> >> Without vtkCleanPolyData the texture mapping worked fine. I think
>>> >> >> the
>>> >> >> problem might be caused by the vertices of the polygons being
>>> >> >> changed
>>> >> >> by vtkCleanPolyData. Is there something I can do to transform the
>>> >> >> texture in the same way?
>>> >> >>
>>> >> >> The code used for texturing is below.
>>> >> >>
>>> >> >> Thanks a lot in advance!
>>> >> >>
>>> >> >> Best,
>>> >> >> Mika
>>> >> >>
>>> >> >> ------------------------------------------------------------
>>> >> >> vtkSmartPointer<vtkBMPReader> bmpReader =
>>> >> >> vtkSmartPointer<vtkBMPReader>::New();
>>> >> >> bmpReader->SetFileName(fileBmp.c_str());
>>> >> >> bmpReader->Update();
>>> >> >>
>>> >> >> vtkImageData* image = bmpReader->GetOutput();
>>> >> >> vtkTexture *texture = vtkTexture::New();
>>> >> >> texture->SetInputConnection(bmpReader->GetOutputPort());
>>> >> >> texture->InterpolateOn();
>>> >> >>
>>> >> >> [...]
>>> >> >>
>>> >> >> solidActor->SetTexture(texture);
>>> >> >>
>>> >> >>
>>> >> >> On Fri, Jul 6, 2012 at 3:06 PM, Mika Fischer
>>> >> >> <mika.fischer at zoopnet.de>
>>> >> >> wrote:
>>> >> >> > Yes, that fixed it! Thanks a lot!
>>> >> >> >
>>> >> >> > Best,
>>> >> >> > Mika
>>> >> >> >
>>> >> >> > On Fri, Jul 6, 2012 at 3:01 PM, Bill Lorensen
>>> >> >> > <bill.lorensen at gmail.com>
>>> >> >> > wrote:
>>> >> >> >> Try running vtkCleanPolyData before the normals calculation. The
>>> >> >> >> data
>>> >> >> >> may
>>> >> >> >> duplicate the points for each triangle. clean polydata will
>>> >> >> >> remove
>>> >> >> >> duplicate
>>> >> >> >> points.
>>> >> >> >>
>>> >> >> >> On Fri, Jul 6, 2012 at 5:21 AM, Mika Fischer
>>> >> >> >> <mika.fischer at zoopnet.de>
>>> >> >> >> wrote:
>>> >> >> >>>
>>> >> >> >>> Hi,
>>> >> >> >>>
>>> >> >> >>> first of all I have to say that is the first time that I use vtk
>>> >> >> >>> and I
>>> >> >> >>> don't have much experience with 3D graphics.
>>> >> >> >>>
>>> >> >> >>> I have a 3d triangle mesh of a face in wrl format. I also
>>> >> >> >>> managed
>>> >> >> >>> to
>>> >> >> >>> display it. However the shading of the triangles seems to be
>>> >> >> >>> flat.
>>> >> >> >>> Calling SetInterpolationToGouraud() or SetInterpolationToFlat()
>>> >> >> >>> seems
>>> >> >> >>> to make no difference.
>>> >> >> >>>
>>> >> >> >>> The code used to load the data and display it is below. Am I
>>> >> >> >>> missing
>>> >> >> >>> an important step here?
>>> >> >> >>>
>>> >> >> >>> Also, if I load the file in ParaView, it has the same issue and
>>> >> >> >>> switching from Flat to Gouraud makes no visible difference.
>>> >> >> >>> However
>>> >> >> >>> if
>>> >> >> >>> I use a CylinderSource, the shading is smooth as I would expect
>>> >> >> >>> it
>>> >> >> >>> (and switching to flat makes a huge difference).
>>> >> >> >>>
>>> >> >> >>> Here's a screenshot of the data in paraview:
>>> >> >> >>> http://zoopnet.de/vrml.png
>>> >> >> >>>
>>> >> >> >>> Any tips would be very much appreciated!
>>> >> >> >>>
>>> >> >> >>> Best,
>>> >> >> >>> Mika
>>> >> >> >>>
>>> >> >> >>> -------------------------------------
>>> >> >> >>> vtkSmartPointer<vtkVRMLImporter> importer =
>>> >> >> >>> vtkSmartPointer<vtkVRMLImporter>::New();
>>> >> >> >>> importer->SetFileName(fileWrl.c_str());
>>> >> >> >>> importer->Read();
>>> >> >> >>> importer->Update();
>>> >> >> >>>
>>> >> >> >>> vtkActorCollection* actors =
>>> >> >> >>> importer->GetRenderer()->GetActors();
>>> >> >> >>> actors->InitTraversal();
>>> >> >> >>> vtkDataSet* pDataset =
>>> >> >> >>> actors->GetNextActor()->GetMapper()->GetInput();
>>> >> >> >>>
>>> >> >> >>> vtkPolyData* polyData = vtkPolyData::SafeDownCast(pDataset);
>>> >> >> >>> polyData->Update();
>>> >> >> >>>
>>> >> >> >>> vtkSmartPointer<vtkPolyDataNormals> skinNormals =
>>> >> >> >>> vtkSmartPointer<vtkPolyDataNormals>::New();
>>> >> >> >>> skinNormals->SetFeatureAngle(90.0);
>>> >> >> >>> skinNormals->SetInput(polyData);
>>> >> >> >>> skinNormals->Update();
>>> >> >> >>>
>>> >> >> >>> vtkSmartPointer<vtkPolyDataMapper> solidMapper =
>>> >> >> >>> vtkSmartPointer<vtkPolyDataMapper>::New();
>>> >> >> >>> solidMapper->SetInputConnection(skinNormals->GetOutputPort());
>>> >> >> >>> solidMapper->ScalarVisibilityOff();
>>> >> >> >>>
>>> >> >> >>> vtkSmartPointer<vtkActor> solidActor =
>>> >> >> >>> vtkSmartPointer<vtkActor>::New();
>>> >> >> >>> solidActor->SetMapper(solidMapper);
>>> >> >> >>> solidActor->GetProperty()->SetInterpolationToGouraud();
>>> >> >> >>>
>>> >> >> >>> -------------------------------------
>>> >> >> >>> _______________________________________________
>>> >> >> >>> Powered by www.kitware.com
>>> >> >> >>>
>>> >> >> >>> Visit other Kitware open-source projects at
>>> >> >> >>> http://www.kitware.com/opensource/opensource.html
>>> >> >> >>>
>>> >> >> >>> Please keep messages on-topic and check the VTK FAQ at:
>>> >> >> >>> http://www.vtk.org/Wiki/VTK_FAQ
>>> >> >> >>>
>>> >> >> >>> Follow this link to subscribe/unsubscribe:
>>> >> >> >>> http://www.vtk.org/mailman/listinfo/vtkusers
>>> >> >> >>
>>> >> >> >>
>>> >> >> >>
>>> >> >> >>
>>> >> >> >> --
>>> >> >> >> Unpaid intern in BillsBasement at noware dot com
>>> >> >> >>
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >> > --
>>> >> > Unpaid intern in BillsBasement at noware dot com
>>> >> >
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Unpaid intern in BillsBasement at noware dot com
>>> >
>>
>>
>>
>>
>> --
>> Unpaid intern in BillsBasement at noware dot com
>>
More information about the vtkusers
mailing list