Re: [osg-users] How to avoid Javas Garbage Collection to free large data array elements ?

2015-07-30 Thread Rafa Gaitan
Hi Christian,

Dealing with the GC in Java is always a pain. Some time ago I worked doing
some JNI libraries with OSG and we had problems with the GC don't freeing
small objects in Java (wrappers for big C++ objects). In the end the more
you can do in the native part the better if you need performance and an
strict memory control.

For the android I recommend you take a look to the osgjni sample:
https://github.com/miragetech/osgAndroid/tree/master/org.openscenegraph.osgjni

The purpose of this sample was making complex  things that were not
supported in the JNI wrapper. As you can see in the Activity:

Node node = ReadFile.readNodeFile(path);
MatrixTransform m = new MatrixTransform();
m.addChild(node);
mView.setSceneData(OSGConfiguration.configureScene(m));

The osgAndroid library is used for loading a node but then before setting
the scene to the viewer I call to a OSGConfiguration class that is
another JNI wrapper in the current project:
https://github.com/miragetech/osgAndroid/blob/master/org.openscenegraph.osgjni/src/org/openscenegraph/osgjni/OSGConfiguration.java
https://github.com/miragetech/osgAndroid/blob/master/org.openscenegraph.osgjni/jni/JNIOSGConfiguration.cpp

This creates a simple animation with OSG in the native part, I think a
similar approach could be used for you, avoiding all the GC thing. You can
also create new wrappers of your own classes following the same schema used
in osgAndroid if you think it could be useful :).

I hope it helps!

Regards,
Rafa

El jue., 30 jul. 2015 a las 20:35, Christian Kehl (christian-k...@web.de)
escribió:

 Hi to everyone,

 I currently extend the osgAndroid project (attempt) to do Texture
 Projection and Mapping with mobile images. I already extended the codebase
 so to get access to the geometry, Vector Arrays etc. of a loaded geometry.
 Now, the geometry loading function looks as follows:


 Code:

 private void _load_geometry()
 {
   Node mesh_node = ReadFile.readNodeFile(pointcloud_path);
   mesh = new Group(mesh_node.getNativePtr());
   Geode mesh_geode = new Geode(mesh.getLastChild().getNativePtr());
   _drawable = new Geometry(mesh_geode.getLastDrawable().getNativePtr());
   vertex_array = _drawable.getVertexArray();
   Log.i(TEXTUREMAPPING, Vertex array loaded);
   geometry = new ArrayListPoint3();
   Log.i(TEXTUREMAPPING, Geometry allocated);
   for(int i = 0; i  vertex_array.size(); i++)
   {
 geometry.add(new Point3(vertex_array.get(i).x(),
 vertex_array.get(i).y(), vertex_array.get(i).z()));
   }
   Log.i(TEXTUREMAPPING, Geometry set.);
   geometry_as_matrix = new MatOfPoint3f();
   Log.i(TEXTUREMAPPING, Number of 3D points:  +
 Integer.toString(geometry.size()));
 }




 geometry is here an ArrayList of OpenCV's Point3. As you can see, In the
 for-loop I touch every element in the Vec3Array. The Vec3Array itself is a
 wrapped version of the original C++ class, accessed with its object
 pointer, as seen in this JNI wrapper code:


 Code:

 JNIEXPORT jlong JNICALL
 Java_org_openscenegraph_osg_core_Vec3Array_nativeCreateVec3Array(JNIEnv *,
 jclass)
 {
   osg::Vec3Array *a = new osg::Vec3Array();
   a-ref();
   return reinterpret_castjlong(a);
 }




 Now, the trouble: with a certain geometry (test:40k vertices), the test
 message of actually accessed elements [Number of 3D Points:
 geometry.size(), see above] prints ~11k vertices. In the java console logs
 (LogCat), I see that Java's GC cleared its memory two times during the
 upper function execution.

 My question: How can I avoid it ? How can/should I do the per-Vertex
 operations ? Has anybody encountered problems with Java's GC formerly,
 either in former Android wrappers or in old Java platform portations ?

 The internet with several blogs and lectures tells me there is (especially
 with Android) no way to actually control the GC, or protect certain
 objects from not being freed. The only option mentioned is to code the
 things in JNI (C++), as the Garbage Collector obviously doesn't operate on
 the C++ code.

 Opinions and suggestions are welcome.

 Cheers,
 Christian

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





 ___
 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


Re: [osg-users] How to avoid Javas Garbage Collection to free large data array elements ?

2015-07-30 Thread Christian Kehl
Hi Rafa,

Thanks for the feedback - I'll have a look into the osgjni part again. The 
extended wrappers work well until now, but the arrays (Vec2,3,4Array) I just 
wrapped via their object pointer in osgAndroid, as all other classes. So, I can 
add them to the upper-level geometry, but somwhere along the line the 
RefVec2,3,4 objects bound to the Java Vec2,3,4 classes get lost.

I'll post some update when I get further.

Cheers,
Christian

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





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


Re: [osg-users] OpenSceneGrah-3.4.0 release candidate 4 tagged

2015-07-30 Thread Eric Sokolowsky
Hi Robert,

I'm away from my office at the moment, but I plan to test the latest beta
with my project next week when I return (probably be able to test Monday or
Tuesday. If you want to wait for my feedback before you proceed that would
be helpful.

Eric

On Mon, Jul 20, 2015 at 9:43 AM, Robert Osfield robert.osfi...@gmail.com
wrote:

 Hi Dizl,

 Thanks for the testing and clarification.  I have checked the
 following into OSG svn/trunk and OSG-3.4 branch.  The next 3.4.0-rc
 will have this fix.

 Cheers,
 Robert.

 On 20 July 2015 at 08:37, DizL karc...@poczta.onet.pl wrote:
  oops,
 
  #if defined(WIN32)  !defined(__MINGW32__)  (!defined(_MSC_VER) ||
  _MSC_VER=1600)
  inline int isfinite( double x ) { return _finite( x ); }
  inline int isinf( double x ) { return !_finite( x )  !_isnan( x ); }
  #endif
 
  should be 1700 instead of 1600
  (in last post '=' was lost)
 
  regards,
  DizL
 
 
  ___
  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

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


[osg-users] How to avoid Javas Garbage Collection to free large data array elements ?

2015-07-30 Thread Christian Kehl
Hi to everyone,

I currently extend the osgAndroid project (attempt) to do Texture Projection 
and Mapping with mobile images. I already extended the codebase so to get 
access to the geometry, Vector Arrays etc. of a loaded geometry. Now, the 
geometry loading function looks as follows:


Code:

private void _load_geometry()
{
  Node mesh_node = ReadFile.readNodeFile(pointcloud_path);
  mesh = new Group(mesh_node.getNativePtr());
  Geode mesh_geode = new Geode(mesh.getLastChild().getNativePtr());
  _drawable = new Geometry(mesh_geode.getLastDrawable().getNativePtr());
  vertex_array = _drawable.getVertexArray();
  Log.i(TEXTUREMAPPING, Vertex array loaded);
  geometry = new ArrayListPoint3();
  Log.i(TEXTUREMAPPING, Geometry allocated);
  for(int i = 0; i  vertex_array.size(); i++)
  {
geometry.add(new Point3(vertex_array.get(i).x(), vertex_array.get(i).y(), 
vertex_array.get(i).z()));
  }
  Log.i(TEXTUREMAPPING, Geometry set.);
  geometry_as_matrix = new MatOfPoint3f();
  Log.i(TEXTUREMAPPING, Number of 3D points:  + 
Integer.toString(geometry.size()));
}




geometry is here an ArrayList of OpenCV's Point3. As you can see, In the 
for-loop I touch every element in the Vec3Array. The Vec3Array itself is a 
wrapped version of the original C++ class, accessed with its object pointer, as 
seen in this JNI wrapper code:


Code:

JNIEXPORT jlong JNICALL 
Java_org_openscenegraph_osg_core_Vec3Array_nativeCreateVec3Array(JNIEnv *, 
jclass)
{
  osg::Vec3Array *a = new osg::Vec3Array();
  a-ref();
  return reinterpret_castjlong(a);
}




Now, the trouble: with a certain geometry (test:40k vertices), the test message 
of actually accessed elements [Number of 3D Points: geometry.size(), see 
above] prints ~11k vertices. In the java console logs (LogCat), I see that 
Java's GC cleared its memory two times during the upper function execution.

My question: How can I avoid it ? How can/should I do the per-Vertex operations 
? Has anybody encountered problems with Java's GC formerly, either in former 
Android wrappers or in old Java platform portations ?

The internet with several blogs and lectures tells me there is (especially with 
Android) no way to actually control the GC, or protect certain objects from 
not being freed. The only option mentioned is to code the things in JNI (C++), 
as the Garbage Collector obviously doesn't operate on the C++ code.

Opinions and suggestions are welcome.

Cheers,
Christian

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





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


[osg-users] Problems with fuction viewer

2015-07-30 Thread alvaro ginestar rodriguez
hi everyone !!. i have a problem with return viewer in a fuction, and to add 
the viewer of the fuction in de main.#include ventana.h

osg::Camera* ventana::createCamera(int x, int y, int w, int h)
{
	osg::ref_ptrosg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits;
	traits-x = x;
	traits-y = y;
	traits-width = w;
	traits-height = h;
	traits-doubleBuffer = true;
	traits-windowName = Funcion de Ventana;
	traits-windowDecoration = true;

	osg::ref_ptrosg::GraphicsContext gc = osg::GraphicsContext::createGraphicsContext(traits.get());

	osg::ref_ptrosg::Camera camera = new osg::Camera;
	camera-setGraphicsContext(gc.get());
	camera-setViewport(new osg::Viewport(0, 0, traits-width, traits-height));
	return camera.release();

}

osgViewer::Viewer* ventana::crearMultipleVentana(int numeroColumnas, int numeroFilas)
{
	int totalWidth = 1024, totalHeight = 768;

	osgViewer::Viewer viewer;

	int tileWidth = totalWidth / numeroColumnas;
	int tileHeight = totalHeight / numeroFilas;

	//Cremos una instancia de la nueva clase para llamar a la funcion para crear la ventana
	ventana* myVentana = new ventana();

	for (int i = 0; inumeroFilas; ++i)
	{
		for (int j = 0; jnumeroColumnas; ++j)
		{
			osg::Camera* camera = myVentana-createCamera(tileWidth*j, totalHeight - tileHeight*(i + 1), tileWidth - 1, tileHeight - 1);
			osg::Matrix projOffset = osg::Matrix::scale(numeroColumnas, numeroFilas, 1.0) * osg::Matrix::translate(numeroColumnas - 1 - 2 * j, numeroFilas - 1 - 2 * i, 0.0);
			viewer.addSlave(camera, projOffset, osg::Matrix(), true);
		}
	}

	return viewer;

}#ifndef H_VENTANA
#define H_VENTANA

#include osg/Group
#include osgViewer/Viewer

class ventana 
{

public:
osg::Camera* ventana::createCamera(int x, int y, int w, int h);
osgViewer::Viewer* ventana::crearMultipleVentana(int 
numeroColumnas, int numeroFilas);

};
#endif#include osgDB/ReadFile

#include ventana.h

using namespace std;

int main(int argc, char** argv)
{
	
	osg::DisplaySettings::instance()-setStereoMode(osg::DisplaySettings::ANAGLYPHIC);
	osg::DisplaySettings::instance()-setEyeSeparation(0.05f);
	osg::DisplaySettings::instance()-setStereo(true);

	//Añadimos el modelo a la variable
	osg::ref_ptrosg::Node modelo = osgDB::readNodeFile(cessna.osg);
	//Comprobamos si hemos añadido el modelo correctamente
	if (!modelo)
	{
		cout Error al leer el modelo, comprueve la ruta endl;
	}

	//Creamos la vista
	osgViewer::Viewer viewer;

	//Cremos una instancia de la nueva clase para llamar a la funcion para crear la ventana
	ventana* myVentana = new ventana();

	//Añadimos la nueva ventana a la vista
	//viewer.addSlave(myVentana-createCamera(300, 100, 900, 600));

	viewer.getViews(myVentana-crearMultipleVentana(2, 2));

	//Añadimos el modelo a la vista
	viewer.setSceneData(modelo);
	//Bucle de la simulacion de la vista
	return viewer.run();
}___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Problems with fuction viewer

2015-07-30 Thread Rafa Gaitan
Hi Alvaro,

As pointed by Christian all your problems are pure C++ problems. I
recommend you to learn more C++ and how to code to avoid leaks and memory
corruption and for OSG I recommend you get a copy of the Quick Start Guide.

Doing a quick review I've discovered that your are returning a pointer from
a local variable created inside crearMultipleVenata so after the function
returns that viewer is destroyed!. Use a raw pointer or even better a
osg::ref_ptr, but really you need to read about smart pointers in C++ and
also how the smart pointers are used in OSG :)

Also I recommend as a general rule use always English in the code (even for
the comments), using Spanish will be easy for you but others might don't
understand the meaning of the methods.

Regards,
Rafa.


El jue., 30 jul. 2015 a las 12:31, alvaro ginestar rodriguez (
alvarogines...@hotmail.com) escribió:

 hi everyone !!. i have a problem with return viewer in a fuction, and to
 add the viewer of the fuction in de main.
 ___
 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