[osg-submissions] Fix georeference of gdal plugin
Robert Osfield
robert.osfield at gmail.com
Sun Dec 16 08:55:51 PST 2007
Hi Cedric,
Thanks for the data, I've now been able to recreate the problem you've
seen using:
osgviewer --dem dtm_200m.tif.gdal lines.shp
And have reviewed your changes, but decided to rewrite the setup of
the HeightField coordinates so that it works correctly and supports
rotation of the data in the GDAL geotransform includes it. The above
now works just fine too. This is now checked into SVN.
Could you check out svn and let me know if things are working fine at
your end as well.
Robert.
On Dec 12, 2007 10:30 AM, Cedric Pinson <mornifle at plopbyte.net> wrote:
> Hi Robert,
>
> Here two files that must be at the same locations. the dtm.tif is loaded
> with the plugin gdal and lines.shp is loaded with the standard
> plugin.
>
> Cheers Cedric
>
>
> >
> > Thanks for explanation. The invert of the data is to go from GDAL
> > default of top left orign, to bottom left origin that OpenGL/OSG use.
> >
> > Could you send me the data you had problems with an I'll have a bash
> > at reproducing the problem at my end.
> >
> > Robert.
> >
> > On Dec 11, 2007 3:16 PM, Cedric Pinson <mornifle at plopbyte.net> wrote:
> >
> >> I read the georeferenced tiff with this plugin it return me an
> >> osg::HeightField
> >> then i use it like that:
> >>
> >> osg::ref_ptr<osg::ShapeDrawable> shape = new
> >> osg::ShapeDrawable(heightField);
> >> {
> >> MyTriangulatorForDisplay triangulator;
> >> shape->accept(triangulator);
> >> triangulator.postProcess();
> >> _geometry = triangulator._geometry;
> >> }
> >>
> >> so the i passe in void PrimitiveShapeVisitor::apply(const HeightField&
> >> field) that call my functor below.
> >> It's ok for that just the result is not what it should be i mean
> >> vertexes position are not where they would be.
> >> From the gdal documentation http://www.gdal.org/gdal_tutorial.html
> >>
> >> adfGeoTransform[0] /* top left x */
> >> adfGeoTransform[1] /* w-e pixel resolution */
> >> adfGeoTransform[2] /* rotation, 0 if image is "north up" */
> >> adfGeoTransform[3] /* top left y */
> >> adfGeoTransform[4] /* rotation, 0 if image is "north up" */
> >> adfGeoTransform[5] /* n-s pixel resolution */
> >>
> >> and in the original plugin at line 679 there is TopLeft[1] =
> >> geoTransform[1]; so it's not the good index it should be geoTransform[3];
> >> because geoTransform[1] is the w-e pixel resolution. So i just fixed the
> >> topLeft position.
> >>
> >> Then the other fix is the setOrigin . the original version switch the
> >> corner of the origin, i think it was done to have the computation of
> >> normal and the triangle in counter clockwize. But it does not work, i
> >> imagine it works for special case because value from TopLeft are bad and
> >> other value are computed with it.
> >>
> >> hf->setOrigin(osg::Vec3(BottomLeft[0],-BottomLeft[1],0));
> >>
> >>
> >> So i change it to have the good origin (top left x, and bottom left y),
> >> and the pixel delta are taken from the georeference data but i change
> >> the sign of y pixel delta because the corner is not on the top but on
> >> the bottom to have triangle in counter clockwize. (the -100 in my
> >> version is a mistake from a test, it should be 0)
> >>
> >> hf->setOrigin(osg::Vec3(TopLeft[0],BottomLeft[1],-100));
> >> hf->setXInterval(geoTransform[1]); the pixel in x
> >> hf->setYInterval(-geoTransform[5]); the pixel in y
> >>
> >> and the x, y interval are taken from the geotransform.
> >>
> >> I imagine the original version worked but not for a georeferenced tiff
> >> in a arbitrary location. I can't send you the data i used to test. I
> >> hope there is enough
> >> explanation. I dont if the other part work or not i used only
> >> readHeightField.
> >>
> >>
> >> cheers
> >>
> >> struct MyFunctor {
> >> // do nothing
> >> void operator ()(const osg::Vec3& v1, const osg::Vec3& v2, const
> >> osg::Vec3& v3, bool treatVertexDataAsTemporary) {
> >> }
> >> };
> >> struct MyTriangulatorForDisplay : osg::TriangleFunctor<MyFunctor>
> >> {
> >> osg::ref_ptr<osg::Geometry> _geometry;
> >> osg::ref_ptr<osg::Vec3Array> _vertexes;
> >>
> >> MyTriangulatorForDisplay() {
> >> _vertexes = new osg::Vec3Array;
> >> _geometry = new osg::Geometry;
> >> _geometry->setVertexArray(_vertexes.get());
> >> }
> >> void drawArrays(GLenum mode,GLint first,GLsizei count) {
> >> osg::DrawArrays* primitive = new osg::DrawArrays(mode,
> >> _vertexes->size()+first, count);
> >> _vertexes->insert(_vertexes->end(), _vertexCache.begin(),
> >> _vertexCache.end());
> >> _geometry->addPrimitiveSet(primitive);
> >> }
> >> void postProcess();
> >>
> >> };
> >>
> >>
> >>
> >>
> >>
> >> Robert Osfield wrote:
> >>
> >>> HI Cedric,
> >>>
> >>> Could you provide work flow which illustrates the problem you've seen
> >>> so I can recreate at me end.
> >>>
> >>> I don't believe your changes are wholly appropriate, and perhaps miss
> >>> the point of the some of the code, this code might be buggy... but
> >>> does have a purpose.
> >>>
> >>> Cheers,
> >>> Robert.
> >>>
> >>> On Dec 8, 2007 2:36 PM, Cedric Pinson <mornifle at plopbyte.net> wrote:
> >>>
> >>>
> >>>> Hi Robert,
> >>>> Here a patch for gdal reader, it did not take the georeference
> >>>> correctly. I added a diff to show you the difference. with my fix it
> >>>> works as expected for a tiff georeferenced.
> >>>>
> >>>>
> >>>> diff for info:
> >>>> 0a1,9
> >>>> > /**
> >>>> > * Who is the original author ???
> >>>> > *
> >>>> > *
> >>>> > * Modified (2007)
> >>>> > *
> >>>> > * Authors:
> >>>> > * Cedric Pinson <mornifle at plopbyte.net>
> >>>> > */
> >>>> 666c675
> >>>> < TopLeft[1] = geoTransform[1];
> >>>> ---
> >>>> > TopLeft[1] = geoTransform[3];
> >>>> 736c745
> >>>> <
> >>>> ---
> >>>> >
> >>>> 738,739c747,748
> >>>> < osg::notify(osg::INFO)<<"flipping"<<std::endl;
> >>>> < unsigned int copy_r = hf->getNumRows()-1;
> >>>> ---
> >>>> > osg::notify(osg::INFO)<<"flipping"<<std::endl;
> >>>> > unsigned int copy_r = hf->getNumRows()-1;
> >>>> 742,751c751,760
> >>>> < for(unsigned int c=0;c<hf->getNumColumns();++c)
> >>>> < {
> >>>> < float temp = hf->getHeight(c,r);
> >>>> < hf->setHeight(c,r,hf->getHeight(c,copy_r));
> >>>> < hf->setHeight(c,copy_r,temp);
> >>>> < }
> >>>> < }
> >>>> < hf->setOrigin(osg::Vec3(BottomLeft[0],-BottomLeft[1],0));
> >>>> <
> >>>> hf->setXInterval((BottomRight[0]-BottomLeft[0])/destWidth);
> >>>> < hf->setYInterval((TopLeft[1]-BottomLeft[1])/destHeight);
> >>>> ---
> >>>> > for(unsigned int c=0;c<hf->getNumColumns();++c)
> >>>> > {
> >>>> > float temp = hf->getHeight(c,r);
> >>>> > hf->setHeight(c,r,hf->getHeight(c,copy_r));
> >>>> > hf->setHeight(c,copy_r,temp);
> >>>> > }
> >>>> > }
> >>>> > hf->setOrigin(osg::Vec3(TopLeft[0],BottomLeft[1],-100));
> >>>> > hf->setXInterval(geoTransform[1]);
> >>>> > hf->setYInterval(-geoTransform[5]);
> >>>>
> >>>> Cheers
> >>>>
> >>>> --
> >>>> +33 (0) 6 63 20 03 56 Cedric Pinson mailto:mornifle at plopbyte.net http://www.plopbyte.net
> >>>>
> >>>>
> >>>>
> >>>> _______________________________________________
> >>>> osg-submissions mailing list
> >>>> osg-submissions at lists.openscenegraph.org
> >>>> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>> _______________________________________________
> >>> osg-submissions mailing list
> >>> osg-submissions at lists.openscenegraph.org
> >>> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
> >>>
> >>>
> >> --
> >>
> >> +33 (0) 6 63 20 03 56 Cedric Pinson mailto:mornifle at plopbyte.net http://www.plopbyte.net
> >>
> >>
> >> _______________________________________________
> >> osg-submissions mailing list
> >> osg-submissions at lists.openscenegraph.org
> >> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
> >>
> >>
> > _______________________________________________
> > osg-submissions mailing list
> > osg-submissions at lists.openscenegraph.org
> > http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
> >
>
> --
> +33 (0) 6 63 20 03 56 Cedric Pinson mailto:mornifle at plopbyte.net http://www.plopbyte.net
>
>
>
> _______________________________________________
> osg-submissions mailing list
> osg-submissions at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
>
More information about the osg-submissions
mailing list