[osg-users] File loading and reading

2015-06-26 Thread sam
When it comes to OSG, is there a reader type class that will handle all the
endianness of a file for you? Or is it up to the responsibility of the
programmer creating the plugin to do the data reading?
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [build] Building OpenSceneGraph-3.3.4 with GDAL 2.0

2015-06-26 Thread Robert Osfield
On 26 June 2015 at 13:39, Tony Vasile  wrote:

> Not sure if you came up with this but since I couldn't see your version of
> the patch I recreated it.
>

Oppps. Must have missed attaching the file...

You file looks roughly the same.  In my change I cleaned up one of the
commented out lines in your code.

Robert.
/* -*- mode: c++; c-default-style: k&r; tab-width: 4; c-basic-offset: 4; -*-
 * Copyright (C) 2007 Cedric Pinson - morni...@plopbyte.net
 *
 * This library is open source and may be redistributed and/or modified under
 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
 * (at your option) any later version.  The full license is in LICENSE file
 * included with this distribution, and on the openscenegraph.org website.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * OpenSceneGraph Public License for more details.
*/

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define SERIALIZER() OpenThreads::ScopedLock lock(_serializerMutex)

void CPL_STDCALL CPLOSGErrorHandler( CPLErr eErrClass, int nError,
 const char * pszErrorMsg )
{
if( eErrClass == CE_Debug )
{
OSG_DEBUG << pszErrorMsg << std::endl;
}
else if( eErrClass == CE_Warning )
{
OSG_WARN << nError << " " << pszErrorMsg << std::endl;
}
else
{
OSG_FATAL << nError << " " << pszErrorMsg << std::endl;
}
}

static osg::Material* createDefaultMaterial()
{
osg::Vec4 color;
for (int i = 0; i < 3; i++)
color[i] = (1.0 * (rand() / (1.0*RAND_MAX)));
color[3] = 1;
osg::Material* mat = new osg::Material;
mat->setDiffuse(osg::Material::FRONT_AND_BACK, color);
return mat;
}

struct TriangulizeFunctor
{
osg::Vec3Array* _vertexes;

// do nothing
void operator ()(const osg::Vec3& v1, const osg::Vec3& v2, const osg::Vec3& v3, bool treatVertexDataAsTemporary) {
_vertexes->push_back(v1);
_vertexes->push_back(v2);
_vertexes->push_back(v3);
}
};

static osg::Vec3Array* triangulizeGeometry(osg::Geometry* src)
{
if (src->getNumPrimitiveSets() == 1 &&
src->getPrimitiveSet(0)->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType &&
src->getVertexArray() &&
src->getVertexArray()->getType() == osg::Array::Vec3ArrayType)
return static_cast(src->getVertexArray());

osg::TriangleFunctor functor;
osg::Vec3Array* array = new osg::Vec3Array;
functor._vertexes = array;
src->accept(functor);
return array;
}


class ReaderWriterOGR : public osgDB::ReaderWriter
{

public:
ReaderWriterOGR()
{
supportsExtension("ogr","OGR file reader");
supportsOption("useRandomColorByFeature", "Assign a random color to each feature.");
supportsOption("addGroupPerFeature", "Places each feature in a separate group.");
oldHandler = CPLSetErrorHandler(CPLOSGErrorHandler);
}

virtual ~ReaderWriterOGR()
{
CPLSetErrorHandler(oldHandler);
}

virtual const char* className() const { return "OGR file reader"; }

virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{
OSG_INFO<<"OGR::readNode("< lock(_serializerMutex);
return readFile(osgDB::getNameLessExtension(file), options);
}

OpenThreads::ScopedLock lock(_serializerMutex);
std::string fileName = osgDB::findDataFile( file, options );
if (fileName.empty()) return readFile(file, options); // ReadResult::FILE_NOT_FOUND;

return readFile(fileName, options);
}

virtual ReadResult readFile(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const
{
#if GDAL_VERSION_MAJOR<2
if (OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount() == 0)
OGRRegisterAll();

// Try to open data source
OGRDataSource* file = OGRSFDriverRegistrar::Open(fileName.c_str());
#else
if (GDALGetDriverCount() == 0)
GDALAllRegister();

// Try to open data source
GDALDataset* file  = (GDALDataset*) GDALOpenEx( fileName.c_str(), GDAL_OF_VECTOR, NULL, NULL, NULL );
#endif

if (!file)
return 0;

bool useRandomColorByFeature = false;
bool addGroupPerFeature = false;
if (options)
{
if (options->getOptionString().find("UseRandomColorByFeature") != std::string::npos)
useRandomColorByFeature = true;
if (options->getOptionString().find("useRandomColorByFeature") != std::string::npos)
useRandomColorByFeature = true;
if (options->getOpti

Re: [osg-users] [build] Building OpenSceneGraph-3.3.4 with GDAL 2.0

2015-06-26 Thread Tony Vasile
Hi Robert

Not sure if you came up with this but since I couldn't see your version of the 
patch I recreated it.

... 


Thank you!

Cheers,
Tony

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64201#64201



--- OpenSceneGraph-3.2.1/src/osgPlugins/ogr/ReaderWriterOGR.cpp 2012-03-22 
04:36:20.0 +1100
+++ ../OpenSceneGraph-3.2.1/src/osgPlugins/ogr/ReaderWriterOGR.cpp  
2015-06-26 21:53:33.349709134 +1000
@@ -134,11 +134,21 @@
 
 virtual ReadResult readFile(const std::string& fileName, const 
osgDB::ReaderWriter::Options* options) const
 {
+#if GDAL_VERSION_MAJOR < 2
 if (OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount() == 0)
 OGRRegisterAll();
+#else
+if (GDALGetDriverCount() == 0)
+GDALAllRegister();
+#endif
 
 // Try to open data source
+#if GDAL_VERSION_MAJOR < 2
 OGRDataSource* file = OGRSFDriverRegistrar::Open(fileName.c_str());
+#else
+GDALDataset   *file;
+file = (GDALDataset*) GDALOpenEx( fileName.c_str(), GDAL_OF_VECTOR, 
NULL, NULL, NULL );
+#endif
 if (!file)
 return 0;
 
@@ -156,6 +166,7 @@
 
 osg::Group* group = new osg::Group;
 
+#if GDAL_VERSION_MAJOR < 2
 for (int i = 0; i < file->GetLayerCount(); i++)
 {
 osg::Group* node = readLayer(file->GetLayer(i), file->GetName(), 
useRandomColorByFeature, addGroupPerFeature);
@@ -163,6 +174,16 @@
 group->addChild( node );
 }
 OGRDataSource::DestroyDataSource( file );
+#else
+for (int i = 0; i < file->GetLayerCount(); i++)
+{
+OGRLayer* layer = (OGRLayer *)GDALDatasetGetLayer(file, i); 
+osg::Group* node = readLayer(layer, layer->GetName(), 
useRandomColorByFeature, addGroupPerFeature);
+if (node)
+group->addChild( node );
+}
+GDALClose( file );
+#endif
 return group;
 }
 
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [build] Building OpenSceneGraph-3.3.4 with GDAL 2.0

2015-06-26 Thread Tony Vasile
Hi Robert,
  Am I going blind I can see your attachment with your modified patch?

... 


Thank you!

Cheers,
Tony

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64200#64200





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [build] Building OpenSceneGraph-3.3.4 with GDAL 2.0

2015-06-26 Thread Robert Osfield
 Hi Tony,

You suggested changed breaks the build for GDAL<2.0.

I have changed the ReaderWriterOGR.cpp to contain both the original code
blocks and the ones modified by you with a GDAL_VERSION_MAJOR<2 check.
Attached is the modified file.  Could you try this out, if it works fine
I'll check it into svn/trunk and the OSG-3.2 branch.

Robert.

On 25 June 2015 at 09:01, Tony Vasile  wrote:

> Hi,
>
> I have this patch so that it compiles but I don't have a ogr source file
> to test it against. But this allows OpenSceneGraph 3.2.1 to compile.
>
> ...
>
>
> Thank you!
>
> Cheers,
> Tony
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=64190#64190
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org