[vtkusers] How To Texture Map a patch with vtkGlobeSource

Donny donnyz at charter.net
Thu Nov 4 00:43:10 EDT 2010


I just figured out that the vtkGlobeSource already converts the lat,lon
points to world points in meters from a defined origin that can be set via
SetOrigin().

Problem solved. Thanks Aashish!!!

 

-----Original Message-----
From: Donny [mailto:donnyz at charter.net] 
Sent: Wednesday, November 03, 2010 9:40 PM
To: 'Aashish Chaudhary'
Cc: 'vtkusers at vtk.org'
Subject: RE: [vtkusers] How To Texture Map a patch with vtkGlobeSource

 

Wow. Thanks Aashish. 

It would be nice if vtkTextureMapToSphere would do this mapping correctly.

I have one question about implementing this. I need to convert the lat lon
coordinates to meters from a defined origin. I think vtkGeoAssignCoordinates
will do the job. Can I use this filter after the texture coordinates are set
using your code? 

 

-----Original Message-----
From: Aashish Chaudhary [mailto:aashish.chaudhary at kitware.com] 
Sent: Wednesday, November 03, 2010 1:05 AM
To: Donny
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] How To Texture Map a patch with vtkGlobeSource

 

Hi Donny, 

 

I didn't get the time to  clean this code but it will work for you .. 

 

I just modified a test (and hence it look bit different)





  


  
  


  


  
  
#include <vtkGlobeSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkPointData.h>
#include <vtkDoubleArray.h>
#include "vtkBMPReader.h"
#include "vtkCamera.h"
#include "vtkGeoAlignedImageRepresentation.h"
#include "vtkGeoAlignedImageSource.h"
#include "vtkGeoEdgeStrategy.h"
#include "vtkGeoFileImageSource.h"
#include "vtkGeoFileTerrainSource.h"
#include "vtkGeoGlobeSource.h"
#include "vtkGeoProjection.h"
#include "vtkGeoProjectionSource.h"
#include "vtkGeoRandomGraphSource.h"
#include "vtkGeoSphereTransform.h"
#include "vtkGeoTerrain.h"
#include "vtkGeoTerrainNode.h"
#include "vtkGeoTerrain2D.h"
#include "vtkGeoTransform.h"
#include "vtkGeoView.h"
#include "vtkGeoView2D.h"
#include "vtkGraphLayoutView.h"
#include "vtkJPEGReader.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderedGraphRepresentation.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkStdString.h"
#include "vtkTestUtilities.h"
#include "vtkTIFFReader.h"
#include "vtkViewTheme.h"
#include "vtkViewUpdater.h"
#include <vtksys/SystemTools.hxx>
 
#define VTK_CREATE(type,name) \
  vtkSmartPointer<type> name = vtkSmartPointer<type>::New();
int TestGeoView(int argc, char* argv[])
{
  char* image = vtkTestUtilities::ExpandDataFileName(
    argc, argv, "Data/usa_image.jpg");
  vtkStdString imageFile = image;
  vtkSmartPointer<vtkJPEGReader> reader =
    vtkSmartPointer<vtkJPEGReader>::New();
  reader->SetFileName(imageFile.c_str());
  reader->Update();
  double latRange[]  = {24, 50};
  double longRange[] = {-126, -66};
  VTK_CREATE(vtkGlobeSource, globeSource);
  globeSource->SetStartLatitude(latRange[0]);
  globeSource->SetEndLatitude(latRange[1]);
  globeSource->SetStartLongitude(longRange[0]);
  globeSource->SetEndLongitude(longRange[1]);
  globeSource->Update();
  VTK_CREATE(vtkActor, actor);
  VTK_CREATE(vtkPolyDataMapper, mapper);
  vtkDoubleArray* newArray (vtkDoubleArray::New());
  newArray->SetNumberOfComponents(2);
  vtkDoubleArray* array =
vtkDoubleArray::SafeDownCast(globeSource->GetOutput(0)->GetPointData()->GetA
bstractArray("LatLong"));
  double range[] = { (latRange[1] -latRange[0]),
                     (longRange[1] - longRange[0]) };
  double val[2];
  double newVal[2];
  for(int i=0; i < array->GetNumberOfTuples(); ++i)
    {
     array->GetTupleValue(i, val);
     newVal[1] = (val[0] - latRange[0])  / range[0];
     newVal[0] = (val[1] - longRange[1]) / range[1];
     newArray->InsertNextTuple(newVal);
    }
  globeSource->GetOutput(0)->GetPointData()->SetTCoords(newArray);
  mapper->SetInput( globeSource->GetOutput(0) );
  actor->SetMapper(mapper);
  VTK_CREATE(vtkTexture, texture);
  texture->SetInput(reader->GetOutputDataObject(0));
  actor->SetTexture(texture);
  VTK_CREATE(vtkRenderWindow, renWin);
  VTK_CREATE(vtkRenderWindowInteractor, renWinInt);
  VTK_CREATE(vtkRenderer, ren);
  ren->AddActor(actor);
  renWin->AddRenderer(ren);
  renWinInt->SetRenderWindow(renWin);
  renWin->SetSize(400,400);
  renWin->Render();
  renWinInt->Initialize();
  renWin->Render();
  int retVal = vtkRegressionTestImage( renWin );
  if( retVal == vtkRegressionTester::DO_INTERACTOR)
    {
    renWinInt->Start();
    }
  return 0;
}

 

Attached is the screenshot of my test.. 

 

 

On Tue, Nov 2, 2010 at 10:56 PM, Donny <donnyz at charter.net> wrote:

Thanks for the help Aashish. I have attached 3 image files, one with the
AutomaticSphereGenerationOff() set on the vtkTextureMapToSphere object and
one with AutomaticSphereGenerationOn(). The third image is not a screenshot,
it is the actual texture I am trying to map to the patch.  The only settings
I set on the vtkGlobeSource are :
gs->SetStartLatitude(24.0);
gs->SetEndLatitude(50.0);
gs->SetStartLongitude(-126.0);
gs->SetEndLongitude(-66.0);

As you can see the GlobeSource patch geometry is rendering as intended, but
the texture is not appearing correctly.


"you can have

tx = asin(Nx)/PI  + 0.5
ty = asin(Ny)/PI + 0.5"

Is there a filter that will perform this mapping for me?

Thanks.


-----Original Message-----
From: Aashish Chaudhary [mailto:aashish.chaudhary at kitware.com]
Sent: Tuesday, November 02, 2010 10:11 AM
To: Donny
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] How To Texture Map a patch with vtkGlobeSource

Hi Donny,
- Show quoted text -
I have not used vtkTextureMapToSphere myself but can you try to
generate your own texture coordinates? globe source does produce
normals and in its very simplistic approach  ...

you can have

tx = asin(Nx)/PI  + 0.5
ty = asin(Ny)/PI + 0.5

In a shader you can do it easily.  Not sure why vtkTextureMapToSphere
didn't work. Will find out.

Can you post a snapshot?

On Tue, Nov 2, 2010 at 12:01 AM, Donny <donnyz at charter.net> wrote:
> I have created a globe patch with vtkGlobeSource for the general area of
the
> United States (Lat 24 to 50 Deg, Lon -126 to -66 Deg.) using
> SetLatitudeStart, SetLatitudeEnd ... I also have a .bmp image that
> corresponds to these extents and cannot find a filter to generate the
> texture coordinates for this patch so I can texture it. I tried
> vtkTextureMapToSphere and turned auto generate sphere to off but it only
> displayed a small portion of the image onto the patch. How can I generate
> the texture coordinates for a patch such as this?
>
>
>
> Thanks.
>
>
>
> Donny Zimmerman
>
>
>
> _______________________________________________
> 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
>
>



--
| Aashish Chaudhary
| R&D Engineer
| Kitware Inc.
| www.kitware.com




-- 
| Aashish Chaudhary 
| R&D Engineer         
| Kitware Inc.            
| www.kitware.com    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101103/820e02ba/attachment.htm>


More information about the vtkusers mailing list