Esempio n. 1
0
void loadGeom( const char *filename, osg::NodePtr *node )
{
	// load file
	osg::NodePtr filescene = osg::SceneFileHandler::the().read( filename );
	if ( filescene == osg::NullFC )
	{
		fprintf(stderr, "\nCouldn't open file %s\n", filename );
		exit(-1);
	}

	// create new geometry
	osg::NodePtr nod = osg::Node::create();
	col::mergeGeom( filescene, &nod );

	// scale geom
	nod->updateVolume();
	 
	//tanglei comment this, act as kcbp_cgal_cuda
	Pnt3f low, high;
	nod->getVolume().getBounds( low, high );
	Pnt3f c = col::lincomb( 0.5, low,   0.5, high );
	Pnt3f d = col::lincomb( 0.5, high, -0.5, low );
									// d=0.5*(high-low), is actually a vector
	float s = col_max3( d[0], d[1], d[2] );
	osg::MFPnt3f *points = col::getPoints( nod );
	beginEditCP( nod );
	for ( unsigned int i = 0; i < points->size(); i ++ )
		for ( unsigned int j = 0; j < 3; j ++ )
			(*points)[i][j] = ((*points)[i][j] - c[j]) / s;
	endEditCP( nod );
	nod->updateVolume();
	 
	*node = nod;
}
Esempio n. 2
0
 void SlitPotentialTest::MethodGetSlitWidthWorks() {
     SlitPotential p(Vec2(0.0, 0.0), Vec2(6.0, 6.0), 2);
     QCOMPARE(p.getSlitWidth(), DEFAULT_SLIT_WIDTH);
     const Real newSlitWidth = 1.1 * DEFAULT_SLIT_WIDTH;
     p.setSlitWidth(newSlitWidth);
     QCOMPARE(p.getSlitWidth(), newSlitWidth);
 }
Esempio n. 3
0
void addWithHull( osg::NodePtr	testObj )
{
	testGeom = osg::GeometryPtr::dcast( testObj->getCore() );
	testHull = testGeom;
	testHullObj = testHull.getGeomNode();

	testHull.print();

	// set material
	osg::SimpleMaterialPtr mat = osg::SimpleMaterial::create();
    	mat->setDiffuse( osg::Color3f( 1.0,0.7,1.0 ) );
    	mat->setAmbient( osg::Color3f( 0.2,0.2,0.2 ) );
    	mat->setSpecular( osg::Color3f( 1,1,1 ) );
    	mat->setShininess( 20 );

	testGeom->setMaterial( mat );
	osg::GeometryPtr::dcast(testHullObj->getCore())->setMaterial( mat );

	// add to scene graph
	beginEditCP(root);

	root->addChild( testObj );
	root->addChild( testHullObj );

	endEditCP(root);
}
Esempio n. 4
0
 void SlitPotentialTest::MethodGetSlitLocationWorks() {
     SlitPotential p(Vec2(0.0, 0.0), Vec2(5.0, 5.0));
     p.addSlit(0.5);
     p.addSlit(0.25);
     p.addSlit(0.75);
     QCOMPARE(p.getSlitLocation(0), Vec2(1.25, 1.25));
     QCOMPARE(p.getSlitLocation(1), Vec2(2.5, 2.5));
     QCOMPARE(p.getSlitLocation(2), Vec2(3.75, 3.75));
 }
Esempio n. 5
0
 void SlitPotentialTest::MethodRemoveSlitWorks() {
     SlitPotential p(Vec2(0.0, 0.0), Vec2(6.0, 6.0), 2);
     QCOMPARE(p.getSlitLocation(0), Vec2(2.0, 2.0));
     QCOMPARE(p.getSlitLocation(1), Vec2(4.0, 4.0));
     p.removeSlit(0);
     QCOMPARE(p.getSlitLocation(0), Vec2(4.0, 4.0));
     p.removeSlit(1); // Should do nothing since we now only have one slit
     QCOMPARE(p.getSlitLocation(0), Vec2(4.0, 4.0));
 }
Esempio n. 6
0
void SWWReaderTest::testBedslopeNormalArray()
{
    CPPUNIT_ASSERT( _sww->isValid() );

    osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeNormalArray();
    CPPUNIT_ASSERT( actual );

    // expected number of bedslope normals
    const size_t nvertices = 24;
    CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices );

    // hard-coded values (bedslope is flat plane)
    using osg::Vec3;
    using osg::Vec3Array;
    Vec3Array *expected = new Vec3Array; 
    expected->assign(24, Vec3( 0.301511, -0.301511, 0.904534 ) );

    for (size_t i=0; i<nvertices; i++)
        CPPUNIT_ASSERT_VEC3_EQUAL( actual->at(i), expected->at(i) );
}
Esempio n. 7
0
void SWWReaderTest::testBedslopeVertexArray()
{
    osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeVertexArray();
    CPPUNIT_ASSERT( _sww->isValid() );
    CPPUNIT_ASSERT( actual );

    // expected number of bedslope vertices
    const size_t nvertices = 20;
    CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices );

    // hard-coded values extracted from sww file - note that these values are normalised by the reader
    using osg::Vec3;
    using osg::Vec3Array;
    Vec3Array *expected = new Vec3Array(20);
    (*expected)[ 0] = Vec3(-0.5, -0.5, 0.333333);
    (*expected)[ 1] = Vec3(-0.5, -0.166667, 0.444444);
    (*expected)[ 2] = Vec3(-0.5, 0.166667, 0.555556);
    (*expected)[ 3] = Vec3(-0.5, 0.5, 0.666667);
    (*expected)[ 4] = Vec3(-0.25, -0.5, 0.25);
    (*expected)[ 5] = Vec3(-0.25, -0.166667, 0.361111);
    (*expected)[ 6] = Vec3(-0.25, 0.166667, 0.472222);
    (*expected)[ 7] = Vec3(-0.25, 0.5, 0.583333);
    (*expected)[ 8] = Vec3(0, -0.5, 0.166667);
    (*expected)[ 9] = Vec3(0, -0.166667, 0.277778);
    (*expected)[10] = Vec3(0, 0.166667, 0.388889);
    (*expected)[11] = Vec3(0, 0.5, 0.5);
    (*expected)[12] = Vec3(0.25, -0.5, 0.0833333);
    (*expected)[13] = Vec3(0.25, -0.166667, 0.194444);
    (*expected)[14] = Vec3(0.25, 0.166667, 0.305556);
    (*expected)[15] = Vec3(0.25, 0.5, 0.416667);
    (*expected)[16] = Vec3(0.5, -0.5, 0);
    (*expected)[17] = Vec3(0.5, -0.166667, 0.111111);
    (*expected)[18] = Vec3(0.5, 0.166667, 0.222222);
    (*expected)[19] = Vec3(0.5, 0.5, 0.333333);

    for (size_t i=0; i<nvertices; i++)
	{
        CPPUNIT_ASSERT_VEC3_EQUAL( expected->at(i), actual->at(i) );
	}
}
Esempio n. 8
0
osg::Node* Shape::createOSGAxes(const base::Dimension3& dim)
{
  const Real s = 1.5;
  Real d = Math::minimum(0.06,Math::minimum(dim.x,dim.y,dim.z)/16.0);

  Group* g = NewObj Group;
  g->setName("debug");

  // color the axes X:red, Y:green and Z:blue, with white end cones
  StateSet* red = NewObj StateSet();
  osg::Material* rmat = NewObj osg::Material();
  Vec4 cred(1,0,0,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  rmat->setDiffuse( osg::Material::FRONT_AND_BACK, cred );
  rmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  rmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  red->setAttribute( rmat );

  StateSet* green = NewObj StateSet();
  osg::Material* gmat = NewObj osg::Material();
  Vec4 cgreen(0,1,0,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  gmat->setDiffuse( osg::Material::FRONT_AND_BACK, cgreen );
  gmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  gmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  green->setAttribute( gmat );
  
  StateSet* blue = NewObj StateSet();
  osg::Material* bmat = NewObj osg::Material();
  Vec4 cblue(0,0,1,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  bmat->setDiffuse( osg::Material::FRONT_AND_BACK, cblue );
  bmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  bmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  blue->setAttribute( bmat );

  StateSet* white = NewObj StateSet();
  osg::Material* wmat = NewObj osg::Material();
  Vec4 cwhite(1,1,1,1);
  //  mat->setEmission( osg::Material::FRONT_AND_BACK, Vec4(0,0,0,0) );
  //mat->setAmbient( osg::Material::FRONT_AND_BACK, col );
  wmat->setDiffuse( osg::Material::FRONT_AND_BACK, cwhite );
  wmat->setSpecular( osg::Material::FRONT_AND_BACK, Vec4(1,1,1,0) );
  wmat->setShininess( osg::Material::FRONT_AND_BACK, 1.0);
  white->setAttribute( wmat );


  // a long Clyinder for the axis and a cone-like cylinder 
  //  for the arrow head of each X,Y and Z.

  MatrixTransform* xrot = NewObj MatrixTransform();
  xrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(0,1,0)));
  xrot->postMult(osg::Matrix::translate(s*dim.x/4.0,0,0));
  g->addChild(xrot);
		
  MatrixTransform* yrot = NewObj MatrixTransform();
  yrot->setMatrix(osg::Matrix::rotate(consts::Pi/2.0,Vec3(-1,0,0)));
  yrot->postMult(osg::Matrix::translate(0,s*dim.y/4.0,0));
  g->addChild(yrot);
		
  MatrixTransform* zrot = NewObj MatrixTransform();
  zrot->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0));
  g->addChild(zrot);
		
  // the cylinder axes
  ref<Cylinder> xc(NewObj Cylinder(s*dim.x/2.0,d));
  xrot->addChild(xc->createOSGVisual());
  xrot->setStateSet(red);

  ref<Cylinder> yc(NewObj Cylinder(s*dim.y/2.0,d));
  yrot->addChild(yc->createOSGVisual());
  yrot->setStateSet(green);

  ref<Cylinder> zc(NewObj Cylinder(s*dim.z/2.0,d));
  zrot->addChild(zc->createOSGVisual());
  zrot->setStateSet(blue);

  // Translate each axis cone to the end
  MatrixTransform* xtrans = NewObj MatrixTransform();
  xtrans->setMatrix(osg::Matrix::translate(0,0,s*dim.x/4.0+d));
  xrot->addChild(xtrans);
  
  MatrixTransform* ytrans = NewObj MatrixTransform();
  ytrans->setMatrix(osg::Matrix::translate(0,0,s*dim.y/4.0+d));
  yrot->addChild(ytrans);
  
  MatrixTransform* ztrans = NewObj MatrixTransform();
  ztrans->setMatrix(osg::Matrix::translate(0,0,s*dim.z/4.0+d));
  zrot->addChild(ztrans);
  
  // the end cones
  ref<Cone> cone(NewObj Cone(4*d,2*d));
  osg::Node* coneNode = cone->createOSGVisual();
  coneNode->setStateSet(white);
  
  xtrans->addChild(coneNode);
  ytrans->addChild(coneNode);
  ztrans->addChild(coneNode);

  return g;
}
Esempio n. 9
0
 void SlitPotentialTest::MethodGetPotentialWorks() {
     SlitPotential p(Vec2(60.0, 0.0), Vec2(60.0, 60.0), 2);
     QCOMPARE(p.getPotential(60.0, 10.0), HAS_POTENTIAL);
     QCOMPARE(p.getPotential(60.0, 20.0), NO_POTENTIAL);
     QCOMPARE(p.getPotential(50.0, 10.0), NO_POTENTIAL);
 }
Esempio n. 10
0
 void SlitPotentialTest::MethodAddSlitWorks() {
     SlitPotential p(Vec2(0.0, 0.0), Vec2(5.0, 5.0));
     p.addSlit(0.5);
     QCOMPARE(p.getSlitLocation(0), Vec2(2.5, 2.5));
 }
Esempio n. 11
0
 void SlitPotentialTest::PreferredConstructorWorks() {
     SlitPotential p(Vec2(0.0, 0.0), Vec2(6.0, 6.0), 2);
     QCOMPARE(p.getSlitLocation(0), Vec2(2.0, 2.0));
     QCOMPARE(p.getSlitLocation(1), Vec2(4.0, 4.0));
 }
Esempio n. 12
0
int main( int argc, char *argv[] )
{
	// parse command line options
	parsecommandline( argc, argv );


	// OSG init
	osg::osgLog().setLogLevel(osg::LOG_WARNING);
	osg::osgInit(argc, argv);

	// disable display lists
	osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
	osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
    if ( pGeoProto != osg::NullFC )
        pGeoProto->setDlistCache(false);

	// create the graph
	osg::NodePtr node;

	// root
	root = osg::Node::create();
	beginEditCP(root);
	root->setCore( osg::Group::create() );

	// beacon for camera and light
	osg::NodePtr beacon;
	beacon = osg::Node::create();
	beginEditCP(beacon);
	beacon->setCore( osg::Group::create() );
	endEditCP(beacon);

	// light
	light_node = osg::Node::create();
	osg::DirectionalLightPtr light = osg::DirectionalLight::create();
	beginEditCP( light_node );
	light_node->setCore( light );
	endEditCP( light_node );
	root->addChild( light_node );
	beginEditCP(light);
	light->setAmbient( .3, .3, .3, 1 );
	light->setDiffuse( 1, 1, 1, 1 );
	light->setDirection(0,0,1);
	light->setBeacon( beacon );
	endEditCP(light);

	// transformation, parent of beacon
	node = osg::Node::create();
	cam_trans = osg::Transform::create();
	beginEditCP(node);
	node->setCore( cam_trans );
	node->addChild( beacon );
	endEditCP(node);
	root->addChild( node );

	// finish scene graph
	endEditCP(root);

	// Camera
	osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
	cam->setBeacon( beacon );
	cam->setFov( 50 );
	cam->setNear( 0.1 );
	cam->setFar( 10000 );

	// Background
	osg::SolidBackgroundPtr background = osg::SolidBackground::create();

	// Viewport
	osg::ViewportPtr vp = osg::Viewport::create();
	vp->setCamera( cam );
	vp->setBackground( background );
	vp->setRoot( root );
	vp->setSize( 0,0, 1,1 );

	if ( with_window )
	{
		// GLUT init
		glutInitWindowSize( 400, 400 );		// before glutInit so user can
		glutInitWindowPosition( 100, 100 );	// override with comannd line args
		glutInit(&argc, argv);
		glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
		int winid = glutCreateWindow("Polygon Intersection Check Test");
		glutKeyboardFunc(key);
		glutVisibilityFunc(vis);
		glutReshapeFunc(reshape);
		glutDisplayFunc(display);
		glutMouseFunc(mouse);
		glutMotionFunc(motion);

		glutIdleFunc(display);

		glEnable( GL_DEPTH_TEST );
		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );

		// Window
		osg::GLUTWindowPtr gwin;
		GLint glvp[4];
		glGetIntegerv( GL_VIEWPORT, glvp );
		gwin = osg::GLUTWindow::create();
		gwin->setId(winid);
		gwin->setSize( glvp[2], glvp[3] );
		win = gwin;
		win->addPort( vp );

		// Action
		render_action = osg::DrawAction::create();
		// trackball
		Vec3f min(-1,-1,-1), max(1,1,1);
		// root->updateVolume();
		// const osg::BoxVolume &vol = dynamic_cast<const osg::BoxVolume &>(root->getVolume());
		// // in the long term, the abstract volume will be able to provide min/max
		// vol.getBounds( min, max );
		trackball.setMode( osg::Trackball::OSGObject );
		float d = max[2] + (max[2]-min[2])*1.5;
		trackball.setStartPosition( 0, 0, d, true );
		trackball.setSum( true );
		trackball.setTranslationMode( osg::Trackball::OSGFree );

		// run...
		glutMainLoop();
	}
	else
	{
		// run in batch mode
		int phase = 0;
		do
			testcase( &phase );
		while ( phase > 0 );
	}

	return 0;
}
Esempio n. 13
0
void testcase( int *phase )
{
	static testObj poly1( 3 );  // triangle
	static testObj poly2( 3 );  // triangle
	static testObj poly3( 4 );  // quadrangle
	static testObj poly4( -4 ); // quadstrip

	osg::MFPnt3f& p1 = * poly1.p;
	osg::MFPnt3f& p2 = * poly2.p;
	osg::MFPnt3f& p3 = * poly3.p;
	osg::MFPnt3f& p4 = * poly4.p;

	int result_wanted;
	bool result;
	static int n_rand_trian = 0;

	// We do a default selection for every test frame. Only for the cases
	// where poly3 and/or poly4 is used, a special selection is necessary!
	poly1.setActive( light_node, false );
	poly2.setActive( light_node, false );
	poly3.setActive( light_node, false );
	poly4.setActive( light_node, false );

	static testObjP obj1 = &poly1;
	testObjP obj2 = &poly2;

	printf("phase %d\n", *phase );
 	switch ( *phase )
	{
		// selection and deselection of nodes is necessary b/c of the
		// possibility to jump into each phase by pressing keys 0..9
	    	
    
        case 0:
			// 2 triangles touching in one vertex
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0;  p1[0][2] = 0;
			p1[1][0] = 1;  p1[1][1] = 0;  p1[1][2] = 0;
			p1[2][0] = 0;  p1[2][1] = 1;  p1[2][2] = 0;
			endEditCP(poly1.pnts);

			beginEditCP(poly2.pnts);
			p2[0][0] =  0;  p2[0][1] =  0;  p2[0][2] = 0;
			p2[1][0] = -1;  p2[1][1] =  0;  p2[1][2] = 0;
			p2[2][0] =  0;  p2[2][1] = -1;  p2[2][2] = 0;
			endEditCP(poly2.pnts);

			result_wanted = 1;
			(*phase) ++ ;
			break;

		case 1:
			// 2 triangles touching edge on vertex
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0;  p1[0][2] = 0;
			p1[1][0] = 1;  p1[1][1] = 0;  p1[1][2] = 0;
			p1[2][0] = 0;  p1[2][1] = 1;  p1[2][2] = 0;
			endEditCP(poly1.pnts);

			beginEditCP(poly2.pnts);
			p2[0][0] = -1.0;  p2[0][1] =  1.0;  p2[0][2] = 0;
			p2[1][0] = -1.0;  p2[1][1] = -1.0;  p2[1][2] = 0;
			p2[2][0] =  1.0;  p2[2][1] = -1.0;  p2[2][2] = 0;
			endEditCP(poly2.pnts);

			(*phase) ++ ;
			result_wanted = 1;
			break;

		case 2:
			// 2 parallel triangles not quite touching
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0.0;  p1[0][2] = 0.0;
			p1[1][0] = 1;  p1[1][1] = 0.1;  p1[1][2] = 0.2;
			p1[2][0] = 0;  p1[2][1] = 1.0;  p1[2][2] = 0.3;
			endEditCP(poly1.pnts);

			beginEditCP(poly2.pnts);
			for ( int i = 0; i < 3; i ++ )
			{
				p2[i][0] = p1[i][0];
				p2[i][1] = p1[i][1];
				p2[i][2] = p1[i][2] + 1E-4;
			}
			endEditCP(poly2.pnts);

			(*phase) ++ ;
			result_wanted = 0;
			break;

		case 3:
			// 2 triangles touching plane on vertex
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0;  p1[0][2] = 0;
			p1[1][0] = 1;  p1[1][1] = 0;  p1[1][2] = 0;
			p1[2][0] = 0;  p1[2][1] = 1;  p1[2][2] = 0;
			endEditCP(poly1.pnts);

			beginEditCP(poly2.pnts);
			p2[0][0] = -1;  p2[0][1] =  1;  p2[0][2] =  1;
			p2[1][0] =  0;  p2[1][1] =  0;  p2[1][2] = -1;
			p2[2][0] =  1;  p2[2][1] = -1;  p2[2][2] =  1;
			endEditCP(poly2.pnts);

			(*phase) ++ ;
			result_wanted = 1;
			break;

		case 4:
			// 2 triangles touching plane on edge
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0;  p1[0][2] = 0;
			p1[1][0] = 1;  p1[1][1] = 0;  p1[1][2] = 0;
			p1[2][0] = 0;  p1[2][1] = 1;  p1[2][2] = 0;
			endEditCP(poly1.pnts);

			beginEditCP(poly2.pnts);
			p2[0][0] =  0;  p2[0][1] =  0;  p2[0][2] =  2;
			p2[1][0] =  0;  p2[1][1] = -1;  p2[1][2] = -1;
			p2[2][0] =  0;  p2[2][1] =  2;  p2[2][2] = -1;
			endEditCP(poly2.pnts);

			(*phase) ++ ;
			result_wanted = 1;
			break;

		case 5:
			// triangle and quadrangle touching
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0;  p1[0][2] = 0;
			p1[1][0] = 1;  p1[1][1] = 0;  p1[1][2] = 0;
			p1[2][0] = 0;  p1[2][1] = 1;  p1[2][2] = 0;
			endEditCP(poly1.pnts);
			
			obj2 = &poly3;

			beginEditCP(poly3.pnts);
			p3[0][0] =  0;  p3[0][1] =  1;  p3[0][2] =  1;
			p3[1][0] =  0;  p3[1][1] =  1;  p3[1][2] = -1;
			p3[2][0] =  0;  p3[2][1] = -1;  p3[2][2] = -1;
			p3[3][0] =  0;  p3[3][1] = -1;  p3[3][2] =  1;
			endEditCP(poly3.pnts);

			obj2 = &poly3; // select poly3 !!!

			(*phase) ++ ;
			result_wanted = 1;
			break;

		case 6:
			// triangle and quadstrip touching
			beginEditCP(poly1.pnts);
			p1[0][0] = 0;  p1[0][1] = 0;  p1[0][2] = 0;
			p1[1][0] = 1;  p1[1][1] = 0;  p1[1][2] = 0;
			p1[2][0] = 0;  p1[2][1] = 1;  p1[2][2] = 0;
			endEditCP(poly1.pnts);

			beginEditCP(poly4.pnts);
			p4[0][0] =  0;  p4[0][1] =  1;  p4[0][2] =  1;
			p4[1][0] =  0;  p4[1][1] =  1;  p4[1][2] = -1;
			p4[2][0] =  0;  p4[2][1] = -1;  p4[2][2] =  1;
			p4[3][0] =  0;  p4[3][1] = -1;  p4[3][2] = -1;
			endEditCP(poly4.pnts);

			obj2 = &poly4; // select poly4 !!!

			(*phase) ++ ;
			result_wanted = 1;
			break;
                    
        case 7 :
            
            //poly3.setActive( light_node, false );//de-select poly3

            beginEditCP(poly1.pnts);
            p1[0][0] = -0.176454; p1[0][1] = 0.071328; p1[0][2] = 0.213297;
            p1[1][0] = -0.163126; p1[2][1] = 0.060675; p1[1][2] = 0.197186;
            p1[2][0] = -0.201797; p1[1][1] = 0.071328; p1[2][2] = 0.189499;
            endEditCP(poly1.pnts);

            beginEditCP(poly2.pnts);
            p2[0][0] = -0.202112; p2[0][1] = 0.080522; p2[0][2] = 0.183896;
            p2[1][0] = -0.178983; p2[1][1] = 0.083684; p2[1][2] = 0.212995;
            p2[2][0] = -0.165755; p2[2][1] = 0.072958; p2[2][2] = 0.191836;
            endEditCP(poly2.pnts);
            
            (*phase) ++ ;
	        result_wanted = 0;
	        break;

        case 8:
            beginEditCP(poly1.pnts);
            p1[0][0] = -0.163126; p1[0][1] = 0.060675; p1[0][2] = 0.197186;
            p1[1][0] = -0.186555; p1[1][1] = 0.060675; p1[1][2] = 0.175186;
            p1[2][0] = -0.201797; p1[2][1] = 0.071328; p1[2][2] = 0.189499;
            endEditCP(poly1.pnts);

            beginEditCP(poly2.pnts);
            p2[0][0] = -0.202112; p2[0][1] = 0.080522; p2[0][2] = 0.183896;
            p2[1][0] = -0.178983; p2[1][1] = 0.083684; p2[1][2] = 0.212995;
            p2[2][0] = -0.165755; p2[2][1] = 0.072958; p2[2][2] = 0.191836;
            endEditCP(poly2.pnts);

            (*phase) ++ ;
	        result_wanted = 0;
	        break;

        case 9:
            beginEditCP(poly1.pnts);
            p1[0][0] = -0.176454; p1[0][1] = 0.071328; p1[0][2] = 0.213297;
            p1[1][0] = -0.201797; p1[1][1] = 0.071328; p1[1][2] = 0.189499;
            p1[2][0] = -0.218691; p1[2][1] = 0.075000; p1[2][2] = 0.205365;
            endEditCP(poly1.pnts);

            beginEditCP(poly2.pnts);
            p2[0][0] = -0.202112; p2[0][1] = 0.080522; p2[0][2] = 0.183896;
            p2[1][0] = -0.178983; p2[1][1] = 0.083684; p2[1][2] = 0.212995;
            p2[2][0] = -0.165755; p2[2][1] = 0.072958; p2[2][2] = 0.191836;
            endEditCP(poly2.pnts);

            (*phase) ++ ;
	        result_wanted = 0;
	        break;

        case 10:
            beginEditCP(poly1.pnts);
            p1[0][0] = -0.018837; p1[0][1] = 0.075000; p1[0][2] = 0.299408;
            p1[1][0] = -0.056214; p1[1][1] = 0.075000; p1[1][2] = 0.294687;
            p1[2][0] = -0.060557; p1[2][1] = 0.071328; p1[2][2] = 0.317451;
            endEditCP(poly1.pnts);

            p2[0][0] = -0.049907; p2[0][1] = 0.086203; p2[0][2] = 0.296841;
            p2[1][0] = -0.057335; p2[1][1] = 0.080902; p2[1][2] = 0.326649;
            p2[2][0] = -0.043106; p2[2][1] = 0.084220; p2[2][2] = 0.338304;
            endEditCP(poly2.pnts);

            (*phase) ++ ;
	        result_wanted = 0;
	        break;

        case 11:
			// 2 out of 1000 random triangles
			beginEditCP(poly1.pnts);
			for ( unsigned int i = 0; i < 3; i ++ )
				for ( unsigned int j = 0; j < 3; j ++ )
					p1[i][j] = col::pseudo_randomf();
					// should produce the same sequence every time
			endEditCP(poly1.pnts);

			beginEditCP(poly2.pnts);
			for ( unsigned int i = 0; i < 3; i ++ )
				for ( unsigned int j = 0; j < 3; j ++ )
					p2[i][j] = col::pseudo_randomf();
			endEditCP(poly2.pnts);

			n_rand_trian ++ ;
			if ( n_rand_trian >= Num_rand_triangles )
			{
				n_rand_trian = 0;					// else repeat this phase
				(*phase) ++ ;
			}

			result_wanted = -1;							// = don't know
			break;

		default:
			// last phase has been reached, signal to caller
			*phase = 0;
	}

	// activate selected objects for rendering (don't do this before the switch
	// statement - there are cases, where obj1 or obj2 is changed!)
	obj1->setActive( light_node, true );
	obj2->setActive( light_node, true );

	try
	{
		// check intersection of the 2 triangles
		result = col::intersectPolygons( &((*obj1->p)[0]), obj1->_nPnts,
										 &((*obj2->p)[0]), obj2->_nPnts );
	}
	catch ( col::XCollision /*&x*/ )
	{
		fputs("intersect: exception XCollision!\n", stderr );
	}

	if ( *phase > 0 )  // skip default: case
	{
		if ( result_wanted == -1 )
		{
			printf("Polygons %s\n", result ? "intersect" : "don't intersect" );
		}
		else
		{
			printf("Polygons %s %s\n",
				   result ? "intersect" : "don't intersect",
				   ( result != result_wanted ) ? "ERROR!" : " -> OK" );
		}
	}
}
Esempio n. 14
0
testObj::testObj( int nPnts )
	: _nPnts(nPnts),
	  _isActive(false)
{
								node 	= osg::Node::create();
	osg::GeometryPtr			geom 	= osg::Geometry::create();
								pnts 	= osg::GeoPositions3f::create();
	osg::GeoIndicesUI32Ptr 		index 	= osg::GeoIndicesUI32::create();
	osg::GeoPLengthsUI32Ptr 	lengths = osg::GeoPLengthsUI32::create();
	osg::GeoPTypesUI8Ptr 		type 	= osg::GeoPTypesUI8::create();

	// special for quadstrips:
	if ( nPnts == -4 )
		nPnts = 4;
	// CAUTION: don't use _nPnts for the next initialization steps!!!

	// node
	beginEditCP( node );
	node->setCore( geom );
	endEditCP( node );

	// geometry
	p = pnts->getFieldPtr();
	geom->setPositions( pnts );
	beginEditCP( pnts );
	for ( int i = 0; i < nPnts; i ++ )
		pnts->addValue( Pnt3f( -1, -1, -1) );
	endEditCP( pnts );

	// indexes
	geom->setIndices( index );
	beginEditCP( index );
	for ( int i = 0; i < nPnts; i ++ )
		index->addValue( i );
	endEditCP( index );

	// lengths
	geom->setLengths( lengths );
	beginEditCP( lengths );
	lengths->addValue( nPnts );
	endEditCP( lengths );

    
	// set material
	osg::SimpleMaterialPtr mat = osg::SimpleMaterial::create();
	mat->setDiffuse( osg::Color3f( 1,.7,1 ) );
	mat->setAmbient( osg::Color3f( 0.2,0.2,0.2 ) );
	mat->setSpecular( osg::Color3f( 0.5,0.5,0.5 ) );
	mat->setShininess( 20 );
	mat->setEmission ( osg::Color3f( col::pseudo_randomf(), 0, 0 ) );

	(geom)->setMaterial( mat );

	// types
	geom->setTypes( type );
	beginEditCP( type );
	if ( _nPnts == -4 )
		type->addValue( GL_QUAD_STRIP );
	else
		type->addValue( GL_POLYGON );
	endEditCP( type );
}
Esempio n. 15
0
int main( int argc, char *argv[] )
{

	// OSG init
	osg::osgLog().setLogLevel(osg::LOG_WARNING);
	osg::osgInit(argc, argv);

	// parse command line options
	parsecommandline( argc, argv );

	// disable display lists
	osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype();
	osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto);
    if ( pGeoProto != osg::NullFC )
        pGeoProto->setDlistCache(false);

	// create the graph
	osg::NodePtr node;

	// root
	root = osg::Node::create();
	beginEditCP(root);
	root->setCore( osg::Group::create() );

	// beacon for camera and light
	osg::NodePtr beacon;
	beacon = osg::Node::create();
	beginEditCP(beacon);
	beacon->setCore( osg::Group::create() );
	endEditCP(beacon);

	// light
	light_node = osg::Node::create();
	osg::DirectionalLightPtr light = osg::DirectionalLight::create();
	beginEditCP( light_node );
	light_node->setCore( light );
	root->addChild( light_node );
	beginEditCP(light);
	light->setAmbient( .3, .3, .3, 1 );
	light->setDiffuse( 1, 1, 1, 1 );
	light->setDirection(0,0,1);
	light->setBeacon( beacon );
	endEditCP(light);

	// transformation, parent of beacon
	node = osg::Node::create();
	cam_trans = osg::Transform::create();
	beginEditCP(node);
	node->setCore( cam_trans );
	node->addChild( beacon );
	endEditCP(node);
	root->addChild( node );

	// Camera
	osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create();
	cam->setBeacon( beacon );
	cam->setFov( 50 );
	cam->setNear( 0.1 );
	cam->setFar( 10000 );

	// Background
	osg::SolidBackgroundPtr background = osg::SolidBackground::create();
	if ( White_background )
	{
		beginEditCP( background );
		background->setColor(osg::Color3f(1,1,1));
		endEditCP( background );
	}

	// Viewport
	osg::ViewportPtr vp = osg::Viewport::create();
	vp->setCamera( cam );
	vp->setBackground( background );
	vp->setRoot( root );
	vp->setSize( 0,0, 1,1 );

	if ( With_window )
	{
		// GLUT init
		glutInitWindowSize( 400, 400 );		// before glutInit so user can
		glutInitWindowPosition( 100, 100 );	// override with comannd line args
		glutInit(&argc, argv);
		glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
		int winid = glutCreateWindow("Collision Benchmark");
		glutKeyboardFunc(key);
		glutVisibilityFunc(vis);
		glutReshapeFunc(reshape);
		glutDisplayFunc(display);
		glutMouseFunc(mouse);
		glutMotionFunc(motion);

		glutIdleFunc(display);

		glEnable( GL_DEPTH_TEST );
		glEnable( GL_LIGHTING );
		glEnable( GL_LIGHT0 );
		glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

		// Window
		osg::GLUTWindowPtr gwin;
		GLint glvp[4];
		glGetIntegerv( GL_VIEWPORT, glvp );
		gwin = osg::GLUTWindow::create();
		gwin->setId(winid);
		gwin->setSize( glvp[2], glvp[3] );
		win = gwin;
		win->addPort( vp );

		// Action
		render_action = osg::DrawAction::create();

		// trackball
			Vec3f min(-2.5,-2.5,-2.5), max(2.5,2.5,2.5);
		trackball.setMode( osg::Trackball::OSGObject );
			float d = max[2] + (max[2]-min[2]);
		trackball.setStartPosition( 0, 0, d, true );
		trackball.setSum( true );
		trackball.setTranslationMode( osg::Trackball::OSGFree );
	}

	// create moving objects
	if ( geom_type != OBJ_FILE )
		createGeom( geom_type, Complexity, &fixed_node, &fixed_geom );
	// else: has been loaded from file
	light_node->addChild( fixed_node );

	if ( geom_type != OBJ_FILE )
		createGeom( geom_type, Complexity, &moving_node, &moving_geom );


	//#define DOPTREE_NUM_ORI 16

	double pi = 3.141592653589793f;
	vector<Vec3f> translates;
	vector<Vec3f> rotation_xyzs;
	vector<float> rotates;
	//string config("");
	if(configFile.length() == 0)
	{
		printf("config file is null, use -r configFileName\n");
		return 0;
	}

	ifstream fin(configFile.data());
    string line;
    int i = 0;
    int angle;
    float x,y,z;
    while(std::getline(fin, line))
    {
        stringstream ss;
        ss << line;
        if(i & 0x1) // tranls
        {
            ss >> x >> y >> z;
            translates.push_back(Vec3f(x,y,z));
            
        }else //angle rot
        {
Esempio n. 16
0
void createGeom( GeometryTypeE type, unsigned int complexity,
				 osg::NodePtr *node, osg::GeometryPtr *geom )
{
	char name[1000];
	static unsigned int ngeom = 0;
	static float red = 1.0, green = 0.2, blue = 1.0;

	switch ( type )
	{
		case OBJ_PLANES:
		{
			*node = osg::makePlane( 1, 1, complexity, complexity );
			// move one point, so that convex hull can be computed
			osg::MFPnt3f *points = col::getPoints( *node );
			beginEditCP( *node );
			(*points)[0][2] += 3;
			(*points)[points->size()-1][2] -= 3;
			endEditCP( *node );
			sprintf( name, "pl_%u_%u", complexity, ngeom );
			break;
		}

		case OBJ_SPHERES:
			complexity = static_cast<unsigned int>( logf( complexity*complexity ) / 1.7 );
			*node = osg::makeSphere( complexity, 0.5 );
			sprintf( name, "sh_%u_%u", complexity, ngeom );
			break;

		case OBJ_TORUS:
			*node = osg::makeTorus( 0.35, 0.5, complexity+1, complexity+1 );
			sprintf( name, "to_%u_%u", complexity, ngeom );
			break;

		default:
			fputs("createGeom: BUG: type is out of range!\n",stderr);
			exit(-1);
	}
	ngeom ++ ;

	if ( *node == osg::NullFC )
	{
		fprintf(stderr,"interactive: createGeom failed!\n");
		exit(-1);					// makes no sense to continue
	}

	*geom = col::getGeom( *node );

	// set material
	osg::SimpleMaterialPtr mat = osg::SimpleMaterial::create();
    mat->setDiffuse( osg::Color3f( red, green, blue ) );
    mat->setAmbient( osg::Color3f( 0.5,0.5,0.5 ) );
    mat->setSpecular( osg::Color3f( 0.5,0.5,0.5 ) );
    mat->setShininess( 20 );
	// change color for next createGeom call (doesn't work too often)
	red -= 0.2;
	green += 0.2;
	blue -= 0.2;

	(*geom)->setMaterial( mat );


	// set name
	osg::NamePtr name_attachm = osg::Name::create();
	name_attachm->getFieldPtr()->getValue().assign( name );
	(*node)->addAttachment( name_attachm );
}