Hi Manjunath,
as andreas mentioned, it is not a good idea to load all faces of a ply
file into a single geometry object. I've written a ply to osb converter
that
is able to split a ply geometry into a number of osb files. The tool
works offline and is able to load and convert even the stanford
michelangelo
with 50 mil polygons. The result of the progr. are a number of
osb-files. I'm using this files to do distributed loading on a cluster.
14 frames with the dragon is very fast. This makes more then 100 mil
polygons/s. Is it possible to get a copy of you plane opengl program?
That would make it easier to compare it with opensg rendering.
Marcus
#include <stdio.h>
#include <math.h>
#include <strings.h>
#include <ply.h>
#include <OpenSG/OSGBaseFunctions.h>
#include <OpenSG/OSGSceneFileHandler.h>
#include <OpenSG/OSGGeometry.h>
#include <OpenSG/OSGGeoFunctions.h>
#include <OpenSG/OSGSimpleMaterial.h>
#include <OpenSG/OSGGraphOpSeq.h>
#include <OpenSG/OSGStripeGraphOp.h>
using namespace osg;
/* user's vertex and face definitions for a polygonal object */
typedef struct Vertex {
float x,y,z;
void *other_props; /* other properties */
} Vertex;
typedef struct Face {
unsigned char nverts; /* number of vertex indices in list */
int *verts; /* vertex index list */
void *other_props; /* other properties */
} Face;
char *elem_names[] = { /* list of the kinds of elements in the user's
object */
"vertex", "face"
};
PlyProperty vert_props[] = { /* list of property information for a vertex */
{"x", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,x), 0, 0, 0, 0},
{"y", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,y), 0, 0, 0, 0},
{"z", PLY_FLOAT, PLY_FLOAT, offsetof(Vertex,z), 0, 0, 0, 0},
};
PlyProperty face_props[] = { /* list of property information for a vertex */
{"vertex_indices", PLY_INT, PLY_INT, offsetof(Face,verts),
1, PLY_UCHAR, PLY_UCHAR, offsetof(Face,nverts)},
};
/*** the PLY object ***/
static int nverts,nfaces;
//static Vertex **vlist;
//static Face **flist;
static PlyOtherElems *other_elements = NULL;
static PlyOtherProp *vert_other,*face_other;
static int nelems;
static char **elist;
static int num_comments;
static char **comments;
static int num_obj_info;
static char **obj_info;
static int file_type;
static float xtrans = 0;
static float ytrans = 0;
static float ztrans = 0;
static float xscale = 1;
static float yscale = 1;
static float zscale = 1;
int maxFaces = 10000;
typedef struct pol_header
{
char format_version[64];
char user_comments[128];
char dummy[4];
int nv;
int vblock_length;
int np;
int pblock_length;
int color_texture_flag;
int ctblock_length;
int dummy2[73];
} POL_Header;
GeometryPtr geo;
GeoPTypesPtr type;
GeoPositions3fPtr pnts;
GeoPLengthsPtr lens;
GeoIndicesUI32Ptr indices;
char *outFile;
char *inFile;
int fileCount=0;
void startGeo()
{
geo = Geometry::create();
pnts = GeoPositions3f::create();
type = GeoPTypesUI8::create();
lens = GeoPLengthsUI32::create();
indices = GeoIndicesUI32::create();
beginEditCP(type);
type->addValue(GL_TRIANGLES);
endEditCP(type);
beginEditCP(geo);
geo->setTypes (type);
geo->setLengths (lens);
geo->setPositions(pnts);
geo->setIndices (indices);
endEditCP(geo);
}
void writeGeo()
{
NodePtr node = Node::create();
addRefCP(node);
beginEditCP(node);
node->setCore(geo);
endEditCP(node);
SimpleMaterialPtr m1 = SimpleMaterial::create();
beginEditCP(m1);
{
m1->setAmbient (Color3f(0.2,0.2,0.2));
m1->setDiffuse (Color3f(0.8,0.7,0.7));
m1->setEmission (Color3f(0.0,0.0,0.0));
m1->setSpecular (Color3f(1.0,1.0,1.0));
m1->setShininess (10);
m1->setColorMaterial(GL_NONE);
}
endEditCP (m1);
geo->setMaterial(m1);
calcVertexNormals(geo);
osg::GraphOpSeq op;
op.addGraphOp(new StripeGraphOp);
op.run(node);
char outName[1024];
sprintf(outName,"%s_%d.osb",outFile,fileCount++);
printf("Write %s\n",outName);
OSG::SceneFileHandler::the().write(node,outName,true);
subRefCP(node);
}
/******************************************************************************
Read in the PLY file from standard in.
******************************************************************************/
void read_file()
{
int i,j,k;
PlyFile *ply;
int nprops;
int num_elems;
PlyProperty **plist;
char *elem_name;
float version;
/*** Read in the original PLY object ***/
FILE *in = fopen(inFile,"r");
ply = ply_read (in, &nelems, &elist);
ply_get_info (ply, &version, &file_type);
std::vector<Vertex> vertices;
for (i = 0; i < nelems; i++) {
/* get the description of the first element */
elem_name = elist[i];
plist = ply_get_element_description (ply, elem_name, &num_elems,
&nprops);
if (equal_strings ("vertex", elem_name)) {
nverts = num_elems;
vertices.resize(nverts);
/* set up for getting vertex elements */
ply_get_property (ply, elem_name, &vert_props[0]);
ply_get_property (ply, elem_name, &vert_props[1]);
ply_get_property (ply, elem_name, &vert_props[2]);
vert_other = ply_get_other_properties (ply, elem_name,
offsetof(Vertex,other_props));
/* grab all the vertex elements */
for (j = 0; j < num_elems; j++) {
ply_get_element (ply, (void *) &vertices[j]);
/*
pnts->addValue(Pnt3f(
vlist[j]->x,
vlist[j]->y,
vlist[j]->z));
*/
}
}
else if (equal_strings ("face", elem_name)) {
nfaces = num_elems;
/* set up for getting face elements */
ply_get_property (ply, elem_name, &face_props[0]);
face_other = ply_get_other_properties (ply, elem_name,
offsetof(Face,other_props));
std::map<int,int> used;
int faceCount=0;
int ind,posCount=0;
/* grab all the face elements */
for (j = 0; j < num_elems;) {
startGeo();
if((num_elems-j) > maxFaces) {
lens->addValue(maxFaces * 3);
} else {
lens->addValue((num_elems - j)*3);
}
used.clear();
posCount = 0;
for(faceCount = 0; faceCount < maxFaces && j < num_elems
; j++,faceCount++) {
Face f;
ply_get_element (ply, (void *) &f);
for(k = 0; k < f.nverts ; ++k) {
if(used.find(f.verts[k]) == used.end()) {
used[f.verts[k]] = posCount;
posCount++;
}
ind = used[f.verts[k]];
indices->addValue(ind);
}
}
pnts->resize(used.size());
for(std::map<int,int>::iterator uI = used.begin();
uI != used.end() ; ++uI) {
ind = uI->first;
pnts->setValue(Pnt3f(
vertices[ind].x,
vertices[ind].y,
vertices[ind].z),uI->second);
}
writeGeo();
}
}
else
other_elements = ply_get_other_element (ply, elem_name,
num_elems);
}
comments = ply_get_comments (ply, &num_comments);
obj_info = ply_get_obj_info (ply, &num_obj_info);
ply_close (ply);
}
/******************************************************************************
Main program.
******************************************************************************/
int main(int argc, char *argv[])
{
int i,j;
char *s;
char *progname;
osgInit(argc,argv);
inFile = argv[1];
outFile = argv[2];
if(argc>3)
maxFaces = atoi(argv[3]);
read_file();
}
Andreas Zieringer wrote:
Hi Manjunath,
just loaded it with my vred app. After optimizing it a bit I get about
5 fps on my old ATI 9600 and 8 fps on a FX3000. Well rendering one
Geometry node with about 7 million triangles is not a good idea. How
much memory do you have?
As default the SceneFileHandler calls the tri stipper you can disable
this if you provide as the second parameter a NULL pointer. Perhaps
this solves your problem.
scene = SceneFileHandler::the().read(fileName, NULL);
Andreas
Hi Dirk,
That didn't work either. Here is a model
http://graphics.stanford.edu/data/3Dscanrep/xyzrgb/xyzrgb_dragon.ply.gz
that I am trying to load on a single node. This doesn't have anything to
do with the cluster. This model we can load using a plain
opengl program and get around 14 FPS. But when I convert
it to .osb (I convert to .off then .osb) and then try loading it with
the 10loading.cpp
example, opensg cannot load it.
Can anybody check if they can load this model
and report the frame rates they get ?
Can I also get the code that was used to load
this model, if it can be loaded successfully ?
Thanks,
Manju
On 6/3/05, Dirk Reiners <[EMAIL PROTECTED]> wrote:
Hi Manju,
On Fri, 2005-06-03 at 18:22 +0530, Manjunath Sripadarao wrote:
I am trying to (still) load a huge model using opensg. I had a
question regarding
geometry creation in opensg. Does opensg have 2 copies of vertices and
indices in memory ?
That is one that is loaded into opengl using
glBegin(...)
glVertex
glend(...)
This only consumes memory if it's inside a display list (which OpenSG
uses by default).
and another that is
GeoPositions3fPtr pnts = GeoPositions3f::create();
beginEditCP(pnts, GeoPositions3f::GeoPropDataFieldMask);
{
pnts->addValue(Pnt3f(x, y, z));
}
endEditCP(pnts, GeoPositions3f::GeoPropDataFieldMask);
Are there 2 copies in memory that are kept ? Or is there only one copy
in memory ?
If you use dlists yes, there are two copies in memory.
Is there a way to make it use a opengl display list directly ?
Not currently.
That is I create an opengl display list and pass to opensg and opensg
uses this display
list to render geometry.
Not currently. The problem is that it's impossible to read display
lists, there is no way to get at the information for e.g. normal
calculation, bounding volume calculation or intersection.
You can turn display lists off before rendering to see if that fixes
your problem (geo->setDlistCache(false);, or add the attached code to
just turn it off).
But AFAIK you're on a cluster anyway, so no single node should need to
render the full model. Can you give us a little more background on when
exactly you're having problems?
Dirk
Add this before Geometry creation to turn off all dlists:
FieldContainerPtr pProto = Geometry::getClassType().getPrototype();
GeometryPtr pGeoProto = GeometryPtr::dcast(pProto);
if(pGeoProto != NullFC)
{
pGeoProto->setDlistCache(false);
}
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit
http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you
shotput
a projector? How fast can you ride your desk chair down the office
luge track?
If you want to score the big prize, get to know the little guy. Play
to win an NEC 61" plasma display: http://www.necitguy.com/?r
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you
shotput
a projector? How fast can you ride your desk chair down the office
luge track?
If you want to score the big prize, get to know the little guy. Play
to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users
-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
Opensg-users mailing list
Opensg-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensg-users