[vtkusers] Infinite sea plane - what's the best way?

Jesse Kinross-Smith Jesse.Kinross-Smith at bentley.com
Mon Apr 9 22:05:02 EDT 2018


So I need to create an infinite textured plane to represent the sea.
vtkPlaneSource seems like the right object, but I can't seem to get any of the examples to display anything.
A colleague tried a while back also but said he could only get it to work with OpenGL not OpenGL2.
Anyone able to offer any ideas?
I've got a rectilinear grid working, but it's not ideal, really need an infinite textured plane.

Using VTK 8.1.0, C++

void CModelView::vtkRenderImageToPlane(const CString& inputFilename, float x, float y, float z)
{
       USES_CONVERSION;
       std::string filename = W2A(inputFilename);

       // Read the image which will be the texture,
       Image_Type imageType = GetImageType(inputFilename);
       vtkAlgorithmOutput* ImageOutput = NULL;
       vtkSmartPointer<vtkPNGReader> pNGReader = NULL;
       vtkSmartPointer<vtkJPEGReader> jPEGReader = NULL;
       vtkSmartPointer<vtkBMPReader> bMPReader = NULL;
       switch (imageType)
       {
              case Image_Type::PNG:
              {
                      pNGReader = vtkSmartPointer<vtkPNGReader>::New();
                      pNGReader->SetFileName(filename.c_str());
                      pNGReader->Update();
                      ImageOutput = pNGReader->GetOutputPort();
              }
              break;
              case Image_Type::JPG:
              {
                      jPEGReader = vtkSmartPointer<vtkJPEGReader>::New();
                      jPEGReader->SetFileName(filename.c_str());
                      jPEGReader->Update();
                      ImageOutput = jPEGReader->GetOutputPort();
              }
              break;
              case Image_Type::BMP:
              {
                      bMPReader = vtkSmartPointer<vtkBMPReader>::New();
                      bMPReader->SetFileName(filename.c_str());
                      bMPReader->Update();
                      ImageOutput = bMPReader->GetOutputPort();
              }
              break;
       }
       if (ImageOutput == NULL || (pNGReader == NULL && jPEGReader == NULL && bMPReader == NULL))
              return;

       // Create a plane
       vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New();
       plane->SetNormal(0.0, 0.0, 1.0);
       plane->SetCenter(0, 0, 0);
       //plane->SetResolution(100, 100);
       //plane->SetPoint1(100000, -100000, 0);
       //plane->SetPoint2(-100000, 100000, 0);

       // Apply the texture
       vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
       texture->SetInputConnection(ImageOutput);
       texture->InterpolateOn();
       texture->RepeatOn();

       vtkSmartPointer<vtkTextureMapToPlane> texturePlane = vtkSmartPointer<vtkTextureMapToPlane>::New();
       texturePlane->SetInputConnection(plane->GetOutputPort());

       vtkSmartPointer<vtkPolyDataMapper> planeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
       planeMapper->SetInputConnection(texturePlane->GetOutputPort());

       vtkSmartPointer<vtkActor> texturedPlane = vtkSmartPointer<vtkActor>::New();
       texturedPlane->SetMapper(planeMapper);
       texturedPlane->SetTexture(texture);
       texturedPlane->GetProperty()->SetOpacity(0.7);
       texturedPlane->SetPickable(FALSE);

       // Visualize the textured plane
       m_vtkRenderer->AddActor(texturedPlane);

}

--
Jesse Kinross-Smith
Senior Software Engineer - BSW
Bentley Systems, Fremantle

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180410/1c50ddc0/attachment.html>


More information about the vtkusers mailing list